[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), |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 228 | client_maker_( |
| 229 | version_, |
| 230 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 231 | &clock_, |
| 232 | kDefaultServerHostName, |
| 233 | quic::Perspective::IS_CLIENT, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 234 | client_headers_include_h2_stream_dependency), |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 235 | server_maker_( |
| 236 | version_, |
| 237 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 238 | &clock_, |
| 239 | kDefaultServerHostName, |
| 240 | quic::Perspective::IS_SERVER, |
| 241 | false), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 242 | cert_verifier_(std::make_unique<MockCertVerifier>()), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 243 | cert_transparency_verifier_(std::make_unique<DoNothingCTVerifier>()), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 244 | scoped_mock_network_change_notifier_(nullptr), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 245 | factory_(nullptr), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 246 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 247 | url_(kDefaultUrl), |
| 248 | url2_(kServer2Url), |
| 249 | url3_(kServer3Url), |
| 250 | url4_(kServer4Url), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 251 | privacy_mode_(PRIVACY_MODE_DISABLED), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 252 | failed_on_default_network_callback_(base::BindRepeating( |
| 253 | &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, |
| 254 | base::Unretained(this))), |
| 255 | failed_on_default_network_(false), |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 256 | store_server_configs_in_properties_(false) { |
| 257 | test_params_.quic_headers_include_h2_stream_dependency = |
| 258 | client_headers_include_h2_stream_dependency; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 259 | clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 260 | } |
| 261 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 262 | void Initialize() { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 263 | DCHECK(!factory_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 264 | factory_.reset(new QuicStreamFactory( |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 265 | net_log_.net_log(), host_resolver_.get(), ssl_config_service_.get(), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 266 | socket_factory_.get(), &http_server_properties_, cert_verifier_.get(), |
Nick Harper | ecf319d | 2018-10-16 07:58:54 | [diff] [blame] | 267 | &ct_policy_enforcer_, &transport_security_state_, |
| 268 | cert_transparency_verifier_.get(), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 269 | /*SocketPerformanceWatcherFactory*/ nullptr, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 270 | &crypto_client_stream_factory_, &random_generator_, &clock_, |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 271 | test_params_.quic_max_packet_length, test_params_.quic_user_agent_id, |
| 272 | store_server_configs_in_properties_, |
| 273 | test_params_.quic_close_sessions_on_ip_change, |
| 274 | test_params_.quic_goaway_sessions_on_ip_change, |
| 275 | test_params_.mark_quic_broken_when_network_blackholes, |
| 276 | test_params_.quic_idle_connection_timeout_seconds, |
| 277 | test_params_.quic_reduced_ping_timeout_seconds, |
| 278 | test_params_.quic_max_time_before_crypto_handshake_seconds, |
| 279 | test_params_.quic_max_idle_time_before_crypto_handshake_seconds, |
| 280 | test_params_.quic_migrate_sessions_on_network_change_v2, |
| 281 | test_params_.quic_migrate_sessions_early_v2, |
| 282 | test_params_.quic_retry_on_alternate_network_before_handshake, |
| 283 | test_params_.quic_max_time_on_non_default_network, |
| 284 | test_params_.quic_max_migrations_to_non_default_network_on_write_error, |
| 285 | test_params_ |
| 286 | .quic_max_migrations_to_non_default_network_on_path_degrading, |
| 287 | test_params_.quic_allow_server_migration, |
| 288 | test_params_.quic_race_stale_dns_on_connection, |
| 289 | test_params_.quic_go_away_on_path_degrading, |
| 290 | test_params_.quic_race_cert_verification, |
| 291 | test_params_.quic_estimate_initial_rtt, |
| 292 | test_params_.quic_headers_include_h2_stream_dependency, |
| 293 | test_params_.quic_connection_options, |
| 294 | test_params_.quic_client_connection_options, |
| 295 | test_params_.quic_enable_socket_recv_optimization)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 296 | } |
| 297 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 298 | void InitializeConnectionMigrationV2Test( |
| 299 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 300 | scoped_mock_network_change_notifier_.reset( |
| 301 | new ScopedMockNetworkChangeNotifier()); |
| 302 | MockNetworkChangeNotifier* mock_ncn = |
| 303 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 304 | mock_ncn->ForceNetworkHandlesSupported(); |
| 305 | mock_ncn->SetConnectedNetworksList(connected_networks); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 306 | test_params_.quic_migrate_sessions_on_network_change_v2 = true; |
| 307 | test_params_.quic_migrate_sessions_early_v2 = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 308 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 309 | Initialize(); |
| 310 | } |
| 311 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 312 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 313 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 314 | request->ReleaseSessionHandle(); |
| 315 | if (!session || !session->IsConnected()) |
| 316 | return nullptr; |
| 317 | |
| 318 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 319 | } |
| 320 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 321 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 322 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 323 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 324 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 325 | } |
| 326 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 327 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 328 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 329 | false); |
| 330 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 331 | server_id); |
| 332 | } |
| 333 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 334 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 335 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 336 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 337 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 338 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 339 | } |
| 340 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 341 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 342 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 343 | server_id); |
| 344 | } |
| 345 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 346 | // Get the pending, not activated session, if there is only one session alive. |
| 347 | QuicChromiumClientSession* GetPendingSession( |
| 348 | const HostPortPair& host_port_pair) { |
| 349 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 350 | false); |
| 351 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 352 | host_port_pair); |
| 353 | } |
| 354 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 355 | QuicChromiumClientSession* GetActiveSession( |
| 356 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 357 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 358 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 359 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 362 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 363 | return GetSourcePortForNewSessionInner(destination, false); |
| 364 | } |
| 365 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 366 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 367 | return GetSourcePortForNewSessionInner(destination, true); |
| 368 | } |
| 369 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 370 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 371 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 372 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 373 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 374 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 375 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 376 | MockQuicData socket_data; |
| 377 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 378 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 379 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 380 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 381 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 382 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 383 | EXPECT_EQ( |
| 384 | ERR_IO_PENDING, |
| 385 | request.Request( |
| 386 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 387 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 388 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 389 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 390 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 391 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 392 | EXPECT_TRUE(stream.get()); |
| 393 | stream.reset(); |
| 394 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 395 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 396 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 397 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 398 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 402 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 403 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 404 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 405 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 406 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 407 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 408 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 409 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 410 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 411 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 412 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 413 | } |
| 414 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 415 | std::unique_ptr<quic::QuicEncryptedPacket> |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 416 | ConstructClientConnectionClosePacket(uint64_t num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 417 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 418 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 419 | } |
| 420 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 421 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 422 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 423 | quic::QuicRstStreamErrorCode error_code) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 424 | quic::QuicStreamId stream_id = |
| 425 | GetNthClientInitiatedBidirectionalStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 426 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 427 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 428 | } |
| 429 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 430 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 431 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 432 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 433 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 434 | EXPECT_TRUE(test_cert.get()); |
| 435 | ProofVerifyDetailsChromium verify_details; |
| 436 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 437 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 438 | return verify_details; |
| 439 | } |
| 440 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 441 | void NotifyIPAddressChanged() { |
| 442 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 443 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 444 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 445 | } |
| 446 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 447 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 448 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 449 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 450 | bool should_include_version, |
| 451 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 452 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 453 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 454 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 455 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 456 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 457 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 458 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 459 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 460 | } |
| 461 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 462 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 463 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 464 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 465 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 466 | bool should_include_version, |
| 467 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 468 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 469 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 470 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 471 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 472 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 473 | size_t spdy_headers_frame_len; |
| 474 | return client_maker_.MakeRequestHeadersPacket( |
| 475 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 476 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 477 | } |
| 478 | |
| 479 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 480 | uint64_t packet_number, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 481 | quic::QuicStreamId stream_id, |
| 482 | bool should_include_version, |
| 483 | bool fin, |
| 484 | quic::QuicStreamOffset* offset) { |
| 485 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 486 | /*parent_stream_id=*/0, |
| 487 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 488 | } |
| 489 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 490 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 491 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 492 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 493 | bool should_include_version, |
| 494 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 495 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 496 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 497 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 498 | packet_number, stream_id, should_include_version, fin, |
| 499 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 500 | } |
| 501 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 502 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 503 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 504 | } |
| 505 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 506 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 507 | uint64_t packet_number, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 508 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 509 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 510 | } |
| 511 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 512 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 513 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 514 | IPEndPoint expected_address) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 515 | test_params_.quic_allow_server_migration = true; |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 516 | Initialize(); |
| 517 | |
| 518 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 519 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 520 | crypto_client_stream_factory_.SetConfig(config); |
| 521 | |
| 522 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 523 | MockQuicData socket_data1; |
| 524 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 525 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 526 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 527 | // Set up second socket data provider that is used after |
| 528 | // migration. |
| 529 | MockQuicData socket_data2; |
| 530 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 531 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 532 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 533 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 534 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 535 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 536 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 537 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 538 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 539 | |
| 540 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 541 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 542 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 543 | request.Request( |
| 544 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 545 | SocketTag(), |
| 546 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 547 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 548 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 549 | |
| 550 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 551 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 552 | base::RunLoop().RunUntilIdle(); |
| 553 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 554 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 555 | EXPECT_TRUE(stream.get()); |
| 556 | |
| 557 | // Cause QUIC stream to be created. |
| 558 | HttpRequestInfo request_info; |
| 559 | request_info.method = "GET"; |
| 560 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 561 | request_info.traffic_annotation = |
| 562 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 563 | EXPECT_EQ(OK, |
| 564 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 565 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 566 | // Ensure that session is alive and active. |
| 567 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 568 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 569 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 570 | |
| 571 | IPEndPoint actual_address; |
| 572 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 573 | EXPECT_EQ(actual_address, expected_address); |
| 574 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 575 | << " " << actual_address.port(); |
| 576 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 577 | << " " << expected_address.port(); |
| 578 | |
| 579 | stream.reset(); |
| 580 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 581 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 582 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 583 | } |
| 584 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 585 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 586 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 587 | store_server_configs_in_properties_ = true; |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 588 | test_params_.quic_idle_connection_timeout_seconds = 500; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 589 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 590 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 591 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 592 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 593 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 594 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 595 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 596 | const quic::QuicConfig* config = |
| 597 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 598 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 599 | |
| 600 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 601 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 602 | const AlternativeService alternative_service1( |
| 603 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 604 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 605 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 606 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 607 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 608 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 609 | http_server_properties_.SetAlternativeServices( |
| 610 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 611 | |
| 612 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 613 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 614 | const AlternativeService alternative_service2( |
| 615 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 616 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 617 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 618 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 619 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 620 | |
| 621 | http_server_properties_.SetAlternativeServices( |
| 622 | server2, alternative_service_info_vector2); |
| 623 | // Verify that the properties of both QUIC servers are stored in the |
| 624 | // HTTP properties map. |
| 625 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 626 | |
| 627 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 628 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 629 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 630 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 631 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 632 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 633 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 634 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 635 | |
| 636 | // Update quic_server_info's server_config and persist it. |
| 637 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 638 | // Minimum SCFG that passes config validation checks. |
| 639 | const char scfg[] = {// SCFG |
| 640 | 0x53, 0x43, 0x46, 0x47, |
| 641 | // num entries |
| 642 | 0x01, 0x00, |
| 643 | // padding |
| 644 | 0x00, 0x00, |
| 645 | // EXPY |
| 646 | 0x45, 0x58, 0x50, 0x59, |
| 647 | // EXPY end offset |
| 648 | 0x08, 0x00, 0x00, 0x00, |
| 649 | // Value |
| 650 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 651 | |
| 652 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 653 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 654 | string source_address_token("test_source_address_token"); |
| 655 | string cert_sct("test_cert_sct"); |
| 656 | string chlo_hash("test_chlo_hash"); |
| 657 | string signature("test_signature"); |
| 658 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 659 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 660 | certs.push_back(test_cert); |
| 661 | state->server_config = server_config; |
| 662 | state->source_address_token = source_address_token; |
| 663 | state->cert_sct = cert_sct; |
| 664 | state->chlo_hash = chlo_hash; |
| 665 | state->server_config_sig = signature; |
| 666 | state->certs = certs; |
| 667 | |
| 668 | quic_server_info->Persist(); |
| 669 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 670 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 671 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 672 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 673 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 674 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 675 | // Update quic_server_info2's server_config and persist it. |
| 676 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 677 | |
| 678 | // Minimum SCFG that passes config validation checks. |
| 679 | const char scfg2[] = {// SCFG |
| 680 | 0x53, 0x43, 0x46, 0x47, |
| 681 | // num entries |
| 682 | 0x01, 0x00, |
| 683 | // padding |
| 684 | 0x00, 0x00, |
| 685 | // EXPY |
| 686 | 0x45, 0x58, 0x50, 0x59, |
| 687 | // EXPY end offset |
| 688 | 0x08, 0x00, 0x00, 0x00, |
| 689 | // Value |
| 690 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 691 | |
| 692 | // Create temporary strings becasue Persist() clears string data in |
| 693 | // |state2|. |
| 694 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 695 | string source_address_token2("test_source_address_token2"); |
| 696 | string cert_sct2("test_cert_sct2"); |
| 697 | string chlo_hash2("test_chlo_hash2"); |
| 698 | string signature2("test_signature2"); |
| 699 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 700 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 701 | certs2.push_back(test_cert2); |
| 702 | state2->server_config = server_config2; |
| 703 | state2->source_address_token = source_address_token2; |
| 704 | state2->cert_sct = cert_sct2; |
| 705 | state2->chlo_hash = chlo_hash2; |
| 706 | state2->server_config_sig = signature2; |
| 707 | state2->certs = certs2; |
| 708 | |
| 709 | quic_server_info2->Persist(); |
| 710 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 711 | // Verify the MRU order is maintained. |
| 712 | const QuicServerInfoMap& quic_server_info_map = |
| 713 | http_server_properties_.quic_server_info_map(); |
| 714 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 715 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 716 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 717 | ++quic_server_info_map_it; |
| 718 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 719 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 720 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 721 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 722 | |
| 723 | // Create a session and verify that the cached state is loaded. |
| 724 | MockQuicData socket_data; |
| 725 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 726 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 727 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 728 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 729 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 730 | request.Request( |
| 731 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 732 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 733 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 734 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 735 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 736 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 737 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 738 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 739 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 740 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 741 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 742 | crypto_config->LookupOrCreate(quic_server_id); |
| 743 | EXPECT_FALSE(cached->server_config().empty()); |
| 744 | EXPECT_TRUE(cached->GetServerConfig()); |
| 745 | EXPECT_EQ(server_config, cached->server_config()); |
| 746 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 747 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 748 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 749 | EXPECT_EQ(signature, cached->signature()); |
| 750 | ASSERT_EQ(1U, cached->certs().size()); |
| 751 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 752 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 753 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 754 | |
| 755 | // Create a session and verify that the cached state is loaded. |
| 756 | MockQuicData socket_data2; |
| 757 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 758 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 759 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 760 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 761 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 762 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 763 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 764 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 765 | request2.Request( |
| 766 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 767 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 768 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 769 | net_log_, &net_error_details_, |
| 770 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 771 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 772 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 773 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 774 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 775 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 776 | crypto_config->LookupOrCreate(quic_server_id2); |
| 777 | EXPECT_FALSE(cached2->server_config().empty()); |
| 778 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 779 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 780 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 781 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 782 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 783 | EXPECT_EQ(signature2, cached2->signature()); |
| 784 | ASSERT_EQ(1U, cached->certs().size()); |
| 785 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 786 | } |
| 787 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 788 | void RunTestLoopUntilIdle() { |
| 789 | while (!runner_->GetPostedTasks().empty()) |
| 790 | runner_->RunNextTask(); |
| 791 | } |
| 792 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 793 | quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { |
| 794 | return quic::test::GetNthClientInitiatedBidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 795 | } |
| 796 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 797 | quic::QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(int n) { |
| 798 | return quic::test::GetNthServerInitiatedUnidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 799 | } |
| 800 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 801 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 802 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 803 | // Helper methods for tests of connection migration on write error. |
| 804 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 805 | // Migratable stream triggers write error. |
| 806 | void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); |
| 807 | // Non-migratable stream triggers write error. |
| 808 | void TestMigrationOnWriteErrorMixedStreams2(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 809 | void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 810 | void TestMigrationOnWriteError(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 811 | void TestMigrationOnWriteErrorWithMultipleRequests(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 812 | void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 813 | void TestMigrationOnMultipleWriteErrors( |
| 814 | IoMode write_error_mode_on_old_network, |
| 815 | IoMode write_error_mode_on_new_network); |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 816 | void TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 817 | bool disconnected); |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 818 | void TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 819 | void TestMigrationOnNetworkDisconnected(bool async_write_before); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 820 | void TestMigrationOnNetworkMadeDefault(IoMode write_mode); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 821 | void TestMigrationOnPathDegrading(bool async_write_before); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 822 | void TestMigrateSessionWithDrainingStream( |
| 823 | IoMode write_mode_for_queued_packet); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 824 | void TestMigrationOnWriteErrorPauseBeforeConnected(IoMode write_error_mode); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 825 | void TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 826 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 827 | bool disconnect_before_connect); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 828 | void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 829 | void TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 830 | quic::QuicErrorCode error); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 831 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 832 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 833 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 834 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 835 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 836 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 837 | quic::test::MockRandom random_generator_; |
| 838 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 839 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 840 | const quic::QuicTransportVersion version_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 841 | QuicTestPacketMaker client_maker_; |
| 842 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 843 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 844 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 845 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 846 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 847 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 848 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 849 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 850 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 851 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 852 | GURL url_; |
| 853 | GURL url2_; |
| 854 | GURL url3_; |
| 855 | GURL url4_; |
| 856 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 857 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 858 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 859 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 860 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 861 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 862 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 863 | |
| 864 | // Variables to configure QuicStreamFactory. |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 865 | HttpNetworkSession::Params test_params_; |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 866 | bool store_server_configs_in_properties_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 867 | }; |
| 868 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 869 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 870 | public ::testing::TestWithParam<TestParams> { |
| 871 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 872 | QuicStreamFactoryTest() |
| 873 | : QuicStreamFactoryTestBase( |
| 874 | GetParam().version, |
| 875 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 876 | }; |
| 877 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 878 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 879 | QuicStreamFactoryTest, |
| 880 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 881 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 882 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 883 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 884 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 885 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 886 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 887 | MockQuicData socket_data; |
| 888 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 889 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 890 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 891 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 892 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 893 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 894 | request.Request( |
| 895 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 896 | SocketTag(), |
| 897 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 898 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 899 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 900 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 901 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 902 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 903 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 904 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 905 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 906 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 907 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 908 | DEFAULT_PRIORITY, SocketTag(), |
| 909 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 910 | &net_error_details_, |
| 911 | failed_on_default_network_callback_, |
| 912 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 913 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 914 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 915 | |
| 916 | EXPECT_TRUE(stream.get()); |
| 917 | |
| 918 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 919 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 920 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 921 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 922 | DEFAULT_PRIORITY, SocketTag(), |
| 923 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 924 | &net_error_details_, |
| 925 | failed_on_default_network_callback_, |
| 926 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 927 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 928 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 929 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 930 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 931 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 932 | } |
| 933 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 934 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 935 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 936 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 937 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 938 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 939 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 940 | MockQuicData socket_data; |
| 941 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 942 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 943 | |
| 944 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 945 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 946 | host_resolver_->set_synchronous_mode(true); |
| 947 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 948 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 949 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 950 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 951 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 952 | DEFAULT_PRIORITY, SocketTag(), |
| 953 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 954 | &net_error_details_, |
| 955 | failed_on_default_network_callback_, |
| 956 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 957 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 958 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 959 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 960 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 961 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 962 | } |
| 963 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 964 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 965 | Initialize(); |
| 966 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 967 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 968 | |
| 969 | MockQuicData socket_data; |
| 970 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 971 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 972 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [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(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 976 | request.Request( |
| 977 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 978 | SocketTag(), |
| 979 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 980 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 981 | |
| 982 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 983 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 984 | EXPECT_TRUE(stream.get()); |
| 985 | |
| 986 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 987 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 988 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 989 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 990 | } |
| 991 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 992 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 993 | Initialize(); |
| 994 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 995 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 996 | |
| 997 | MockQuicData socket_data; |
| 998 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 999 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1000 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1001 | |
| 1002 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1003 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1004 | request->Request( |
| 1005 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1006 | SocketTag(), |
| 1007 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1008 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1009 | request.reset(); |
| 1010 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1011 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1012 | // crash. crbug.com/768343. |
| 1013 | factory_.reset(); |
| 1014 | } |
| 1015 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1016 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1017 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1018 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1019 | host_resolver_->set_synchronous_mode(true); |
| 1020 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1021 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1022 | Initialize(); |
| 1023 | factory_->set_require_confirmation(true); |
| 1024 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1025 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1026 | |
| 1027 | MockQuicData socket_data; |
| 1028 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1029 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1030 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1031 | |
| 1032 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1033 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1034 | request.Request( |
| 1035 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1036 | SocketTag(), |
| 1037 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1038 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1039 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1040 | IPAddress last_address; |
| 1041 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1042 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1043 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1044 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1045 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1046 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1047 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1048 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1049 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1050 | EXPECT_TRUE(stream.get()); |
| 1051 | |
| 1052 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1053 | EXPECT_TRUE(session->require_confirmation()); |
| 1054 | } |
| 1055 | |
| 1056 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1057 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1058 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1059 | host_resolver_->set_synchronous_mode(true); |
| 1060 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1061 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1062 | Initialize(); |
| 1063 | factory_->set_require_confirmation(true); |
| 1064 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1065 | |
| 1066 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1067 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1068 | |
| 1069 | MockQuicData socket_data; |
| 1070 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1071 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1072 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1073 | |
| 1074 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1075 | EXPECT_THAT(request.Request( |
| 1076 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1077 | SocketTag(), |
| 1078 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1079 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1080 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1081 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1082 | IPAddress last_address; |
| 1083 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1084 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1085 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1086 | EXPECT_TRUE(stream.get()); |
| 1087 | |
| 1088 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1089 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1090 | |
| 1091 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1092 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1093 | |
| 1094 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1095 | } |
| 1096 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1097 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1098 | ServerNetworkStats stats; |
| 1099 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1100 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1101 | stats); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 1102 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1103 | |
| 1104 | Initialize(); |
| 1105 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1106 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1107 | |
| 1108 | MockQuicData socket_data; |
| 1109 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1110 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1111 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1112 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1113 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1114 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1115 | request.Request( |
| 1116 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1117 | SocketTag(), |
| 1118 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1119 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1120 | |
| 1121 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1122 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1123 | EXPECT_TRUE(stream.get()); |
| 1124 | |
| 1125 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1126 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1127 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1128 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1129 | } |
| 1130 | |
| 1131 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1132 | ScopedMockNetworkChangeNotifier notifier; |
| 1133 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1134 | NetworkChangeNotifier::CONNECTION_2G); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 1135 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1136 | |
| 1137 | Initialize(); |
| 1138 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1139 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1140 | |
| 1141 | MockQuicData socket_data; |
| 1142 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1143 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1144 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1145 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1146 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1147 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1148 | request.Request( |
| 1149 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1150 | SocketTag(), |
| 1151 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1152 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1153 | |
| 1154 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1155 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1156 | EXPECT_TRUE(stream.get()); |
| 1157 | |
| 1158 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1159 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1160 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1161 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1162 | } |
| 1163 | |
| 1164 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1165 | ScopedMockNetworkChangeNotifier notifier; |
| 1166 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1167 | NetworkChangeNotifier::CONNECTION_3G); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 1168 | test_params_.quic_estimate_initial_rtt = true; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1169 | |
| 1170 | Initialize(); |
| 1171 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1172 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1173 | |
| 1174 | MockQuicData socket_data; |
| 1175 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1176 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1177 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1178 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1179 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1180 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1181 | request.Request( |
| 1182 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1183 | SocketTag(), |
| 1184 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1185 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1186 | |
| 1187 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1188 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1189 | EXPECT_TRUE(stream.get()); |
| 1190 | |
| 1191 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1192 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1193 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1194 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1195 | } |
| 1196 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1197 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1198 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1199 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1200 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1201 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1202 | MockQuicData socket_data; |
| 1203 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1204 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1205 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1206 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1207 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1208 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1209 | request.Request( |
| 1210 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1211 | SocketTag(), |
| 1212 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1213 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1214 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1215 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1216 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1217 | EXPECT_TRUE(stream.get()); |
| 1218 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1219 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1220 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1221 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1222 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1223 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1224 | |
| 1225 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1226 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1227 | } |
| 1228 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1229 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1230 | Initialize(); |
| 1231 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1232 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1233 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1234 | MockQuicData socket_data; |
| 1235 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1236 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1237 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1238 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1239 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1240 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1241 | request.Request( |
| 1242 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1243 | SocketTag(), |
| 1244 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1245 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1246 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1247 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1248 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1249 | EXPECT_TRUE(stream.get()); |
| 1250 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1251 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1252 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1253 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1254 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1255 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1256 | NetErrorDetails details; |
| 1257 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1258 | session->PopulateNetErrorDetails(&details); |
| 1259 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1260 | details.quic_port_migration_detected = false; |
| 1261 | stream->PopulateNetErrorDetails(&details); |
| 1262 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1263 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1264 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1265 | |
| 1266 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1267 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1268 | } |
| 1269 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1270 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1271 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1272 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1273 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1274 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1275 | MockQuicData socket_data; |
| 1276 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1277 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1278 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1279 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1280 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1281 | host_resolver_->set_synchronous_mode(true); |
| 1282 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1283 | "192.168.0.1", ""); |
| 1284 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1285 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1286 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1287 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1288 | DEFAULT_PRIORITY, SocketTag(), |
| 1289 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1290 | &net_error_details_, |
| 1291 | failed_on_default_network_callback_, |
| 1292 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1293 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1294 | EXPECT_TRUE(stream.get()); |
| 1295 | |
| 1296 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1297 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1298 | EXPECT_EQ(OK, |
| 1299 | request2.Request( |
| 1300 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1301 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1302 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1303 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1304 | EXPECT_TRUE(stream2.get()); |
| 1305 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1306 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1307 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1308 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1309 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1310 | } |
| 1311 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1312 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1313 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1314 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1315 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1316 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1317 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1318 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1319 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1320 | |
| 1321 | VerifyServerMigration(config, alt_address); |
| 1322 | |
| 1323 | // Close server-migrated session. |
| 1324 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1325 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1326 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1327 | |
| 1328 | // Set up server IP, socket, proof, and config for new session. |
| 1329 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1330 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1331 | |
| 1332 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1333 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1334 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1335 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1336 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1337 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1338 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1339 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1340 | |
| 1341 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1342 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1343 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1344 | crypto_client_stream_factory_.SetConfig(config2); |
| 1345 | |
| 1346 | // Create new request to cause new session creation. |
| 1347 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1348 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1349 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1350 | request2.Request( |
| 1351 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1352 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1353 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1354 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1355 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1356 | EXPECT_TRUE(stream2.get()); |
| 1357 | |
| 1358 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1359 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1360 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1361 | } |
| 1362 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1363 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1364 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1365 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1366 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1367 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1368 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1369 | MockQuicData socket_data1; |
| 1370 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1371 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1372 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1373 | MockQuicData socket_data2; |
| 1374 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1375 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1376 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1377 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1378 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1379 | host_resolver_->set_synchronous_mode(true); |
| 1380 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1381 | "192.168.0.1", ""); |
| 1382 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1383 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1384 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1385 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1386 | DEFAULT_PRIORITY, SocketTag(), |
| 1387 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1388 | &net_error_details_, |
| 1389 | failed_on_default_network_callback_, |
| 1390 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1391 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1392 | EXPECT_TRUE(stream.get()); |
| 1393 | |
| 1394 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1395 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1396 | EXPECT_EQ(OK, |
| 1397 | request2.Request( |
| 1398 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1399 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1400 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1401 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1402 | EXPECT_TRUE(stream2.get()); |
| 1403 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1404 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1405 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1406 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1407 | |
| 1408 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1409 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1410 | EXPECT_EQ(OK, |
| 1411 | request3.Request( |
| 1412 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1413 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1414 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1415 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1416 | EXPECT_TRUE(stream3.get()); |
| 1417 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1418 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1419 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1420 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1421 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1422 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1423 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1424 | } |
| 1425 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1426 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1427 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1428 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1429 | MockQuicData socket_data; |
| 1430 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1431 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1432 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1433 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1434 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1435 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1436 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1437 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1438 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1439 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1440 | host_resolver_->set_synchronous_mode(true); |
| 1441 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1442 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1443 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1444 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1445 | EXPECT_EQ(OK, |
| 1446 | request.Request( |
| 1447 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1448 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1449 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1450 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1451 | EXPECT_TRUE(stream.get()); |
| 1452 | |
| 1453 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1454 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1455 | EXPECT_EQ(OK, |
| 1456 | request2.Request( |
| 1457 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1458 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1459 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1460 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1461 | EXPECT_TRUE(stream2.get()); |
| 1462 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1463 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1464 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1465 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1466 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1467 | } |
| 1468 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1469 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1470 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1471 | MockQuicData socket_data; |
| 1472 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1473 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1474 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1475 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1476 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1477 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1478 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1479 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1480 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1481 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1482 | EXPECT_TRUE(primary_pin.FromString( |
| 1483 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1484 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1485 | verify_details.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1486 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1487 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1488 | host_resolver_->set_synchronous_mode(true); |
| 1489 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1490 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1491 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1492 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1493 | EXPECT_EQ(OK, |
| 1494 | request.Request( |
| 1495 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1496 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1497 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1498 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1499 | EXPECT_TRUE(stream.get()); |
| 1500 | |
| 1501 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1502 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1503 | EXPECT_EQ(OK, |
| 1504 | request2.Request( |
| 1505 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1506 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1507 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1508 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1509 | EXPECT_TRUE(stream2.get()); |
| 1510 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1511 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1512 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1513 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1514 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1518 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1519 | |
| 1520 | MockQuicData socket_data1; |
| 1521 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1522 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1523 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1524 | MockQuicData socket_data2; |
| 1525 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1526 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1527 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1528 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1529 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1530 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1531 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1532 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1533 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1534 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1535 | uint8_t bad_pin = 3; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1536 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1537 | test::GetTestHashValue(bad_pin)); |
| 1538 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1539 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1540 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1541 | EXPECT_TRUE(primary_pin.FromString( |
| 1542 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1543 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1544 | verify_details2.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1545 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1546 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1547 | host_resolver_->set_synchronous_mode(true); |
| 1548 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1549 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1550 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1551 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1552 | EXPECT_EQ(OK, |
| 1553 | request.Request( |
| 1554 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1555 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1556 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1557 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1558 | EXPECT_TRUE(stream.get()); |
| 1559 | |
| 1560 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1561 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1562 | EXPECT_EQ(OK, |
| 1563 | request2.Request( |
| 1564 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1565 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1566 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1567 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1568 | EXPECT_TRUE(stream2.get()); |
| 1569 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1570 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1571 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1572 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1573 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1574 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1575 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1576 | } |
| 1577 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1578 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1579 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1580 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1581 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1582 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1583 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1584 | MockQuicData socket_data; |
| 1585 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1586 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1587 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1588 | MockQuicData socket_data2; |
| 1589 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1590 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1591 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1592 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1593 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1594 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1595 | request.Request( |
| 1596 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1597 | SocketTag(), |
| 1598 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1599 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1600 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1601 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1602 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1603 | EXPECT_TRUE(stream.get()); |
| 1604 | |
| 1605 | // Mark the session as going away. Ensure that while it is still alive |
| 1606 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1607 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1608 | factory_->OnSessionGoingAway(session); |
| 1609 | EXPECT_EQ(true, |
| 1610 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1611 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1612 | |
| 1613 | // Create a new request for the same destination and verify that a |
| 1614 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1615 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1616 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1617 | request2.Request( |
| 1618 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1619 | SocketTag(), |
| 1620 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1621 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1622 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1623 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1624 | EXPECT_TRUE(stream2.get()); |
| 1625 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1626 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1627 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1628 | EXPECT_EQ(true, |
| 1629 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1630 | |
| 1631 | stream2.reset(); |
| 1632 | stream.reset(); |
| 1633 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1634 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1635 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1636 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1637 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1638 | } |
| 1639 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1640 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1641 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1642 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1643 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1644 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1645 | quic::QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1646 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1647 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1648 | if (version_ == quic::QUIC_VERSION_99) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1649 | socket_data.AddWrite( |
| 1650 | SYNCHRONOUS, |
| 1651 | client_maker_.MakeStreamIdBlockedPacket( |
| 1652 | 2, true, GetNthClientInitiatedBidirectionalStreamId(49))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1653 | socket_data.AddWrite( |
| 1654 | SYNCHRONOUS, client_maker_.MakeRstPacket(3, true, stream_id, |
| 1655 | quic::QUIC_STREAM_CANCELLED)); |
| 1656 | socket_data.AddRead( |
| 1657 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1658 | quic::QUIC_STREAM_CANCELLED)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1659 | socket_data.AddRead( |
| 1660 | ASYNC, server_maker_.MakeMaxStreamIdPacket( |
| 1661 | 4, true, GetNthClientInitiatedBidirectionalStreamId(50))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1662 | } else { |
| 1663 | socket_data.AddWrite( |
| 1664 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1665 | quic::QUIC_STREAM_CANCELLED)); |
| 1666 | socket_data.AddRead( |
| 1667 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1668 | quic::QUIC_STREAM_CANCELLED)); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1669 | } |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1670 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1671 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1672 | |
| 1673 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1674 | request_info.traffic_annotation = |
| 1675 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1676 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1677 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1678 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1679 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1680 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1681 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1682 | int rv = request.Request( |
| 1683 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1684 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1685 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1686 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1688 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1689 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1690 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1691 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1692 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1693 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1694 | EXPECT_EQ(OK, |
| 1695 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1696 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1697 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1698 | } |
| 1699 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1700 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1701 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1702 | DEFAULT_PRIORITY, SocketTag(), |
| 1703 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1704 | &net_error_details_, |
| 1705 | failed_on_default_network_callback_, |
| 1706 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1707 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1708 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1709 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1710 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1711 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1712 | |
| 1713 | // Close the first stream. |
| 1714 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1715 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1716 | // stream. |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1717 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1718 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1719 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1720 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1721 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1722 | |
| 1723 | // Force close of the connection to suppress the generation of RST |
| 1724 | // packets when streams are torn down, which wouldn't be relevant to |
| 1725 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1726 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1727 | session->connection()->CloseConnection( |
| 1728 | quic::QUIC_PUBLIC_RESET, "test", |
| 1729 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1730 | } |
| 1731 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1732 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1733 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1734 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1735 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1736 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1737 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1738 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1739 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1740 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1741 | request.Request( |
| 1742 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1743 | SocketTag(), |
| 1744 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1745 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1746 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1747 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1748 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1749 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1750 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1751 | } |
| 1752 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1753 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1754 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1755 | |
| 1756 | MockQuicData socket_data; |
| 1757 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1758 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1759 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1760 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1761 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1762 | request.Request( |
| 1763 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1764 | SocketTag(), |
| 1765 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1766 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1767 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1768 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1769 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1770 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1771 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1772 | } |
| 1773 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1774 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1775 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1776 | MockQuicData socket_data; |
| 1777 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1778 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1779 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1780 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1781 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1782 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1783 | request.Request( |
| 1784 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1785 | SocketTag(), |
| 1786 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1787 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1788 | } |
| 1789 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1790 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1791 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1792 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1793 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1794 | DEFAULT_PRIORITY, SocketTag(), |
| 1795 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1796 | &net_error_details_, |
| 1797 | failed_on_default_network_callback_, |
| 1798 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1799 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1800 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1801 | EXPECT_TRUE(stream.get()); |
| 1802 | stream.reset(); |
| 1803 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1804 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1805 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1806 | } |
| 1807 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1808 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1809 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1810 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1811 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1812 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1813 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1814 | MockQuicData socket_data; |
| 1815 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1816 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1817 | socket_data.AddWrite( |
| 1818 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1819 | socket_data.AddWrite(SYNCHRONOUS, |
| 1820 | client_maker_.MakeConnectionClosePacket( |
| 1821 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1822 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1823 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1824 | MockQuicData socket_data2; |
| 1825 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1826 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1827 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1828 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1829 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1830 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1831 | request.Request( |
| 1832 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1833 | SocketTag(), |
| 1834 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1835 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1836 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1837 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1838 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1839 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1840 | request_info.traffic_annotation = |
| 1841 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1842 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1843 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1844 | |
| 1845 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1846 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1847 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1848 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1849 | stream->ReadResponseHeaders(callback_.callback())); |
| 1850 | |
| 1851 | // Now attempting to request a stream to the same origin should create |
| 1852 | // a new session. |
| 1853 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1854 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1855 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1856 | request2.Request( |
| 1857 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1858 | SocketTag(), |
| 1859 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1860 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1861 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1862 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1863 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1864 | stream.reset(); // Will reset stream 3. |
| 1865 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1866 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1867 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1868 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1869 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1870 | } |
| 1871 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1872 | // Regression test for crbug.com/700617. Test a write error during the |
| 1873 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1874 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1875 | // QuicStreamRequest should succeed without hanging. |
| 1876 | TEST_P(QuicStreamFactoryTest, |
| 1877 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1878 | Initialize(); |
| 1879 | // Use unmocked crypto stream to do crypto connect. |
| 1880 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1881 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1882 | |
| 1883 | MockQuicData socket_data; |
| 1884 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1885 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1886 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1887 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1888 | |
| 1889 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1890 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1891 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1892 | request.Request( |
| 1893 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1894 | SocketTag(), |
| 1895 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1896 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1897 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1898 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1899 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1900 | |
| 1901 | // Verify new requests can be sent normally without hanging. |
| 1902 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1903 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1904 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1905 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1906 | MockQuicData socket_data2; |
| 1907 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1908 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1909 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1910 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1911 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1912 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1913 | request2.Request( |
| 1914 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1915 | SocketTag(), |
| 1916 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1917 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1918 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1919 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1920 | // Run the message loop to complete host resolution. |
| 1921 | base::RunLoop().RunUntilIdle(); |
| 1922 | |
| 1923 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1924 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1925 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1926 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1927 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1928 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1929 | |
| 1930 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1931 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1932 | EXPECT_TRUE(stream.get()); |
| 1933 | stream.reset(); |
| 1934 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1935 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1936 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1937 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1938 | } |
| 1939 | |
| 1940 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1941 | Initialize(); |
| 1942 | // Use unmocked crypto stream to do crypto connect. |
| 1943 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1944 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1945 | host_resolver_->set_synchronous_mode(true); |
| 1946 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1947 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1948 | |
| 1949 | MockQuicData socket_data; |
| 1950 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1951 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1952 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1953 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1954 | |
| 1955 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1956 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1957 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1958 | request.Request( |
| 1959 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1960 | SocketTag(), |
| 1961 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1962 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1963 | // Check no active session, or active jobs left for this server. |
| 1964 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1965 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1966 | |
| 1967 | // Verify new requests can be sent normally without hanging. |
| 1968 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1969 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1970 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1971 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1972 | MockQuicData socket_data2; |
| 1973 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1974 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1975 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1976 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1977 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1978 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1979 | request2.Request( |
| 1980 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1981 | SocketTag(), |
| 1982 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1983 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1984 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1985 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1986 | |
| 1987 | // Complete handshake. |
| 1988 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1989 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1990 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1991 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1992 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1993 | |
| 1994 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1995 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1996 | EXPECT_TRUE(stream.get()); |
| 1997 | stream.reset(); |
| 1998 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1999 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2000 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2001 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2002 | } |
| 2003 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2004 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 2005 | test_params_.quic_close_sessions_on_ip_change = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2006 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2007 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2008 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2009 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2010 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2011 | MockQuicData socket_data; |
| 2012 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2013 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2014 | socket_data.AddWrite( |
| 2015 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2016 | socket_data.AddWrite( |
| 2017 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2018 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2019 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2020 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2021 | MockQuicData socket_data2; |
| 2022 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2023 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2024 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2025 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2026 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2027 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2028 | request.Request( |
| 2029 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2030 | SocketTag(), |
| 2031 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2032 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2033 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2034 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2035 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2036 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2037 | request_info.traffic_annotation = |
| 2038 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2039 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2040 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2041 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2042 | // Check an active session exisits for the destination. |
| 2043 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2044 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2045 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2046 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2047 | IPAddress last_address; |
| 2048 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2049 | // Change the IP address and verify that stream saw the error and the active |
| 2050 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2051 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2052 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2053 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2054 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2055 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2056 | // Check no active session exists for the destination. |
| 2057 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2058 | |
| 2059 | // Now attempting to request a stream to the same origin should create |
| 2060 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2061 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2062 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2063 | request2.Request( |
| 2064 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2065 | SocketTag(), |
| 2066 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2067 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2068 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2069 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2070 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2071 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2072 | // Check a new active session exisits for the destination and the old session |
| 2073 | // is no longer live. |
| 2074 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2075 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2076 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2077 | |
| 2078 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2079 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2080 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2081 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2082 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2083 | } |
| 2084 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2085 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2086 | // as going away on IP address change instead of being closed. New requests will |
| 2087 | // go to a new connection. |
| 2088 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 2089 | test_params_.quic_goaway_sessions_on_ip_change = true; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2090 | Initialize(); |
| 2091 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2092 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2093 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2094 | |
| 2095 | MockQuicData quic_data1; |
| 2096 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2097 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2098 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2099 | quic_data1.AddWrite( |
| 2100 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2101 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2102 | true, &header_stream_offset)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2103 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2104 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2105 | ASYNC, |
| 2106 | ConstructOkResponsePacket( |
| 2107 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2108 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2109 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2110 | |
| 2111 | MockQuicData quic_data2; |
| 2112 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2113 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2114 | quic_data2.AddWrite( |
| 2115 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2116 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2117 | |
| 2118 | // Create request and QuicHttpStream. |
| 2119 | QuicStreamRequest request(factory_.get()); |
| 2120 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2121 | request.Request( |
| 2122 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2123 | SocketTag(), |
| 2124 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2125 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2126 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2127 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2128 | EXPECT_TRUE(stream.get()); |
| 2129 | |
| 2130 | // Cause QUIC stream to be created. |
| 2131 | HttpRequestInfo request_info; |
| 2132 | request_info.method = "GET"; |
| 2133 | request_info.url = url_; |
| 2134 | request_info.traffic_annotation = |
| 2135 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2136 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2137 | net_log_, CompletionOnceCallback())); |
| 2138 | |
| 2139 | // Ensure that session is alive and active. |
| 2140 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2141 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2142 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2143 | |
| 2144 | // Send GET request on stream. |
| 2145 | HttpResponseInfo response; |
| 2146 | HttpRequestHeaders request_headers; |
| 2147 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2148 | callback_.callback())); |
| 2149 | |
| 2150 | // Receive an IP address change notification. |
| 2151 | NotifyIPAddressChanged(); |
| 2152 | |
| 2153 | // The connection should still be alive, but marked as going away. |
| 2154 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2155 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2156 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2157 | |
| 2158 | // Resume the data, response should be read from the original connection. |
| 2159 | quic_data1.Resume(); |
| 2160 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2161 | EXPECT_EQ(200, response.headers->response_code()); |
| 2162 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2163 | |
| 2164 | // Second request should be sent on a new connection. |
| 2165 | QuicStreamRequest request2(factory_.get()); |
| 2166 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2167 | request2.Request( |
| 2168 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2169 | SocketTag(), |
| 2170 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2171 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2172 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2173 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2174 | EXPECT_TRUE(stream2.get()); |
| 2175 | |
| 2176 | // Check an active session exisits for the destination. |
| 2177 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2178 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2179 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2180 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2181 | |
| 2182 | stream.reset(); |
| 2183 | stream2.reset(); |
| 2184 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2185 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2186 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2187 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2188 | } |
| 2189 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2190 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2191 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2192 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2193 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2194 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2195 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2196 | |
| 2197 | MockQuicData socket_data; |
| 2198 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2199 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2200 | socket_data.AddWrite( |
| 2201 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2202 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2203 | |
| 2204 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2205 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2206 | request.Request( |
| 2207 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2208 | SocketTag(), |
| 2209 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2210 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2211 | |
| 2212 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2213 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2214 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2215 | request_info.traffic_annotation = |
| 2216 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2217 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2218 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2219 | |
| 2220 | IPAddress last_address; |
| 2221 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2222 | |
| 2223 | // Change the IP address and verify that the connection is unaffected. |
| 2224 | NotifyIPAddressChanged(); |
| 2225 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2226 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2227 | |
| 2228 | // Attempting a new request to the same origin uses the same connection. |
| 2229 | QuicStreamRequest request2(factory_.get()); |
| 2230 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2231 | DEFAULT_PRIORITY, SocketTag(), |
| 2232 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2233 | &net_error_details_, |
| 2234 | failed_on_default_network_callback_, |
| 2235 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2236 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2237 | |
| 2238 | stream.reset(); |
| 2239 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2240 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2241 | } |
| 2242 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2243 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
| 2244 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2245 | } |
| 2246 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2247 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
| 2248 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2249 | } |
| 2250 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2251 | // Sets up a test which attempts connection migration successfully after probing |
| 2252 | // when a new network is made as default and the old default is still available. |
| 2253 | // |write_mode| specifies the write mode for the last write before |
| 2254 | // OnNetworkMadeDefault is delivered to session. |
| 2255 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2256 | IoMode write_mode) { |
| 2257 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2258 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2259 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2260 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2261 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2262 | // Using a testing task runner so that we can control time. |
| 2263 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2264 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2265 | |
| 2266 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2267 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2268 | |
| 2269 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2270 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2271 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2272 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2273 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2274 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2275 | write_mode, ConstructGetRequestPacket( |
| 2276 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2277 | true, &header_stream_offset)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2278 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2279 | |
| 2280 | // Set up the second socket data provider that is used after migration. |
| 2281 | // The response to the earlier request is read on the new socket. |
| 2282 | MockQuicData quic_data2; |
| 2283 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2284 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2285 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2286 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2287 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2288 | quic_data2.AddRead(ASYNC, |
| 2289 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2290 | // Ping packet to send after migration is completed. |
| 2291 | quic_data2.AddWrite(ASYNC, |
| 2292 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2293 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2294 | ASYNC, |
| 2295 | ConstructOkResponsePacket( |
| 2296 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2297 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2298 | quic_data2.AddWrite( |
| 2299 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2300 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2301 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2302 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2303 | |
| 2304 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2305 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2306 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2307 | request.Request( |
| 2308 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2309 | SocketTag(), |
| 2310 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2311 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2312 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2313 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2314 | EXPECT_TRUE(stream.get()); |
| 2315 | |
| 2316 | // Cause QUIC stream to be created. |
| 2317 | HttpRequestInfo request_info; |
| 2318 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2319 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2320 | request_info.traffic_annotation = |
| 2321 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2322 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2323 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2324 | |
| 2325 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2326 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2327 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2328 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2329 | |
| 2330 | // Send GET request on stream. |
| 2331 | HttpResponseInfo response; |
| 2332 | HttpRequestHeaders request_headers; |
| 2333 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2334 | callback_.callback())); |
| 2335 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2336 | // Deliver a signal that a alternate network is connected now, this should |
| 2337 | // cause the connection to start early migration on path degrading. |
| 2338 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2339 | ->SetConnectedNetworksList( |
| 2340 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2341 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2342 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2343 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2344 | // Cause the connection to report path degrading to the session. |
| 2345 | // Due to lack of alternate network, session will not mgirate connection. |
| 2346 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2347 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2348 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2349 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2350 | // A task will be posted to migrate to the new default network. |
| 2351 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2352 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2353 | |
| 2354 | // Execute the posted task to migrate back to the default network. |
| 2355 | task_runner->RunUntilIdle(); |
| 2356 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2357 | // retry migrate back to default network is scheduled. |
| 2358 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2359 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2360 | // kDefaultRTTMilliSecs. |
| 2361 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2362 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2363 | next_task_delay); |
| 2364 | |
| 2365 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2366 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2367 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2368 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2369 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2370 | |
| 2371 | // Resume quic data and a connectivity probe response will be read on the new |
| 2372 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2373 | // will be posted to complete migration. |
| 2374 | quic_data2.Resume(); |
| 2375 | |
| 2376 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2377 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2378 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2379 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2380 | // There should be three pending tasks, the nearest one will complete |
| 2381 | // migration to the new network. |
| 2382 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2383 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2384 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2385 | task_runner->FastForwardBy(next_task_delay); |
| 2386 | |
| 2387 | // Response headers are received over the new network. |
| 2388 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2389 | EXPECT_EQ(200, response.headers->response_code()); |
| 2390 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2391 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2392 | // probe and has been cancelled due to successful migration. |
| 2393 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2394 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2395 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2396 | next_task_delay); |
| 2397 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2398 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2399 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2400 | // is also cancelled due to the success migration on the previous trial. |
| 2401 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2402 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2403 | base::TimeDelta expected_delay = |
| 2404 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2405 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2406 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2407 | task_runner->FastForwardBy(next_task_delay); |
| 2408 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2409 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2410 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2411 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2412 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2413 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2414 | stream.reset(); |
| 2415 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2416 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2417 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2418 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2419 | } |
| 2420 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2421 | // Regression test for http://859674. |
| 2422 | // This test veries that a writer will not attempt to write packets until being |
| 2423 | // unblocked on both socket level and network level. In this test, a probing |
| 2424 | // writer is used to send two connectivity probes to the peer: where the first |
| 2425 | // one completes successfully, while a connectivity response is received before |
| 2426 | // completes sending the second one. The connection migration attempt will |
| 2427 | // proceed while the probing writer is blocked at the socket level, which will |
| 2428 | // block the writer on the network level. Once connection migration completes |
| 2429 | // successfully, the probing writer will be unblocked on the network level, it |
| 2430 | // will not attempt to write new packets until the socket level is unblocked. |
| 2431 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
| 2432 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2433 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2434 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2435 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2436 | |
| 2437 | // Using a testing task runner so that we can control time. |
| 2438 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2439 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2440 | |
| 2441 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2442 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2443 | |
| 2444 | MockQuicData quic_data1; |
| 2445 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2446 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2447 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2448 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2449 | quic_data1.AddWrite( |
| 2450 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2451 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2452 | true, &header_stream_offset)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2453 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2454 | |
| 2455 | // Set up the second socket data provider that is used after migration. |
| 2456 | // The response to the earlier request is read on the new socket. |
| 2457 | MockQuicData quic_data2; |
| 2458 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2459 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2460 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2461 | quic_data2.AddRead(ASYNC, |
| 2462 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2463 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2464 | quic_data2.AddRead(ASYNC, |
| 2465 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2466 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2467 | quic_data2.AddWrite(ASYNC, |
| 2468 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2469 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2470 | ASYNC, |
| 2471 | ConstructOkResponsePacket( |
| 2472 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2473 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2474 | quic_data2.AddWrite(ASYNC, |
| 2475 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2476 | quic_data2.AddWrite( |
| 2477 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2478 | 6, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2479 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2480 | |
| 2481 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2482 | |
| 2483 | // Create request and QuicHttpStream. |
| 2484 | QuicStreamRequest request(factory_.get()); |
| 2485 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2486 | request.Request( |
| 2487 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2488 | SocketTag(), |
| 2489 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2490 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2491 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2492 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2493 | EXPECT_TRUE(stream.get()); |
| 2494 | |
| 2495 | // Cause QUIC stream to be created. |
| 2496 | HttpRequestInfo request_info; |
| 2497 | request_info.method = "GET"; |
| 2498 | request_info.url = url_; |
| 2499 | request_info.traffic_annotation = |
| 2500 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2501 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2502 | net_log_, CompletionOnceCallback())); |
| 2503 | |
| 2504 | // Ensure that session is alive and active. |
| 2505 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2506 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2507 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2508 | |
| 2509 | // Send GET request on stream. |
| 2510 | HttpResponseInfo response; |
| 2511 | HttpRequestHeaders request_headers; |
| 2512 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2513 | callback_.callback())); |
| 2514 | |
| 2515 | // Deliver a signal that a alternate network is connected now, this should |
| 2516 | // cause the connection to start early migration on path degrading. |
| 2517 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2518 | ->SetConnectedNetworksList( |
| 2519 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2520 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2521 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2522 | |
| 2523 | // Cause the connection to report path degrading to the session. |
| 2524 | // Due to lack of alternate network, session will not mgirate connection. |
| 2525 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2526 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2527 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2528 | |
| 2529 | // A task will be posted to migrate to the new default network. |
| 2530 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2531 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2532 | |
| 2533 | // Execute the posted task to migrate back to the default network. |
| 2534 | task_runner->RunUntilIdle(); |
| 2535 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2536 | // retry migrate back to default network is scheduled. |
| 2537 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2538 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2539 | // kDefaultRTTMilliSecs. |
| 2540 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2541 | base::TimeDelta expected_delay = |
| 2542 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2543 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2544 | |
| 2545 | // Fast forward to send the second connectivity probe. The write will be |
| 2546 | // asynchronous and complete after the read completes. |
| 2547 | task_runner->FastForwardBy(next_task_delay); |
| 2548 | |
| 2549 | // Resume quic data and a connectivity probe response will be read on the new |
| 2550 | // socket, declare probing as successful. |
| 2551 | quic_data2.Resume(); |
| 2552 | |
| 2553 | // The connection should still be alive, and not marked as going away. |
| 2554 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2555 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2556 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2557 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2558 | |
| 2559 | // There should be three pending tasks, the nearest one will complete |
| 2560 | // migration to the new network. Second task will retry migrate back to |
| 2561 | // default but cancelled, and the third task will retry send connectivity |
| 2562 | // probe but also cancelled. |
| 2563 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2564 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2565 | task_runner->RunUntilIdle(); |
| 2566 | |
| 2567 | // Response headers are received over the new network. |
| 2568 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2569 | EXPECT_EQ(200, response.headers->response_code()); |
| 2570 | |
| 2571 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2572 | base::RunLoop().RunUntilIdle(); |
| 2573 | |
| 2574 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2575 | // to default network and has been cancelled due to successful migration. |
| 2576 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2577 | expected_delay = |
| 2578 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2579 | expected_delay; |
| 2580 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2581 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2582 | task_runner->FastForwardBy(next_task_delay); |
| 2583 | |
| 2584 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2585 | // also been cancelled due to the successful probing. |
| 2586 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2587 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2588 | expected_delay = |
| 2589 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2590 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2591 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2592 | task_runner->FastForwardBy(next_task_delay); |
| 2593 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2594 | |
| 2595 | // Verify that the session is still alive. |
| 2596 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2597 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2598 | |
| 2599 | stream.reset(); |
| 2600 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2601 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2602 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2603 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2604 | } |
| 2605 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2606 | // This test verifies that session times out connection migration attempt |
| 2607 | // with signals delivered in the following order (no alternate network is |
| 2608 | // available): |
| 2609 | // - default network disconnected is delivered: session attempts connection |
| 2610 | // migration but found not alternate network. Session waits for a new network |
| 2611 | // comes up in the next kWaitTimeForNewNetworkSecs seonds. |
| 2612 | // - no new network is connected, migration times out. Session is closed. |
| 2613 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
| 2614 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2615 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2616 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2617 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2618 | // Using a testing task runner so that we can control time. |
| 2619 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2620 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2621 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2622 | MockQuicData socket_data; |
| 2623 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2624 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2625 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2626 | |
| 2627 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2628 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2629 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2630 | request.Request( |
| 2631 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2632 | SocketTag(), |
| 2633 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2634 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2635 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2636 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2637 | EXPECT_TRUE(stream.get()); |
| 2638 | |
| 2639 | // Cause QUIC stream to be created. |
| 2640 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2641 | request_info.traffic_annotation = |
| 2642 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2643 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2644 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2645 | |
| 2646 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2647 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2648 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2649 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2650 | |
| 2651 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2652 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2653 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2654 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2655 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2656 | // The migration will not fail until the migration alarm timeout. |
| 2657 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2658 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2659 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2660 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2661 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2662 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2663 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2664 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2665 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2666 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2667 | next_task_delay); |
| 2668 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2669 | |
| 2670 | // The connection should now be closed. A request for response |
| 2671 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2672 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2673 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2674 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2675 | |
| 2676 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2677 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2678 | } |
| 2679 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2680 | // This test verifies that connectivity probes will be sent even if there is |
| 2681 | // a non-migratable stream. However, when connection migrates to the |
| 2682 | // successfully probed path, any non-migratable stream will be reset. And if |
| 2683 | // the connection becomes idle then, close the connection. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2684 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2685 | InitializeConnectionMigrationV2Test( |
| 2686 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2687 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2688 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2689 | |
| 2690 | MockQuicData socket_data; |
| 2691 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2692 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2693 | socket_data.AddWrite( |
| 2694 | SYNCHRONOUS, |
| 2695 | client_maker_.MakeRstAckAndConnectionClosePacket( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2696 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Fan Yang | 7c68f63 | 2018-11-06 03:05:38 | [diff] [blame] | 2697 | quic::QUIC_STREAM_CANCELLED, |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2698 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 2699 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
| 2700 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2701 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2702 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2703 | // Set up the second socket data provider that is used for probing. |
| 2704 | MockQuicData quic_data1; |
| 2705 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2706 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2707 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2708 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2709 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2710 | quic_data1.AddRead(ASYNC, |
| 2711 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2712 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2713 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2714 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2715 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2716 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2717 | request.Request( |
| 2718 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2719 | SocketTag(), |
| 2720 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2721 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2722 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2723 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2724 | EXPECT_TRUE(stream.get()); |
| 2725 | |
| 2726 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2727 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2728 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2729 | request_info.traffic_annotation = |
| 2730 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2731 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2732 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2733 | |
| 2734 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2735 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2736 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2737 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2738 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2739 | // Trigger connection migration. Session will start to probe the alternative |
| 2740 | // network. Although there is a non-migratable stream, session will still be |
| 2741 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2742 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2743 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2744 | |
| 2745 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2746 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2747 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2748 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2749 | // Resume data to read a connectivity probing response, which will cause |
| 2750 | // non-migtable streams to be closed. As session becomes idle, connection will |
| 2751 | // be closed. |
| 2752 | quic_data1.Resume(); |
| 2753 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2754 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2755 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2756 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2757 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2758 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2759 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2760 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2761 | } |
| 2762 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2763 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2764 | InitializeConnectionMigrationV2Test( |
| 2765 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2766 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2767 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2768 | |
| 2769 | MockQuicData socket_data; |
| 2770 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2771 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2772 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2773 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2774 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2775 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2776 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2777 | |
| 2778 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2779 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2780 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2781 | request.Request( |
| 2782 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2783 | SocketTag(), |
| 2784 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2785 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2786 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2787 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2788 | EXPECT_TRUE(stream.get()); |
| 2789 | |
| 2790 | // Cause QUIC stream to be created. |
| 2791 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2792 | request_info.traffic_annotation = |
| 2793 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2794 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2795 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2796 | |
| 2797 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2798 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2799 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2800 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2801 | |
| 2802 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2803 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2804 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2805 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2806 | |
| 2807 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2808 | // this should cause session to continue but be marked as going away. |
| 2809 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2810 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2811 | |
| 2812 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2813 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2814 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2815 | |
| 2816 | stream.reset(); |
| 2817 | |
| 2818 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2819 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2820 | } |
| 2821 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2822 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2823 | InitializeConnectionMigrationV2Test( |
| 2824 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2825 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2826 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2827 | |
| 2828 | MockQuicData socket_data; |
| 2829 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2830 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2831 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2832 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2833 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2834 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2835 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2836 | |
| 2837 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2838 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2839 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2840 | request.Request( |
| 2841 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2842 | SocketTag(), |
| 2843 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2844 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2845 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2846 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2847 | EXPECT_TRUE(stream.get()); |
| 2848 | |
| 2849 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2850 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2851 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2852 | request_info.traffic_annotation = |
| 2853 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2854 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2855 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2856 | |
| 2857 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2858 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2859 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2860 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2861 | |
| 2862 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2863 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2864 | // quic::QUIC_STREAM_CANCELLED error code, and the session will be closed. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2865 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2866 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2867 | |
| 2868 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2869 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2870 | |
| 2871 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2872 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2873 | } |
| 2874 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2875 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2876 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2877 | InitializeConnectionMigrationV2Test( |
| 2878 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2879 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2880 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2881 | |
| 2882 | MockQuicData socket_data; |
| 2883 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2884 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2885 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2886 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2887 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2888 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2889 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2890 | |
| 2891 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2892 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2893 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2894 | request.Request( |
| 2895 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2896 | SocketTag(), |
| 2897 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2898 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2899 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2900 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2901 | EXPECT_TRUE(stream.get()); |
| 2902 | |
| 2903 | // Cause QUIC stream to be created. |
| 2904 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2905 | request_info.traffic_annotation = |
| 2906 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2907 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2908 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2909 | |
| 2910 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2911 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2912 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2913 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2914 | |
| 2915 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2916 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2917 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2918 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2919 | |
| 2920 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2921 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2922 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2923 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2924 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2925 | |
| 2926 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2927 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2928 | |
| 2929 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2930 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2931 | } |
| 2932 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2933 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2934 | InitializeConnectionMigrationV2Test( |
| 2935 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2936 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2937 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2938 | |
| 2939 | MockQuicData socket_data; |
| 2940 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2941 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2942 | socket_data.AddWrite( |
| 2943 | SYNCHRONOUS, |
| 2944 | client_maker_.MakeConnectionClosePacket( |
| 2945 | 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 2946 | "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2947 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2948 | |
| 2949 | // Create request and QuicHttpStream. |
| 2950 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2951 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2952 | request.Request( |
| 2953 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2954 | SocketTag(), |
| 2955 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2956 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2957 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2958 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2959 | EXPECT_TRUE(stream.get()); |
| 2960 | |
| 2961 | // Ensure that session is alive and active. |
| 2962 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2963 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2964 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2965 | |
| 2966 | // Trigger connection migration. |
| 2967 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2968 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2969 | |
| 2970 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2971 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2972 | |
| 2973 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2974 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2975 | } |
| 2976 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2977 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2978 | InitializeConnectionMigrationV2Test( |
| 2979 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2980 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2981 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2982 | |
| 2983 | MockQuicData socket_data; |
| 2984 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2985 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2986 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2987 | |
| 2988 | // Create request and QuicHttpStream. |
| 2989 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2990 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2991 | request.Request( |
| 2992 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2993 | SocketTag(), |
| 2994 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2995 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2996 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2997 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2998 | EXPECT_TRUE(stream.get()); |
| 2999 | |
| 3000 | // Ensure that session is alive and active. |
| 3001 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3002 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3003 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3004 | |
| 3005 | // Trigger connection migration. Since there are no active streams, |
| 3006 | // the session will be closed. |
| 3007 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3008 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3009 | |
| 3010 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3011 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3012 | |
| 3013 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3014 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3015 | } |
| 3016 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3017 | // This test verifies session migrates to the alternate network immediately when |
| 3018 | // default network disconnects with a synchronous write before migration. |
| 3019 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3020 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3021 | } |
| 3022 | |
| 3023 | // This test verifies session migrates to the alternate network immediately when |
| 3024 | // default network disconnects with an asynchronously write before migration. |
| 3025 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3026 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3027 | } |
| 3028 | |
| 3029 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3030 | bool async_write_before) { |
| 3031 | InitializeConnectionMigrationV2Test( |
| 3032 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3033 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3034 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3035 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3036 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3037 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3038 | |
| 3039 | // Use the test task runner. |
| 3040 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3041 | |
| 3042 | int packet_number = 1; |
| 3043 | MockQuicData socket_data; |
| 3044 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3045 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3046 | socket_data.AddWrite( |
| 3047 | SYNCHRONOUS, |
| 3048 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3049 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3050 | SYNCHRONOUS, |
| 3051 | ConstructGetRequestPacket(packet_number++, |
| 3052 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3053 | true, true, &header_stream_offset)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3054 | if (async_write_before) { |
| 3055 | socket_data.AddWrite(ASYNC, OK); |
| 3056 | packet_number++; |
| 3057 | } |
| 3058 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3059 | |
| 3060 | // Create request and QuicHttpStream. |
| 3061 | QuicStreamRequest request(factory_.get()); |
| 3062 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3063 | request.Request( |
| 3064 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3065 | SocketTag(), |
| 3066 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3067 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3068 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3069 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3070 | EXPECT_TRUE(stream.get()); |
| 3071 | |
| 3072 | // Cause QUIC stream to be created. |
| 3073 | HttpRequestInfo request_info; |
| 3074 | request_info.method = "GET"; |
| 3075 | request_info.url = url_; |
| 3076 | request_info.traffic_annotation = |
| 3077 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3078 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3079 | net_log_, CompletionOnceCallback())); |
| 3080 | |
| 3081 | // Ensure that session is alive and active. |
| 3082 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3083 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3084 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3085 | |
| 3086 | // Send GET request on stream. |
| 3087 | HttpResponseInfo response; |
| 3088 | HttpRequestHeaders request_headers; |
| 3089 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3090 | callback_.callback())); |
| 3091 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3092 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3093 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3094 | |
| 3095 | // Set up second socket data provider that is used after migration. |
| 3096 | // The response to the earlier request is read on this new socket. |
| 3097 | MockQuicData socket_data1; |
| 3098 | socket_data1.AddWrite( |
| 3099 | SYNCHRONOUS, |
| 3100 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3101 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3102 | ASYNC, |
| 3103 | ConstructOkResponsePacket( |
| 3104 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3105 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3106 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3107 | SYNCHRONOUS, |
| 3108 | client_maker_.MakeAckAndRstPacket( |
| 3109 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3110 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3111 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3112 | |
| 3113 | // Trigger connection migration. |
| 3114 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3115 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3116 | |
| 3117 | // The connection should still be alive, not marked as going away. |
| 3118 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3119 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3120 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3121 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3122 | |
| 3123 | // Ensure that the session is still alive. |
| 3124 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3125 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3126 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3127 | |
| 3128 | // Run the message loop so that data queued in the new socket is read by the |
| 3129 | // packet reader. |
| 3130 | runner_->RunNextTask(); |
| 3131 | |
| 3132 | // Response headers are received over the new network. |
| 3133 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3134 | EXPECT_EQ(200, response.headers->response_code()); |
| 3135 | |
| 3136 | // Check that the session is still alive. |
| 3137 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3138 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3139 | |
| 3140 | // There should be posted tasks not executed, which is to migrate back to |
| 3141 | // default network. |
| 3142 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3143 | |
| 3144 | // Receive signal to mark new network as default. |
| 3145 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3146 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3147 | |
| 3148 | stream.reset(); |
| 3149 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3150 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3151 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3152 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3153 | } |
| 3154 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3155 | // This test receives NCN signals in the following order: |
| 3156 | // - default network disconnected |
| 3157 | // - after a pause, new network is connected. |
| 3158 | // - new network is made default. |
| 3159 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3160 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3161 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3162 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3163 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3164 | |
| 3165 | // Use the test task runner. |
| 3166 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3167 | |
| 3168 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3169 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3170 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3171 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3172 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3173 | socket_data.AddWrite( |
| 3174 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3175 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3176 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3177 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3178 | |
| 3179 | // Create request and QuicHttpStream. |
| 3180 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3181 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3182 | request.Request( |
| 3183 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3184 | SocketTag(), |
| 3185 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3186 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3187 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3188 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3189 | EXPECT_TRUE(stream.get()); |
| 3190 | |
| 3191 | // Cause QUIC stream to be created. |
| 3192 | HttpRequestInfo request_info; |
| 3193 | request_info.method = "GET"; |
| 3194 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3195 | request_info.traffic_annotation = |
| 3196 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3197 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3198 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3199 | |
| 3200 | // Ensure that session is alive and active. |
| 3201 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3202 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3203 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3204 | |
| 3205 | // Send GET request on stream. |
| 3206 | HttpResponseInfo response; |
| 3207 | HttpRequestHeaders request_headers; |
| 3208 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3209 | callback_.callback())); |
| 3210 | |
| 3211 | // Trigger connection migration. Since there are no networks |
| 3212 | // to migrate to, this should cause the session to wait for a new network. |
| 3213 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3214 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3215 | |
| 3216 | // The connection should still be alive, not marked as going away. |
| 3217 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3218 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3219 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3220 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3221 | |
| 3222 | // Set up second socket data provider that is used after migration. |
| 3223 | // The response to the earlier request is read on this new socket. |
| 3224 | MockQuicData socket_data1; |
| 3225 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3226 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3227 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3228 | ASYNC, |
| 3229 | ConstructOkResponsePacket( |
| 3230 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3231 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3232 | socket_data1.AddWrite( |
| 3233 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3234 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3235 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3236 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3237 | |
| 3238 | // Add a new network and notify the stream factory of a new connected network. |
| 3239 | // This causes a PING packet to be sent over the new network. |
| 3240 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3241 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3242 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3243 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3244 | |
| 3245 | // Ensure that the session is still alive. |
| 3246 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3247 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3248 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3249 | |
| 3250 | // Run the message loop so that data queued in the new socket is read by the |
| 3251 | // packet reader. |
| 3252 | runner_->RunNextTask(); |
| 3253 | |
| 3254 | // Response headers are received over the new network. |
| 3255 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3256 | EXPECT_EQ(200, response.headers->response_code()); |
| 3257 | |
| 3258 | // Check that the session is still alive. |
| 3259 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3260 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3261 | |
| 3262 | // There should posted tasks not executed, which is to migrate back to default |
| 3263 | // network. |
| 3264 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3265 | |
| 3266 | // Receive signal to mark new network as default. |
| 3267 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3268 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3269 | |
| 3270 | stream.reset(); |
| 3271 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3272 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3273 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3274 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3275 | } |
| 3276 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3277 | // Regression test for http://crbug.com/872011. |
| 3278 | // This test verifies that migrate to the probing socket will not trigger |
| 3279 | // new packets being read synchronously and generate ACK frame while |
| 3280 | // processing the initial connectivity probe response, which may cause a |
| 3281 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3282 | // allowed when processing a new packet. |
Zhongyi Shi | 6a7323b | 2018-12-07 01:26:32 | [diff] [blame] | 3283 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3284 | InitializeConnectionMigrationV2Test( |
| 3285 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3286 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3287 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3288 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3289 | |
| 3290 | // Using a testing task runner so that we can control time. |
| 3291 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3292 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3293 | |
| 3294 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3295 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3296 | |
| 3297 | int packet_number = 1; |
| 3298 | MockQuicData quic_data1; |
| 3299 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3300 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3301 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3302 | packet_number++, &header_stream_offset)); |
| 3303 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3304 | SYNCHRONOUS, |
| 3305 | ConstructGetRequestPacket(packet_number++, |
| 3306 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3307 | true, true, &header_stream_offset)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3308 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3309 | |
| 3310 | // Set up the second socket data provider that is used for probing on the |
| 3311 | // alternate network. |
| 3312 | MockQuicData quic_data2; |
| 3313 | // Connectivity probe to be sent on the new path. |
| 3314 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3315 | packet_number++, true)); |
| 3316 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3317 | // First connectivity probe to receive from the server, which will complete |
| 3318 | // connection migraiton on path degrading. |
| 3319 | quic_data2.AddRead(ASYNC, |
| 3320 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3321 | // Read multiple connectivity probes synchronously. |
| 3322 | quic_data2.AddRead(SYNCHRONOUS, |
| 3323 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3324 | quic_data2.AddRead(SYNCHRONOUS, |
| 3325 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3326 | quic_data2.AddRead(SYNCHRONOUS, |
| 3327 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3328 | quic_data2.AddWrite( |
| 3329 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3330 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3331 | ASYNC, |
| 3332 | ConstructOkResponsePacket( |
| 3333 | 5, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3334 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3335 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3336 | SYNCHRONOUS, |
| 3337 | client_maker_.MakeAckAndRstPacket( |
| 3338 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3339 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3340 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3341 | |
| 3342 | // Create request and QuicHttpStream. |
| 3343 | QuicStreamRequest request(factory_.get()); |
| 3344 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3345 | request.Request( |
| 3346 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3347 | SocketTag(), |
| 3348 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3349 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3350 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3351 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3352 | EXPECT_TRUE(stream.get()); |
| 3353 | |
| 3354 | // Cause QUIC stream to be created. |
| 3355 | HttpRequestInfo request_info; |
| 3356 | request_info.method = "GET"; |
| 3357 | request_info.url = url_; |
| 3358 | request_info.traffic_annotation = |
| 3359 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3360 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3361 | net_log_, CompletionOnceCallback())); |
| 3362 | |
| 3363 | // Ensure that session is alive and active. |
| 3364 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3365 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3366 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3367 | |
| 3368 | // Send GET request on stream. |
| 3369 | HttpResponseInfo response; |
| 3370 | HttpRequestHeaders request_headers; |
| 3371 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3372 | callback_.callback())); |
| 3373 | |
| 3374 | // Cause the connection to report path degrading to the session. |
| 3375 | // Session will start to probe the alternate network. |
| 3376 | session->connection()->OnPathDegradingTimeout(); |
| 3377 | |
| 3378 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3379 | // kDefaultRTTMilliSecs. |
| 3380 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3381 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3382 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3383 | next_task_delay); |
| 3384 | |
| 3385 | // The connection should still be alive, and not marked as going away. |
| 3386 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3387 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3388 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3389 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3390 | |
| 3391 | // Resume quic data and a connectivity probe response will be read on the new |
| 3392 | // socket. |
| 3393 | quic_data2.Resume(); |
| 3394 | |
| 3395 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3396 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3397 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3398 | |
| 3399 | // There should be three pending tasks, the nearest one will complete |
| 3400 | // migration to the new network. |
| 3401 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3402 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3403 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3404 | task_runner->FastForwardBy(next_task_delay); |
| 3405 | |
| 3406 | // Response headers are received over the new network. |
| 3407 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3408 | EXPECT_EQ(200, response.headers->response_code()); |
| 3409 | |
| 3410 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3411 | // probe and has been cancelled due to successful migration. |
| 3412 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3413 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3414 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3415 | next_task_delay); |
| 3416 | task_runner->FastForwardBy(next_task_delay); |
| 3417 | |
| 3418 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3419 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3420 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3421 | base::TimeDelta expected_delay = |
| 3422 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3423 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3424 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3425 | |
| 3426 | // Deliver a signal that the alternate network now becomes default to session, |
| 3427 | // this will cancel mgirate back to default network timer. |
| 3428 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3429 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3430 | |
| 3431 | task_runner->FastForwardBy(next_task_delay); |
| 3432 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3433 | |
| 3434 | // Verify that the session is still alive. |
| 3435 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3436 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3437 | |
| 3438 | stream.reset(); |
| 3439 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3440 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3441 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3442 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3443 | } |
| 3444 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3445 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3446 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3447 | // migration. |
| 3448 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
| 3449 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3450 | } |
| 3451 | |
| 3452 | // This test verifies that the connection migrates to the alternate network |
| 3453 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3454 | // migration. |
| 3455 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
| 3456 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3457 | } |
| 3458 | |
| 3459 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3460 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3461 | InitializeConnectionMigrationV2Test( |
| 3462 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3463 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3464 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3465 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3466 | |
| 3467 | // Using a testing task runner so that we can control time. |
| 3468 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3469 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3470 | |
| 3471 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3472 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3473 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3474 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3475 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3476 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3477 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3478 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3479 | packet_number++, &header_stream_offset)); |
| 3480 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3481 | SYNCHRONOUS, |
| 3482 | ConstructGetRequestPacket(packet_number++, |
| 3483 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3484 | true, true, &header_stream_offset)); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3485 | if (async_write_before) { |
| 3486 | quic_data1.AddWrite(ASYNC, OK); |
| 3487 | packet_number++; |
| 3488 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3489 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3490 | |
| 3491 | // Set up the second socket data provider that is used after migration. |
| 3492 | // The response to the earlier request is read on the new socket. |
| 3493 | MockQuicData quic_data2; |
| 3494 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3495 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3496 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3497 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3498 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3499 | quic_data2.AddRead(ASYNC, |
| 3500 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3501 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3502 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3503 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3504 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3505 | ASYNC, |
| 3506 | ConstructOkResponsePacket( |
| 3507 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3508 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3509 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3510 | SYNCHRONOUS, |
| 3511 | client_maker_.MakeAckAndRstPacket( |
| 3512 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3513 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3514 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3515 | |
| 3516 | // Create request and QuicHttpStream. |
| 3517 | QuicStreamRequest request(factory_.get()); |
| 3518 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3519 | request.Request( |
| 3520 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3521 | SocketTag(), |
| 3522 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3523 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3524 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3525 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3526 | EXPECT_TRUE(stream.get()); |
| 3527 | |
| 3528 | // Cause QUIC stream to be created. |
| 3529 | HttpRequestInfo request_info; |
| 3530 | request_info.method = "GET"; |
| 3531 | request_info.url = url_; |
| 3532 | request_info.traffic_annotation = |
| 3533 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3534 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3535 | net_log_, CompletionOnceCallback())); |
| 3536 | |
| 3537 | // Ensure that session is alive and active. |
| 3538 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3539 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3540 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3541 | |
| 3542 | // Send GET request on stream. |
| 3543 | HttpResponseInfo response; |
| 3544 | HttpRequestHeaders request_headers; |
| 3545 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3546 | callback_.callback())); |
| 3547 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3548 | if (async_write_before) |
| 3549 | session->SendPing(); |
| 3550 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3551 | // Cause the connection to report path degrading to the session. |
| 3552 | // Session will start to probe the alternate network. |
| 3553 | session->connection()->OnPathDegradingTimeout(); |
| 3554 | |
| 3555 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3556 | // kDefaultRTTMilliSecs. |
| 3557 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3558 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3559 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3560 | next_task_delay); |
| 3561 | |
| 3562 | // The connection should still be alive, and not marked as going away. |
| 3563 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3564 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3565 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3566 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3567 | |
| 3568 | // Resume quic data and a connectivity probe response will be read on the new |
| 3569 | // socket. |
| 3570 | quic_data2.Resume(); |
| 3571 | |
| 3572 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3573 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3574 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3575 | |
| 3576 | // There should be three pending tasks, the nearest one will complete |
| 3577 | // migration to the new network. |
| 3578 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3579 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3580 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3581 | task_runner->FastForwardBy(next_task_delay); |
| 3582 | |
| 3583 | // Response headers are received over the new network. |
| 3584 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3585 | EXPECT_EQ(200, response.headers->response_code()); |
| 3586 | |
| 3587 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3588 | // probe and has been cancelled due to successful migration. |
| 3589 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3590 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3591 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3592 | next_task_delay); |
| 3593 | task_runner->FastForwardBy(next_task_delay); |
| 3594 | |
| 3595 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3596 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3597 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3598 | base::TimeDelta expected_delay = |
| 3599 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3600 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3601 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3602 | |
| 3603 | // Deliver a signal that the alternate network now becomes default to session, |
| 3604 | // this will cancel mgirate back to default network timer. |
| 3605 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3606 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3607 | |
| 3608 | task_runner->FastForwardBy(next_task_delay); |
| 3609 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3610 | |
| 3611 | // Verify that the session is still alive. |
| 3612 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3613 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3614 | |
| 3615 | stream.reset(); |
| 3616 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3617 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3618 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3619 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3620 | } |
| 3621 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3622 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3623 | // and it does not receive any new request |
| 3624 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 3625 | test_params_.quic_go_away_on_path_degrading = true; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3626 | Initialize(); |
| 3627 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3628 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3629 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3630 | |
| 3631 | MockQuicData quic_data1; |
| 3632 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3633 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3634 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3635 | quic_data1.AddWrite( |
| 3636 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3637 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3638 | true, &header_stream_offset)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3639 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3640 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3641 | ASYNC, |
| 3642 | ConstructOkResponsePacket( |
| 3643 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3644 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3645 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3646 | |
| 3647 | MockQuicData quic_data2; |
| 3648 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3649 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3650 | quic_data2.AddWrite( |
| 3651 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3652 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3653 | |
| 3654 | // Creat request and QuicHttpStream. |
| 3655 | QuicStreamRequest request(factory_.get()); |
| 3656 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3657 | request.Request( |
| 3658 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3659 | SocketTag(), |
| 3660 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3661 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3662 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3663 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3664 | EXPECT_TRUE(stream.get()); |
| 3665 | |
| 3666 | // Cause QUIC stream to be created. |
| 3667 | HttpRequestInfo request_info; |
| 3668 | request_info.method = "GET"; |
| 3669 | request_info.url = url_; |
| 3670 | request_info.traffic_annotation = |
| 3671 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3672 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3673 | net_log_, CompletionOnceCallback())); |
| 3674 | |
| 3675 | // Ensure that session is alive and active. |
| 3676 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3677 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3678 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3679 | |
| 3680 | // Send GET request on stream. |
| 3681 | HttpResponseInfo response; |
| 3682 | HttpRequestHeaders request_headers; |
| 3683 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3684 | callback_.callback())); |
| 3685 | |
| 3686 | // Trigger the connection to report path degrading to the session. |
| 3687 | // Session will mark itself GOAWAY. |
| 3688 | session->connection()->OnPathDegradingTimeout(); |
| 3689 | |
| 3690 | // The connection should still be alive, but marked as going away. |
| 3691 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3692 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3693 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3694 | |
| 3695 | // Second request should be sent on a new connection. |
| 3696 | QuicStreamRequest request2(factory_.get()); |
| 3697 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3698 | request2.Request( |
| 3699 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3700 | SocketTag(), |
| 3701 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3702 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3703 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3704 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3705 | EXPECT_TRUE(stream2.get()); |
| 3706 | |
| 3707 | // Resume the data, verify old request can read response on the old session |
| 3708 | // successfully. |
| 3709 | quic_data1.Resume(); |
| 3710 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3711 | EXPECT_EQ(200, response.headers->response_code()); |
| 3712 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3713 | |
| 3714 | // Check an active session exists for the destination. |
| 3715 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3716 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3717 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3718 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3719 | EXPECT_NE(session, session2); |
| 3720 | |
| 3721 | stream.reset(); |
| 3722 | stream2.reset(); |
| 3723 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3724 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3725 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3726 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3727 | } |
| 3728 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3729 | // This test verifies that the connection will not migrate to a bad socket |
| 3730 | // when path degrading is detected. |
| 3731 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3732 | InitializeConnectionMigrationV2Test( |
| 3733 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3734 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3735 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3736 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3737 | |
| 3738 | // Using a testing task runner so that we can control time. |
| 3739 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3740 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3741 | |
| 3742 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3743 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3744 | |
| 3745 | MockQuicData quic_data; |
| 3746 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3747 | quic_data.AddWrite(SYNCHRONOUS, |
| 3748 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3749 | quic_data.AddWrite(SYNCHRONOUS, |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3750 | ConstructGetRequestPacket( |
| 3751 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3752 | true, &header_stream_offset)); |
| 3753 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3754 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 3755 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3756 | false, false)); |
| 3757 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3758 | quic_data.AddWrite( |
| 3759 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3760 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3761 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3762 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3763 | |
| 3764 | // Set up second socket that will immediately return disconnected. |
| 3765 | // The stream factory will abort probe the alternate network. |
| 3766 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3767 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3768 | base::span<MockWrite>()); |
| 3769 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3770 | |
| 3771 | // Create request and QuicHttpStream. |
| 3772 | QuicStreamRequest request(factory_.get()); |
| 3773 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3774 | request.Request( |
| 3775 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3776 | SocketTag(), |
| 3777 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3778 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3779 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3780 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3781 | EXPECT_TRUE(stream.get()); |
| 3782 | |
| 3783 | // Cause QUIC stream to be created. |
| 3784 | HttpRequestInfo request_info; |
| 3785 | request_info.method = "GET"; |
| 3786 | request_info.url = url_; |
| 3787 | request_info.traffic_annotation = |
| 3788 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3789 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3790 | net_log_, CompletionOnceCallback())); |
| 3791 | |
| 3792 | // Ensure that session is alive and active. |
| 3793 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3794 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3795 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3796 | |
| 3797 | // Send GET request on stream. |
| 3798 | HttpResponseInfo response; |
| 3799 | HttpRequestHeaders request_headers; |
| 3800 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3801 | callback_.callback())); |
| 3802 | |
| 3803 | // Cause the connection to report path degrading to the session. |
| 3804 | // Session will start to probe the alternate network. |
| 3805 | session->connection()->OnPathDegradingTimeout(); |
| 3806 | |
| 3807 | // The connection should still be alive, and not marked as going away. |
| 3808 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3809 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3810 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3811 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3812 | |
| 3813 | // Resume the data, and response header is received over the original network. |
| 3814 | quic_data.Resume(); |
| 3815 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3816 | EXPECT_EQ(200, response.headers->response_code()); |
| 3817 | |
| 3818 | // Verify there is no pending task as probing alternate network is halted. |
| 3819 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3820 | |
| 3821 | // Verify that the session is still alive. |
| 3822 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3823 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3824 | |
| 3825 | stream.reset(); |
| 3826 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3827 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3828 | } |
| 3829 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3830 | // Regression test for http://crbug.com/847569. |
| 3831 | // This test verifies that the connection migrates to the alternate network |
| 3832 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3833 | // The first packet being written after migration is a synchrnous write, which |
| 3834 | // will cause a PING packet being sent. |
| 3835 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
| 3836 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3837 | } |
| 3838 | |
| 3839 | // Regression test for http://crbug.com/847569. |
| 3840 | // This test verifies that the connection migrates to the alternate network |
| 3841 | // early when there is no active stream but a draining stream. |
| 3842 | // The first packet being written after migration is an asynchronous write, no |
| 3843 | // PING packet will be sent. |
| 3844 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
| 3845 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3846 | } |
| 3847 | |
| 3848 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3849 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3850 | InitializeConnectionMigrationV2Test( |
| 3851 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3852 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3853 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3854 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3855 | |
| 3856 | // Using a testing task runner so that we can control time. |
| 3857 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3858 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3859 | |
| 3860 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3861 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3862 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3863 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3864 | MockQuicData quic_data1; |
| 3865 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3866 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3867 | packet_number++, &header_stream_offset)); |
| 3868 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3869 | SYNCHRONOUS, |
| 3870 | ConstructGetRequestPacket(packet_number++, |
| 3871 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3872 | true, true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3873 | // Read an out of order packet with FIN to drain the stream. |
| 3874 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3875 | ASYNC, ConstructOkResponsePacket( |
| 3876 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, |
| 3877 | true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3878 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3879 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3880 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3881 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3882 | |
| 3883 | // Set up the second socket data provider that is used after migration. |
| 3884 | MockQuicData quic_data2; |
| 3885 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3886 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3887 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3888 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3889 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3890 | quic_data2.AddRead(ASYNC, |
| 3891 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3892 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3893 | quic_data2.AddWrite( |
| 3894 | write_mode_for_queued_packet, |
| 3895 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 3896 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 3897 | quic_data2.AddWrite(ASYNC, |
| 3898 | client_maker_.MakePingPacket(packet_number++, false)); |
| 3899 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3900 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3901 | ASYNC, |
| 3902 | ConstructOkResponsePacket( |
| 3903 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3904 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3905 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3906 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3907 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3908 | |
| 3909 | // Create request and QuicHttpStream. |
| 3910 | QuicStreamRequest request(factory_.get()); |
| 3911 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3912 | request.Request( |
| 3913 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3914 | SocketTag(), |
| 3915 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3916 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3917 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3918 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3919 | EXPECT_TRUE(stream.get()); |
| 3920 | |
| 3921 | // Cause QUIC stream to be created. |
| 3922 | HttpRequestInfo request_info; |
| 3923 | request_info.method = "GET"; |
| 3924 | request_info.url = url_; |
| 3925 | request_info.traffic_annotation = |
| 3926 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3927 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3928 | net_log_, CompletionOnceCallback())); |
| 3929 | |
| 3930 | // Ensure that session is alive and active. |
| 3931 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3932 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3933 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3934 | |
| 3935 | // Send GET request on stream. |
| 3936 | HttpResponseInfo response; |
| 3937 | HttpRequestHeaders request_headers; |
| 3938 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3939 | callback_.callback())); |
| 3940 | |
| 3941 | // Run the message loop to receive the out of order packet which contains a |
| 3942 | // FIN and drains the stream. |
| 3943 | base::RunLoop().RunUntilIdle(); |
| 3944 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3945 | |
| 3946 | // Cause the connection to report path degrading to the session. |
| 3947 | // Session should still start to probe the alternate network. |
| 3948 | session->connection()->OnPathDegradingTimeout(); |
| 3949 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3950 | |
| 3951 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3952 | // kDefaultRTTMilliSecs. |
| 3953 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3954 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3955 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3956 | next_task_delay); |
| 3957 | |
| 3958 | // The connection should still be alive, and not marked as going away. |
| 3959 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3960 | |
| 3961 | // Resume quic data and a connectivity probe response will be read on the new |
| 3962 | // socket. |
| 3963 | quic_data2.Resume(); |
| 3964 | |
| 3965 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3966 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 3967 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3968 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3969 | |
| 3970 | // There should be three pending tasks, the nearest one will complete |
| 3971 | // migration to the new network. |
| 3972 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3973 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3974 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3975 | task_runner->FastForwardBy(next_task_delay); |
| 3976 | |
| 3977 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3978 | // probe and has been cancelled due to successful migration. |
| 3979 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3980 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3981 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3982 | next_task_delay); |
| 3983 | task_runner->FastForwardBy(next_task_delay); |
| 3984 | |
| 3985 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3986 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3987 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3988 | base::TimeDelta expected_delay = |
| 3989 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3990 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3991 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3992 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3993 | base::RunLoop().RunUntilIdle(); |
| 3994 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3995 | // Deliver a signal that the alternate network now becomes default to session, |
| 3996 | // this will cancel mgirate back to default network timer. |
| 3997 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3998 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3999 | |
| 4000 | task_runner->FastForwardBy(next_task_delay); |
| 4001 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4002 | |
| 4003 | // Verify that the session is still alive. |
| 4004 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4005 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4006 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4007 | |
| 4008 | stream.reset(); |
| 4009 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4010 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4011 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4012 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4013 | } |
| 4014 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4015 | // Regression test for http://crbug.com/835444. |
| 4016 | // This test verifies that the connection migrates to the alternate network |
| 4017 | // when the alternate network is connected after path has been degrading. |
| 4018 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
| 4019 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4020 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4021 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4022 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4023 | |
| 4024 | // Using a testing task runner so that we can control time. |
| 4025 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4026 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4027 | |
| 4028 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4029 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4030 | |
| 4031 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4032 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4033 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4034 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4035 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4036 | quic_data1.AddWrite( |
| 4037 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4038 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4039 | true, &header_stream_offset)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4040 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4041 | |
| 4042 | // Set up the second socket data provider that is used after migration. |
| 4043 | // The response to the earlier request is read on the new socket. |
| 4044 | MockQuicData quic_data2; |
| 4045 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4046 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4047 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4048 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4049 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4050 | quic_data2.AddRead(ASYNC, |
| 4051 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4052 | // Ping packet to send after migration is completed. |
| 4053 | quic_data2.AddWrite(ASYNC, |
| 4054 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4055 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4056 | ASYNC, |
| 4057 | ConstructOkResponsePacket( |
| 4058 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4059 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4060 | quic_data2.AddWrite( |
| 4061 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4062 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4063 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4064 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4065 | |
| 4066 | // Create request and QuicHttpStream. |
| 4067 | QuicStreamRequest request(factory_.get()); |
| 4068 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4069 | request.Request( |
| 4070 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4071 | SocketTag(), |
| 4072 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4073 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4074 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4075 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4076 | EXPECT_TRUE(stream.get()); |
| 4077 | |
| 4078 | // Cause QUIC stream to be created. |
| 4079 | HttpRequestInfo request_info; |
| 4080 | request_info.method = "GET"; |
| 4081 | request_info.url = url_; |
| 4082 | request_info.traffic_annotation = |
| 4083 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4084 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4085 | net_log_, CompletionOnceCallback())); |
| 4086 | |
| 4087 | // Ensure that session is alive and active. |
| 4088 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4089 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4090 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4091 | |
| 4092 | // Send GET request on stream. |
| 4093 | HttpResponseInfo response; |
| 4094 | HttpRequestHeaders request_headers; |
| 4095 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4096 | callback_.callback())); |
| 4097 | |
| 4098 | // Cause the connection to report path degrading to the session. |
| 4099 | // Due to lack of alternate network, session will not mgirate connection. |
| 4100 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4101 | session->connection()->OnPathDegradingTimeout(); |
| 4102 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4103 | |
| 4104 | // Deliver a signal that a alternate network is connected now, this should |
| 4105 | // cause the connection to start early migration on path degrading. |
| 4106 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4107 | ->SetConnectedNetworksList( |
| 4108 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4109 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4110 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4111 | |
| 4112 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4113 | // kDefaultRTTMilliSecs. |
| 4114 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4115 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4116 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4117 | next_task_delay); |
| 4118 | |
| 4119 | // The connection should still be alive, and not marked as going away. |
| 4120 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4121 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4122 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4123 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4124 | |
| 4125 | // Resume quic data and a connectivity probe response will be read on the new |
| 4126 | // socket. |
| 4127 | quic_data2.Resume(); |
| 4128 | |
| 4129 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4130 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4131 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4132 | |
| 4133 | // There should be three pending tasks, the nearest one will complete |
| 4134 | // migration to the new network. |
| 4135 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4136 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4137 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4138 | task_runner->FastForwardBy(next_task_delay); |
| 4139 | |
| 4140 | // Response headers are received over the new network. |
| 4141 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4142 | EXPECT_EQ(200, response.headers->response_code()); |
| 4143 | |
| 4144 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4145 | // probe and has been cancelled due to successful migration. |
| 4146 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4147 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4148 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4149 | next_task_delay); |
| 4150 | task_runner->FastForwardBy(next_task_delay); |
| 4151 | |
| 4152 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4153 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4154 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4155 | base::TimeDelta expected_delay = |
| 4156 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4157 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4158 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4159 | |
| 4160 | // Deliver a signal that the alternate network now becomes default to session, |
| 4161 | // this will cancel mgirate back to default network timer. |
| 4162 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4163 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4164 | |
| 4165 | task_runner->FastForwardBy(next_task_delay); |
| 4166 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4167 | |
| 4168 | // Verify that the session is still alive. |
| 4169 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4170 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4171 | |
| 4172 | stream.reset(); |
| 4173 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4174 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4175 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4176 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4177 | } |
| 4178 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4179 | // This test verifies that multiple sessions are migrated on connection |
| 4180 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4181 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4182 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4183 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4184 | |
| 4185 | MockQuicData socket_data1; |
| 4186 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4187 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4188 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4189 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4190 | MockQuicData socket_data2; |
| 4191 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4192 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4193 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4194 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4195 | |
| 4196 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4197 | HostPortPair server2(kServer2HostName, 443); |
| 4198 | |
| 4199 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4200 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4201 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4202 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4203 | host_resolver_->set_synchronous_mode(true); |
| 4204 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4205 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4206 | |
| 4207 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4208 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4209 | EXPECT_EQ(OK, |
| 4210 | request1.Request( |
| 4211 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4212 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4213 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4214 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4215 | EXPECT_TRUE(stream1.get()); |
| 4216 | |
| 4217 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4218 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4219 | EXPECT_EQ(OK, |
| 4220 | request2.Request( |
| 4221 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4222 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4223 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4224 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4225 | EXPECT_TRUE(stream2.get()); |
| 4226 | |
| 4227 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4228 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4229 | EXPECT_NE(session1, session2); |
| 4230 | |
| 4231 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4232 | // stream. |
| 4233 | HttpRequestInfo request_info1; |
| 4234 | request_info1.method = "GET"; |
| 4235 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4236 | request_info1.traffic_annotation = |
| 4237 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4238 | EXPECT_EQ(OK, |
| 4239 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4240 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4241 | HttpResponseInfo response1; |
| 4242 | HttpRequestHeaders request_headers1; |
| 4243 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4244 | callback_.callback())); |
| 4245 | |
| 4246 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4247 | // stream. |
| 4248 | HttpRequestInfo request_info2; |
| 4249 | request_info2.method = "GET"; |
| 4250 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4251 | request_info2.traffic_annotation = |
| 4252 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4253 | EXPECT_EQ(OK, |
| 4254 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4255 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4256 | HttpResponseInfo response2; |
| 4257 | HttpRequestHeaders request_headers2; |
| 4258 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4259 | callback_.callback())); |
| 4260 | |
| 4261 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4262 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4263 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4264 | |
| 4265 | // Ensure that both sessions are paused but alive. |
| 4266 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4267 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4268 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4269 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4270 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4271 | MockConnect connect_result = |
| 4272 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4273 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4274 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4275 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4276 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4277 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4278 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4279 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4280 | // Connect the new network and cause migration to bad sockets, causing |
| 4281 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4282 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4283 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4284 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4285 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4286 | |
| 4287 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4288 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4289 | |
| 4290 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4291 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4292 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4293 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4294 | } |
| 4295 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4296 | // This test verifies that session attempts connection migration with signals |
| 4297 | // delivered in the following order (no alternate network is available): |
| 4298 | // - path degrading is detected: session attempts connection migration but no |
| 4299 | // alternate network is available, session caches path degrading signal in |
| 4300 | // connection and stays on the original network. |
| 4301 | // - original network backs up, request is served in the orignal network, |
| 4302 | // session is not marked as going away. |
| 4303 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4304 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4305 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4306 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4307 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4308 | MockQuicData quic_data; |
| 4309 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4310 | quic_data.AddWrite(SYNCHRONOUS, |
| 4311 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4312 | quic_data.AddWrite(SYNCHRONOUS, |
| 4313 | ConstructGetRequestPacket( |
| 4314 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4315 | true, &header_stream_offset)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4316 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4317 | |
| 4318 | // The rest of the data will still flow in the original socket as there is no |
| 4319 | // new network after path degrading. |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4320 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 4321 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4322 | false, false)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4323 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4324 | quic_data.AddWrite( |
| 4325 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4326 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4327 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4328 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4329 | |
| 4330 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4331 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4332 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4333 | request.Request( |
| 4334 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4335 | SocketTag(), |
| 4336 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4337 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4338 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4339 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4340 | EXPECT_TRUE(stream.get()); |
| 4341 | |
| 4342 | // Cause QUIC stream to be created. |
| 4343 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4344 | request_info.method = "GET"; |
| 4345 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4346 | request_info.traffic_annotation = |
| 4347 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4348 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4349 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4350 | |
| 4351 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4352 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4353 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4354 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4355 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4356 | // Send GET request on stream. |
| 4357 | HttpResponseInfo response; |
| 4358 | HttpRequestHeaders request_headers; |
| 4359 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4360 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4361 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4362 | // Trigger connection migration on path degrading. Since there are no networks |
| 4363 | // to migrate to, the session will remain on the original network, not marked |
| 4364 | // as going away. |
| 4365 | session->connection()->OnPathDegradingTimeout(); |
| 4366 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4367 | |
| 4368 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4369 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4370 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4371 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4372 | |
| 4373 | // Resume so that rest of the data will flow in the original socket. |
| 4374 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4375 | |
| 4376 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4377 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4378 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4379 | |
| 4380 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4381 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4382 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4383 | } |
| 4384 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4385 | // This test verifies that session with non-migratable stream will probe the |
| 4386 | // alternate network on path degrading, and close the non-migratable streams |
| 4387 | // when probe is successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4388 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4389 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4390 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4391 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4392 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4393 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4394 | MockQuicData socket_data; |
| 4395 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4396 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4397 | socket_data.AddWrite( |
| 4398 | SYNCHRONOUS, |
| 4399 | client_maker_.MakeRstAckAndConnectionClosePacket( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4400 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Fan Yang | 7c68f63 | 2018-11-06 03:05:38 | [diff] [blame] | 4401 | quic::QUIC_STREAM_CANCELLED, |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4402 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 4403 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4404 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4405 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4406 | // Set up the second socket data provider that is used for probing. |
| 4407 | MockQuicData quic_data1; |
| 4408 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4409 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4410 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4411 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4412 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4413 | quic_data1.AddRead(ASYNC, |
| 4414 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4415 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4416 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4417 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4418 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4419 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4420 | request.Request( |
| 4421 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4422 | SocketTag(), |
| 4423 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4424 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4425 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4426 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4427 | EXPECT_TRUE(stream.get()); |
| 4428 | |
| 4429 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4430 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4431 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4432 | request_info.traffic_annotation = |
| 4433 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4434 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4435 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4436 | |
| 4437 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4438 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4439 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4440 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4441 | |
| 4442 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4443 | // this should cause session to be continue without migrating. |
| 4444 | session->OnPathDegrading(); |
| 4445 | |
| 4446 | // Run the message loop so that data queued in the new socket is read by the |
| 4447 | // packet reader. |
| 4448 | base::RunLoop().RunUntilIdle(); |
| 4449 | |
| 4450 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4451 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4452 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4453 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4454 | // Resume the data to read the connectivity probing response to declare probe |
| 4455 | // as successful. Non-migratable streams will be closed. |
| 4456 | quic_data1.Resume(); |
| 4457 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4458 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4459 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4460 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4461 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4462 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4463 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4464 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4465 | } |
| 4466 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4467 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4468 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4469 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4470 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4471 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4472 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4473 | MockQuicData socket_data; |
| 4474 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4475 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4476 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4477 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4478 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4479 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4480 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4481 | |
| 4482 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4483 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4484 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4485 | request.Request( |
| 4486 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4487 | SocketTag(), |
| 4488 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4489 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4490 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4491 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4492 | EXPECT_TRUE(stream.get()); |
| 4493 | |
| 4494 | // Cause QUIC stream to be created. |
| 4495 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4496 | request_info.traffic_annotation = |
| 4497 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4498 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4499 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4500 | |
| 4501 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4502 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4503 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4504 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4505 | |
| 4506 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4507 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4508 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4509 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4510 | |
| 4511 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4512 | // this should cause session to be continue without migrating. |
| 4513 | session->OnPathDegrading(); |
| 4514 | |
| 4515 | // Run the message loop so that data queued in the new socket is read by the |
| 4516 | // packet reader. |
| 4517 | base::RunLoop().RunUntilIdle(); |
| 4518 | |
| 4519 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4520 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4521 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4522 | |
| 4523 | stream.reset(); |
| 4524 | |
| 4525 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4526 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4527 | } |
| 4528 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4529 | // Regression test for http://crbug.com/791886. |
| 4530 | // This test verifies that the old packet writer which encountered an |
| 4531 | // asynchronous write error will be blocked during migration on write error. New |
| 4532 | // packets would not be written until the one with write error is rewritten on |
| 4533 | // the new network. |
| 4534 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4535 | InitializeConnectionMigrationV2Test( |
| 4536 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4537 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4538 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4539 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4540 | |
| 4541 | // Using a testing task runner so that we can control time. |
| 4542 | // base::RunLoop() controls mocked socket writes and reads. |
| 4543 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4544 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4545 | |
| 4546 | MockQuicData socket_data; |
| 4547 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4548 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4549 | socket_data.AddWrite( |
| 4550 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4551 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4552 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4553 | |
| 4554 | // Set up second socket data provider that is used after |
| 4555 | // migration. The request is rewritten to this new socket, and the |
| 4556 | // response to the request is read on this new socket. |
| 4557 | MockQuicData socket_data1; |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4558 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4559 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4560 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4561 | true, &header_stream_offset)); |
| 4562 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4563 | ConstructGetRequestPacket( |
| 4564 | 3, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4565 | GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4566 | true, &header_stream_offset)); |
| 4567 | socket_data1.AddRead( |
| 4568 | ASYNC, |
| 4569 | ConstructOkResponsePacket( |
| 4570 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 4571 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4572 | socket_data1.AddWrite( |
| 4573 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4574 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4575 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4576 | socket_data1.AddWrite( |
| 4577 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4578 | 5, false, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4579 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4580 | |
| 4581 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4582 | |
| 4583 | // Create request #1 and QuicHttpStream. |
| 4584 | QuicStreamRequest request1(factory_.get()); |
| 4585 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4586 | request1.Request( |
| 4587 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4588 | SocketTag(), |
| 4589 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4590 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4591 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4592 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4593 | EXPECT_TRUE(stream1.get()); |
| 4594 | |
| 4595 | HttpRequestInfo request_info1; |
| 4596 | request_info1.method = "GET"; |
| 4597 | request_info1.url = GURL("https://www.example.org/"); |
| 4598 | request_info1.traffic_annotation = |
| 4599 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4600 | EXPECT_EQ(OK, |
| 4601 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4602 | net_log_, CompletionOnceCallback())); |
| 4603 | |
| 4604 | // Request #2 returns synchronously because it pools to existing session. |
| 4605 | TestCompletionCallback callback2; |
| 4606 | QuicStreamRequest request2(factory_.get()); |
| 4607 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4608 | DEFAULT_PRIORITY, SocketTag(), |
| 4609 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4610 | &net_error_details_, |
| 4611 | failed_on_default_network_callback_, |
| 4612 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4613 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4614 | EXPECT_TRUE(stream2.get()); |
| 4615 | |
| 4616 | HttpRequestInfo request_info2; |
| 4617 | request_info2.method = "GET"; |
| 4618 | request_info2.url = GURL("https://www.example.org/"); |
| 4619 | request_info2.traffic_annotation = |
| 4620 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4621 | EXPECT_EQ(OK, |
| 4622 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4623 | net_log_, CompletionOnceCallback())); |
| 4624 | |
| 4625 | // Ensure that session is alive and active. |
| 4626 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4627 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4628 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4629 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4630 | |
| 4631 | // Send GET request on stream1. This should cause an async write error. |
| 4632 | HttpResponseInfo response; |
| 4633 | HttpRequestHeaders request_headers; |
| 4634 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4635 | callback_.callback())); |
| 4636 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4637 | |
| 4638 | // Run the message loop so that asynchronous write completes and a connection |
| 4639 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4640 | // runner. |
| 4641 | base::RunLoop().RunUntilIdle(); |
| 4642 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4643 | |
| 4644 | // Send GET request on stream. This will cause another write attempt before |
| 4645 | // migration on write error is exectued. |
| 4646 | HttpResponseInfo response2; |
| 4647 | HttpRequestHeaders request_headers2; |
| 4648 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4649 | callback2.callback())); |
| 4650 | |
| 4651 | // Run the task runner so that migration on write error is finally executed. |
| 4652 | task_runner->RunUntilIdle(); |
| 4653 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4654 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4655 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4656 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4657 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4658 | // There should be one task posted to migrate back to the default network in |
| 4659 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4660 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4661 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4662 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4663 | |
| 4664 | // Verify that response headers on the migrated socket were delivered to the |
| 4665 | // stream. |
| 4666 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4667 | EXPECT_EQ(200, response.headers->response_code()); |
| 4668 | |
| 4669 | stream1.reset(); |
| 4670 | stream2.reset(); |
| 4671 | |
| 4672 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4673 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4674 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4675 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4676 | } |
| 4677 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4678 | // Verify session is not marked as going away after connection migration on |
| 4679 | // write error and migrate back to default network logic is applied to bring the |
| 4680 | // migrated session back to the default network. Migration singals delivered |
| 4681 | // in the following order (alternate network is always availabe): |
| 4682 | // - session on the default network encountered a write error; |
| 4683 | // - session successfully migrated to the non-default network; |
| 4684 | // - session attempts to migrate back to default network post migration; |
| 4685 | // - migration back to the default network is successful. |
| 4686 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
| 4687 | InitializeConnectionMigrationV2Test( |
| 4688 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4689 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4690 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4691 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4692 | |
| 4693 | // Using a testing task runner so that we can control time. |
| 4694 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4695 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4696 | |
| 4697 | MockQuicData socket_data; |
| 4698 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4699 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4700 | socket_data.AddWrite( |
| 4701 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4702 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4703 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4704 | |
| 4705 | // Set up second socket data provider that is used after |
| 4706 | // migration. The request is rewritten to this new socket, and the |
| 4707 | // response to the request is read on this new socket. |
| 4708 | MockQuicData quic_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4709 | quic_data2.AddWrite( |
| 4710 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4711 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4712 | true, &header_stream_offset)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4713 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4714 | ASYNC, |
| 4715 | ConstructOkResponsePacket( |
| 4716 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4717 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4718 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4719 | |
| 4720 | // Create request QuicHttpStream. |
| 4721 | QuicStreamRequest request1(factory_.get()); |
| 4722 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4723 | request1.Request( |
| 4724 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4725 | SocketTag(), |
| 4726 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4727 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4728 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4729 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4730 | EXPECT_TRUE(stream1.get()); |
| 4731 | |
| 4732 | HttpRequestInfo request_info1; |
| 4733 | request_info1.method = "GET"; |
| 4734 | request_info1.url = GURL("https://www.example.org/"); |
| 4735 | request_info1.traffic_annotation = |
| 4736 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4737 | EXPECT_EQ(OK, |
| 4738 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4739 | net_log_, CompletionOnceCallback())); |
| 4740 | |
| 4741 | // Ensure that session is alive and active. |
| 4742 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4743 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4744 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4745 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4746 | |
| 4747 | // Send GET request. This should cause an async write error. |
| 4748 | HttpResponseInfo response; |
| 4749 | HttpRequestHeaders request_headers; |
| 4750 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4751 | callback_.callback())); |
| 4752 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4753 | |
| 4754 | // Run the message loop so that asynchronous write completes and a connection |
| 4755 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4756 | // runner. |
| 4757 | base::RunLoop().RunUntilIdle(); |
| 4758 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4759 | |
| 4760 | // Run the task runner so that migration on write error is finally executed. |
| 4761 | task_runner->RunUntilIdle(); |
| 4762 | |
| 4763 | // Verify the session is still alive and not marked as going away. |
| 4764 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4765 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4766 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4767 | // There should be one task posted to migrate back to the default network in |
| 4768 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4769 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4770 | base::TimeDelta expected_delay = |
| 4771 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4772 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4773 | |
| 4774 | // Verify that response headers on the migrated socket were delivered to the |
| 4775 | // stream. |
| 4776 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4777 | EXPECT_EQ(200, response.headers->response_code()); |
| 4778 | |
| 4779 | // Set up the third socket data provider for migrate back to default network. |
| 4780 | MockQuicData quic_data3; |
| 4781 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4782 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4783 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4784 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4785 | quic_data3.AddRead(ASYNC, |
| 4786 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4787 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4788 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4789 | quic_data3.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4790 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4791 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4792 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4793 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4794 | |
| 4795 | // Fast forward to fire the migrate back timer and verify the session |
| 4796 | // successfully migrates back to the default network. |
| 4797 | task_runner->FastForwardBy(expected_delay); |
| 4798 | |
| 4799 | // Verify the session is still alive and not marked as going away. |
| 4800 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4801 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4802 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4803 | |
| 4804 | // There should be one task posted to one will resend a connectivity probe and |
| 4805 | // the other will retry migrate back, both are cancelled. |
| 4806 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4807 | task_runner->FastForwardBy( |
| 4808 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4809 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4810 | |
| 4811 | stream1.reset(); |
| 4812 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4813 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4814 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4815 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4816 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4817 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4818 | } |
| 4819 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4820 | // This test verifies that the connection will not attempt connection migration |
| 4821 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4822 | // and handshake is not confirmed. |
| 4823 | TEST_P(QuicStreamFactoryTest, |
| 4824 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 4825 | InitializeConnectionMigrationV2Test( |
| 4826 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4827 | |
| 4828 | // Using a testing task runner. |
| 4829 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4830 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4831 | |
| 4832 | // Use cold start mode to send crypto message for handshake. |
| 4833 | crypto_client_stream_factory_.set_handshake_mode( |
| 4834 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4835 | |
| 4836 | MockQuicData socket_data; |
| 4837 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4838 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4839 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4840 | |
| 4841 | // Create request and QuicHttpStream. |
| 4842 | QuicStreamRequest request(factory_.get()); |
| 4843 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4844 | request.Request( |
| 4845 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4846 | SocketTag(), |
| 4847 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4848 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4849 | |
| 4850 | base::RunLoop().RunUntilIdle(); |
| 4851 | |
| 4852 | // Ensure that session is alive but not active. |
| 4853 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4854 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4855 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4856 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4857 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4858 | |
| 4859 | // Cause the connection to report path degrading to the session. |
| 4860 | // Session will ignore the signal as handshake is not completed. |
| 4861 | session->connection()->OnPathDegradingTimeout(); |
| 4862 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4863 | |
| 4864 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4865 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4866 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4867 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4868 | } |
| 4869 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4870 | // This test verifies that if a connection is closed with |
| 4871 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 4872 | // alternate network, no new connection will be created. |
| 4873 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 4874 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4875 | } |
| 4876 | |
| 4877 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 4878 | // and there is no alternate network, no new connection will be created. |
| 4879 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 4880 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4881 | } |
| 4882 | |
| 4883 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 4884 | quic::QuicErrorCode quic_error) { |
| 4885 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4886 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4887 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4888 | |
| 4889 | // Using a testing task runner. |
| 4890 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4891 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4892 | |
| 4893 | // Use cold start mode to send crypto message for handshake. |
| 4894 | crypto_client_stream_factory_.set_handshake_mode( |
| 4895 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4896 | |
| 4897 | MockQuicData socket_data; |
| 4898 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4899 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4900 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4901 | |
| 4902 | // Create request. |
| 4903 | QuicStreamRequest request(factory_.get()); |
| 4904 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4905 | request.Request( |
| 4906 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4907 | SocketTag(), |
| 4908 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4909 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4910 | |
| 4911 | base::RunLoop().RunUntilIdle(); |
| 4912 | |
| 4913 | // Ensure that session is alive but not active. |
| 4914 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4915 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4916 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4917 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4918 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4919 | |
| 4920 | // Cause the connection to report path degrading to the session. |
| 4921 | // Session will ignore the signal as handshake is not completed. |
| 4922 | session->connection()->OnPathDegradingTimeout(); |
| 4923 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4924 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4925 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4926 | |
| 4927 | // Cause the connection to close due to |quic_error| before handshake. |
| 4928 | quic::QuicString error_details; |
| 4929 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 4930 | error_details = "No recent network activity."; |
| 4931 | } else { |
| 4932 | error_details = "Handshake timeout expired."; |
| 4933 | } |
| 4934 | session->connection()->CloseConnection( |
| 4935 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 4936 | |
| 4937 | // A task will be posted to clean up the session in the factory. |
| 4938 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4939 | task_runner->FastForwardUntilNoTasksRemain(); |
| 4940 | |
| 4941 | // No new session should be created as there is no alternate network. |
| 4942 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4943 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4944 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4945 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4946 | } |
| 4947 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4948 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
| 4949 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4950 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4951 | } |
| 4952 | |
| 4953 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
| 4954 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4955 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4956 | } |
| 4957 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 4958 | // Sets up a test to verify that a new connection will be created on the |
| 4959 | // alternate network after the initial connection fails before handshake with |
| 4960 | // signals delivered in the following order (alternate network is available): |
| 4961 | // - the default network is not able to complete crypto handshake; |
| 4962 | // - the original connection is closed with |quic_error|; |
| 4963 | // - a new connection is created on the alternate network and is able to finish |
| 4964 | // crypto handshake; |
| 4965 | // - the new session on the alternate network attempts to migrate back to the |
| 4966 | // default network by sending probes; |
| 4967 | // - default network being disconnected is delivered: session will stop probing |
| 4968 | // the original network. |
| 4969 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4970 | void QuicStreamFactoryTestBase:: |
| 4971 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4972 | quic::QuicErrorCode quic_error) { |
| 4973 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4974 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 4975 | test_params_.quic_retry_on_alternate_network_before_handshake = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4976 | InitializeConnectionMigrationV2Test( |
| 4977 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4978 | |
| 4979 | // Using a testing task runner. |
| 4980 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4981 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4982 | |
| 4983 | // Use cold start mode to send crypto message for handshake. |
| 4984 | crypto_client_stream_factory_.set_handshake_mode( |
| 4985 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4986 | |
| 4987 | // Socket data for connection on the default network. |
| 4988 | MockQuicData socket_data; |
| 4989 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4990 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4991 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4992 | |
| 4993 | // Socket data for connection on the alternate network. |
| 4994 | MockQuicData socket_data2; |
| 4995 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4996 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 4997 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 4998 | // Change the encryption level after handshake is confirmed. |
| 4999 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5000 | socket_data2.AddWrite( |
| 5001 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5002 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5003 | ASYNC, ConstructGetRequestPacket( |
| 5004 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5005 | &header_stream_offset)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5006 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5007 | ASYNC, |
| 5008 | ConstructOkResponsePacket( |
| 5009 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5010 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5011 | socket_data2.AddWrite( |
| 5012 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5013 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5014 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5015 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5016 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5017 | // Socket data for probing on the default network. |
| 5018 | MockQuicData probing_data; |
| 5019 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5020 | probing_data.AddWrite(SYNCHRONOUS, |
| 5021 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5022 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5023 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5024 | // Create request and QuicHttpStream. |
| 5025 | QuicStreamRequest request(factory_.get()); |
| 5026 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5027 | request.Request( |
| 5028 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5029 | SocketTag(), |
| 5030 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5031 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5032 | |
| 5033 | base::RunLoop().RunUntilIdle(); |
| 5034 | |
| 5035 | // Ensure that session is alive but not active. |
| 5036 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5037 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5038 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5039 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5040 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5041 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5042 | |
| 5043 | quic::QuicString error_details; |
| 5044 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5045 | error_details = "No recent network activity."; |
| 5046 | } else { |
| 5047 | error_details = "Handshake timeout expired."; |
| 5048 | } |
| 5049 | session->connection()->CloseConnection( |
| 5050 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5051 | |
| 5052 | // A task will be posted to clean up the session in the factory. |
| 5053 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5054 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5055 | |
| 5056 | // Verify a new session is created on the alternate network. |
| 5057 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5058 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5059 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5060 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5061 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5062 | |
| 5063 | // Confirm the handshake on the alternate network. |
| 5064 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5065 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5066 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5067 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5068 | // Resume the data now so that data can be sent and read. |
| 5069 | socket_data2.Resume(); |
| 5070 | |
| 5071 | // Create the stream. |
| 5072 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5073 | EXPECT_TRUE(stream.get()); |
| 5074 | HttpRequestInfo request_info; |
| 5075 | request_info.method = "GET"; |
| 5076 | request_info.url = GURL("https://www.example.org/"); |
| 5077 | request_info.traffic_annotation = |
| 5078 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5079 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5080 | net_log_, CompletionOnceCallback())); |
| 5081 | // Send the request. |
| 5082 | HttpResponseInfo response; |
| 5083 | HttpRequestHeaders request_headers; |
| 5084 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5085 | callback_.callback())); |
| 5086 | // Run the message loop to finish asynchronous mock write. |
| 5087 | base::RunLoop().RunUntilIdle(); |
| 5088 | // Read the response. |
| 5089 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5090 | EXPECT_EQ(200, response.headers->response_code()); |
| 5091 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5092 | // There should be a new task posted to migrate back to the default network. |
| 5093 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5094 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5095 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5096 | next_task_delay); |
| 5097 | task_runner->FastForwardBy(next_task_delay); |
| 5098 | |
| 5099 | // There should be two tasks posted. One will retry probing and the other |
| 5100 | // will retry migrate back. |
| 5101 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5102 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5103 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5104 | next_task_delay); |
| 5105 | |
| 5106 | // Deliver the signal that the default network is disconnected. |
| 5107 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5108 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5109 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5110 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5111 | // Deliver the signal that the alternate network is made default. |
| 5112 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5113 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5114 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5115 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5116 | stream.reset(); |
| 5117 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5118 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5119 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5120 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5121 | } |
| 5122 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5123 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5124 | // is triggered before handshake is confirmed and connection migration is turned |
| 5125 | // on. |
| 5126 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 5127 | DCHECK(!test_params_.quic_retry_on_alternate_network_before_handshake); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5128 | InitializeConnectionMigrationV2Test( |
| 5129 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5130 | |
| 5131 | // Use unmocked crypto stream to do crypto connect. |
| 5132 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5133 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5134 | |
| 5135 | MockQuicData socket_data; |
| 5136 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5137 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5138 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5139 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5140 | |
| 5141 | // Create request, should fail after the write of the CHLO fails. |
| 5142 | QuicStreamRequest request(factory_.get()); |
| 5143 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5144 | request.Request( |
| 5145 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5146 | SocketTag(), |
| 5147 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5148 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5149 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5150 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5151 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5152 | |
| 5153 | // Verify new requests can be sent normally. |
| 5154 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5155 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5156 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5157 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5158 | MockQuicData socket_data2; |
| 5159 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5160 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5161 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5162 | |
| 5163 | QuicStreamRequest request2(factory_.get()); |
| 5164 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5165 | request2.Request( |
| 5166 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5167 | SocketTag(), |
| 5168 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5169 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5170 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5171 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5172 | // Run the message loop to complete host resolution. |
| 5173 | base::RunLoop().RunUntilIdle(); |
| 5174 | |
| 5175 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5176 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5177 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5178 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5179 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5180 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5181 | |
| 5182 | // Create QuicHttpStream. |
| 5183 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5184 | EXPECT_TRUE(stream.get()); |
| 5185 | stream.reset(); |
| 5186 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5187 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5188 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5189 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5190 | } |
| 5191 | |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5192 | // Test that if the original connection is closed with QUIC_PACKET_WRITE_ERROR |
| 5193 | // before handshake is confirmed and new connection before handshake is turned |
| 5194 | // on, a new connection will be retried on the alternate network. |
| 5195 | TEST_P(QuicStreamFactoryTest, |
| 5196 | RetryConnectionOnWriteErrorBeforeHandshakeConfirmed) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 5197 | test_params_.quic_retry_on_alternate_network_before_handshake = true; |
Zhongyi Shi | f2524bf | 2019-01-27 07:44:03 | [diff] [blame] | 5198 | InitializeConnectionMigrationV2Test( |
| 5199 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5200 | |
| 5201 | // Use unmocked crypto stream to do crypto connect. |
| 5202 | crypto_client_stream_factory_.set_handshake_mode( |
| 5203 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5204 | |
| 5205 | // Socket data for connection on the default network. |
| 5206 | MockQuicData socket_data; |
| 5207 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5208 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5209 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5210 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5211 | |
| 5212 | // Socket data for connection on the alternate network. |
| 5213 | MockQuicData socket_data2; |
| 5214 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5215 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5216 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5217 | // Change the encryption level after handshake is confirmed. |
| 5218 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5219 | socket_data2.AddWrite( |
| 5220 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5221 | socket_data2.AddWrite( |
| 5222 | ASYNC, ConstructGetRequestPacket( |
| 5223 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5224 | &header_stream_offset)); |
| 5225 | socket_data2.AddRead( |
| 5226 | ASYNC, |
| 5227 | ConstructOkResponsePacket( |
| 5228 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5229 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5230 | socket_data2.AddWrite( |
| 5231 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5232 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5233 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5234 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5235 | |
| 5236 | // Create request, should fail after the write of the CHLO fails. |
| 5237 | QuicStreamRequest request(factory_.get()); |
| 5238 | EXPECT_EQ(ERR_IO_PENDING, |
| 5239 | request.Request( |
| 5240 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5241 | SocketTag(), |
| 5242 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5243 | failed_on_default_network_callback_, callback_.callback())); |
| 5244 | // Ensure that the session is alive but not active. |
| 5245 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5246 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5247 | base::RunLoop().RunUntilIdle(); |
| 5248 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5249 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5250 | |
| 5251 | // Confirm the handshake on the alternate network. |
| 5252 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5253 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5254 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5255 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5256 | |
| 5257 | // Resume the data now so that data can be sent and read. |
| 5258 | socket_data2.Resume(); |
| 5259 | |
| 5260 | // Create the stream. |
| 5261 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5262 | EXPECT_TRUE(stream.get()); |
| 5263 | HttpRequestInfo request_info; |
| 5264 | request_info.method = "GET"; |
| 5265 | request_info.url = GURL("https://www.example.org/"); |
| 5266 | request_info.traffic_annotation = |
| 5267 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5268 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5269 | net_log_, CompletionOnceCallback())); |
| 5270 | // Send the request. |
| 5271 | HttpResponseInfo response; |
| 5272 | HttpRequestHeaders request_headers; |
| 5273 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5274 | callback_.callback())); |
| 5275 | // Run the message loop to finish asynchronous mock write. |
| 5276 | base::RunLoop().RunUntilIdle(); |
| 5277 | // Read the response. |
| 5278 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5279 | EXPECT_EQ(200, response.headers->response_code()); |
| 5280 | |
| 5281 | stream.reset(); |
| 5282 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5283 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5284 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5285 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5286 | } |
| 5287 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5288 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5289 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5290 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5291 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5292 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5293 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5294 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5295 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5296 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5297 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5298 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5299 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5300 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5301 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5302 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5303 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5304 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5305 | |
| 5306 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5307 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5308 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5309 | request.Request( |
| 5310 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5311 | SocketTag(), |
| 5312 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5313 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5314 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5315 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5316 | EXPECT_TRUE(stream.get()); |
| 5317 | |
| 5318 | // Cause QUIC stream to be created. |
| 5319 | HttpRequestInfo request_info; |
| 5320 | request_info.method = "GET"; |
| 5321 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5322 | request_info.traffic_annotation = |
| 5323 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5324 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5325 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5326 | |
| 5327 | // Ensure that session is alive and active. |
| 5328 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5329 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5330 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5331 | |
| 5332 | // Set up second socket data provider that is used after |
| 5333 | // migration. The request is rewritten to this new socket, and the |
| 5334 | // response to the request is read on this new socket. |
| 5335 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5336 | socket_data1.AddWrite( |
| 5337 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5338 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5339 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5340 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5341 | ASYNC, |
| 5342 | ConstructOkResponsePacket( |
| 5343 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5344 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5345 | socket_data1.AddWrite( |
| 5346 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5347 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5348 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5349 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5350 | |
| 5351 | // Send GET request on stream. This should cause a write error, which triggers |
| 5352 | // a connection migration attempt. |
| 5353 | HttpResponseInfo response; |
| 5354 | HttpRequestHeaders request_headers; |
| 5355 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5356 | callback_.callback())); |
| 5357 | |
| 5358 | // Run the message loop so that the migration attempt is executed and |
| 5359 | // data queued in the new socket is read by the packet reader. |
| 5360 | base::RunLoop().RunUntilIdle(); |
| 5361 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5362 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5363 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5364 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5365 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5366 | |
| 5367 | // Verify that response headers on the migrated socket were delivered to the |
| 5368 | // stream. |
| 5369 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5370 | EXPECT_EQ(200, response.headers->response_code()); |
| 5371 | |
| 5372 | stream.reset(); |
| 5373 | |
| 5374 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5375 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5376 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5377 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5378 | } |
| 5379 | |
| 5380 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5381 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5382 | } |
| 5383 | |
| 5384 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5385 | TestMigrationOnWriteError(ASYNC); |
| 5386 | } |
| 5387 | |
| 5388 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5389 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5390 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5391 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5392 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5393 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5394 | // Use the test task runner, to force the migration alarm timeout later. |
| 5395 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5396 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5397 | MockQuicData socket_data; |
| 5398 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5399 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5400 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5401 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5402 | |
| 5403 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5404 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5405 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5406 | request.Request( |
| 5407 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5408 | SocketTag(), |
| 5409 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5410 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5411 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5412 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5413 | EXPECT_TRUE(stream.get()); |
| 5414 | |
| 5415 | // Cause QUIC stream to be created. |
| 5416 | HttpRequestInfo request_info; |
| 5417 | request_info.method = "GET"; |
| 5418 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5419 | request_info.traffic_annotation = |
| 5420 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5421 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5422 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5423 | |
| 5424 | // Ensure that session is alive and active. |
| 5425 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5426 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5427 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5428 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5429 | // Send GET request on stream. This causes a write error, which triggers |
| 5430 | // a connection migration attempt. Since there are no networks |
| 5431 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5432 | HttpResponseInfo response; |
| 5433 | HttpRequestHeaders request_headers; |
| 5434 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5435 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5436 | |
| 5437 | // Complete any pending writes. Pending async MockQuicData writes |
| 5438 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5439 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5440 | |
| 5441 | // Write error causes migration task to be posted. Spin the loop. |
| 5442 | if (write_error_mode == ASYNC) |
| 5443 | runner_->RunNextTask(); |
| 5444 | |
| 5445 | // Migration has not yet failed. The session should be alive and active. |
| 5446 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5447 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5448 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5449 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5450 | |
| 5451 | // The migration will not fail until the migration alarm timeout. |
| 5452 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5453 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5454 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5455 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5456 | |
| 5457 | // Force migration alarm timeout to run. |
| 5458 | RunTestLoopUntilIdle(); |
| 5459 | |
| 5460 | // The connection should be closed. A request for response headers |
| 5461 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5462 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5463 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5464 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5465 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5466 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5467 | |
Zhongyi Shi | 59aaf07 | 2019-01-17 03:32:13 | [diff] [blame] | 5468 | NetErrorDetails error_details; |
| 5469 | stream->PopulateNetErrorDetails(&error_details); |
| 5470 | EXPECT_EQ(error_details.quic_connection_error, |
| 5471 | quic::QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
| 5472 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5473 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5474 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5475 | } |
| 5476 | |
| 5477 | TEST_P(QuicStreamFactoryTest, |
| 5478 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5479 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5480 | } |
| 5481 | |
| 5482 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5483 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5484 | } |
| 5485 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5486 | TEST_P(QuicStreamFactoryTest, |
| 5487 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5488 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5489 | } |
| 5490 | |
| 5491 | TEST_P(QuicStreamFactoryTest, |
| 5492 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5493 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5494 | } |
| 5495 | |
| 5496 | // Sets up a test which verifies that connection migration on write error can |
| 5497 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5498 | // migratable streams. |
| 5499 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5500 | IoMode write_error_mode) { |
| 5501 | InitializeConnectionMigrationV2Test( |
| 5502 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5503 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5504 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5505 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5506 | |
| 5507 | MockQuicData socket_data; |
| 5508 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5509 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5510 | socket_data.AddWrite( |
| 5511 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5512 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5513 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5514 | |
| 5515 | // Set up second socket data provider that is used after |
| 5516 | // migration. The request is rewritten to this new socket, and the |
| 5517 | // response to the request is read on this new socket. |
| 5518 | MockQuicData socket_data1; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5519 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5520 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5521 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5522 | true, &header_stream_offset)); |
| 5523 | socket_data1.AddRead( |
| 5524 | ASYNC, |
| 5525 | ConstructOkResponsePacket( |
| 5526 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5527 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5528 | socket_data1.AddWrite( |
| 5529 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5530 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5531 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5532 | socket_data1.AddWrite( |
| 5533 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 5534 | 4, false, GetNthClientInitiatedBidirectionalStreamId(1), |
| 5535 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5536 | |
| 5537 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5538 | |
| 5539 | // Create request #1 and QuicHttpStream. |
| 5540 | QuicStreamRequest request1(factory_.get()); |
| 5541 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5542 | request1.Request( |
| 5543 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5544 | SocketTag(), |
| 5545 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5546 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5547 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5548 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5549 | EXPECT_TRUE(stream1.get()); |
| 5550 | |
| 5551 | HttpRequestInfo request_info1; |
| 5552 | request_info1.method = "GET"; |
| 5553 | request_info1.url = GURL("https://www.example.org/"); |
| 5554 | request_info1.traffic_annotation = |
| 5555 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5556 | EXPECT_EQ(OK, |
| 5557 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5558 | net_log_, CompletionOnceCallback())); |
| 5559 | |
| 5560 | // Second request returns synchronously because it pools to existing session. |
| 5561 | TestCompletionCallback callback2; |
| 5562 | QuicStreamRequest request2(factory_.get()); |
| 5563 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5564 | DEFAULT_PRIORITY, SocketTag(), |
| 5565 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5566 | &net_error_details_, |
| 5567 | failed_on_default_network_callback_, |
| 5568 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5569 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5570 | EXPECT_TRUE(stream2.get()); |
| 5571 | HttpRequestInfo request_info2; |
| 5572 | request_info2.method = "GET"; |
| 5573 | request_info2.url = GURL("https://www.example.org/"); |
| 5574 | request_info2.traffic_annotation = |
| 5575 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5576 | EXPECT_EQ(OK, |
| 5577 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5578 | net_log_, CompletionOnceCallback())); |
| 5579 | |
| 5580 | // Ensure that session is alive and active. |
| 5581 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5582 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5583 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5584 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5585 | |
| 5586 | // Send GET request on stream. This should cause a write error, which triggers |
| 5587 | // a connection migration attempt. |
| 5588 | HttpResponseInfo response; |
| 5589 | HttpRequestHeaders request_headers; |
| 5590 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5591 | callback_.callback())); |
| 5592 | |
| 5593 | // Run the message loop so that the migration attempt is executed and |
| 5594 | // data queued in the new socket is read by the packet reader. |
| 5595 | base::RunLoop().RunUntilIdle(); |
| 5596 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5597 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5598 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5599 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5600 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5601 | |
| 5602 | // Verify that response headers on the migrated socket were delivered to the |
| 5603 | // stream. |
| 5604 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5605 | EXPECT_EQ(200, response.headers->response_code()); |
| 5606 | |
| 5607 | stream1.reset(); |
| 5608 | stream2.reset(); |
| 5609 | |
| 5610 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5611 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5612 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5613 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5614 | } |
| 5615 | |
| 5616 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5617 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5618 | } |
| 5619 | |
| 5620 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5621 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5622 | } |
| 5623 | |
| 5624 | // Sets up a test that verifies connection migration manages to migrate to |
| 5625 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5626 | // |write_error_mode| on the original network. |
| 5627 | // Note there are mixed types of unfinished requests before migration: one |
| 5628 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5629 | // error. |
| 5630 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5631 | IoMode write_error_mode) { |
| 5632 | InitializeConnectionMigrationV2Test( |
| 5633 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5634 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5635 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5636 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5637 | |
| 5638 | int packet_number = 1; |
| 5639 | MockQuicData socket_data; |
| 5640 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5641 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5642 | socket_data.AddWrite( |
| 5643 | SYNCHRONOUS, |
| 5644 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5645 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5646 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5647 | |
| 5648 | // Set up second socket data provider that is used after |
| 5649 | // migration. The request is rewritten to this new socket, and the |
| 5650 | // response to the request is read on this new socket. |
| 5651 | MockQuicData socket_data1; |
| 5652 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5653 | SYNCHRONOUS, |
| 5654 | ConstructGetRequestPacket(packet_number++, |
| 5655 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5656 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5657 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5658 | SYNCHRONOUS, |
| 5659 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5660 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5661 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5662 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5663 | ASYNC, |
| 5664 | ConstructOkResponsePacket( |
| 5665 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5666 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5667 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5668 | SYNCHRONOUS, |
| 5669 | client_maker_.MakeAckAndRstPacket( |
| 5670 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5671 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5672 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5673 | |
| 5674 | // Create request #1 and QuicHttpStream. |
| 5675 | QuicStreamRequest request1(factory_.get()); |
| 5676 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5677 | request1.Request( |
| 5678 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5679 | SocketTag(), |
| 5680 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5681 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5682 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5683 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5684 | EXPECT_TRUE(stream1.get()); |
| 5685 | |
| 5686 | HttpRequestInfo request_info1; |
| 5687 | request_info1.method = "GET"; |
| 5688 | request_info1.url = GURL("https://www.example.org/"); |
| 5689 | request_info1.traffic_annotation = |
| 5690 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5691 | EXPECT_EQ(OK, |
| 5692 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5693 | net_log_, CompletionOnceCallback())); |
| 5694 | |
| 5695 | // Second request returns synchronously because it pools to existing session. |
| 5696 | TestCompletionCallback callback2; |
| 5697 | QuicStreamRequest request2(factory_.get()); |
| 5698 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5699 | DEFAULT_PRIORITY, SocketTag(), |
| 5700 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5701 | &net_error_details_, |
| 5702 | failed_on_default_network_callback_, |
| 5703 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5704 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5705 | EXPECT_TRUE(stream2.get()); |
| 5706 | |
| 5707 | HttpRequestInfo request_info2; |
| 5708 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5709 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5710 | request_info2.url = GURL("https://www.example.org/"); |
| 5711 | request_info2.traffic_annotation = |
| 5712 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5713 | EXPECT_EQ(OK, |
| 5714 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5715 | net_log_, CompletionOnceCallback())); |
| 5716 | |
| 5717 | // Ensure that session is alive and active. |
| 5718 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5719 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5720 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5721 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5722 | |
| 5723 | // Send GET request on stream 1. This should cause a write error, which |
| 5724 | // triggers a connection migration attempt. |
| 5725 | HttpResponseInfo response; |
| 5726 | HttpRequestHeaders request_headers; |
| 5727 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5728 | callback_.callback())); |
| 5729 | |
| 5730 | // Run the message loop so that the migration attempt is executed and |
| 5731 | // data queued in the new socket is read by the packet reader. |
| 5732 | base::RunLoop().RunUntilIdle(); |
| 5733 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5734 | // Verify that the session is still alive and not marked as going away. |
| 5735 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5736 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5737 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5738 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5739 | |
| 5740 | // Verify that response headers on the migrated socket were delivered to the |
| 5741 | // stream. |
| 5742 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5743 | EXPECT_EQ(200, response.headers->response_code()); |
| 5744 | |
| 5745 | stream1.reset(); |
| 5746 | |
| 5747 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5748 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5749 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5750 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5751 | } |
| 5752 | |
| 5753 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5754 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5755 | } |
| 5756 | |
| 5757 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5758 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5759 | } |
| 5760 | |
| 5761 | // The one triggers write error is a non-migratable stream. |
| 5762 | // Sets up a test that verifies connection migration manages to migrate to |
| 5763 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5764 | // |write_error_mode| on the original network. |
| 5765 | // Note there are mixed types of unfinished requests before migration: one |
| 5766 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5767 | // error. |
| 5768 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5769 | IoMode write_error_mode) { |
| 5770 | InitializeConnectionMigrationV2Test( |
| 5771 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5772 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5773 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5774 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5775 | |
| 5776 | int packet_number = 1; |
| 5777 | MockQuicData socket_data; |
| 5778 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5779 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5780 | socket_data.AddWrite( |
| 5781 | SYNCHRONOUS, |
| 5782 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5783 | socket_data.AddWrite(write_error_mode, |
| 5784 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5785 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5786 | |
| 5787 | // Set up second socket data provider that is used after |
| 5788 | // migration. The request is rewritten to this new socket, and the |
| 5789 | // response to the request is read on this new socket. |
| 5790 | MockQuicData socket_data1; |
| 5791 | // The packet triggered writer error will be sent anyway even if the stream |
| 5792 | // will be cancelled later. |
| 5793 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5794 | SYNCHRONOUS, |
| 5795 | ConstructGetRequestPacket(packet_number++, |
| 5796 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5797 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5798 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5799 | SYNCHRONOUS, |
| 5800 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5801 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5802 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5803 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5804 | SYNCHRONOUS, |
| 5805 | ConstructGetRequestPacket(packet_number++, |
| 5806 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5807 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5808 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5809 | ASYNC, |
| 5810 | ConstructOkResponsePacket( |
| 5811 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5812 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5813 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5814 | SYNCHRONOUS, |
| 5815 | client_maker_.MakeAckAndRstPacket( |
| 5816 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5817 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5818 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5819 | |
| 5820 | // Create request #1 and QuicHttpStream. |
| 5821 | QuicStreamRequest request1(factory_.get()); |
| 5822 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5823 | request1.Request( |
| 5824 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5825 | SocketTag(), |
| 5826 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5827 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5828 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5829 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5830 | EXPECT_TRUE(stream1.get()); |
| 5831 | |
| 5832 | HttpRequestInfo request_info1; |
| 5833 | request_info1.method = "GET"; |
| 5834 | request_info1.url = GURL("https://www.example.org/"); |
| 5835 | request_info1.traffic_annotation = |
| 5836 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5837 | EXPECT_EQ(OK, |
| 5838 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5839 | net_log_, CompletionOnceCallback())); |
| 5840 | |
| 5841 | // Second request returns synchronously because it pools to existing session. |
| 5842 | TestCompletionCallback callback2; |
| 5843 | QuicStreamRequest request2(factory_.get()); |
| 5844 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5845 | DEFAULT_PRIORITY, SocketTag(), |
| 5846 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5847 | &net_error_details_, |
| 5848 | failed_on_default_network_callback_, |
| 5849 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5850 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5851 | EXPECT_TRUE(stream2.get()); |
| 5852 | |
| 5853 | HttpRequestInfo request_info2; |
| 5854 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5855 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5856 | request_info2.url = GURL("https://www.example.org/"); |
| 5857 | request_info2.traffic_annotation = |
| 5858 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5859 | EXPECT_EQ(OK, |
| 5860 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5861 | net_log_, CompletionOnceCallback())); |
| 5862 | |
| 5863 | // Ensure that session is alive and active. |
| 5864 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5865 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5866 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5867 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5868 | |
| 5869 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 5870 | // write error, which triggers a connection migration attempt. |
| 5871 | HttpResponseInfo response2; |
| 5872 | HttpRequestHeaders request_headers2; |
| 5873 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 5874 | callback2.callback())); |
| 5875 | |
| 5876 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5877 | // data queued in the new socket is read by the packet reader. Session is |
| 5878 | // still alive and not marked as going away, non-migratable stream will be |
| 5879 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5880 | base::RunLoop().RunUntilIdle(); |
| 5881 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5882 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5883 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5884 | |
| 5885 | // Send GET request on stream 1. |
| 5886 | HttpResponseInfo response; |
| 5887 | HttpRequestHeaders request_headers; |
| 5888 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5889 | callback_.callback())); |
| 5890 | |
| 5891 | base::RunLoop().RunUntilIdle(); |
| 5892 | |
| 5893 | // Verify that response headers on the migrated socket were delivered to the |
| 5894 | // stream. |
| 5895 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5896 | EXPECT_EQ(200, response.headers->response_code()); |
| 5897 | |
| 5898 | stream1.reset(); |
| 5899 | |
| 5900 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5901 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5902 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5903 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5904 | } |
| 5905 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5906 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
| 5907 | IoMode write_error_mode) { |
| 5908 | DVLOG(1) << "Mode: " |
| 5909 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5910 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5911 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5912 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5913 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5914 | |
| 5915 | MockQuicData socket_data; |
| 5916 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5917 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5918 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5919 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5920 | |
| 5921 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5922 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5923 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5924 | request.Request( |
| 5925 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5926 | SocketTag(), |
| 5927 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5928 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5929 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5930 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5931 | EXPECT_TRUE(stream.get()); |
| 5932 | |
| 5933 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 5934 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5935 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5936 | request_info.method = "GET"; |
| 5937 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5938 | request_info.traffic_annotation = |
| 5939 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5940 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5941 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5942 | |
| 5943 | // Ensure that session is alive and active. |
| 5944 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5945 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5946 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5947 | |
| 5948 | // Send GET request on stream. This should cause a write error, which triggers |
| 5949 | // a connection migration attempt. |
| 5950 | HttpResponseInfo response; |
| 5951 | HttpRequestHeaders request_headers; |
| 5952 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5953 | callback_.callback())); |
| 5954 | |
| 5955 | // Run message loop to execute migration attempt. |
| 5956 | base::RunLoop().RunUntilIdle(); |
| 5957 | |
| 5958 | // Migration fails, and session is closed and deleted. |
| 5959 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5960 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5961 | |
| 5962 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5963 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5964 | } |
| 5965 | |
| 5966 | TEST_P(QuicStreamFactoryTest, |
| 5967 | MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 5968 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 5969 | } |
| 5970 | |
| 5971 | TEST_P(QuicStreamFactoryTest, |
| 5972 | MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 5973 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC); |
| 5974 | } |
| 5975 | |
| 5976 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 5977 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5978 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5979 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5980 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5981 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5982 | |
| 5983 | MockQuicData socket_data; |
| 5984 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5985 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5986 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5987 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5988 | |
| 5989 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5990 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5991 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5992 | request.Request( |
| 5993 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5994 | SocketTag(), |
| 5995 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5996 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5997 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5998 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5999 | EXPECT_TRUE(stream.get()); |
| 6000 | |
| 6001 | // Cause QUIC stream to be created. |
| 6002 | HttpRequestInfo request_info; |
| 6003 | request_info.method = "GET"; |
| 6004 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6005 | request_info.traffic_annotation = |
| 6006 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6007 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6008 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6009 | |
| 6010 | // Ensure that session is alive and active. |
| 6011 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6012 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6013 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6014 | |
| 6015 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6016 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 6017 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6018 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 6019 | |
| 6020 | // Send GET request on stream. This should cause a write error, which triggers |
| 6021 | // a connection migration attempt. |
| 6022 | HttpResponseInfo response; |
| 6023 | HttpRequestHeaders request_headers; |
| 6024 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6025 | callback_.callback())); |
| 6026 | // Run message loop to execute migration attempt. |
| 6027 | base::RunLoop().RunUntilIdle(); |
| 6028 | // Migration fails, and session is closed and deleted. |
| 6029 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6030 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6031 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6032 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6033 | } |
| 6034 | |
| 6035 | TEST_P(QuicStreamFactoryTest, |
| 6036 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 6037 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 6038 | } |
| 6039 | |
| 6040 | TEST_P(QuicStreamFactoryTest, |
| 6041 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 6042 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 6043 | } |
| 6044 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6045 | // Sets up a test which verifies that connection migration on write error can |
| 6046 | // eventually succeed and rewrite the packet on the new network with singals |
| 6047 | // delivered in the following order (alternate network is always availabe): |
| 6048 | // - original network encounters a SYNC/ASYNC write error based on |
| 6049 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 6050 | // cached, session migrates immediately to the alternate network. |
| 6051 | // - an immediate SYNC/ASYNC write error based on |
| 6052 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 6053 | // alternate network, session migrates immediately to the original network. |
| 6054 | // - an immediate SYNC/ASYNC write error based on |
| 6055 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 6056 | // original network, session migrates immediately to the alternate network. |
| 6057 | // - finally, session successfully sends the packet and reads the response on |
| 6058 | // the alternate network. |
| 6059 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 6060 | // modified to test that session is closed early if hopping between networks |
| 6061 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6062 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6063 | IoMode write_error_mode_on_old_network, |
| 6064 | IoMode write_error_mode_on_new_network) { |
| 6065 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6066 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6067 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6068 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6069 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6070 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6071 | // Set up the socket data used by the original network, which encounters a |
| 6072 | // write erorr. |
| 6073 | MockQuicData socket_data1; |
| 6074 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6075 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6076 | socket_data1.AddWrite( |
| 6077 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6078 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 6079 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 6080 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6081 | |
| 6082 | // Set up the socket data used by the alternate network, which also |
| 6083 | // encounters a write error. |
| 6084 | MockQuicData failed_quic_data2; |
| 6085 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6086 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 6087 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 6088 | |
| 6089 | // Set up the third socket data used by original network, which encounters a |
| 6090 | // write error again. |
| 6091 | MockQuicData failed_quic_data1; |
| 6092 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6093 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 6094 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6095 | |
| 6096 | // Set up the last socket data used by the alternate network, which will |
| 6097 | // finish migration successfully. The request is rewritten to this new socket, |
| 6098 | // and the response to the request is read on this socket. |
| 6099 | MockQuicData socket_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6100 | socket_data2.AddWrite( |
| 6101 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6102 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6103 | true, &header_stream_offset)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6104 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6105 | ASYNC, |
| 6106 | ConstructOkResponsePacket( |
| 6107 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6108 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6109 | socket_data2.AddWrite( |
| 6110 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6111 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6112 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6113 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6114 | |
| 6115 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6116 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6117 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6118 | request.Request( |
| 6119 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6120 | SocketTag(), |
| 6121 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6122 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6123 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6124 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6125 | EXPECT_TRUE(stream.get()); |
| 6126 | |
| 6127 | // Cause QUIC stream to be created. |
| 6128 | HttpRequestInfo request_info; |
| 6129 | request_info.method = "GET"; |
| 6130 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6131 | request_info.traffic_annotation = |
| 6132 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6133 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6134 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6135 | |
| 6136 | // Ensure that session is alive and active. |
| 6137 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6138 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6139 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6140 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6141 | // Send GET request on stream. |
| 6142 | // This should encounter a write error on network 1, |
| 6143 | // then migrate to network 2, which encounters another write error, |
| 6144 | // and migrate again to network 1, which encoutners one more write error. |
| 6145 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6146 | HttpResponseInfo response; |
| 6147 | HttpRequestHeaders request_headers; |
| 6148 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6149 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6150 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6151 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6152 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6153 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6154 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6155 | // Verify that response headers on the migrated socket were delivered to the |
| 6156 | // stream. |
| 6157 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6158 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6159 | |
| 6160 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6161 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6162 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6163 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6164 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6165 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6166 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6167 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6168 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6172 | TestMigrationOnMultipleWriteErrors( |
| 6173 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6174 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6178 | TestMigrationOnMultipleWriteErrors( |
| 6179 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6180 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6181 | } |
| 6182 | |
| 6183 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6184 | TestMigrationOnMultipleWriteErrors( |
| 6185 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6186 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6190 | TestMigrationOnMultipleWriteErrors( |
| 6191 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6192 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6193 | } |
| 6194 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6195 | // Verifies that a connection is closed when connection migration is triggered |
| 6196 | // on network being disconnected and the handshake is not confirmed. |
| 6197 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6198 | InitializeConnectionMigrationV2Test( |
| 6199 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6200 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6201 | // 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] | 6202 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6203 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6204 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6205 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6206 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6207 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6208 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6209 | |
| 6210 | // Create request and QuicHttpStream. |
| 6211 | QuicStreamRequest request(factory_.get()); |
| 6212 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6213 | request.Request( |
| 6214 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6215 | SocketTag(), |
| 6216 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6217 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6218 | // Deliver the network notification, which should cause the connection to be |
| 6219 | // closed. |
| 6220 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6221 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6222 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6223 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6224 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6225 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6226 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6227 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6228 | } |
| 6229 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6230 | // Sets up the connection migration test where network change notification is |
| 6231 | // queued BEFORE connection migration attempt on write error is posted. |
| 6232 | void QuicStreamFactoryTestBase:: |
| 6233 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6234 | bool disconnected) { |
| 6235 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6236 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6237 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6238 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6239 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6240 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6241 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6242 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6243 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6244 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6245 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6246 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6247 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6248 | |
| 6249 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6250 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6251 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6252 | request.Request( |
| 6253 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6254 | SocketTag(), |
| 6255 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6256 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6257 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6258 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6259 | EXPECT_TRUE(stream.get()); |
| 6260 | |
| 6261 | // Cause QUIC stream to be created. |
| 6262 | HttpRequestInfo request_info; |
| 6263 | request_info.method = "GET"; |
| 6264 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6265 | request_info.traffic_annotation = |
| 6266 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6267 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6268 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6269 | |
| 6270 | // Ensure that session is alive and active. |
| 6271 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6272 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6273 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6274 | |
| 6275 | // Set up second socket data provider that is used after |
| 6276 | // migration. The request is rewritten to this new socket, and the |
| 6277 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6278 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6279 | socket_data1.AddWrite( |
| 6280 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6281 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6282 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6283 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6284 | ASYNC, |
| 6285 | ConstructOkResponsePacket( |
| 6286 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6287 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6288 | socket_data1.AddWrite( |
| 6289 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6290 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6291 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6292 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6293 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6294 | // First queue a network change notification in the message loop. |
| 6295 | if (disconnected) { |
| 6296 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6297 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6298 | } else { |
| 6299 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6300 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6301 | } |
| 6302 | // Send GET request on stream. This should cause a write error, |
| 6303 | // which triggers a connection migration attempt. This will queue a |
| 6304 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6305 | HttpResponseInfo response; |
| 6306 | HttpRequestHeaders request_headers; |
| 6307 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6308 | callback_.callback())); |
| 6309 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6310 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6311 | // Verify the session is still alive and not marked as going away post |
| 6312 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6313 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6314 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6315 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6316 | |
| 6317 | // Verify that response headers on the migrated socket were delivered to the |
| 6318 | // stream. |
| 6319 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6320 | EXPECT_EQ(200, response.headers->response_code()); |
| 6321 | |
| 6322 | stream.reset(); |
| 6323 | |
| 6324 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6325 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6326 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6327 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6328 | } |
| 6329 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6330 | // This test verifies that session attempts connection migration successfully |
| 6331 | // with signals delivered in the following order (alternate network is always |
| 6332 | // available): |
| 6333 | // - a notification that default network is disconnected is queued. |
| 6334 | // - write error is triggered: session posts a task to attempt connection |
| 6335 | // migration, |migration_pending_| set to true. |
| 6336 | // - default network disconnected is delivered: session immediately migrates to |
| 6337 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6338 | // - connection migration on write error attempt aborts: writer encountered |
| 6339 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6340 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6341 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6342 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6343 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6344 | } |
| 6345 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6346 | // This test verifies that session attempts connection migration successfully |
| 6347 | // with signals delivered in the following order (alternate network is always |
| 6348 | // available): |
| 6349 | // - a notification that alternate network is made default is queued. |
| 6350 | // - write error is triggered: session posts a task to attempt connection |
| 6351 | // migration, block future migrations. |
| 6352 | // - new default notification is delivered: migrate back timer spins and task is |
| 6353 | // posted to migrate to the new default network. |
| 6354 | // - connection migration on write error attempt proceeds successfully: session |
| 6355 | // is |
| 6356 | // marked as going away, future migrations unblocked. |
| 6357 | // - migrate back to default network task executed: session is already on the |
| 6358 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6359 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6360 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6361 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6362 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6363 | } |
| 6364 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6365 | // Sets up the connection migration test where network change notification is |
| 6366 | // queued AFTER connection migration attempt on write error is posted. |
| 6367 | void QuicStreamFactoryTestBase:: |
| 6368 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6369 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6370 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6371 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6372 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6373 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6374 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6375 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6376 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6377 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6378 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6379 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6380 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6381 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6382 | |
| 6383 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6384 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6385 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6386 | request.Request( |
| 6387 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6388 | SocketTag(), |
| 6389 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6390 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6391 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6392 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6393 | EXPECT_TRUE(stream.get()); |
| 6394 | |
| 6395 | // Cause QUIC stream to be created. |
| 6396 | HttpRequestInfo request_info; |
| 6397 | request_info.method = "GET"; |
| 6398 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6399 | request_info.traffic_annotation = |
| 6400 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6401 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6402 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6403 | |
| 6404 | // Ensure that session is alive and active. |
| 6405 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6406 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6407 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6408 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6409 | // Set up second socket data provider that is used after |
| 6410 | // migration. The request is rewritten to this new socket, and the |
| 6411 | // response to the request is read on this new socket. |
| 6412 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6413 | socket_data1.AddWrite( |
| 6414 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6415 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6416 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6417 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6418 | ASYNC, |
| 6419 | ConstructOkResponsePacket( |
| 6420 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6421 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6422 | socket_data1.AddWrite( |
| 6423 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6424 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6425 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6426 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6427 | |
| 6428 | // Send GET request on stream. This should cause a write error, |
| 6429 | // which triggers a connection migration attempt. This will queue a |
| 6430 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6431 | HttpResponseInfo response; |
| 6432 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6433 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6434 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6435 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6436 | // Now queue a network change notification in the message loop behind |
| 6437 | // the migration attempt. |
| 6438 | if (disconnected) { |
| 6439 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6440 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6441 | } else { |
| 6442 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6443 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6444 | } |
| 6445 | |
| 6446 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6447 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6448 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6449 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6450 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6451 | |
| 6452 | // Verify that response headers on the migrated socket were delivered to the |
| 6453 | // stream. |
| 6454 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6455 | EXPECT_EQ(200, response.headers->response_code()); |
| 6456 | |
| 6457 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6458 | |
| 6459 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6460 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6461 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6462 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6463 | } |
| 6464 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6465 | // This test verifies that session attempts connection migration successfully |
| 6466 | // with signals delivered in the following order (alternate network is always |
| 6467 | // available): |
| 6468 | // - write error is triggered: session posts a task to complete connection |
| 6469 | // migration. |
| 6470 | // - a notification that alternate network is made default is queued. |
| 6471 | // - connection migration attempt proceeds successfully, session is marked as |
| 6472 | // going away. |
| 6473 | // - new default notification is delivered after connection migration has been |
| 6474 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6475 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6476 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6477 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6478 | } |
| 6479 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6480 | // This test verifies that session attempts connection migration successfully |
| 6481 | // with signals delivered in the following order (alternate network is always |
| 6482 | // available): |
| 6483 | // - write error is triggered: session posts a task to complete connection |
| 6484 | // migration. |
| 6485 | // - a notification that default network is diconnected is queued. |
| 6486 | // - connection migration attempt proceeds successfully, session is marked as |
| 6487 | // going away. |
| 6488 | // - disconnect notification is delivered after connection migration has been |
| 6489 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6490 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6491 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6492 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6493 | } |
| 6494 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6495 | // This tests connection migration on write error with signals delivered in the |
| 6496 | // following order: |
| 6497 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6498 | // |write_error_mode|: connection migration attempt is posted. |
| 6499 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6500 | // - after a pause, new network is connected: session will migrate to new |
| 6501 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6502 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6503 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6504 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6505 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6506 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6507 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6508 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6509 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6510 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6511 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6512 | // Use the test task runner. |
| 6513 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6514 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6515 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6516 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6517 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6518 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6519 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6520 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6521 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6522 | |
| 6523 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6524 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6525 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6526 | request.Request( |
| 6527 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6528 | SocketTag(), |
| 6529 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6530 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6531 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6532 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6533 | EXPECT_TRUE(stream.get()); |
| 6534 | |
| 6535 | // Cause QUIC stream to be created. |
| 6536 | HttpRequestInfo request_info; |
| 6537 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6538 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6539 | request_info.traffic_annotation = |
| 6540 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6541 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6542 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6543 | |
| 6544 | // Ensure that session is alive and active. |
| 6545 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6546 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6547 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6548 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6549 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6550 | HttpResponseInfo response; |
| 6551 | HttpRequestHeaders request_headers; |
| 6552 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6553 | callback_.callback())); |
| 6554 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6555 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6556 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6557 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6558 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6559 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6560 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6561 | // Set up second socket data provider that is used after migration. |
| 6562 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6563 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6564 | socket_data1.AddWrite( |
| 6565 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6566 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6567 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6568 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6569 | ASYNC, |
| 6570 | ConstructOkResponsePacket( |
| 6571 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6572 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6573 | socket_data1.AddWrite( |
| 6574 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6575 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6576 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6577 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6578 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6579 | // On a DISCONNECTED notification, nothing happens. |
| 6580 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6581 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6582 | // Add a new network and notify the stream factory of a new connected network. |
| 6583 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6584 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6585 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6586 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6587 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6588 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6589 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6590 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6591 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6592 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6593 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6594 | // Run the message loop migration for write error can finish. |
| 6595 | runner_->RunUntilIdle(); |
| 6596 | |
| 6597 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6598 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6599 | EXPECT_EQ(200, response.headers->response_code()); |
| 6600 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6601 | // Check that the session is still alive. |
| 6602 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6603 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6604 | |
| 6605 | // There should be no posted tasks not executed, no way to migrate back to |
| 6606 | // default network. |
| 6607 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6608 | |
| 6609 | // Receive signal to mark new network as default. |
| 6610 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6611 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6612 | |
| 6613 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6614 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6615 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6616 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6617 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6618 | } |
| 6619 | |
| 6620 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6621 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6622 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6623 | } |
| 6624 | |
| 6625 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6626 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6627 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6628 | } |
| 6629 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6630 | // This test verifies that when session successfully migrate to the alternate |
| 6631 | // network, packet write error on the old writer will be ignored and will not |
| 6632 | // trigger connection migration on write error. |
| 6633 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6634 | InitializeConnectionMigrationV2Test( |
| 6635 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6636 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6637 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6638 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6639 | |
| 6640 | // Using a testing task runner so that we can verify whether the migrate on |
| 6641 | // write error task is posted. |
| 6642 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6643 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6644 | |
| 6645 | MockQuicData socket_data; |
| 6646 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6647 | socket_data.AddWrite( |
| 6648 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6649 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6650 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6651 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6652 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6653 | |
| 6654 | // Create request and QuicHttpStream. |
| 6655 | QuicStreamRequest request(factory_.get()); |
| 6656 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6657 | request.Request( |
| 6658 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6659 | SocketTag(), |
| 6660 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6661 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6662 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6663 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6664 | EXPECT_TRUE(stream.get()); |
| 6665 | |
| 6666 | // Cause QUIC stream to be created. |
| 6667 | HttpRequestInfo request_info; |
| 6668 | request_info.method = "GET"; |
| 6669 | request_info.url = GURL("https://www.example.org/"); |
| 6670 | request_info.traffic_annotation = |
| 6671 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6672 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6673 | net_log_, CompletionOnceCallback())); |
| 6674 | |
| 6675 | // Ensure that session is alive and active. |
| 6676 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6677 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6678 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6679 | |
| 6680 | // Set up second socket data provider that is used after |
| 6681 | // migration. The response to the request is read on this new socket. |
| 6682 | MockQuicData socket_data1; |
| 6683 | socket_data1.AddWrite( |
| 6684 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6685 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6686 | ASYNC, |
| 6687 | ConstructOkResponsePacket( |
| 6688 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6689 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6690 | socket_data1.AddWrite( |
| 6691 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6692 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6693 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6694 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6695 | |
| 6696 | // Send GET request on stream. |
| 6697 | HttpResponseInfo response; |
| 6698 | HttpRequestHeaders request_headers; |
| 6699 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6700 | callback_.callback())); |
| 6701 | |
| 6702 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6703 | // Now notify network is disconnected, cause the migration to complete |
| 6704 | // immediately. |
| 6705 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6706 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6707 | // There will be two pending task, one will complete migration with no delay |
| 6708 | // and the other will attempt to migrate back to the default network with |
| 6709 | // delay. |
| 6710 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6711 | |
| 6712 | // Complete migration. |
| 6713 | task_runner->RunUntilIdle(); |
| 6714 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6715 | |
| 6716 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6717 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6718 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6719 | |
| 6720 | // Verify that response headers on the migrated socket were delivered to the |
| 6721 | // stream. |
| 6722 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6723 | EXPECT_EQ(200, response.headers->response_code()); |
| 6724 | |
| 6725 | // Resume the old socket data, a write error will be delivered to the old |
| 6726 | // packet writer. Verify no additional task is posted. |
| 6727 | socket_data.Resume(); |
| 6728 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6729 | |
| 6730 | stream.reset(); |
| 6731 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6732 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6733 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6734 | } |
| 6735 | |
| 6736 | // This test verifies that when session successfully migrate to the alternate |
| 6737 | // network, packet read error on the old reader will be ignored and will not |
| 6738 | // close the connection. |
| 6739 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6740 | InitializeConnectionMigrationV2Test( |
| 6741 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6742 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6743 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6744 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6745 | |
| 6746 | // Using a testing task runner. |
| 6747 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6748 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6749 | |
| 6750 | MockQuicData socket_data; |
| 6751 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6752 | socket_data.AddWrite( |
| 6753 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6754 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6755 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6756 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6757 | |
| 6758 | // Create request and QuicHttpStream. |
| 6759 | QuicStreamRequest request(factory_.get()); |
| 6760 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6761 | request.Request( |
| 6762 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6763 | SocketTag(), |
| 6764 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6765 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6766 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6767 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6768 | EXPECT_TRUE(stream.get()); |
| 6769 | |
| 6770 | // Cause QUIC stream to be created. |
| 6771 | HttpRequestInfo request_info; |
| 6772 | request_info.method = "GET"; |
| 6773 | request_info.url = GURL("https://www.example.org/"); |
| 6774 | request_info.traffic_annotation = |
| 6775 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6776 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6777 | net_log_, CompletionOnceCallback())); |
| 6778 | |
| 6779 | // Ensure that session is alive and active. |
| 6780 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6781 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6782 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6783 | |
| 6784 | // Set up second socket data provider that is used after |
| 6785 | // migration. The request is written to this new socket, and the |
| 6786 | // response to the request is read on this new socket. |
| 6787 | MockQuicData socket_data1; |
| 6788 | socket_data1.AddWrite( |
| 6789 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6790 | socket_data1.AddWrite( |
| 6791 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6792 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6793 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6794 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6795 | ASYNC, |
| 6796 | ConstructOkResponsePacket( |
| 6797 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6798 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6799 | socket_data1.AddWrite( |
| 6800 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6801 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6802 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6803 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6804 | |
| 6805 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6806 | // Now notify network is disconnected, cause the migration to complete |
| 6807 | // immediately. |
| 6808 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6809 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6810 | // There will be two pending task, one will complete migration with no delay |
| 6811 | // and the other will attempt to migrate back to the default network with |
| 6812 | // delay. |
| 6813 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6814 | |
| 6815 | // Complete migration. |
| 6816 | task_runner->RunUntilIdle(); |
| 6817 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6818 | |
| 6819 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6820 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6821 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6822 | |
| 6823 | // Send GET request on stream. |
| 6824 | HttpResponseInfo response; |
| 6825 | HttpRequestHeaders request_headers; |
| 6826 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6827 | callback_.callback())); |
| 6828 | |
| 6829 | // Verify that response headers on the migrated socket were delivered to the |
| 6830 | // stream. |
| 6831 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6832 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6833 | EXPECT_EQ(200, response.headers->response_code()); |
| 6834 | |
| 6835 | // Resume the old socket data, a read error will be delivered to the old |
| 6836 | // packet reader. Verify that the session is not affected. |
| 6837 | socket_data.Resume(); |
| 6838 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6839 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6840 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6841 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6842 | |
| 6843 | stream.reset(); |
| 6844 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6845 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6846 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6847 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6848 | } |
| 6849 | |
| 6850 | // This test verifies that after migration on network is executed, packet |
| 6851 | // read error on the old reader will be ignored and will not close the |
| 6852 | // connection. |
| 6853 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 6854 | InitializeConnectionMigrationV2Test( |
| 6855 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6856 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6857 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6858 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6859 | |
| 6860 | // Using a testing task runner. |
| 6861 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6862 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6863 | |
| 6864 | MockQuicData socket_data; |
| 6865 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6866 | socket_data.AddWrite( |
| 6867 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6868 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6869 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6870 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6871 | |
| 6872 | // Create request and QuicHttpStream. |
| 6873 | QuicStreamRequest request(factory_.get()); |
| 6874 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6875 | request.Request( |
| 6876 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6877 | SocketTag(), |
| 6878 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6879 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6880 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6881 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6882 | EXPECT_TRUE(stream.get()); |
| 6883 | |
| 6884 | // Cause QUIC stream to be created. |
| 6885 | HttpRequestInfo request_info; |
| 6886 | request_info.method = "GET"; |
| 6887 | request_info.url = GURL("https://www.example.org/"); |
| 6888 | request_info.traffic_annotation = |
| 6889 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6890 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6891 | net_log_, CompletionOnceCallback())); |
| 6892 | |
| 6893 | // Ensure that session is alive and active. |
| 6894 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6895 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6896 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6897 | |
| 6898 | // Set up second socket data provider that is used after |
| 6899 | // migration. The request is written to this new socket, and the |
| 6900 | // response to the request is read on this new socket. |
| 6901 | MockQuicData socket_data1; |
| 6902 | socket_data1.AddWrite( |
| 6903 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6904 | socket_data1.AddWrite( |
| 6905 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6906 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6907 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6908 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6909 | ASYNC, |
| 6910 | ConstructOkResponsePacket( |
| 6911 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6912 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6913 | socket_data1.AddWrite( |
| 6914 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6915 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6916 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6917 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6918 | |
| 6919 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6920 | // Now notify network is disconnected, cause the migration to complete |
| 6921 | // immediately. |
| 6922 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6923 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6924 | // There will be two pending task, one will complete migration with no delay |
| 6925 | // and the other will attempt to migrate back to the default network with |
| 6926 | // delay. |
| 6927 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6928 | |
| 6929 | // Resume the old socket data, a read error will be delivered to the old |
| 6930 | // packet reader. Verify that the session is not affected. |
| 6931 | socket_data.Resume(); |
| 6932 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6933 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6934 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6935 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6936 | |
| 6937 | // Complete migration. |
| 6938 | task_runner->RunUntilIdle(); |
| 6939 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6940 | |
| 6941 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6942 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6943 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6944 | |
| 6945 | // Send GET request on stream. |
| 6946 | HttpResponseInfo response; |
| 6947 | HttpRequestHeaders request_headers; |
| 6948 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6949 | callback_.callback())); |
| 6950 | |
| 6951 | // Verify that response headers on the migrated socket were delivered to the |
| 6952 | // stream. |
| 6953 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6954 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6955 | EXPECT_EQ(200, response.headers->response_code()); |
| 6956 | |
| 6957 | stream.reset(); |
| 6958 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6959 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6960 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6961 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6962 | } |
| 6963 | |
| 6964 | // This test verifies that after migration on write error is posted, packet |
| 6965 | // read error on the old reader will be ignored and will not close the |
| 6966 | // connection. |
| 6967 | TEST_P(QuicStreamFactoryTest, |
| 6968 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 6969 | InitializeConnectionMigrationV2Test( |
| 6970 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6971 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6972 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6973 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6974 | |
| 6975 | // Using a testing task runner. |
| 6976 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6977 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6978 | |
| 6979 | MockQuicData socket_data; |
| 6980 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6981 | socket_data.AddWrite( |
| 6982 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6983 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 6984 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 6985 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6986 | |
| 6987 | // Create request and QuicHttpStream. |
| 6988 | QuicStreamRequest request(factory_.get()); |
| 6989 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6990 | request.Request( |
| 6991 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6992 | SocketTag(), |
| 6993 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6994 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6995 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6996 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6997 | EXPECT_TRUE(stream.get()); |
| 6998 | |
| 6999 | // Cause QUIC stream to be created. |
| 7000 | HttpRequestInfo request_info; |
| 7001 | request_info.method = "GET"; |
| 7002 | request_info.url = GURL("https://www.example.org/"); |
| 7003 | request_info.traffic_annotation = |
| 7004 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7005 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 7006 | net_log_, CompletionOnceCallback())); |
| 7007 | |
| 7008 | // Ensure that session is alive and active. |
| 7009 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7010 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7011 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7012 | |
| 7013 | // Set up second socket data provider that is used after |
| 7014 | // migration. The request is written to this new socket, and the |
| 7015 | // response to the request is read on this new socket. |
| 7016 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7017 | socket_data1.AddWrite( |
| 7018 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7019 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7020 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7021 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7022 | ASYNC, |
| 7023 | ConstructOkResponsePacket( |
| 7024 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7025 | |
| 7026 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 7027 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 7028 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 7029 | |
| 7030 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 7031 | // Send GET request on stream. |
| 7032 | HttpResponseInfo response; |
| 7033 | HttpRequestHeaders request_headers; |
| 7034 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7035 | callback_.callback())); |
| 7036 | // Run the message loop to complete asynchronous write and read with errors. |
| 7037 | base::RunLoop().RunUntilIdle(); |
| 7038 | // There will be one pending task to complete migration on write error. |
| 7039 | // Verify session is not closed with read error. |
| 7040 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 7041 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7042 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7043 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7044 | |
| 7045 | // Complete migration. |
| 7046 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7047 | // There will be one more task posted attempting to migrate back to the |
| 7048 | // default network. |
| 7049 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7050 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 7051 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 7052 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7053 | |
| 7054 | // Verify that response headers on the migrated socket were delivered to the |
| 7055 | // stream. |
| 7056 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7057 | EXPECT_EQ(200, response.headers->response_code()); |
| 7058 | |
| 7059 | // Resume to consume the read error on new socket, which will close |
| 7060 | // the connection. |
| 7061 | socket_data1.Resume(); |
| 7062 | |
| 7063 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7064 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7065 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7066 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7067 | } |
| 7068 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7069 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 7070 | // network connects. |
| 7071 | TEST_P(QuicStreamFactoryTest, |
| 7072 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 7073 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7074 | ASYNC, /*disconnect_before_connect*/ false); |
| 7075 | } |
| 7076 | |
| 7077 | // Migrate on synchronous write error, old network disconnects after alternate |
| 7078 | // network connects. |
| 7079 | TEST_P(QuicStreamFactoryTest, |
| 7080 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 7081 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7082 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 7083 | } |
| 7084 | |
| 7085 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 7086 | // network connects. |
| 7087 | TEST_P(QuicStreamFactoryTest, |
| 7088 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 7089 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7090 | ASYNC, /*disconnect_before_connect*/ true); |
| 7091 | } |
| 7092 | |
| 7093 | // Migrate on synchronous write error, old network disconnects before alternate |
| 7094 | // network connects. |
| 7095 | TEST_P(QuicStreamFactoryTest, |
| 7096 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 7097 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7098 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 7099 | } |
| 7100 | |
| 7101 | // Setps up test which verifies that session successfully migrate to alternate |
| 7102 | // network with signals delivered in the following order: |
| 7103 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 7104 | // |disconnect_before_connect|. |
| 7105 | // - (No alternate network is connected) session connects to |
| 7106 | // kDefaultNetworkForTests. |
| 7107 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 7108 | // session posted task to migrate session on write error. |
| 7109 | // - Posted task is executed, miration moves to pending state due to lack of |
| 7110 | // alternate network. |
| 7111 | // - (A) An alternate network is connected, pending migration completes. |
| 7112 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7113 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7114 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7115 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7116 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7117 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7118 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7119 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7120 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7121 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7122 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7123 | |
| 7124 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7125 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7126 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7127 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7128 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7129 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7130 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7131 | |
| 7132 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7133 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7134 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7135 | request.Request( |
| 7136 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7137 | SocketTag(), |
| 7138 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7139 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7140 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7141 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7142 | EXPECT_TRUE(stream.get()); |
| 7143 | |
| 7144 | // Cause QUIC stream to be created. |
| 7145 | HttpRequestInfo request_info; |
| 7146 | request_info.method = "GET"; |
| 7147 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7148 | request_info.traffic_annotation = |
| 7149 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7150 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7151 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7152 | |
| 7153 | // Ensure that session is alive and active. |
| 7154 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7155 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7156 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7157 | |
| 7158 | // Send GET request on stream. This should cause a write error, which triggers |
| 7159 | // a connection migration attempt. |
| 7160 | HttpResponseInfo response; |
| 7161 | HttpRequestHeaders request_headers; |
| 7162 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7163 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7164 | // Run the message loop so that posted task to migrate to socket will be |
| 7165 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7166 | base::RunLoop().RunUntilIdle(); |
| 7167 | |
| 7168 | // In this particular code path, the network will not yet be marked |
| 7169 | // as going away and the session will still be alive. |
| 7170 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7171 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7172 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7173 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7174 | |
| 7175 | // Set up second socket data provider that is used after |
| 7176 | // migration. The request is rewritten to this new socket, and the |
| 7177 | // response to the request is read on this new socket. |
| 7178 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7179 | socket_data1.AddWrite( |
| 7180 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7181 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7182 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7183 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7184 | ASYNC, |
| 7185 | ConstructOkResponsePacket( |
| 7186 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7187 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7188 | socket_data1.AddWrite( |
| 7189 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7190 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7191 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7192 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7193 | |
| 7194 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7195 | ->SetConnectedNetworksList( |
| 7196 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7197 | if (disconnect_before_connect) { |
| 7198 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7199 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7200 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7201 | |
| 7202 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7203 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7204 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7205 | } else { |
| 7206 | // Now deliver a CONNECTED notification and completes migration. |
| 7207 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7208 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7209 | |
| 7210 | // Now deliver a DISCONNECT notification. |
| 7211 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7212 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7213 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7214 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7215 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7216 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7217 | |
| 7218 | // This is the callback for the response headers that returned |
| 7219 | // pending previously, because no result was available. Check that |
| 7220 | // the result is now available due to the successful migration. |
| 7221 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7222 | EXPECT_EQ(200, response.headers->response_code()); |
| 7223 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7224 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7225 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7226 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7227 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7228 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7229 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7230 | DEFAULT_PRIORITY, SocketTag(), |
| 7231 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7232 | &net_error_details_, |
| 7233 | failed_on_default_network_callback_, |
| 7234 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7235 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7236 | EXPECT_TRUE(stream2.get()); |
| 7237 | |
| 7238 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7239 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7240 | |
| 7241 | stream.reset(); |
| 7242 | stream2.reset(); |
| 7243 | |
| 7244 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7245 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7246 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7247 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7248 | } |
| 7249 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7250 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 7251 | test_params_.quic_allow_server_migration = true; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7252 | Initialize(); |
| 7253 | |
| 7254 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7255 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7256 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7257 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7258 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7259 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7260 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7261 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7262 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7263 | socket_data1.AddWrite( |
| 7264 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7265 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7266 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7267 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7268 | |
| 7269 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7270 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7271 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7272 | request.Request( |
| 7273 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7274 | SocketTag(), |
| 7275 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7276 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7277 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7278 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7279 | EXPECT_TRUE(stream.get()); |
| 7280 | |
| 7281 | // Cause QUIC stream to be created. |
| 7282 | HttpRequestInfo request_info; |
| 7283 | request_info.method = "GET"; |
| 7284 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7285 | request_info.traffic_annotation = |
| 7286 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7287 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7288 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7289 | |
| 7290 | // Ensure that session is alive and active. |
| 7291 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7292 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7293 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7294 | |
| 7295 | // Send GET request on stream. |
| 7296 | HttpResponseInfo response; |
| 7297 | HttpRequestHeaders request_headers; |
| 7298 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7299 | callback_.callback())); |
| 7300 | |
| 7301 | IPEndPoint ip; |
| 7302 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7303 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7304 | << ip.port(); |
| 7305 | |
| 7306 | // Set up second socket data provider that is used after |
| 7307 | // migration. The request is rewritten to this new socket, and the |
| 7308 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7309 | MockQuicData socket_data2; |
| 7310 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7311 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7312 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7313 | ASYNC, |
| 7314 | ConstructOkResponsePacket( |
| 7315 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7316 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7317 | socket_data2.AddWrite( |
| 7318 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7319 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7320 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7321 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7322 | |
| 7323 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7324 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7325 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7326 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7327 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7328 | |
| 7329 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7330 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7331 | << ip.port(); |
| 7332 | |
| 7333 | // The session should be alive and active. |
| 7334 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7335 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7336 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7337 | |
| 7338 | // Run the message loop so that data queued in the new socket is read by the |
| 7339 | // packet reader. |
| 7340 | base::RunLoop().RunUntilIdle(); |
| 7341 | |
| 7342 | // Verify that response headers on the migrated socket were delivered to the |
| 7343 | // stream. |
| 7344 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7345 | EXPECT_EQ(200, response.headers->response_code()); |
| 7346 | |
| 7347 | stream.reset(); |
| 7348 | |
| 7349 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7350 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7351 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7352 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7353 | } |
| 7354 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7355 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7356 | // Add alternate IPv4 server address to config. |
| 7357 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7358 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7359 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7360 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7361 | VerifyServerMigration(config, alt_address); |
| 7362 | } |
| 7363 | |
| 7364 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7365 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7366 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7367 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7368 | // Add alternate IPv6 server address to config. |
| 7369 | IPEndPoint alt_address = IPEndPoint( |
| 7370 | 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] | 7371 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7372 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7373 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7374 | VerifyServerMigration(config, alt_address); |
| 7375 | } |
| 7376 | |
| 7377 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7378 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7379 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7380 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7381 | // Add alternate IPv4 server address to config. |
| 7382 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7383 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7384 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7385 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7386 | IPEndPoint expected_address( |
| 7387 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7388 | VerifyServerMigration(config, expected_address); |
| 7389 | } |
| 7390 | |
| 7391 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 7392 | test_params_.quic_allow_server_migration = true; |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7393 | Initialize(); |
| 7394 | |
| 7395 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7396 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7397 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7398 | // Add alternate IPv6 server address to config. |
| 7399 | IPEndPoint alt_address = IPEndPoint( |
| 7400 | 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] | 7401 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7402 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7403 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7404 | |
| 7405 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7406 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7407 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7408 | |
| 7409 | crypto_client_stream_factory_.SetConfig(config); |
| 7410 | |
| 7411 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7412 | MockQuicData socket_data1; |
| 7413 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7414 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7415 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7416 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7417 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7418 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7419 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7420 | |
| 7421 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7422 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7423 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7424 | request.Request( |
| 7425 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7426 | SocketTag(), |
| 7427 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7428 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7429 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7430 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7431 | EXPECT_TRUE(stream.get()); |
| 7432 | |
| 7433 | // Cause QUIC stream to be created. |
| 7434 | HttpRequestInfo request_info; |
| 7435 | request_info.method = "GET"; |
| 7436 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7437 | request_info.traffic_annotation = |
| 7438 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7439 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7440 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7441 | |
| 7442 | // Ensure that session is alive and active. |
| 7443 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7444 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7445 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7446 | |
| 7447 | IPEndPoint actual_address; |
| 7448 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7449 | // No migration should have happened. |
| 7450 | IPEndPoint expected_address = |
| 7451 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7452 | EXPECT_EQ(actual_address, expected_address); |
| 7453 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7454 | << " " << actual_address.port(); |
| 7455 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7456 | << " " << expected_address.port(); |
| 7457 | |
| 7458 | stream.reset(); |
| 7459 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7460 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7461 | } |
| 7462 | |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 7463 | TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7464 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7465 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7466 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7467 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7468 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7469 | MockQuicData socket_data; |
| 7470 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7471 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7472 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7473 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7474 | MockQuicData socket_data2; |
| 7475 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7476 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7477 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7478 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7479 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7480 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7481 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7482 | request.Request( |
| 7483 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7484 | SocketTag(), |
| 7485 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7486 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7487 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7488 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7489 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7490 | EXPECT_TRUE(stream); |
| 7491 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7492 | |
| 7493 | // Change the CA cert and verify that stream saw the event. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 7494 | factory_->OnCertDBChanged(); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7495 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7496 | EXPECT_FALSE(factory_->require_confirmation()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7497 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7498 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7499 | |
| 7500 | // Now attempting to request a stream to the same origin should create |
| 7501 | // a new session. |
| 7502 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7503 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7504 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7505 | request2.Request( |
| 7506 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7507 | SocketTag(), |
| 7508 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7509 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7510 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7511 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7512 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 7513 | EXPECT_TRUE(stream2); |
| 7514 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 7515 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7516 | EXPECT_NE(session, session2); |
| 7517 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7518 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 7519 | |
| 7520 | stream2.reset(); |
| 7521 | stream.reset(); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7522 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7523 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7524 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7525 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7526 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7527 | } |
| 7528 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7529 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7530 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7531 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7532 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7533 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7534 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7535 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7536 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7537 | string r1_host_name("r1"); |
| 7538 | string r2_host_name("r2"); |
| 7539 | r1_host_name.append(cannoncial_suffixes[i]); |
| 7540 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7541 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7542 | HostPortPair host_port_pair1(r1_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7543 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7544 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7545 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7546 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7547 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7548 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7549 | EXPECT_FALSE(cached1->proof_valid()); |
| 7550 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7551 | |
| 7552 | // Mutate the cached1 to have different data. |
| 7553 | // TODO(rtenneti): mutate other members of CachedState. |
| 7554 | cached1->set_source_address_token(r1_host_name); |
| 7555 | cached1->SetProofValid(); |
| 7556 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7557 | HostPortPair host_port_pair2(r2_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7558 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7559 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7560 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7561 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7562 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 7563 | EXPECT_TRUE(cached2->proof_valid()); |
| 7564 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7565 | } |
| 7566 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7567 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7568 | Initialize(); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7569 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7570 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7571 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7572 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7573 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7574 | string r3_host_name("r3"); |
| 7575 | string r4_host_name("r4"); |
| 7576 | r3_host_name.append(cannoncial_suffixes[i]); |
| 7577 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7578 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7579 | HostPortPair host_port_pair1(r3_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7580 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7581 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7582 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7583 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7584 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7585 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7586 | EXPECT_FALSE(cached1->proof_valid()); |
| 7587 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7588 | |
| 7589 | // Mutate the cached1 to have different data. |
| 7590 | // TODO(rtenneti): mutate other members of CachedState. |
| 7591 | cached1->set_source_address_token(r3_host_name); |
| 7592 | cached1->SetProofInvalid(); |
| 7593 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7594 | HostPortPair host_port_pair2(r4_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7595 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7596 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7597 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7598 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7599 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 7600 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 7601 | EXPECT_FALSE(cached2->proof_valid()); |
| 7602 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7603 | } |
| 7604 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7605 | TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7606 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7607 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7608 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7609 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7610 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7611 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7612 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7613 | MockQuicData socket_data; |
| 7614 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7615 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7616 | |
| 7617 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7618 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7619 | host_resolver_->set_synchronous_mode(true); |
| 7620 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7621 | "192.168.0.1", ""); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7622 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7623 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7624 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7625 | DEFAULT_PRIORITY, SocketTag(), |
| 7626 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7627 | &net_error_details_, |
| 7628 | failed_on_default_network_callback_, |
| 7629 | callback_.callback())); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7630 | |
| 7631 | // If we are waiting for disk cache, we would have posted a task. Verify that |
| 7632 | // the CancelWaitForDataReady task hasn't been posted. |
| 7633 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 7634 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7635 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7636 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7637 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7638 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7639 | } |
| 7640 | |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7641 | TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 7642 | test_params_.quic_reduced_ping_timeout_seconds = 10; |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7643 | Initialize(); |
| 7644 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7645 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7646 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7647 | |
| 7648 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7649 | |
| 7650 | MockQuicData socket_data; |
| 7651 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7652 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7653 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7654 | |
| 7655 | MockQuicData socket_data2; |
| 7656 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7657 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7658 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7659 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7660 | |
| 7661 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 7662 | |
| 7663 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7664 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7665 | host_resolver_->set_synchronous_mode(true); |
| 7666 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7667 | "192.168.0.1", ""); |
| 7668 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7669 | |
| 7670 | // Quic should use default PING timeout when no previous connection times out |
| 7671 | // with open stream. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7672 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7673 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7674 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7675 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7676 | DEFAULT_PRIORITY, SocketTag(), |
| 7677 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7678 | &net_error_details_, |
| 7679 | failed_on_default_network_callback_, |
| 7680 | callback_.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7681 | |
| 7682 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7683 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7684 | session->connection()->ping_timeout()); |
| 7685 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7686 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7687 | EXPECT_TRUE(stream.get()); |
| 7688 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7689 | request_info.traffic_annotation = |
| 7690 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7691 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7692 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7693 | |
| 7694 | DVLOG(1) |
| 7695 | << "Created 1st session and initialized a stream. Now trigger timeout"; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7696 | session->connection()->CloseConnection( |
| 7697 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7698 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7699 | // Need to spin the loop now to ensure that |
| 7700 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7701 | base::RunLoop run_loop; |
| 7702 | run_loop.RunUntilIdle(); |
| 7703 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7704 | // The first connection times out with open stream, QUIC should reduce initial |
| 7705 | // PING time for subsequent connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7706 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7707 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 7708 | |
| 7709 | // Test two-in-a-row timeouts with open streams. |
| 7710 | DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 7711 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7712 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7713 | EXPECT_EQ(OK, |
| 7714 | request2.Request( |
| 7715 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 7716 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 7717 | failed_on_default_network_callback_, callback2.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7718 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7719 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7720 | session2->connection()->ping_timeout()); |
| 7721 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7722 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7723 | EXPECT_TRUE(stream2.get()); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7724 | EXPECT_EQ(OK, |
| 7725 | stream2->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7726 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7727 | session2->connection()->CloseConnection( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7728 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7729 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7730 | // Need to spin the loop now to ensure that |
| 7731 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7732 | base::RunLoop run_loop2; |
| 7733 | run_loop2.RunUntilIdle(); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7734 | |
| 7735 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7736 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7737 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7738 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7739 | } |
| 7740 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 7741 | // Verifies that the QUIC stream factory is initialized correctly. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 7742 | TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 7743 | VerifyInitialization(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 7744 | } |
| 7745 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7746 | TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 7747 | Initialize(); |
| 7748 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7749 | MockQuicData socket_data; |
| 7750 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7751 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7752 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7753 | |
| 7754 | // Save current state of |race_cert_verification|. |
| 7755 | bool race_cert_verification = |
| 7756 | QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 7757 | |
| 7758 | // Load server config. |
| 7759 | HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7760 | quic::QuicServerId quic_server_id(host_port_pair_.host(), |
| 7761 | host_port_pair_.port(), |
| 7762 | privacy_mode_ == PRIVACY_MODE_ENABLED); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7763 | QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 7764 | |
| 7765 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 7766 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7767 | |
| 7768 | // Start CertVerifyJob. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7769 | quic::QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7770 | factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7771 | if (status == quic::QUIC_PENDING) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7772 | // Verify CertVerifierJob has started. |
| 7773 | EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 7774 | |
| 7775 | while (HasActiveCertVerifierJob(quic_server_id)) { |
| 7776 | base::RunLoop().RunUntilIdle(); |
| 7777 | } |
| 7778 | } |
| 7779 | // Verify CertVerifierJob has finished. |
| 7780 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7781 | |
| 7782 | // Start a QUIC request. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7783 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7784 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7785 | request.Request( |
| 7786 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7787 | SocketTag(), |
| 7788 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7789 | failed_on_default_network_callback_, callback_.callback())); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7790 | |
| 7791 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7792 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7793 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7794 | EXPECT_TRUE(stream.get()); |
| 7795 | |
| 7796 | // Restore |race_cert_verification|. |
| 7797 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 7798 | race_cert_verification); |
| 7799 | |
| 7800 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7801 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7802 | |
| 7803 | // Verify there are no outstanding CertVerifierJobs after request has |
| 7804 | // finished. |
| 7805 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7806 | } |
| 7807 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7808 | TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7809 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7810 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7811 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7812 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7813 | QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7814 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7815 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 7816 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7817 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7818 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7819 | |
| 7820 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7821 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7822 | host_resolver_->set_synchronous_mode(true); |
| 7823 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7824 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7825 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7826 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7827 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7828 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7829 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7830 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7831 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7832 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7833 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7834 | DEFAULT_PRIORITY, SocketTag(), |
| 7835 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7836 | &net_error_details_, |
| 7837 | failed_on_default_network_callback_, |
| 7838 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7839 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7840 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7841 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7842 | base::RunLoop run_loop; |
| 7843 | run_loop.RunUntilIdle(); |
| 7844 | |
| 7845 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7846 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7847 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7848 | EXPECT_EQ(1u, observer.executed_count()); |
| 7849 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7850 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7851 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7852 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7853 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7854 | } |
| 7855 | |
| 7856 | TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7857 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7858 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7859 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7860 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7861 | QuicStreamFactoryPeer::SetYieldAfterDuration( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7862 | factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7863 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7864 | MockQuicData socket_data; |
Fan Yang | ac86750 | 2019-01-28 21:10:23 | [diff] [blame] | 7865 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(1)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7866 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7867 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7868 | |
| 7869 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7870 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7871 | host_resolver_->set_synchronous_mode(true); |
| 7872 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7873 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7874 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7875 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7876 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7877 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7878 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7879 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7880 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7881 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7882 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7883 | DEFAULT_PRIORITY, SocketTag(), |
| 7884 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7885 | &net_error_details_, |
| 7886 | failed_on_default_network_callback_, |
| 7887 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7888 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7889 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7890 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7891 | base::RunLoop run_loop; |
| 7892 | run_loop.RunUntilIdle(); |
| 7893 | |
| 7894 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7895 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7896 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7897 | EXPECT_EQ(1u, observer.executed_count()); |
| 7898 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7899 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7900 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7901 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7902 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7903 | } |
| 7904 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7905 | TEST_P(QuicStreamFactoryTest, ServerPushSessionAffinity) { |
| 7906 | Initialize(); |
| 7907 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7908 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7909 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7910 | MockQuicData socket_data; |
| 7911 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7912 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7913 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7914 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7915 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7916 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7917 | request.Request( |
| 7918 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7919 | SocketTag(), |
| 7920 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7921 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7922 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7923 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7924 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7925 | EXPECT_TRUE(stream.get()); |
| 7926 | |
| 7927 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7928 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7929 | string url = "https://www.example.org/"; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7930 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7931 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7932 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7933 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7934 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7935 | (*QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()) |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7936 | ->promised_by_url())[kDefaultUrl] = &promised; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7937 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7938 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 7939 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7940 | DEFAULT_PRIORITY, SocketTag(), |
| 7941 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7942 | &net_error_details_, |
| 7943 | failed_on_default_network_callback_, |
| 7944 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7945 | |
| 7946 | EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7947 | } |
| 7948 | |
| 7949 | TEST_P(QuicStreamFactoryTest, ServerPushPrivacyModeMismatch) { |
| 7950 | Initialize(); |
| 7951 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7952 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7953 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7954 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7955 | MockQuicData socket_data1; |
| 7956 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7957 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7958 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7959 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7960 | 2, true, GetNthServerInitiatedUnidirectionalStreamId(0), |
| 7961 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7962 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7963 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7964 | MockQuicData socket_data2; |
| 7965 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7966 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7967 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7968 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7969 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7970 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7971 | request.Request( |
| 7972 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7973 | SocketTag(), |
| 7974 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7975 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7976 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7977 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7978 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7979 | EXPECT_TRUE(stream.get()); |
| 7980 | |
| 7981 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7982 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7983 | string url = "https://www.example.org/"; |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7984 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7985 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7986 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7987 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7988 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7989 | quic::QuicClientPushPromiseIndex* index = |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7990 | QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()); |
| 7991 | |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7992 | (*index->promised_by_url())[kDefaultUrl] = &promised; |
| 7993 | EXPECT_EQ(index->GetPromised(kDefaultUrl), &promised); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7994 | |
| 7995 | // Doing the request should not use the push stream, but rather |
| 7996 | // cancel it because the privacy modes do not match. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7997 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7998 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7999 | request2.Request( |
| 8000 | host_port_pair_, version_, PRIVACY_MODE_ENABLED, |
| 8001 | DEFAULT_PRIORITY, SocketTag(), |
| 8002 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8003 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8004 | |
| 8005 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 8006 | EXPECT_EQ(index->GetPromised(kDefaultUrl), nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8007 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8008 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8009 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 8010 | EXPECT_TRUE(stream2.get()); |
| 8011 | |
| 8012 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 8013 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 8014 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 8015 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 8016 | } |
| 8017 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8018 | // Pool to existing session with matching quic::QuicServerId |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8019 | // even if destination is different. |
| 8020 | TEST_P(QuicStreamFactoryTest, PoolByOrigin) { |
| 8021 | Initialize(); |
| 8022 | |
| 8023 | HostPortPair destination1("first.example.com", 443); |
| 8024 | HostPortPair destination2("second.example.com", 443); |
| 8025 | |
| 8026 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8027 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8028 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 8029 | MockQuicData socket_data; |
| 8030 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8031 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8032 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8033 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8034 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8035 | EXPECT_EQ( |
| 8036 | ERR_IO_PENDING, |
| 8037 | request1.Request( |
| 8038 | destination1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8039 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8040 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8041 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8042 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8043 | EXPECT_TRUE(stream1.get()); |
| 8044 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 8045 | |
| 8046 | // Second request returns synchronously because it pools to existing session. |
| 8047 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8048 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8049 | EXPECT_EQ(OK, request2.Request(destination2, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8050 | DEFAULT_PRIORITY, SocketTag(), |
| 8051 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8052 | &net_error_details_, |
| 8053 | failed_on_default_network_callback_, |
| 8054 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8055 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8056 | EXPECT_TRUE(stream2.get()); |
| 8057 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8058 | QuicChromiumClientSession::Handle* session1 = |
| 8059 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8060 | QuicChromiumClientSession::Handle* session2 = |
| 8061 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8062 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8063 | EXPECT_EQ(quic::QuicServerId(host_port_pair_.host(), host_port_pair_.port(), |
| 8064 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8065 | session1->server_id()); |
| 8066 | |
| 8067 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8068 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8069 | } |
| 8070 | |
| 8071 | class QuicStreamFactoryWithDestinationTest |
| 8072 | : public QuicStreamFactoryTestBase, |
| 8073 | public ::testing::TestWithParam<PoolingTestParams> { |
| 8074 | protected: |
| 8075 | QuicStreamFactoryWithDestinationTest() |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 8076 | : QuicStreamFactoryTestBase( |
| 8077 | GetParam().version, |
| 8078 | GetParam().client_headers_include_h2_stream_dependency), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8079 | destination_type_(GetParam().destination_type), |
| 8080 | hanging_read_(SYNCHRONOUS, ERR_IO_PENDING, 0) {} |
| 8081 | |
| 8082 | HostPortPair GetDestination() { |
| 8083 | switch (destination_type_) { |
| 8084 | case SAME_AS_FIRST: |
| 8085 | return origin1_; |
| 8086 | case SAME_AS_SECOND: |
| 8087 | return origin2_; |
| 8088 | case DIFFERENT: |
| 8089 | return HostPortPair(kDifferentHostname, 443); |
| 8090 | default: |
| 8091 | NOTREACHED(); |
| 8092 | return HostPortPair(); |
| 8093 | } |
| 8094 | } |
| 8095 | |
| 8096 | void AddHangingSocketData() { |
| 8097 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8098 | new SequencedSocketData(base::make_span(&hanging_read_, 1), |
| 8099 | base::span<MockWrite>())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8100 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8101 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8102 | } |
| 8103 | |
| 8104 | bool AllDataConsumed() { |
| 8105 | for (const auto& socket_data_ptr : sequenced_socket_data_vector_) { |
| 8106 | if (!socket_data_ptr->AllReadDataConsumed() || |
| 8107 | !socket_data_ptr->AllWriteDataConsumed()) { |
| 8108 | return false; |
| 8109 | } |
| 8110 | } |
| 8111 | return true; |
| 8112 | } |
| 8113 | |
| 8114 | DestinationType destination_type_; |
| 8115 | HostPortPair origin1_; |
| 8116 | HostPortPair origin2_; |
| 8117 | MockRead hanging_read_; |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8118 | std::vector<std::unique_ptr<SequencedSocketData>> |
| 8119 | sequenced_socket_data_vector_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8120 | }; |
| 8121 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame] | 8122 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 8123 | QuicStreamFactoryWithDestinationTest, |
| 8124 | ::testing::ValuesIn(GetPoolingTestParams())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8125 | |
| 8126 | // A single QUIC request fails because the certificate does not match the origin |
| 8127 | // hostname, regardless of whether it matches the alternative service hostname. |
| 8128 | TEST_P(QuicStreamFactoryWithDestinationTest, InvalidCertificate) { |
| 8129 | if (destination_type_ == DIFFERENT) |
| 8130 | return; |
| 8131 | |
| 8132 | Initialize(); |
| 8133 | |
| 8134 | GURL url("https://mail.example.com/"); |
| 8135 | origin1_ = HostPortPair::FromURL(url); |
| 8136 | |
| 8137 | // Not used for requests, but this provides a test case where the certificate |
| 8138 | // is valid for the hostname of the alternative service. |
| 8139 | origin2_ = HostPortPair("mail.example.org", 433); |
| 8140 | |
| 8141 | HostPortPair destination = GetDestination(); |
| 8142 | |
| 8143 | scoped_refptr<X509Certificate> cert( |
| 8144 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8145 | ASSERT_FALSE(cert->VerifyNameMatch(origin1_.host())); |
| 8146 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8147 | |
| 8148 | ProofVerifyDetailsChromium verify_details; |
| 8149 | verify_details.cert_verify_result.verified_cert = cert; |
| 8150 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8151 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8152 | |
| 8153 | AddHangingSocketData(); |
| 8154 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8155 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8156 | EXPECT_EQ( |
| 8157 | ERR_IO_PENDING, |
| 8158 | request.Request( |
| 8159 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8160 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 8161 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8162 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8163 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_QUIC_HANDSHAKE_FAILED)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8164 | |
| 8165 | EXPECT_TRUE(AllDataConsumed()); |
| 8166 | } |
| 8167 | |
| 8168 | // QuicStreamRequest is pooled based on |destination| if certificate matches. |
| 8169 | TEST_P(QuicStreamFactoryWithDestinationTest, SharedCertificate) { |
| 8170 | Initialize(); |
| 8171 | |
| 8172 | GURL url1("https://www.example.org/"); |
| 8173 | GURL url2("https://mail.example.org/"); |
| 8174 | origin1_ = HostPortPair::FromURL(url1); |
| 8175 | origin2_ = HostPortPair::FromURL(url2); |
| 8176 | |
| 8177 | HostPortPair destination = GetDestination(); |
| 8178 | |
| 8179 | scoped_refptr<X509Certificate> cert( |
| 8180 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8181 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8182 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8183 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8184 | |
| 8185 | ProofVerifyDetailsChromium verify_details; |
| 8186 | verify_details.cert_verify_result.verified_cert = cert; |
| 8187 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8188 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8189 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8190 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8191 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8192 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8193 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8194 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8195 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8196 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8197 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8198 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8199 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8200 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8201 | EXPECT_EQ( |
| 8202 | ERR_IO_PENDING, |
| 8203 | request1.Request( |
| 8204 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8205 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8206 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8207 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8208 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8209 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8210 | EXPECT_TRUE(stream1.get()); |
| 8211 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8212 | |
| 8213 | // Second request returns synchronously because it pools to existing session. |
| 8214 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8215 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8216 | EXPECT_EQ(OK, request2.Request(destination, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8217 | DEFAULT_PRIORITY, SocketTag(), |
| 8218 | /*cert_verify_flags=*/0, url2, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8219 | &net_error_details_, |
| 8220 | failed_on_default_network_callback_, |
| 8221 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8222 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8223 | EXPECT_TRUE(stream2.get()); |
| 8224 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8225 | QuicChromiumClientSession::Handle* session1 = |
| 8226 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8227 | QuicChromiumClientSession::Handle* session2 = |
| 8228 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8229 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8230 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8231 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8232 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8233 | session1->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8234 | |
| 8235 | EXPECT_TRUE(AllDataConsumed()); |
| 8236 | } |
| 8237 | |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8238 | // QuicStreamRequest is not pooled if PrivacyMode differs. |
| 8239 | TEST_P(QuicStreamFactoryWithDestinationTest, DifferentPrivacyMode) { |
| 8240 | Initialize(); |
| 8241 | |
| 8242 | GURL url1("https://www.example.org/"); |
| 8243 | GURL url2("https://mail.example.org/"); |
| 8244 | origin1_ = HostPortPair::FromURL(url1); |
| 8245 | origin2_ = HostPortPair::FromURL(url2); |
| 8246 | |
| 8247 | HostPortPair destination = GetDestination(); |
| 8248 | |
| 8249 | scoped_refptr<X509Certificate> cert( |
| 8250 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8251 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8252 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8253 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8254 | |
| 8255 | ProofVerifyDetailsChromium verify_details1; |
| 8256 | verify_details1.cert_verify_result.verified_cert = cert; |
| 8257 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8258 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8259 | |
| 8260 | ProofVerifyDetailsChromium verify_details2; |
| 8261 | verify_details2.cert_verify_result.verified_cert = cert; |
| 8262 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8263 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8264 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8265 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8266 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8267 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8268 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8269 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8270 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8271 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8272 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8273 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8274 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8275 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8276 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8277 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8278 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8279 | QuicStreamRequest request1(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8280 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8281 | request1.Request( |
| 8282 | destination, version_, PRIVACY_MODE_DISABLED, DEFAULT_PRIORITY, |
| 8283 | SocketTag(), |
| 8284 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8285 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8286 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8287 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8288 | EXPECT_TRUE(stream1.get()); |
| 8289 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8290 | |
| 8291 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8292 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8293 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8294 | request2.Request( |
| 8295 | destination, version_, PRIVACY_MODE_ENABLED, DEFAULT_PRIORITY, |
| 8296 | SocketTag(), |
| 8297 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8298 | failed_on_default_network_callback_, callback2.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8299 | EXPECT_EQ(OK, callback2.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8300 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8301 | EXPECT_TRUE(stream2.get()); |
| 8302 | |
| 8303 | // |request2| does not pool to the first session, because PrivacyMode does not |
| 8304 | // match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8305 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8306 | QuicChromiumClientSession::Handle* session1 = |
| 8307 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8308 | QuicChromiumClientSession::Handle* session2 = |
| 8309 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8310 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8311 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8312 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), false), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8313 | session1->server_id()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8314 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), true), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8315 | session2->server_id()); |
| 8316 | |
| 8317 | EXPECT_TRUE(AllDataConsumed()); |
| 8318 | } |
| 8319 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8320 | // QuicStreamRequest is not pooled if certificate does not match its origin. |
| 8321 | TEST_P(QuicStreamFactoryWithDestinationTest, DisjointCertificate) { |
| 8322 | Initialize(); |
| 8323 | |
| 8324 | GURL url1("https://news.example.org/"); |
| 8325 | GURL url2("https://mail.example.com/"); |
| 8326 | origin1_ = HostPortPair::FromURL(url1); |
| 8327 | origin2_ = HostPortPair::FromURL(url2); |
| 8328 | |
| 8329 | HostPortPair destination = GetDestination(); |
| 8330 | |
| 8331 | scoped_refptr<X509Certificate> cert1( |
| 8332 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8333 | ASSERT_TRUE(cert1->VerifyNameMatch(origin1_.host())); |
| 8334 | ASSERT_FALSE(cert1->VerifyNameMatch(origin2_.host())); |
| 8335 | ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8336 | |
| 8337 | ProofVerifyDetailsChromium verify_details1; |
| 8338 | verify_details1.cert_verify_result.verified_cert = cert1; |
| 8339 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8340 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8341 | |
| 8342 | scoped_refptr<X509Certificate> cert2( |
| 8343 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8344 | ASSERT_TRUE(cert2->VerifyNameMatch(origin2_.host())); |
| 8345 | ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8346 | |
| 8347 | ProofVerifyDetailsChromium verify_details2; |
| 8348 | verify_details2.cert_verify_result.verified_cert = cert2; |
| 8349 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8350 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8351 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8352 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8353 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8354 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8355 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8356 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8357 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8358 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8359 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8360 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8361 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8362 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8363 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8364 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8365 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8366 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8367 | EXPECT_EQ( |
| 8368 | ERR_IO_PENDING, |
| 8369 | request1.Request( |
| 8370 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8371 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8372 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8373 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8374 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8375 | EXPECT_TRUE(stream1.get()); |
| 8376 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8377 | |
| 8378 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8379 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8380 | EXPECT_EQ( |
| 8381 | ERR_IO_PENDING, |
| 8382 | request2.Request( |
| 8383 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8384 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8385 | failed_on_default_network_callback_, callback2.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8386 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8387 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8388 | EXPECT_TRUE(stream2.get()); |
| 8389 | |
| 8390 | // |request2| does not pool to the first session, because the certificate does |
| 8391 | // not match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8392 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8393 | QuicChromiumClientSession::Handle* session1 = |
| 8394 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8395 | QuicChromiumClientSession::Handle* session2 = |
| 8396 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8397 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8398 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8399 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8400 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8401 | session1->server_id()); |
| 8402 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), |
| 8403 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8404 | session2->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8405 | |
| 8406 | EXPECT_TRUE(AllDataConsumed()); |
| 8407 | } |
| 8408 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8409 | // This test verifies that QuicStreamFactory::ClearCachedStatesInCryptoConfig |
| 8410 | // correctly transform an origin filter to a ServerIdFilter. Whether the |
| 8411 | // deletion itself works correctly is tested in QuicCryptoClientConfigTest. |
| 8412 | TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { |
| 8413 | Initialize(); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8414 | quic::QuicCryptoClientConfig* crypto_config = |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8415 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 8416 | |
| 8417 | struct TestCase { |
| 8418 | TestCase(const std::string& host, |
| 8419 | int port, |
| 8420 | PrivacyMode privacy_mode, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8421 | quic::QuicCryptoClientConfig* crypto_config) |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8422 | : server_id(host, port, privacy_mode), |
| 8423 | state(crypto_config->LookupOrCreate(server_id)) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8424 | std::vector<string> certs(1); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8425 | certs[0] = "cert"; |
| 8426 | state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 8427 | state->set_source_address_token("TOKEN"); |
| 8428 | state->SetProofValid(); |
| 8429 | |
| 8430 | EXPECT_FALSE(state->certs().empty()); |
| 8431 | } |
| 8432 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8433 | quic::QuicServerId server_id; |
| 8434 | quic::QuicCryptoClientConfig::CachedState* state; |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8435 | } test_cases[] = { |
| 8436 | TestCase("www.google.com", 443, privacy_mode_, crypto_config), |
| 8437 | TestCase("www.example.com", 443, privacy_mode_, crypto_config), |
| 8438 | TestCase("www.example.com", 4433, privacy_mode_, crypto_config)}; |
| 8439 | |
| 8440 | // Clear cached states for the origin https://www.example.com:4433. |
| 8441 | GURL origin("https://www.example.com:4433"); |
csharrison | ebeca8e | 2016-10-18 02:35:36 | [diff] [blame] | 8442 | factory_->ClearCachedStatesInCryptoConfig(base::Bind( |
| 8443 | static_cast<bool (*)(const GURL&, const GURL&)>(::operator==), origin)); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8444 | EXPECT_FALSE(test_cases[0].state->certs().empty()); |
| 8445 | EXPECT_FALSE(test_cases[1].state->certs().empty()); |
| 8446 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8447 | |
| 8448 | // Clear all cached states. |
| 8449 | factory_->ClearCachedStatesInCryptoConfig( |
| 8450 | base::Callback<bool(const GURL&)>()); |
| 8451 | EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 8452 | EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 8453 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8454 | } |
| 8455 | |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8456 | // Passes connection options and client connection options to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8457 | // then checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8458 | TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8459 | test_params_.quic_connection_options.push_back(quic::kTIME); |
| 8460 | test_params_.quic_connection_options.push_back(quic::kTBBR); |
| 8461 | test_params_.quic_connection_options.push_back(quic::kREJ); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8462 | |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8463 | test_params_.quic_client_connection_options.push_back(quic::kTBBR); |
| 8464 | test_params_.quic_client_connection_options.push_back(quic::k1RTT); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8465 | |
| 8466 | Initialize(); |
| 8467 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8468 | const quic::QuicConfig* config = |
| 8469 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8470 | EXPECT_EQ(test_params_.quic_connection_options, |
| 8471 | config->SendConnectionOptions()); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8472 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8473 | quic::kTBBR, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8474 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8475 | quic::k1RTT, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8476 | } |
| 8477 | |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8478 | // Verifies that the host resolver uses the request priority passed to |
| 8479 | // QuicStreamRequest::Request(). |
| 8480 | TEST_P(QuicStreamFactoryTest, HostResolverUsesRequestPriority) { |
| 8481 | Initialize(); |
| 8482 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8483 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8484 | |
| 8485 | MockQuicData socket_data; |
| 8486 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8487 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8488 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8489 | |
| 8490 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8491 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8492 | request.Request( |
| 8493 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8494 | SocketTag(), |
| 8495 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8496 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8497 | |
| 8498 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8499 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8500 | EXPECT_TRUE(stream.get()); |
| 8501 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8502 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8503 | |
| 8504 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8505 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8506 | } |
| 8507 | |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 8508 | TEST_P(QuicStreamFactoryTest, HostResolverRequestReprioritizedOnSetPriority) { |
| 8509 | Initialize(); |
| 8510 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8511 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8512 | |
| 8513 | MockQuicData socket_data; |
| 8514 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8515 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8516 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8517 | |
| 8518 | QuicStreamRequest request(factory_.get()); |
| 8519 | EXPECT_EQ(ERR_IO_PENDING, |
| 8520 | request.Request( |
| 8521 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8522 | SocketTag(), |
| 8523 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8524 | failed_on_default_network_callback_, callback_.callback())); |
| 8525 | |
| 8526 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
| 8527 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->request_priority(1)); |
| 8528 | |
| 8529 | QuicStreamRequest request2(factory_.get()); |
| 8530 | EXPECT_EQ(ERR_IO_PENDING, |
| 8531 | request2.Request( |
| 8532 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8533 | SocketTag(), |
| 8534 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8535 | failed_on_default_network_callback_, callback_.callback())); |
| 8536 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
| 8537 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8538 | |
| 8539 | request.SetPriority(LOWEST); |
| 8540 | EXPECT_EQ(LOWEST, host_resolver_->request_priority(1)); |
| 8541 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8542 | } |
| 8543 | |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8544 | // Passes |quic_max_time_before_crypto_handshake_seconds| and |
| 8545 | // |quic_max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8546 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8547 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8548 | test_params_.quic_max_time_before_crypto_handshake_seconds = 11; |
| 8549 | test_params_.quic_max_idle_time_before_crypto_handshake_seconds = 13; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8550 | Initialize(); |
| 8551 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8552 | const quic::QuicConfig* config = |
| 8553 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 8554 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8555 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8556 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8557 | config->max_idle_time_before_crypto_handshake()); |
| 8558 | } |
| 8559 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8560 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8561 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 8562 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 8563 | Initialize(); |
| 8564 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8565 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8566 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8567 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8568 | |
| 8569 | MockQuicData socket_data; |
| 8570 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8571 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8572 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8573 | |
| 8574 | QuicStreamRequest request(factory_.get()); |
| 8575 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8576 | request.Request( |
| 8577 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8578 | SocketTag(), |
| 8579 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8580 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8581 | |
| 8582 | TestCompletionCallback host_resolution_callback; |
| 8583 | EXPECT_TRUE( |
| 8584 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8585 | |
| 8586 | // |host_resolver_| has not finished host resolution at this point, so |
| 8587 | // |host_resolution_callback| should not have a result. |
| 8588 | base::RunLoop().RunUntilIdle(); |
| 8589 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8590 | |
| 8591 | // Allow |host_resolver_| to finish host resolution. |
| 8592 | // Since the request fails immediately after host resolution (getting |
| 8593 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 8594 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 8595 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8596 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8597 | base::RunLoop().RunUntilIdle(); |
| 8598 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8599 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 8600 | |
| 8601 | // Calling WaitForHostResolution() a second time should return |
| 8602 | // false since host resolution has finished already. |
| 8603 | EXPECT_FALSE( |
| 8604 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8605 | |
| 8606 | EXPECT_TRUE(callback_.have_result()); |
| 8607 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8608 | } |
| 8609 | |
| 8610 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8611 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 8612 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 8613 | Initialize(); |
| 8614 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8615 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8616 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8617 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8618 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8619 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8620 | factory_->set_require_confirmation(true); |
| 8621 | |
| 8622 | MockQuicData socket_data; |
| 8623 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8624 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8625 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8626 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8627 | |
| 8628 | QuicStreamRequest request(factory_.get()); |
| 8629 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8630 | request.Request( |
| 8631 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8632 | SocketTag(), |
| 8633 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8634 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8635 | |
| 8636 | TestCompletionCallback host_resolution_callback; |
| 8637 | EXPECT_TRUE( |
| 8638 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8639 | |
| 8640 | // |host_resolver_| has not finished host resolution at this point, so |
| 8641 | // |host_resolution_callback| should not have a result. |
| 8642 | base::RunLoop().RunUntilIdle(); |
| 8643 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8644 | |
| 8645 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 8646 | // will hang after host resolution, |host_resolution_callback| should run with |
| 8647 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8648 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8649 | base::RunLoop().RunUntilIdle(); |
| 8650 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8651 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 8652 | |
| 8653 | // Calling WaitForHostResolution() a second time should return |
| 8654 | // false since host resolution has finished already. |
| 8655 | EXPECT_FALSE( |
| 8656 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8657 | |
| 8658 | EXPECT_FALSE(callback_.have_result()); |
| 8659 | socket_data.GetSequencedSocketData()->Resume(); |
| 8660 | base::RunLoop().RunUntilIdle(); |
| 8661 | EXPECT_TRUE(callback_.have_result()); |
| 8662 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8663 | } |
| 8664 | |
| 8665 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8666 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 8667 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 8668 | Initialize(); |
| 8669 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8670 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8671 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8672 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8673 | |
| 8674 | MockQuicData socket_data; |
| 8675 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8676 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8677 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8678 | |
| 8679 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8680 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8681 | request.Request( |
| 8682 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8683 | SocketTag(), |
| 8684 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8685 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8686 | |
| 8687 | // WaitForHostResolution() should return false since host |
| 8688 | // resolution has finished already. |
| 8689 | TestCompletionCallback host_resolution_callback; |
| 8690 | EXPECT_FALSE( |
| 8691 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8692 | base::RunLoop().RunUntilIdle(); |
| 8693 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8694 | EXPECT_FALSE(callback_.have_result()); |
| 8695 | } |
| 8696 | |
| 8697 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8698 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 8699 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 8700 | Initialize(); |
| 8701 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8702 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8703 | |
| 8704 | // Host resolution will succeed synchronously, but Request() as a whole |
| 8705 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8706 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8707 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8708 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8709 | factory_->set_require_confirmation(true); |
| 8710 | |
| 8711 | MockQuicData socket_data; |
| 8712 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8713 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8714 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8715 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8716 | |
| 8717 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8718 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8719 | request.Request( |
| 8720 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8721 | SocketTag(), |
| 8722 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8723 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8724 | |
| 8725 | // WaitForHostResolution() should return false since host |
| 8726 | // resolution has finished already. |
| 8727 | TestCompletionCallback host_resolution_callback; |
| 8728 | EXPECT_FALSE( |
| 8729 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8730 | base::RunLoop().RunUntilIdle(); |
| 8731 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8732 | |
| 8733 | EXPECT_FALSE(callback_.have_result()); |
| 8734 | socket_data.GetSequencedSocketData()->Resume(); |
| 8735 | base::RunLoop().RunUntilIdle(); |
| 8736 | EXPECT_TRUE(callback_.have_result()); |
| 8737 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8738 | } |
| 8739 | |
| 8740 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8741 | // synchronously. |
| 8742 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 8743 | Initialize(); |
| 8744 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8745 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8746 | |
| 8747 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8748 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 8749 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8750 | |
| 8751 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8752 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8753 | request.Request( |
| 8754 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8755 | SocketTag(), |
| 8756 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8757 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8758 | |
| 8759 | // WaitForHostResolution() should return false since host |
| 8760 | // resolution has failed already. |
| 8761 | TestCompletionCallback host_resolution_callback; |
| 8762 | EXPECT_FALSE( |
| 8763 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8764 | base::RunLoop().RunUntilIdle(); |
| 8765 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8766 | } |
| 8767 | |
| 8768 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8769 | // asynchronously. |
| 8770 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 8771 | Initialize(); |
| 8772 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8773 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8774 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8775 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8776 | |
| 8777 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8778 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8779 | request.Request( |
| 8780 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8781 | SocketTag(), |
| 8782 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8783 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8784 | |
| 8785 | TestCompletionCallback host_resolution_callback; |
| 8786 | EXPECT_TRUE( |
| 8787 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8788 | |
| 8789 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 8790 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 8791 | // resolution failed with. |
| 8792 | base::RunLoop().RunUntilIdle(); |
| 8793 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8794 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 8795 | |
| 8796 | EXPECT_TRUE(callback_.have_result()); |
| 8797 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 8798 | } |
| 8799 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8800 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 8801 | // the final connection is established through the resolved DNS. No racing |
| 8802 | // connection. |
| 8803 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8804 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8805 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8806 | Initialize(); |
| 8807 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8808 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8809 | |
| 8810 | // Set an address in resolver for synchronous return. |
| 8811 | host_resolver_->set_synchronous_mode(true); |
| 8812 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8813 | kNonCachedIPAddress, ""); |
| 8814 | |
| 8815 | // Set up a different address in stale resolver cache. |
| 8816 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8817 | HostCache::Entry entry(OK, |
| 8818 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8819 | HostCache::Entry::SOURCE_DNS); |
| 8820 | base::TimeDelta zero; |
| 8821 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8822 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8823 | // Expire the cache |
| 8824 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 8825 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8826 | MockQuicData quic_data; |
| 8827 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8828 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8829 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8830 | |
| 8831 | QuicStreamRequest request(factory_.get()); |
| 8832 | EXPECT_THAT(request.Request( |
| 8833 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8834 | SocketTag(), |
| 8835 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8836 | failed_on_default_network_callback_, callback_.callback()), |
| 8837 | IsOk()); |
| 8838 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8839 | EXPECT_TRUE(stream.get()); |
| 8840 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8841 | EXPECT_EQ( |
| 8842 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8843 | kNonCachedIPAddress); |
| 8844 | |
| 8845 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8846 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8847 | } |
| 8848 | |
| 8849 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 8850 | // host resolver, connection should be successful and through resolved DNS. No |
| 8851 | // racing connection. |
| 8852 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8853 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8854 | Initialize(); |
| 8855 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8856 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8857 | |
| 8858 | // Set an address in resolver for asynchronous return. |
| 8859 | host_resolver_->set_ondemand_mode(true); |
| 8860 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8861 | kNonCachedIPAddress, ""); |
| 8862 | |
| 8863 | MockQuicData quic_data; |
| 8864 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8865 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8866 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8867 | |
| 8868 | QuicStreamRequest request(factory_.get()); |
| 8869 | EXPECT_EQ(ERR_IO_PENDING, |
| 8870 | request.Request( |
| 8871 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8872 | SocketTag(), |
| 8873 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8874 | failed_on_default_network_callback_, callback_.callback())); |
| 8875 | TestCompletionCallback host_resolution_callback; |
| 8876 | EXPECT_TRUE( |
| 8877 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8878 | base::RunLoop().RunUntilIdle(); |
| 8879 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8880 | |
| 8881 | // Cause the host resolution to return. |
| 8882 | host_resolver_->ResolveAllPending(); |
| 8883 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 8884 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8885 | |
| 8886 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8887 | EXPECT_TRUE(stream.get()); |
| 8888 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8889 | |
| 8890 | EXPECT_EQ( |
| 8891 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8892 | kNonCachedIPAddress); |
| 8893 | |
| 8894 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8895 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8896 | } |
| 8897 | |
| 8898 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 8899 | // connects synchrounously, and then the resolved DNS matches. |
| 8900 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8901 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8902 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8903 | Initialize(); |
| 8904 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8905 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8906 | |
| 8907 | // Set an address in resolver for asynchronous return. |
| 8908 | host_resolver_->set_ondemand_mode(true); |
| 8909 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8910 | kCachedIPAddress.ToString(), ""); |
| 8911 | |
| 8912 | // Set up the same address in the stale resolver cache. |
| 8913 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8914 | HostCache::Entry entry(OK, |
| 8915 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8916 | HostCache::Entry::SOURCE_DNS); |
| 8917 | base::TimeDelta zero; |
| 8918 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8919 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8920 | // Expire the cache |
| 8921 | cache->OnNetworkChange(); |
| 8922 | |
| 8923 | MockQuicData quic_data; |
| 8924 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8925 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8926 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8927 | |
| 8928 | QuicStreamRequest request(factory_.get()); |
| 8929 | EXPECT_EQ(ERR_IO_PENDING, |
| 8930 | request.Request( |
| 8931 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8932 | SocketTag(), |
| 8933 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8934 | failed_on_default_network_callback_, callback_.callback())); |
| 8935 | |
| 8936 | // Check that the racing job is running. |
| 8937 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8938 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8939 | |
| 8940 | // Resolve dns and return. |
| 8941 | host_resolver_->ResolveAllPending(); |
| 8942 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8943 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8944 | EXPECT_TRUE(stream.get()); |
| 8945 | |
| 8946 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8947 | |
| 8948 | EXPECT_EQ( |
| 8949 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8950 | kCachedIPAddress.ToString()); |
| 8951 | |
| 8952 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8953 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8954 | } |
| 8955 | |
| 8956 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 8957 | // async, and then the result matches. |
| 8958 | TEST_P(QuicStreamFactoryTest, |
| 8959 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 8960 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8961 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8962 | Initialize(); |
| 8963 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8964 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8965 | |
| 8966 | // Set an address in resolver for asynchronous return. |
| 8967 | host_resolver_->set_ondemand_mode(true); |
| 8968 | factory_->set_require_confirmation(true); |
| 8969 | crypto_client_stream_factory_.set_handshake_mode( |
| 8970 | MockCryptoClientStream::ZERO_RTT); |
| 8971 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8972 | kCachedIPAddress.ToString(), ""); |
| 8973 | |
| 8974 | // Set up the same address in the stale resolver cache. |
| 8975 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8976 | HostCache::Entry entry(OK, |
| 8977 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8978 | HostCache::Entry::SOURCE_DNS); |
| 8979 | base::TimeDelta zero; |
| 8980 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8981 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8982 | // Expire the cache |
| 8983 | cache->OnNetworkChange(); |
| 8984 | |
| 8985 | MockQuicData quic_data; |
| 8986 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8987 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8988 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8989 | |
| 8990 | QuicStreamRequest request(factory_.get()); |
| 8991 | EXPECT_EQ(ERR_IO_PENDING, |
| 8992 | request.Request( |
| 8993 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8994 | SocketTag(), |
| 8995 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8996 | failed_on_default_network_callback_, callback_.callback())); |
| 8997 | |
| 8998 | // Send Crypto handshake so connect will call back. |
| 8999 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9000 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9001 | base::RunLoop().RunUntilIdle(); |
| 9002 | |
| 9003 | // Check that the racing job is running. |
| 9004 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9005 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9006 | |
| 9007 | // Resolve dns and call back, make sure job finishes. |
| 9008 | host_resolver_->ResolveAllPending(); |
| 9009 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9010 | |
| 9011 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9012 | EXPECT_TRUE(stream.get()); |
| 9013 | |
| 9014 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9015 | |
| 9016 | EXPECT_EQ( |
| 9017 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9018 | kCachedIPAddress.ToString()); |
| 9019 | |
| 9020 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9021 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9022 | } |
| 9023 | |
| 9024 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 9025 | // return, then connection finishes and matches with the result. |
| 9026 | TEST_P(QuicStreamFactoryTest, |
| 9027 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9028 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9029 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9030 | Initialize(); |
| 9031 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9032 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9033 | |
| 9034 | // Set an address in resolver for asynchronous return. |
| 9035 | host_resolver_->set_ondemand_mode(true); |
| 9036 | factory_->set_require_confirmation(true); |
| 9037 | crypto_client_stream_factory_.set_handshake_mode( |
| 9038 | MockCryptoClientStream::ZERO_RTT); |
| 9039 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9040 | kCachedIPAddress.ToString(), ""); |
| 9041 | |
| 9042 | // Set up the same address in the stale resolver cache. |
| 9043 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9044 | HostCache::Entry entry(OK, |
| 9045 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9046 | HostCache::Entry::SOURCE_DNS); |
| 9047 | base::TimeDelta zero; |
| 9048 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9049 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9050 | // Expire the cache |
| 9051 | cache->OnNetworkChange(); |
| 9052 | |
| 9053 | MockQuicData quic_data; |
| 9054 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9055 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9056 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9057 | |
| 9058 | QuicStreamRequest request(factory_.get()); |
| 9059 | EXPECT_EQ(ERR_IO_PENDING, |
| 9060 | request.Request( |
| 9061 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9062 | SocketTag(), |
| 9063 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9064 | failed_on_default_network_callback_, callback_.callback())); |
| 9065 | |
| 9066 | // Finish dns async, check we still need to wait for stale connection async. |
| 9067 | host_resolver_->ResolveAllPending(); |
| 9068 | base::RunLoop().RunUntilIdle(); |
| 9069 | EXPECT_FALSE(callback_.have_result()); |
| 9070 | |
| 9071 | // Finish stale connection async, and the stale connection should pass dns |
| 9072 | // validation. |
| 9073 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9074 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9075 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9076 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9077 | EXPECT_TRUE(stream.get()); |
| 9078 | |
| 9079 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9080 | EXPECT_EQ( |
| 9081 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9082 | kCachedIPAddress.ToString()); |
| 9083 | |
| 9084 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9085 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9086 | } |
| 9087 | |
| 9088 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9089 | // sync, but dns no match |
| 9090 | TEST_P(QuicStreamFactoryTest, |
| 9091 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9092 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9093 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9094 | Initialize(); |
| 9095 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9096 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9097 | |
| 9098 | // Set an address in resolver for asynchronous return. |
| 9099 | host_resolver_->set_ondemand_mode(true); |
| 9100 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9101 | kNonCachedIPAddress, ""); |
| 9102 | |
| 9103 | // Set up a different address in the stale resolver cache. |
| 9104 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9105 | HostCache::Entry entry(OK, |
| 9106 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9107 | HostCache::Entry::SOURCE_DNS); |
| 9108 | base::TimeDelta zero; |
| 9109 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9110 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9111 | // Expire the cache |
| 9112 | cache->OnNetworkChange(); |
| 9113 | |
| 9114 | // Socket for the stale connection which will invoke connection closure. |
| 9115 | MockQuicData quic_data; |
| 9116 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9117 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9118 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9119 | SYNCHRONOUS, |
| 9120 | client_maker_.MakeConnectionClosePacket( |
| 9121 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9122 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9123 | |
| 9124 | // Socket for the new connection. |
| 9125 | MockQuicData quic_data2; |
| 9126 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9127 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9128 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9129 | |
| 9130 | QuicStreamRequest request(factory_.get()); |
| 9131 | EXPECT_EQ(ERR_IO_PENDING, |
| 9132 | request.Request( |
| 9133 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9134 | SocketTag(), |
| 9135 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9136 | failed_on_default_network_callback_, callback_.callback())); |
| 9137 | |
| 9138 | // Check the stale connection is running. |
| 9139 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9140 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9141 | |
| 9142 | // Finish dns resolution and check the job has finished. |
| 9143 | host_resolver_->ResolveAllPending(); |
| 9144 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9145 | |
| 9146 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9147 | EXPECT_TRUE(stream.get()); |
| 9148 | |
| 9149 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9150 | |
| 9151 | EXPECT_EQ( |
| 9152 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9153 | kNonCachedIPAddress); |
| 9154 | |
| 9155 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9156 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9157 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9158 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9159 | } |
| 9160 | |
| 9161 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9162 | // async, finishes before dns, but no match |
| 9163 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9164 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9165 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9166 | Initialize(); |
| 9167 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9168 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9169 | |
| 9170 | // Set an address in resolver for asynchronous return. |
| 9171 | host_resolver_->set_ondemand_mode(true); |
| 9172 | factory_->set_require_confirmation(true); |
| 9173 | crypto_client_stream_factory_.set_handshake_mode( |
| 9174 | MockCryptoClientStream::ZERO_RTT); |
| 9175 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9176 | kNonCachedIPAddress, ""); |
| 9177 | |
| 9178 | // Set up a different address in the stale resolvercache. |
| 9179 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9180 | HostCache::Entry entry(OK, |
| 9181 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9182 | HostCache::Entry::SOURCE_DNS); |
| 9183 | base::TimeDelta zero; |
| 9184 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9185 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9186 | // Expire the cache |
| 9187 | cache->OnNetworkChange(); |
| 9188 | |
| 9189 | MockQuicData quic_data; |
| 9190 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9191 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9192 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9193 | SYNCHRONOUS, |
| 9194 | client_maker_.MakeConnectionClosePacket( |
| 9195 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9196 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9197 | |
| 9198 | MockQuicData quic_data2; |
| 9199 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9200 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9201 | |
| 9202 | QuicStreamRequest request(factory_.get()); |
| 9203 | EXPECT_EQ(ERR_IO_PENDING, |
| 9204 | request.Request( |
| 9205 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9206 | SocketTag(), |
| 9207 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9208 | failed_on_default_network_callback_, callback_.callback())); |
| 9209 | |
| 9210 | // Finish the stale connection. |
| 9211 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9212 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9213 | base::RunLoop().RunUntilIdle(); |
| 9214 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9215 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9216 | |
| 9217 | // Finish host resolution and check the job is done. |
| 9218 | host_resolver_->ResolveAllPending(); |
| 9219 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9220 | |
| 9221 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9222 | EXPECT_TRUE(stream.get()); |
| 9223 | |
| 9224 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9225 | EXPECT_EQ( |
| 9226 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9227 | kNonCachedIPAddress); |
| 9228 | |
| 9229 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9230 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9231 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9232 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9233 | } |
| 9234 | |
| 9235 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9236 | // async, dns finishes first, but no match |
| 9237 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9238 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9239 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9240 | Initialize(); |
| 9241 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9242 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9243 | |
| 9244 | // Set an address in resolver for asynchronous return. |
| 9245 | host_resolver_->set_ondemand_mode(true); |
| 9246 | factory_->set_require_confirmation(true); |
| 9247 | crypto_client_stream_factory_.set_handshake_mode( |
| 9248 | MockCryptoClientStream::ZERO_RTT); |
| 9249 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9250 | kNonCachedIPAddress, ""); |
| 9251 | |
| 9252 | // Set up a different address in the stale resolver cache. |
| 9253 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9254 | HostCache::Entry entry(OK, |
| 9255 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9256 | HostCache::Entry::SOURCE_DNS); |
| 9257 | base::TimeDelta zero; |
| 9258 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9259 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9260 | // Expire the cache |
| 9261 | cache->OnNetworkChange(); |
| 9262 | |
| 9263 | MockQuicData quic_data; |
| 9264 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9265 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9266 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9267 | SYNCHRONOUS, |
| 9268 | client_maker_.MakeConnectionClosePacket( |
| 9269 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9270 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9271 | |
| 9272 | MockQuicData quic_data2; |
| 9273 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9274 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9275 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9276 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9277 | |
| 9278 | QuicStreamRequest request(factory_.get()); |
| 9279 | EXPECT_EQ(ERR_IO_PENDING, |
| 9280 | request.Request( |
| 9281 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9282 | SocketTag(), |
| 9283 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9284 | failed_on_default_network_callback_, callback_.callback())); |
| 9285 | // Finish dns resolution, but need to wait for stale connection. |
| 9286 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9287 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9288 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9289 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9290 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9291 | |
| 9292 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9293 | EXPECT_TRUE(stream.get()); |
| 9294 | |
| 9295 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9296 | EXPECT_EQ( |
| 9297 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9298 | kNonCachedIPAddress); |
| 9299 | |
| 9300 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9301 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9302 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9303 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9304 | } |
| 9305 | |
| 9306 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9307 | // as experiment is not on |
| 9308 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9309 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9310 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9311 | Initialize(); |
| 9312 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9313 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9314 | |
| 9315 | // Set synchronous failure in resolver. |
| 9316 | host_resolver_->set_synchronous_mode(true); |
| 9317 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9318 | |
| 9319 | MockQuicData quic_data; |
| 9320 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9321 | QuicStreamRequest request(factory_.get()); |
| 9322 | |
| 9323 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9324 | request.Request( |
| 9325 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9326 | SocketTag(), |
| 9327 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9328 | failed_on_default_network_callback_, callback_.callback())); |
| 9329 | } |
| 9330 | |
| 9331 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9332 | // async |
| 9333 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9334 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 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 asynchronous failure in resolver. |
| 9341 | host_resolver_->set_ondemand_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_IO_PENDING, |
| 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 | // Resolve and expect result that shows the resolution error. |
| 9356 | host_resolver_->ResolveAllPending(); |
| 9357 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9358 | } |
| 9359 | |
| 9360 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9361 | // sync, dns returns error and no connection is established. |
| 9362 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9363 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9364 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9365 | Initialize(); |
| 9366 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9367 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9368 | |
| 9369 | // Set asynchronous failure in resolver. |
| 9370 | host_resolver_->set_ondemand_mode(true); |
| 9371 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9372 | |
| 9373 | // Set up an address in the stale cache. |
| 9374 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9375 | HostCache::Entry entry(OK, |
| 9376 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9377 | HostCache::Entry::SOURCE_DNS); |
| 9378 | base::TimeDelta zero; |
| 9379 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9380 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9381 | // Expire the cache |
| 9382 | cache->OnNetworkChange(); |
| 9383 | |
| 9384 | // Socket for the stale connection which is supposed to disconnect. |
| 9385 | MockQuicData quic_data; |
| 9386 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9387 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9388 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9389 | SYNCHRONOUS, |
| 9390 | client_maker_.MakeConnectionClosePacket( |
| 9391 | 2, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9392 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9393 | |
| 9394 | QuicStreamRequest request(factory_.get()); |
| 9395 | EXPECT_EQ(ERR_IO_PENDING, |
| 9396 | request.Request( |
| 9397 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9398 | SocketTag(), |
| 9399 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9400 | failed_on_default_network_callback_, callback_.callback())); |
| 9401 | |
| 9402 | // Check that the stale connection is running. |
| 9403 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9404 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9405 | |
| 9406 | // Finish host resolution. |
| 9407 | host_resolver_->ResolveAllPending(); |
| 9408 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9409 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9410 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9411 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9412 | } |
| 9413 | |
| 9414 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9415 | // return error, then dns matches |
| 9416 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9417 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9418 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9419 | Initialize(); |
| 9420 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9421 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9422 | |
| 9423 | // Set an address in host resolver for asynchronous return. |
| 9424 | host_resolver_->set_ondemand_mode(true); |
| 9425 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9426 | kCachedIPAddress.ToString(), ""); |
| 9427 | |
| 9428 | // Set up the same address in the stale resolver cache. |
| 9429 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9430 | HostCache::Entry entry(OK, |
| 9431 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9432 | HostCache::Entry::SOURCE_DNS); |
| 9433 | base::TimeDelta zero; |
| 9434 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9435 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9436 | // Expire the cache |
| 9437 | cache->OnNetworkChange(); |
| 9438 | |
| 9439 | // Simulate synchronous connect failure. |
| 9440 | MockQuicData quic_data; |
| 9441 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9442 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9443 | |
| 9444 | MockQuicData quic_data2; |
| 9445 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9446 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9447 | |
| 9448 | QuicStreamRequest request(factory_.get()); |
| 9449 | EXPECT_EQ(ERR_IO_PENDING, |
| 9450 | request.Request( |
| 9451 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9452 | SocketTag(), |
| 9453 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9454 | failed_on_default_network_callback_, callback_.callback())); |
| 9455 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9456 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9457 | |
| 9458 | host_resolver_->ResolveAllPending(); |
| 9459 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9460 | } |
| 9461 | |
| 9462 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9463 | // returns error, dns no match, new connection is established |
| 9464 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9465 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9466 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9467 | Initialize(); |
| 9468 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9469 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9470 | |
| 9471 | // Set an address in host resolver. |
| 9472 | host_resolver_->set_ondemand_mode(true); |
| 9473 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9474 | kNonCachedIPAddress, ""); |
| 9475 | |
| 9476 | // Set up a different address in stale resolver cache. |
| 9477 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9478 | HostCache::Entry entry(OK, |
| 9479 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9480 | HostCache::Entry::SOURCE_DNS); |
| 9481 | base::TimeDelta zero; |
| 9482 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9483 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9484 | // Expire the cache |
| 9485 | cache->OnNetworkChange(); |
| 9486 | |
| 9487 | // Add failure for the stale connection. |
| 9488 | MockQuicData quic_data; |
| 9489 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9490 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9491 | |
| 9492 | MockQuicData quic_data2; |
| 9493 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9494 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9495 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9496 | |
| 9497 | QuicStreamRequest request(factory_.get()); |
| 9498 | EXPECT_EQ(ERR_IO_PENDING, |
| 9499 | request.Request( |
| 9500 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9501 | SocketTag(), |
| 9502 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9503 | failed_on_default_network_callback_, callback_.callback())); |
| 9504 | |
| 9505 | // Check that the stale connection fails. |
| 9506 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9507 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9508 | |
| 9509 | // Finish host resolution and check the job finishes ok. |
| 9510 | host_resolver_->ResolveAllPending(); |
| 9511 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9512 | |
| 9513 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9514 | EXPECT_TRUE(stream.get()); |
| 9515 | |
| 9516 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9517 | |
| 9518 | EXPECT_EQ( |
| 9519 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9520 | kNonCachedIPAddress); |
| 9521 | |
| 9522 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9523 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9524 | } |
| 9525 | |
| 9526 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9527 | // returns error, dns no match, new connection error |
| 9528 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9529 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9530 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9531 | Initialize(); |
| 9532 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9533 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9534 | |
| 9535 | // Set an address in host resolver asynchronously. |
| 9536 | host_resolver_->set_ondemand_mode(true); |
| 9537 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9538 | kNonCachedIPAddress, ""); |
| 9539 | |
| 9540 | // Set up a different address in the stale cache. |
| 9541 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9542 | HostCache::Entry entry(OK, |
| 9543 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9544 | HostCache::Entry::SOURCE_DNS); |
| 9545 | base::TimeDelta zero; |
| 9546 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9547 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9548 | // Expire the cache |
| 9549 | cache->OnNetworkChange(); |
| 9550 | |
| 9551 | // Add failure for stale connection. |
| 9552 | MockQuicData quic_data; |
| 9553 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9554 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9555 | |
| 9556 | // Add failure for resolved dns connection. |
| 9557 | MockQuicData quic_data2; |
| 9558 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9559 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9560 | |
| 9561 | QuicStreamRequest request(factory_.get()); |
| 9562 | EXPECT_EQ(ERR_IO_PENDING, |
| 9563 | request.Request( |
| 9564 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9565 | SocketTag(), |
| 9566 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9567 | failed_on_default_network_callback_, callback_.callback())); |
| 9568 | |
| 9569 | // Check the stale connection fails. |
| 9570 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9571 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9572 | |
| 9573 | // Check the resolved dns connection fails. |
| 9574 | host_resolver_->ResolveAllPending(); |
| 9575 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9576 | } |
| 9577 | |
| 9578 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 9579 | // resolve returns error and then preconnect finishes |
| 9580 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9581 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9582 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9583 | Initialize(); |
| 9584 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9585 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9586 | |
| 9587 | // Add asynchronous failure in host resolver. |
| 9588 | host_resolver_->set_ondemand_mode(true); |
| 9589 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9590 | factory_->set_require_confirmation(true); |
| 9591 | crypto_client_stream_factory_.set_handshake_mode( |
| 9592 | MockCryptoClientStream::ZERO_RTT); |
| 9593 | |
| 9594 | // Set up an address in stale resolver cache. |
| 9595 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9596 | HostCache::Entry entry(OK, |
| 9597 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9598 | HostCache::Entry::SOURCE_DNS); |
| 9599 | base::TimeDelta zero; |
| 9600 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9601 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9602 | // Expire the cache |
| 9603 | cache->OnNetworkChange(); |
| 9604 | |
| 9605 | // Socket data for stale connection which is supposed to disconnect. |
| 9606 | MockQuicData quic_data; |
| 9607 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9608 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9609 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9610 | SYNCHRONOUS, |
| 9611 | client_maker_.MakeConnectionClosePacket( |
| 9612 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9613 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9614 | |
| 9615 | QuicStreamRequest request(factory_.get()); |
| 9616 | EXPECT_EQ(ERR_IO_PENDING, |
| 9617 | request.Request( |
| 9618 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9619 | SocketTag(), |
| 9620 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9621 | failed_on_default_network_callback_, callback_.callback())); |
| 9622 | |
| 9623 | // host resolution returned but stale connection hasn't finished yet. |
| 9624 | host_resolver_->ResolveAllPending(); |
| 9625 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9626 | |
| 9627 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9628 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9629 | } |
| 9630 | |
| 9631 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9632 | // resolve returns error and then preconnect fails. |
| 9633 | TEST_P(QuicStreamFactoryTest, |
| 9634 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9635 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9636 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9637 | Initialize(); |
| 9638 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9639 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9640 | |
| 9641 | // Add asynchronous failure to host resolver. |
| 9642 | host_resolver_->set_ondemand_mode(true); |
| 9643 | factory_->set_require_confirmation(true); |
| 9644 | crypto_client_stream_factory_.set_handshake_mode( |
| 9645 | MockCryptoClientStream::ZERO_RTT); |
| 9646 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9647 | |
| 9648 | // Set up an address in stale resolver cache. |
| 9649 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9650 | HostCache::Entry entry(OK, |
| 9651 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9652 | HostCache::Entry::SOURCE_DNS); |
| 9653 | base::TimeDelta zero; |
| 9654 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9655 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9656 | // Expire the cache |
| 9657 | cache->OnNetworkChange(); |
| 9658 | |
| 9659 | MockQuicData quic_data; |
| 9660 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9661 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9662 | quic_data.AddWrite( |
Renjie | f5fcb17 | 2019-02-05 01:59:33 | [diff] [blame] | 9663 | SYNCHRONOUS, |
| 9664 | client_maker_.MakeConnectionClosePacket( |
| 9665 | 1, true, quic::QUIC_STALE_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9666 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9667 | |
| 9668 | QuicStreamRequest request(factory_.get()); |
| 9669 | EXPECT_EQ(ERR_IO_PENDING, |
| 9670 | request.Request( |
| 9671 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9672 | SocketTag(), |
| 9673 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9674 | failed_on_default_network_callback_, callback_.callback())); |
| 9675 | |
| 9676 | // Host Resolution returns failure but stale connection hasn't finished. |
| 9677 | host_resolver_->ResolveAllPending(); |
| 9678 | |
| 9679 | // Check that the final error is on resolution failure. |
| 9680 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9681 | |
| 9682 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9683 | } |
| 9684 | |
| 9685 | // With dns race experiment on, test that host resolution callback behaves |
| 9686 | // normal as experiment is not on |
| 9687 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
Zhongyi Shi | 967d2f1 | 2019-02-08 20:58:53 | [diff] [blame^] | 9688 | test_params_.quic_race_stale_dns_on_connection = true; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9689 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9690 | Initialize(); |
| 9691 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9692 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9693 | |
| 9694 | host_resolver_->set_ondemand_mode(true); |
| 9695 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9696 | kNonCachedIPAddress, ""); |
| 9697 | |
| 9698 | MockQuicData quic_data; |
| 9699 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9700 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9701 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9702 | |
| 9703 | QuicStreamRequest request(factory_.get()); |
| 9704 | EXPECT_EQ(ERR_IO_PENDING, |
| 9705 | request.Request( |
| 9706 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9707 | SocketTag(), |
| 9708 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9709 | failed_on_default_network_callback_, callback_.callback())); |
| 9710 | |
| 9711 | // Check that expect_on_host_resolution_ is properlly set. |
| 9712 | TestCompletionCallback host_resolution_callback; |
| 9713 | EXPECT_TRUE( |
| 9714 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9715 | base::RunLoop().RunUntilIdle(); |
| 9716 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9717 | |
| 9718 | host_resolver_->ResolveAllPending(); |
| 9719 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9720 | |
| 9721 | // Check that expect_on_host_resolution_ is flipped back. |
| 9722 | EXPECT_FALSE( |
| 9723 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9724 | |
| 9725 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9726 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9727 | } |
| 9728 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9729 | // Test that QuicStreamRequests with similar and different tags results in |
| 9730 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 9731 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 9732 | MockTaggingClientSocketFactory* socket_factory = |
| 9733 | new MockTaggingClientSocketFactory(); |
| 9734 | socket_factory_.reset(socket_factory); |
| 9735 | Initialize(); |
| 9736 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9737 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9738 | |
| 9739 | // Prepare to establish two QUIC sessions. |
| 9740 | MockQuicData socket_data; |
| 9741 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9742 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9743 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9744 | MockQuicData socket_data2; |
| 9745 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9746 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9747 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9748 | |
| 9749 | #if defined(OS_ANDROID) |
| 9750 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 9751 | SocketTag tag2(getuid(), 0x87654321); |
| 9752 | #else |
| 9753 | // On non-Android platforms we can only use the default constructor. |
| 9754 | SocketTag tag1, tag2; |
| 9755 | #endif |
| 9756 | |
| 9757 | // Request a stream with |tag1|. |
| 9758 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9759 | int rv = request1.Request( |
| 9760 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9761 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9762 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9763 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9764 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 9765 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9766 | ->tagged_before_data_transferred()); |
| 9767 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 9768 | request1.ReleaseSessionHandle(); |
| 9769 | EXPECT_TRUE(stream1); |
| 9770 | EXPECT_TRUE(stream1->IsConnected()); |
| 9771 | |
| 9772 | // Request a stream with |tag1| and verify underlying session is reused. |
| 9773 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9774 | rv = request2.Request( |
| 9775 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9776 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9777 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9778 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9779 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 9780 | request2.ReleaseSessionHandle(); |
| 9781 | EXPECT_TRUE(stream2); |
| 9782 | EXPECT_TRUE(stream2->IsConnected()); |
| 9783 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 9784 | |
| 9785 | // Request a stream with |tag2| and verify a new session is created. |
| 9786 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9787 | rv = request3.Request( |
| 9788 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 9789 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9790 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9791 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9792 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 9793 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9794 | ->tagged_before_data_transferred()); |
| 9795 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 9796 | request3.ReleaseSessionHandle(); |
| 9797 | EXPECT_TRUE(stream3); |
| 9798 | EXPECT_TRUE(stream3->IsConnected()); |
| 9799 | #if defined(OS_ANDROID) |
| 9800 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 9801 | #else |
| 9802 | // Same tag should reuse session. |
| 9803 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 9804 | #endif |
| 9805 | } |
| 9806 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9807 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9808 | } // namespace net |