[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 5 | #include "net/quic/quic_stream_factory.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 6 | |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 7 | #include <memory> |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8 | #include <ostream> |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 9 | #include <utility> |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 10 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/callback.h" |
xunjieli | 48e4f10 | 2017-04-11 23:06:53 | [diff] [blame] | 13 | #include "base/macros.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 14 | #include "base/run_loop.h" |
[email protected] | fc9be580 | 2013-06-11 10:56:51 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 16 | #include "base/test/test_mock_time_task_runner.h" |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 17 | #include "build/build_config.h" |
mgersh | af9a923 | 2017-04-13 20:19:03 | [diff] [blame] | 18 | #include "net/base/mock_network_change_notifier.h" |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 19 | #include "net/cert/ct_policy_enforcer.h" |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 20 | #include "net/cert/do_nothing_ct_verifier.h" |
| 21 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 22 | #include "net/dns/mock_host_resolver.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 23 | #include "net/http/http_response_headers.h" |
| 24 | #include "net/http/http_response_info.h" |
rtenneti | 8332ba5 | 2015-09-17 19:33:41 | [diff] [blame] | 25 | #include "net/http/http_server_properties_impl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 26 | #include "net/http/http_util.h" |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 27 | #include "net/http/transport_security_state.h" |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 28 | #include "net/http/transport_security_state_test_util.h" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 29 | #include "net/quic/crypto/proof_verifier_chromium.h" |
| 30 | #include "net/quic/mock_crypto_client_stream_factory.h" |
| 31 | #include "net/quic/mock_quic_data.h" |
| 32 | #include "net/quic/properties_based_quic_server_info.h" |
| 33 | #include "net/quic/quic_http_stream.h" |
| 34 | #include "net/quic/quic_http_utils.h" |
| 35 | #include "net/quic/quic_server_info.h" |
| 36 | #include "net/quic/quic_stream_factory_peer.h" |
| 37 | #include "net/quic/quic_test_packet_maker.h" |
| 38 | #include "net/quic/test_task_runner.h" |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 39 | #include "net/socket/next_proto.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 40 | #include "net/socket/socket_test_util.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 41 | #include "net/spdy/spdy_session_test_util.h" |
| 42 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 43 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 44 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 45 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 46 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 47 | #include "net/third_party/quic/core/crypto/crypto_handshake.h" |
| 48 | #include "net/third_party/quic/core/crypto/quic_crypto_client_config.h" |
| 49 | #include "net/third_party/quic/core/crypto/quic_decrypter.h" |
| 50 | #include "net/third_party/quic/core/crypto/quic_encrypter.h" |
Victor Vasiliev | c5b409c2 | 2018-07-24 12:23:46 | [diff] [blame] | 51 | #include "net/third_party/quic/core/http/quic_client_promised_info.h" |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 52 | #include "net/third_party/quic/core/quic_utils.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 53 | #include "net/third_party/quic/platform/api/quic_test.h" |
| 54 | #include "net/third_party/quic/test_tools/mock_clock.h" |
| 55 | #include "net/third_party/quic/test_tools/mock_random.h" |
| 56 | #include "net/third_party/quic/test_tools/quic_config_peer.h" |
| 57 | #include "net/third_party/quic/test_tools/quic_spdy_session_peer.h" |
| 58 | #include "net/third_party/quic/test_tools/quic_test_utils.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 59 | #include "net/third_party/quiche/src/spdy/core/spdy_test_utils.h" |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 60 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 61 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 62 | #include "testing/gtest/include/gtest/gtest.h" |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 63 | #include "url/gurl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 64 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 65 | using std::string; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 66 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 67 | namespace net { |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 68 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 69 | namespace { |
| 70 | |
| 71 | class MockSSLConfigService : public SSLConfigService { |
| 72 | public: |
| 73 | MockSSLConfigService() {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 74 | ~MockSSLConfigService() override {} |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 75 | |
| 76 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 77 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 78 | bool CanShareConnectionWithClientCerts( |
| 79 | const std::string& hostname) const override { |
| 80 | return false; |
| 81 | } |
| 82 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 83 | private: |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 84 | SSLConfig config_; |
| 85 | }; |
| 86 | |
| 87 | } // namespace |
| 88 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 89 | namespace test { |
| 90 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 91 | namespace { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 92 | |
| 93 | enum DestinationType { |
| 94 | // In pooling tests with two requests for different origins to the same |
| 95 | // destination, the destination should be |
| 96 | SAME_AS_FIRST, // the same as the first origin, |
| 97 | SAME_AS_SECOND, // the same as the second origin, or |
| 98 | DIFFERENT, // different from both. |
| 99 | }; |
| 100 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 101 | const char kDefaultServerHostName[] = "www.example.org"; |
| 102 | const char kServer2HostName[] = "mail.example.org"; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 103 | const char kDifferentHostname[] = "different.example.com"; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 104 | const int kDefaultServerPort = 443; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 105 | const char kDefaultUrl[] = "https://www.example.org/"; |
| 106 | const char kServer2Url[] = "https://mail.example.org/"; |
| 107 | const char kServer3Url[] = "https://docs.example.org/"; |
| 108 | const char kServer4Url[] = "https://images.example.org/"; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 109 | const int kDefaultRTTMilliSecs = 300; |
| 110 | const size_t kMinRetryTimeForDefaultNetworkSecs = 1; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 111 | const size_t kWaitTimeForNewNetworkSecs = 10; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 112 | const IPAddress kCachedIPAddress = IPAddress(192, 168, 0, 2); |
| 113 | const char kNonCachedIPAddress[] = "192.168.0.1"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 114 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 115 | // Run QuicStreamFactoryTest instances with all value combinations of version |
| 116 | // and enable_connection_racting. |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 117 | struct TestParams { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 118 | friend std::ostream& operator<<(std::ostream& os, const TestParams& p) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 119 | os << "{ version: " << QuicVersionToString(p.version) |
| 120 | << ", client_headers_include_h2_stream_dependency: " |
| 121 | << p.client_headers_include_h2_stream_dependency << " }"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 122 | return os; |
| 123 | } |
| 124 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 125 | quic::QuicTransportVersion version; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 126 | bool client_headers_include_h2_stream_dependency; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 127 | }; |
| 128 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 129 | std::vector<TestParams> GetTestParams() { |
| 130 | std::vector<TestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 131 | quic::QuicTransportVersionVector all_supported_versions = |
| 132 | quic::AllSupportedTransportVersions(); |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 133 | for (const auto& version : all_supported_versions) { |
| 134 | params.push_back(TestParams{version, false}); |
| 135 | params.push_back(TestParams{version, true}); |
| 136 | } |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 137 | return params; |
| 138 | } |
| 139 | |
| 140 | // Run QuicStreamFactoryWithDestinationTest instances with all value |
| 141 | // combinations of version, enable_connection_racting, and destination_type. |
| 142 | struct PoolingTestParams { |
| 143 | friend std::ostream& operator<<(std::ostream& os, |
| 144 | const PoolingTestParams& p) { |
| 145 | os << "{ version: " << QuicVersionToString(p.version) |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 146 | << ", destination_type: "; |
| 147 | switch (p.destination_type) { |
| 148 | case SAME_AS_FIRST: |
| 149 | os << "SAME_AS_FIRST"; |
| 150 | break; |
| 151 | case SAME_AS_SECOND: |
| 152 | os << "SAME_AS_SECOND"; |
| 153 | break; |
| 154 | case DIFFERENT: |
| 155 | os << "DIFFERENT"; |
| 156 | break; |
| 157 | } |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 158 | os << ", client_headers_include_h2_stream_dependency: " |
| 159 | << p.client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 160 | os << " }"; |
| 161 | return os; |
| 162 | } |
| 163 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 164 | quic::QuicTransportVersion version; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 165 | DestinationType destination_type; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 166 | bool client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 167 | }; |
| 168 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 169 | std::vector<PoolingTestParams> GetPoolingTestParams() { |
| 170 | std::vector<PoolingTestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 171 | quic::QuicTransportVersionVector all_supported_versions = |
| 172 | quic::AllSupportedTransportVersions(); |
| 173 | for (const quic::QuicTransportVersion version : all_supported_versions) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 174 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, false}); |
| 175 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, true}); |
| 176 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, false}); |
| 177 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, true}); |
| 178 | params.push_back(PoolingTestParams{version, DIFFERENT, false}); |
| 179 | params.push_back(PoolingTestParams{version, DIFFERENT, true}); |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 180 | } |
| 181 | return params; |
| 182 | } |
| 183 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 184 | } // namespace |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 185 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 186 | class QuicHttpStreamPeer { |
| 187 | public: |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 188 | static QuicChromiumClientSession::Handle* GetSessionHandle( |
| 189 | HttpStream* stream) { |
| 190 | return static_cast<QuicHttpStream*>(stream)->quic_session(); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 191 | } |
| 192 | }; |
| 193 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 194 | // TestConnectionMigrationSocketFactory will vend sockets with incremental port |
| 195 | // number. |
| 196 | class TestConnectionMigrationSocketFactory : public MockClientSocketFactory { |
| 197 | public: |
| 198 | TestConnectionMigrationSocketFactory() : next_source_port_num_(1u) {} |
| 199 | ~TestConnectionMigrationSocketFactory() override {} |
| 200 | |
| 201 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 202 | DatagramSocket::BindType bind_type, |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 203 | NetLog* net_log, |
| 204 | const NetLogSource& source) override { |
| 205 | SocketDataProvider* data_provider = mock_data().GetNext(); |
| 206 | std::unique_ptr<MockUDPClientSocket> socket( |
| 207 | new MockUDPClientSocket(data_provider, net_log)); |
| 208 | socket->set_source_port(next_source_port_num_++); |
| 209 | return std::move(socket); |
| 210 | } |
| 211 | |
| 212 | private: |
| 213 | uint16_t next_source_port_num_; |
| 214 | |
| 215 | DISALLOW_COPY_AND_ASSIGN(TestConnectionMigrationSocketFactory); |
| 216 | }; |
| 217 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 218 | class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 219 | protected: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 220 | QuicStreamFactoryTestBase(quic::QuicTransportVersion version, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 221 | bool client_headers_include_h2_stream_dependency) |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 222 | : host_resolver_(new MockHostResolver), |
| 223 | ssl_config_service_(new MockSSLConfigService), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 224 | socket_factory_(new MockClientSocketFactory), |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 225 | random_generator_(0), |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 226 | runner_(new TestTaskRunner(&clock_)), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 227 | version_(version), |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 228 | client_headers_include_h2_stream_dependency_( |
| 229 | client_headers_include_h2_stream_dependency), |
David Schinazi | c828105 | 2019-01-24 06:14:17 | [diff] [blame] | 230 | client_maker_( |
| 231 | version_, |
| 232 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 233 | &clock_, |
| 234 | kDefaultServerHostName, |
| 235 | quic::Perspective::IS_CLIENT, |
| 236 | client_headers_include_h2_stream_dependency_), |
| 237 | server_maker_( |
| 238 | version_, |
| 239 | quic::QuicUtils::CreateRandomConnectionId(&random_generator_), |
| 240 | &clock_, |
| 241 | kDefaultServerHostName, |
| 242 | quic::Perspective::IS_SERVER, |
| 243 | false), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 244 | cert_verifier_(std::make_unique<MockCertVerifier>()), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 245 | cert_transparency_verifier_(std::make_unique<DoNothingCTVerifier>()), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 246 | scoped_mock_network_change_notifier_(nullptr), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 247 | factory_(nullptr), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 248 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 249 | url_(kDefaultUrl), |
| 250 | url2_(kServer2Url), |
| 251 | url3_(kServer3Url), |
| 252 | url4_(kServer4Url), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 253 | privacy_mode_(PRIVACY_MODE_DISABLED), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 254 | failed_on_default_network_callback_(base::BindRepeating( |
| 255 | &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, |
| 256 | base::Unretained(this))), |
| 257 | failed_on_default_network_(false), |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 258 | store_server_configs_in_properties_(false), |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 259 | close_sessions_on_ip_change_(false), |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 260 | goaway_sessions_on_ip_change_(false), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 261 | idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 262 | reduced_ping_timeout_seconds_(quic::kPingTimeoutSecs), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 263 | max_time_before_crypto_handshake_seconds_( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 264 | quic::kMaxTimeForCryptoHandshakeSecs), |
| 265 | max_idle_time_before_crypto_handshake_seconds_( |
| 266 | quic::kInitialIdleTimeoutSecs), |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 267 | migrate_sessions_on_network_change_v2_(false), |
| 268 | migrate_sessions_early_v2_(false), |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 269 | retry_on_alternate_network_before_handshake_(false), |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 270 | race_stale_dns_on_connection_(false), |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 271 | go_away_on_path_degrading_(false), |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 272 | allow_server_migration_(false), |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 273 | race_cert_verification_(false), |
| 274 | estimate_initial_rtt_(false) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 275 | clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 276 | } |
| 277 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 278 | void Initialize() { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 279 | DCHECK(!factory_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 280 | factory_.reset(new QuicStreamFactory( |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 281 | net_log_.net_log(), host_resolver_.get(), ssl_config_service_.get(), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 282 | socket_factory_.get(), &http_server_properties_, cert_verifier_.get(), |
Nick Harper | ecf319d | 2018-10-16 07:58:54 | [diff] [blame] | 283 | &ct_policy_enforcer_, &transport_security_state_, |
| 284 | cert_transparency_verifier_.get(), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 285 | /*SocketPerformanceWatcherFactory*/ nullptr, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 286 | &crypto_client_stream_factory_, &random_generator_, &clock_, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 287 | quic::kDefaultMaxPacketSize, string(), |
| 288 | store_server_configs_in_properties_, close_sessions_on_ip_change_, |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 289 | goaway_sessions_on_ip_change_, |
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 290 | /*mark_quic_broken_when_network_blackholes*/ false, |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 291 | idle_connection_timeout_seconds_, reduced_ping_timeout_seconds_, |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 292 | max_time_before_crypto_handshake_seconds_, |
| 293 | max_idle_time_before_crypto_handshake_seconds_, |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 294 | migrate_sessions_on_network_change_v2_, migrate_sessions_early_v2_, |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 295 | retry_on_alternate_network_before_handshake_, |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 296 | race_stale_dns_on_connection_, go_away_on_path_degrading_, |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 297 | base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 298 | kMaxMigrationsToNonDefaultNetworkOnWriteError, |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 299 | kMaxMigrationsToNonDefaultNetworkOnPathDegrading, |
Charles 'Buck' Krasic | 0c346c9 | 2017-09-14 18:17:37 | [diff] [blame] | 300 | allow_server_migration_, race_cert_verification_, estimate_initial_rtt_, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 301 | client_headers_include_h2_stream_dependency_, connection_options_, |
Nick Harper | 2243e800 | 2018-09-28 20:33:26 | [diff] [blame] | 302 | client_connection_options_, |
kapishnikov | 7f8dd1e | 2018-01-24 06:10:49 | [diff] [blame] | 303 | /*enable_socket_recv_optimization*/ false)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 304 | } |
| 305 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 306 | void InitializeConnectionMigrationV2Test( |
| 307 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 308 | scoped_mock_network_change_notifier_.reset( |
| 309 | new ScopedMockNetworkChangeNotifier()); |
| 310 | MockNetworkChangeNotifier* mock_ncn = |
| 311 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 312 | mock_ncn->ForceNetworkHandlesSupported(); |
| 313 | mock_ncn->SetConnectedNetworksList(connected_networks); |
| 314 | migrate_sessions_on_network_change_v2_ = true; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 315 | migrate_sessions_early_v2_ = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 316 | retry_on_alternate_network_before_handshake_ = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 317 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 318 | Initialize(); |
| 319 | } |
| 320 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 321 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 322 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 323 | request->ReleaseSessionHandle(); |
| 324 | if (!session || !session->IsConnected()) |
| 325 | return nullptr; |
| 326 | |
| 327 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 328 | } |
| 329 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 330 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 331 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 332 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 333 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 334 | } |
| 335 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 336 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 337 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 338 | false); |
| 339 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 340 | server_id); |
| 341 | } |
| 342 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 343 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 344 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 345 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 346 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 347 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 348 | } |
| 349 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 350 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 351 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 352 | server_id); |
| 353 | } |
| 354 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 355 | // Get the pending, not activated session, if there is only one session alive. |
| 356 | QuicChromiumClientSession* GetPendingSession( |
| 357 | const HostPortPair& host_port_pair) { |
| 358 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 359 | false); |
| 360 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 361 | host_port_pair); |
| 362 | } |
| 363 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 364 | QuicChromiumClientSession* GetActiveSession( |
| 365 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 366 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 367 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 368 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 369 | } |
| 370 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 371 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 372 | return GetSourcePortForNewSessionInner(destination, false); |
| 373 | } |
| 374 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 375 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 376 | return GetSourcePortForNewSessionInner(destination, true); |
| 377 | } |
| 378 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 379 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 380 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 381 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 382 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 383 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 384 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 385 | MockQuicData socket_data; |
| 386 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 387 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 388 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 389 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 390 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 391 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 392 | EXPECT_EQ( |
| 393 | ERR_IO_PENDING, |
| 394 | request.Request( |
| 395 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 396 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 397 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 398 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 399 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 400 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 401 | EXPECT_TRUE(stream.get()); |
| 402 | stream.reset(); |
| 403 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 404 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 405 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 406 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 407 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 411 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 412 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 413 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 414 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 415 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 416 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 417 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 418 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 419 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 420 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 421 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 422 | } |
| 423 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 424 | std::unique_ptr<quic::QuicEncryptedPacket> |
| 425 | ConstructClientConnectionClosePacket(quic::QuicPacketNumber num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 426 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 427 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 428 | } |
| 429 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 430 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
| 431 | quic::QuicPacketNumber packet_number, |
| 432 | quic::QuicRstStreamErrorCode error_code) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 433 | quic::QuicStreamId stream_id = |
| 434 | GetNthClientInitiatedBidirectionalStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 435 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 436 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 437 | } |
| 438 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 439 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 440 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 441 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 442 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 443 | EXPECT_TRUE(test_cert.get()); |
| 444 | ProofVerifyDetailsChromium verify_details; |
| 445 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 446 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 447 | return verify_details; |
| 448 | } |
| 449 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 450 | void NotifyIPAddressChanged() { |
| 451 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 452 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 453 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 454 | } |
| 455 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 456 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 457 | quic::QuicPacketNumber packet_number, |
| 458 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 459 | bool should_include_version, |
| 460 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 461 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 462 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 463 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 464 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 465 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 466 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 467 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 468 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 469 | } |
| 470 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 471 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 472 | quic::QuicPacketNumber packet_number, |
| 473 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 474 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 475 | bool should_include_version, |
| 476 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 477 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 478 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 479 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 480 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 481 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 482 | size_t spdy_headers_frame_len; |
| 483 | return client_maker_.MakeRequestHeadersPacket( |
| 484 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 485 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 486 | } |
| 487 | |
| 488 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 489 | quic::QuicPacketNumber packet_number, |
| 490 | quic::QuicStreamId stream_id, |
| 491 | bool should_include_version, |
| 492 | bool fin, |
| 493 | quic::QuicStreamOffset* offset) { |
| 494 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 495 | /*parent_stream_id=*/0, |
| 496 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 497 | } |
| 498 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 499 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
| 500 | quic::QuicPacketNumber packet_number, |
| 501 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 502 | bool should_include_version, |
| 503 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 504 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 505 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 506 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 507 | packet_number, stream_id, should_include_version, fin, |
| 508 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 509 | } |
| 510 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 511 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 512 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 513 | } |
| 514 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 515 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
| 516 | quic::QuicPacketNumber packet_number, |
| 517 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 518 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 519 | } |
| 520 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 521 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 522 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 523 | IPEndPoint expected_address) { |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 524 | allow_server_migration_ = true; |
| 525 | Initialize(); |
| 526 | |
| 527 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 528 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 529 | crypto_client_stream_factory_.SetConfig(config); |
| 530 | |
| 531 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 532 | MockQuicData socket_data1; |
| 533 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 534 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 535 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 536 | // Set up second socket data provider that is used after |
| 537 | // migration. |
| 538 | MockQuicData socket_data2; |
| 539 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 540 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 541 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 542 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 543 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 544 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 545 | 3, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 546 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 547 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 548 | |
| 549 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 550 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 551 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 552 | request.Request( |
| 553 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 554 | SocketTag(), |
| 555 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 556 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 557 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 558 | |
| 559 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 560 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 561 | base::RunLoop().RunUntilIdle(); |
| 562 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 563 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 564 | EXPECT_TRUE(stream.get()); |
| 565 | |
| 566 | // Cause QUIC stream to be created. |
| 567 | HttpRequestInfo request_info; |
| 568 | request_info.method = "GET"; |
| 569 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 570 | request_info.traffic_annotation = |
| 571 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 572 | EXPECT_EQ(OK, |
| 573 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 574 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 575 | // Ensure that session is alive and active. |
| 576 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 577 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 578 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 579 | |
| 580 | IPEndPoint actual_address; |
| 581 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 582 | EXPECT_EQ(actual_address, expected_address); |
| 583 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 584 | << " " << actual_address.port(); |
| 585 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 586 | << " " << expected_address.port(); |
| 587 | |
| 588 | stream.reset(); |
| 589 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 590 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 591 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 592 | } |
| 593 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 594 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 595 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 596 | store_server_configs_in_properties_ = true; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 597 | idle_connection_timeout_seconds_ = 500; |
| 598 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 599 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 600 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 601 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 602 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 603 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 604 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 605 | const quic::QuicConfig* config = |
| 606 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 607 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 608 | |
| 609 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 610 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 611 | const AlternativeService alternative_service1( |
| 612 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 613 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 614 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 615 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 616 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 617 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 618 | http_server_properties_.SetAlternativeServices( |
| 619 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 620 | |
| 621 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 622 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 623 | const AlternativeService alternative_service2( |
| 624 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 625 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 626 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 627 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 628 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 629 | |
| 630 | http_server_properties_.SetAlternativeServices( |
| 631 | server2, alternative_service_info_vector2); |
| 632 | // Verify that the properties of both QUIC servers are stored in the |
| 633 | // HTTP properties map. |
| 634 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 635 | |
| 636 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 637 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 638 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 639 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 640 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 641 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 642 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 643 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 644 | |
| 645 | // Update quic_server_info's server_config and persist it. |
| 646 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 647 | // Minimum SCFG that passes config validation checks. |
| 648 | const char scfg[] = {// SCFG |
| 649 | 0x53, 0x43, 0x46, 0x47, |
| 650 | // num entries |
| 651 | 0x01, 0x00, |
| 652 | // padding |
| 653 | 0x00, 0x00, |
| 654 | // EXPY |
| 655 | 0x45, 0x58, 0x50, 0x59, |
| 656 | // EXPY end offset |
| 657 | 0x08, 0x00, 0x00, 0x00, |
| 658 | // Value |
| 659 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 660 | |
| 661 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 662 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 663 | string source_address_token("test_source_address_token"); |
| 664 | string cert_sct("test_cert_sct"); |
| 665 | string chlo_hash("test_chlo_hash"); |
| 666 | string signature("test_signature"); |
| 667 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 668 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 669 | certs.push_back(test_cert); |
| 670 | state->server_config = server_config; |
| 671 | state->source_address_token = source_address_token; |
| 672 | state->cert_sct = cert_sct; |
| 673 | state->chlo_hash = chlo_hash; |
| 674 | state->server_config_sig = signature; |
| 675 | state->certs = certs; |
| 676 | |
| 677 | quic_server_info->Persist(); |
| 678 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 679 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 680 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 681 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 682 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 683 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 684 | // Update quic_server_info2's server_config and persist it. |
| 685 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 686 | |
| 687 | // Minimum SCFG that passes config validation checks. |
| 688 | const char scfg2[] = {// SCFG |
| 689 | 0x53, 0x43, 0x46, 0x47, |
| 690 | // num entries |
| 691 | 0x01, 0x00, |
| 692 | // padding |
| 693 | 0x00, 0x00, |
| 694 | // EXPY |
| 695 | 0x45, 0x58, 0x50, 0x59, |
| 696 | // EXPY end offset |
| 697 | 0x08, 0x00, 0x00, 0x00, |
| 698 | // Value |
| 699 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 700 | |
| 701 | // Create temporary strings becasue Persist() clears string data in |
| 702 | // |state2|. |
| 703 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 704 | string source_address_token2("test_source_address_token2"); |
| 705 | string cert_sct2("test_cert_sct2"); |
| 706 | string chlo_hash2("test_chlo_hash2"); |
| 707 | string signature2("test_signature2"); |
| 708 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 709 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 710 | certs2.push_back(test_cert2); |
| 711 | state2->server_config = server_config2; |
| 712 | state2->source_address_token = source_address_token2; |
| 713 | state2->cert_sct = cert_sct2; |
| 714 | state2->chlo_hash = chlo_hash2; |
| 715 | state2->server_config_sig = signature2; |
| 716 | state2->certs = certs2; |
| 717 | |
| 718 | quic_server_info2->Persist(); |
| 719 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 720 | // Verify the MRU order is maintained. |
| 721 | const QuicServerInfoMap& quic_server_info_map = |
| 722 | http_server_properties_.quic_server_info_map(); |
| 723 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 724 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 725 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 726 | ++quic_server_info_map_it; |
| 727 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 728 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 729 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 730 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 731 | |
| 732 | // Create a session and verify that the cached state is loaded. |
| 733 | MockQuicData socket_data; |
| 734 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 735 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 736 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 737 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 738 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 739 | request.Request( |
| 740 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 741 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 742 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 743 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 744 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 745 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 746 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 747 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 748 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 749 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 750 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 751 | crypto_config->LookupOrCreate(quic_server_id); |
| 752 | EXPECT_FALSE(cached->server_config().empty()); |
| 753 | EXPECT_TRUE(cached->GetServerConfig()); |
| 754 | EXPECT_EQ(server_config, cached->server_config()); |
| 755 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 756 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 757 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 758 | EXPECT_EQ(signature, cached->signature()); |
| 759 | ASSERT_EQ(1U, cached->certs().size()); |
| 760 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 761 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 762 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 763 | |
| 764 | // Create a session and verify that the cached state is loaded. |
| 765 | MockQuicData socket_data2; |
| 766 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 767 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 768 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 769 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 770 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 771 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 772 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 773 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 774 | request2.Request( |
| 775 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 776 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 777 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 778 | net_log_, &net_error_details_, |
| 779 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 780 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 781 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 782 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 783 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 784 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 785 | crypto_config->LookupOrCreate(quic_server_id2); |
| 786 | EXPECT_FALSE(cached2->server_config().empty()); |
| 787 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 788 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 789 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 790 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 791 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 792 | EXPECT_EQ(signature2, cached2->signature()); |
| 793 | ASSERT_EQ(1U, cached->certs().size()); |
| 794 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 795 | } |
| 796 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 797 | void RunTestLoopUntilIdle() { |
| 798 | while (!runner_->GetPostedTasks().empty()) |
| 799 | runner_->RunNextTask(); |
| 800 | } |
| 801 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 802 | quic::QuicStreamId GetNthClientInitiatedBidirectionalStreamId(int n) { |
| 803 | return quic::test::GetNthClientInitiatedBidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 804 | } |
| 805 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 806 | quic::QuicStreamId GetNthServerInitiatedUnidirectionalStreamId(int n) { |
| 807 | return quic::test::GetNthServerInitiatedUnidirectionalStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 808 | } |
| 809 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 810 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 811 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 812 | // Helper methods for tests of connection migration on write error. |
| 813 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 814 | // Migratable stream triggers write error. |
| 815 | void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); |
| 816 | // Non-migratable stream triggers write error. |
| 817 | void TestMigrationOnWriteErrorMixedStreams2(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 818 | void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 819 | void TestMigrationOnWriteError(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 820 | void TestMigrationOnWriteErrorWithMultipleRequests(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 821 | void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 822 | void TestMigrationOnMultipleWriteErrors( |
| 823 | IoMode write_error_mode_on_old_network, |
| 824 | IoMode write_error_mode_on_new_network); |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 825 | void TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 826 | bool disconnected); |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 827 | void TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 828 | void TestMigrationOnNetworkDisconnected(bool async_write_before); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 829 | void TestMigrationOnNetworkMadeDefault(IoMode write_mode); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 830 | void TestMigrationOnPathDegrading(bool async_write_before); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 831 | void TestMigrateSessionWithDrainingStream( |
| 832 | IoMode write_mode_for_queued_packet); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 833 | void TestMigrationOnWriteErrorPauseBeforeConnected(IoMode write_error_mode); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 834 | void TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 835 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 836 | bool disconnect_before_connect); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 837 | void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 838 | void TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 839 | quic::QuicErrorCode error); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 840 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 841 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 842 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 843 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 844 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 845 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 846 | quic::test::MockRandom random_generator_; |
| 847 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 848 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 849 | const quic::QuicTransportVersion version_; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 850 | const bool client_headers_include_h2_stream_dependency_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 851 | QuicTestPacketMaker client_maker_; |
| 852 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 853 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 854 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 855 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 856 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 857 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 858 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 859 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 860 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 861 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 862 | GURL url_; |
| 863 | GURL url2_; |
| 864 | GURL url3_; |
| 865 | GURL url4_; |
| 866 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 867 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 868 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 869 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 870 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 871 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 872 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 873 | |
| 874 | // Variables to configure QuicStreamFactory. |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 875 | bool store_server_configs_in_properties_; |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 876 | bool close_sessions_on_ip_change_; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 877 | bool goaway_sessions_on_ip_change_; |
rtenneti | 41c0999 | 2015-11-30 18:24:01 | [diff] [blame] | 878 | int idle_connection_timeout_seconds_; |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 879 | int reduced_ping_timeout_seconds_; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 880 | int max_time_before_crypto_handshake_seconds_; |
| 881 | int max_idle_time_before_crypto_handshake_seconds_; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 882 | bool migrate_sessions_on_network_change_v2_; |
| 883 | bool migrate_sessions_early_v2_; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 884 | bool retry_on_alternate_network_before_handshake_; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 885 | bool race_stale_dns_on_connection_; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 886 | bool go_away_on_path_degrading_; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 887 | bool allow_server_migration_; |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 888 | bool race_cert_verification_; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 889 | bool estimate_initial_rtt_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 890 | quic::QuicTagVector connection_options_; |
| 891 | quic::QuicTagVector client_connection_options_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 892 | }; |
| 893 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 894 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 895 | public ::testing::TestWithParam<TestParams> { |
| 896 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 897 | QuicStreamFactoryTest() |
| 898 | : QuicStreamFactoryTestBase( |
| 899 | GetParam().version, |
| 900 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 901 | }; |
| 902 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame^] | 903 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 904 | QuicStreamFactoryTest, |
| 905 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 906 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 907 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 908 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 909 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 910 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 911 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 912 | MockQuicData socket_data; |
| 913 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 914 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 915 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 916 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 917 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 918 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 919 | request.Request( |
| 920 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 921 | SocketTag(), |
| 922 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 923 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 924 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 925 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 926 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 927 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 928 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 929 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 930 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 931 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 932 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 933 | DEFAULT_PRIORITY, SocketTag(), |
| 934 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 935 | &net_error_details_, |
| 936 | failed_on_default_network_callback_, |
| 937 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 938 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 939 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 940 | |
| 941 | EXPECT_TRUE(stream.get()); |
| 942 | |
| 943 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 944 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 945 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 946 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 947 | DEFAULT_PRIORITY, SocketTag(), |
| 948 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 949 | &net_error_details_, |
| 950 | failed_on_default_network_callback_, |
| 951 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 952 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 953 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 954 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 955 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 956 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 957 | } |
| 958 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 959 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 960 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 961 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 962 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 963 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 964 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 965 | MockQuicData socket_data; |
| 966 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 967 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 968 | |
| 969 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 970 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 971 | host_resolver_->set_synchronous_mode(true); |
| 972 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 973 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 974 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 975 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 976 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 977 | DEFAULT_PRIORITY, SocketTag(), |
| 978 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 979 | &net_error_details_, |
| 980 | failed_on_default_network_callback_, |
| 981 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 982 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 983 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 984 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 985 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 986 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 987 | } |
| 988 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 989 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 990 | Initialize(); |
| 991 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 992 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 993 | |
| 994 | MockQuicData socket_data; |
| 995 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 996 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 997 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 998 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 999 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1000 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1001 | request.Request( |
| 1002 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1003 | SocketTag(), |
| 1004 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1005 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1006 | |
| 1007 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1008 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1009 | EXPECT_TRUE(stream.get()); |
| 1010 | |
| 1011 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1012 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1013 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 1014 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1015 | } |
| 1016 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1017 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 1018 | Initialize(); |
| 1019 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1020 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1021 | |
| 1022 | MockQuicData socket_data; |
| 1023 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1024 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1025 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1026 | |
| 1027 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1028 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1029 | request->Request( |
| 1030 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1031 | SocketTag(), |
| 1032 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1033 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1034 | request.reset(); |
| 1035 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1036 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1037 | // crash. crbug.com/768343. |
| 1038 | factory_.reset(); |
| 1039 | } |
| 1040 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1041 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1042 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1043 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1044 | host_resolver_->set_synchronous_mode(true); |
| 1045 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1046 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1047 | Initialize(); |
| 1048 | factory_->set_require_confirmation(true); |
| 1049 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1050 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1051 | |
| 1052 | MockQuicData socket_data; |
| 1053 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1054 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1055 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1056 | |
| 1057 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1058 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1059 | request.Request( |
| 1060 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1061 | SocketTag(), |
| 1062 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1063 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1064 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1065 | IPAddress last_address; |
| 1066 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1067 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1068 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1069 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1070 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1071 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1072 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1073 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1074 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1075 | EXPECT_TRUE(stream.get()); |
| 1076 | |
| 1077 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1078 | EXPECT_TRUE(session->require_confirmation()); |
| 1079 | } |
| 1080 | |
| 1081 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1082 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1083 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1084 | host_resolver_->set_synchronous_mode(true); |
| 1085 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1086 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1087 | Initialize(); |
| 1088 | factory_->set_require_confirmation(true); |
| 1089 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1090 | |
| 1091 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1092 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1093 | |
| 1094 | MockQuicData socket_data; |
| 1095 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1096 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1097 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1098 | |
| 1099 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1100 | EXPECT_THAT(request.Request( |
| 1101 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1102 | SocketTag(), |
| 1103 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1104 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1105 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1106 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1107 | IPAddress last_address; |
| 1108 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1109 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1110 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1111 | EXPECT_TRUE(stream.get()); |
| 1112 | |
| 1113 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1114 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1115 | |
| 1116 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1117 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1118 | |
| 1119 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1120 | } |
| 1121 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1122 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1123 | ServerNetworkStats stats; |
| 1124 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1125 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1126 | stats); |
| 1127 | estimate_initial_rtt_ = true; |
| 1128 | |
| 1129 | Initialize(); |
| 1130 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1131 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1132 | |
| 1133 | MockQuicData socket_data; |
| 1134 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1135 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1136 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1137 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1138 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1139 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1140 | request.Request( |
| 1141 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1142 | SocketTag(), |
| 1143 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1144 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1145 | |
| 1146 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1147 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1148 | EXPECT_TRUE(stream.get()); |
| 1149 | |
| 1150 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1151 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1152 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1153 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1154 | } |
| 1155 | |
| 1156 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1157 | ScopedMockNetworkChangeNotifier notifier; |
| 1158 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1159 | NetworkChangeNotifier::CONNECTION_2G); |
| 1160 | estimate_initial_rtt_ = true; |
| 1161 | |
| 1162 | Initialize(); |
| 1163 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1164 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1165 | |
| 1166 | MockQuicData socket_data; |
| 1167 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1168 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1169 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1170 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1171 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1172 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1173 | request.Request( |
| 1174 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1175 | SocketTag(), |
| 1176 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1177 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1178 | |
| 1179 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1180 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1181 | EXPECT_TRUE(stream.get()); |
| 1182 | |
| 1183 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1184 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1185 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1186 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1187 | } |
| 1188 | |
| 1189 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1190 | ScopedMockNetworkChangeNotifier notifier; |
| 1191 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1192 | NetworkChangeNotifier::CONNECTION_3G); |
| 1193 | estimate_initial_rtt_ = true; |
| 1194 | |
| 1195 | Initialize(); |
| 1196 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1197 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1198 | |
| 1199 | MockQuicData socket_data; |
| 1200 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1201 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1202 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1203 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1204 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1205 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1206 | request.Request( |
| 1207 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1208 | SocketTag(), |
| 1209 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1210 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1211 | |
| 1212 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1213 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1214 | EXPECT_TRUE(stream.get()); |
| 1215 | |
| 1216 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1217 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1218 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1219 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1220 | } |
| 1221 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1222 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1223 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1224 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1225 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1226 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1227 | MockQuicData socket_data; |
| 1228 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1229 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1230 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1231 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1232 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1233 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1234 | request.Request( |
| 1235 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1236 | SocketTag(), |
| 1237 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1238 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1239 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1240 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1241 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1242 | EXPECT_TRUE(stream.get()); |
| 1243 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1244 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1245 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1246 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1247 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1248 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1249 | |
| 1250 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1251 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1252 | } |
| 1253 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1254 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1255 | Initialize(); |
| 1256 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1257 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1258 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1259 | MockQuicData socket_data; |
| 1260 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1261 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1262 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1263 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1264 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1265 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1266 | request.Request( |
| 1267 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1268 | SocketTag(), |
| 1269 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1270 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1271 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1272 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1273 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1274 | EXPECT_TRUE(stream.get()); |
| 1275 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1276 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1277 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1278 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1279 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1280 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1281 | NetErrorDetails details; |
| 1282 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1283 | session->PopulateNetErrorDetails(&details); |
| 1284 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1285 | details.quic_port_migration_detected = false; |
| 1286 | stream->PopulateNetErrorDetails(&details); |
| 1287 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1288 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1289 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1290 | |
| 1291 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1292 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1293 | } |
| 1294 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1295 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1296 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1297 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1298 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1299 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1300 | MockQuicData socket_data; |
| 1301 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1302 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1303 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1304 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1305 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1306 | host_resolver_->set_synchronous_mode(true); |
| 1307 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1308 | "192.168.0.1", ""); |
| 1309 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1310 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1311 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1312 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1313 | DEFAULT_PRIORITY, SocketTag(), |
| 1314 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1315 | &net_error_details_, |
| 1316 | failed_on_default_network_callback_, |
| 1317 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1318 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1319 | EXPECT_TRUE(stream.get()); |
| 1320 | |
| 1321 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1322 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1323 | EXPECT_EQ(OK, |
| 1324 | request2.Request( |
| 1325 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1326 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1327 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1328 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1329 | EXPECT_TRUE(stream2.get()); |
| 1330 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1331 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1332 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1333 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1334 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1335 | } |
| 1336 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1337 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1338 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1339 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1340 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1341 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1342 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1343 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1344 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1345 | |
| 1346 | VerifyServerMigration(config, alt_address); |
| 1347 | |
| 1348 | // Close server-migrated session. |
| 1349 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1350 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1351 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1352 | |
| 1353 | // Set up server IP, socket, proof, and config for new session. |
| 1354 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1355 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1356 | |
| 1357 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1358 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1359 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1360 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1361 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1362 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1363 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1364 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1365 | |
| 1366 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1367 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1368 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1369 | crypto_client_stream_factory_.SetConfig(config2); |
| 1370 | |
| 1371 | // Create new request to cause new session creation. |
| 1372 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1373 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1374 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1375 | request2.Request( |
| 1376 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1377 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1378 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1379 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1380 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1381 | EXPECT_TRUE(stream2.get()); |
| 1382 | |
| 1383 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1384 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1385 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1386 | } |
| 1387 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1388 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1389 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1390 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1391 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1392 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1393 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1394 | MockQuicData socket_data1; |
| 1395 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1396 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1397 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1398 | MockQuicData socket_data2; |
| 1399 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1400 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1401 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1402 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1403 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1404 | host_resolver_->set_synchronous_mode(true); |
| 1405 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1406 | "192.168.0.1", ""); |
| 1407 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1408 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1409 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1410 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1411 | DEFAULT_PRIORITY, SocketTag(), |
| 1412 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1413 | &net_error_details_, |
| 1414 | failed_on_default_network_callback_, |
| 1415 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1416 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1417 | EXPECT_TRUE(stream.get()); |
| 1418 | |
| 1419 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1420 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1421 | EXPECT_EQ(OK, |
| 1422 | request2.Request( |
| 1423 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1424 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1425 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1426 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1427 | EXPECT_TRUE(stream2.get()); |
| 1428 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1429 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1430 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1431 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1432 | |
| 1433 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1434 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1435 | EXPECT_EQ(OK, |
| 1436 | request3.Request( |
| 1437 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1438 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1439 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1440 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1441 | EXPECT_TRUE(stream3.get()); |
| 1442 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1443 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1444 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1445 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1446 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1447 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1448 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1449 | } |
| 1450 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1451 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1452 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1453 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1454 | MockQuicData socket_data; |
| 1455 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1456 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1457 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1458 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1459 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1460 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1461 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1462 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1463 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1464 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1465 | host_resolver_->set_synchronous_mode(true); |
| 1466 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1467 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1468 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1469 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1470 | EXPECT_EQ(OK, |
| 1471 | request.Request( |
| 1472 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1473 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1474 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1475 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1476 | EXPECT_TRUE(stream.get()); |
| 1477 | |
| 1478 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1479 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1480 | EXPECT_EQ(OK, |
| 1481 | request2.Request( |
| 1482 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1483 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1484 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1485 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1486 | EXPECT_TRUE(stream2.get()); |
| 1487 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1488 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1489 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1490 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1491 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1492 | } |
| 1493 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1494 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1495 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1496 | MockQuicData socket_data; |
| 1497 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1498 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1499 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1500 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1501 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1502 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1503 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1504 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1505 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1506 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1507 | EXPECT_TRUE(primary_pin.FromString( |
| 1508 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1509 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1510 | verify_details.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1511 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1512 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1513 | host_resolver_->set_synchronous_mode(true); |
| 1514 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1515 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1516 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1517 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1518 | EXPECT_EQ(OK, |
| 1519 | request.Request( |
| 1520 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1521 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1522 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1523 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1524 | EXPECT_TRUE(stream.get()); |
| 1525 | |
| 1526 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1527 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1528 | EXPECT_EQ(OK, |
| 1529 | request2.Request( |
| 1530 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1531 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1532 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1533 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1534 | EXPECT_TRUE(stream2.get()); |
| 1535 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1536 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1537 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1538 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1539 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1543 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1544 | |
| 1545 | MockQuicData socket_data1; |
| 1546 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1547 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1548 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1549 | MockQuicData socket_data2; |
| 1550 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1551 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1552 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1553 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1554 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1555 | HostPortPair server2(kServer2HostName, 443); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1556 | transport_security_state_.EnableStaticPinsForTesting(); |
| 1557 | ScopedTransportSecurityStateSource scoped_security_state_source; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1558 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1559 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1560 | uint8_t bad_pin = 3; |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1561 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1562 | test::GetTestHashValue(bad_pin)); |
| 1563 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1564 | |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1565 | HashValue primary_pin(HASH_VALUE_SHA256); |
| 1566 | EXPECT_TRUE(primary_pin.FromString( |
| 1567 | "sha256/Nn8jk5By4Vkq6BeOVZ7R7AC6XUUBZsWmUbJR1f1Y5FY=")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1568 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Matt Mueller | 230996f1 | 2018-10-22 19:39:44 | [diff] [blame] | 1569 | verify_details2.cert_verify_result.public_key_hashes.push_back(primary_pin); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1570 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1571 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1572 | host_resolver_->set_synchronous_mode(true); |
| 1573 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1574 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1575 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1576 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1577 | EXPECT_EQ(OK, |
| 1578 | request.Request( |
| 1579 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1580 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1581 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1582 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1583 | EXPECT_TRUE(stream.get()); |
| 1584 | |
| 1585 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1586 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1587 | EXPECT_EQ(OK, |
| 1588 | request2.Request( |
| 1589 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1590 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1591 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1592 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1593 | EXPECT_TRUE(stream2.get()); |
| 1594 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1595 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1596 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1597 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1598 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1599 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1600 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1601 | } |
| 1602 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1603 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1604 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1605 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1606 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1607 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1608 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1609 | MockQuicData socket_data; |
| 1610 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1611 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1612 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1613 | MockQuicData socket_data2; |
| 1614 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1615 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1616 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1617 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1618 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1619 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1620 | request.Request( |
| 1621 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1622 | SocketTag(), |
| 1623 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1624 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1625 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1626 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1627 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1628 | EXPECT_TRUE(stream.get()); |
| 1629 | |
| 1630 | // Mark the session as going away. Ensure that while it is still alive |
| 1631 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1632 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1633 | factory_->OnSessionGoingAway(session); |
| 1634 | EXPECT_EQ(true, |
| 1635 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1636 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1637 | |
| 1638 | // Create a new request for the same destination and verify that a |
| 1639 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1640 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1641 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1642 | request2.Request( |
| 1643 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1644 | SocketTag(), |
| 1645 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1646 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1647 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1648 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1649 | EXPECT_TRUE(stream2.get()); |
| 1650 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1651 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1652 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1653 | EXPECT_EQ(true, |
| 1654 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1655 | |
| 1656 | stream2.reset(); |
| 1657 | stream.reset(); |
| 1658 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1659 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1660 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1661 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1662 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1663 | } |
| 1664 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1665 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1666 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1667 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1668 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1669 | |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1670 | quic::QuicStreamId stream_id = GetNthClientInitiatedBidirectionalStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1671 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1672 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1673 | if (version_ == quic::QUIC_VERSION_99) { |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1674 | socket_data.AddWrite( |
| 1675 | SYNCHRONOUS, |
| 1676 | client_maker_.MakeStreamIdBlockedPacket( |
| 1677 | 2, true, GetNthClientInitiatedBidirectionalStreamId(49))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1678 | socket_data.AddWrite( |
| 1679 | SYNCHRONOUS, client_maker_.MakeRstPacket(3, true, stream_id, |
| 1680 | quic::QUIC_STREAM_CANCELLED)); |
| 1681 | socket_data.AddRead( |
| 1682 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1683 | quic::QUIC_STREAM_CANCELLED)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 1684 | socket_data.AddRead( |
| 1685 | ASYNC, server_maker_.MakeMaxStreamIdPacket( |
| 1686 | 4, true, GetNthClientInitiatedBidirectionalStreamId(50))); |
Frank Kastenholz | c9b9bea | 2018-12-03 20:13:47 | [diff] [blame] | 1687 | } else { |
| 1688 | socket_data.AddWrite( |
| 1689 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1690 | quic::QUIC_STREAM_CANCELLED)); |
| 1691 | socket_data.AddRead( |
| 1692 | ASYNC, server_maker_.MakeRstPacket(1, false, stream_id, |
| 1693 | quic::QUIC_STREAM_CANCELLED)); |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1694 | } |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1695 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1696 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1697 | |
| 1698 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1699 | request_info.traffic_annotation = |
| 1700 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1701 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1702 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1703 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1704 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1705 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1706 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1707 | int rv = request.Request( |
| 1708 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1709 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1710 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1711 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1713 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1714 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1715 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1716 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1717 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1718 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1719 | EXPECT_EQ(OK, |
| 1720 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1721 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1722 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1723 | } |
| 1724 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1725 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1726 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1727 | DEFAULT_PRIORITY, SocketTag(), |
| 1728 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1729 | &net_error_details_, |
| 1730 | failed_on_default_network_callback_, |
| 1731 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1732 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1733 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1734 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1735 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1736 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1737 | |
| 1738 | // Close the first stream. |
| 1739 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1740 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1741 | // stream. |
Frank Kastenholz | 878763bf | 2018-11-28 19:14:48 | [diff] [blame] | 1742 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1743 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1744 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1745 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1746 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1747 | |
| 1748 | // Force close of the connection to suppress the generation of RST |
| 1749 | // packets when streams are torn down, which wouldn't be relevant to |
| 1750 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1751 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1752 | session->connection()->CloseConnection( |
| 1753 | quic::QUIC_PUBLIC_RESET, "test", |
| 1754 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1755 | } |
| 1756 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1757 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1758 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1759 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1760 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1761 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1762 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1763 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1764 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1765 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1766 | request.Request( |
| 1767 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1768 | SocketTag(), |
| 1769 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1770 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1771 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1772 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1773 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1774 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1775 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1776 | } |
| 1777 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1778 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1779 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1780 | |
| 1781 | MockQuicData socket_data; |
| 1782 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1783 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1784 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1785 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1786 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1787 | request.Request( |
| 1788 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1789 | SocketTag(), |
| 1790 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1791 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1792 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1793 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1794 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1795 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1796 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1797 | } |
| 1798 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1799 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1800 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1801 | MockQuicData socket_data; |
| 1802 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1803 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1804 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1805 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1806 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1807 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1808 | request.Request( |
| 1809 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1810 | SocketTag(), |
| 1811 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1812 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1813 | } |
| 1814 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1815 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1816 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1817 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1818 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1819 | DEFAULT_PRIORITY, SocketTag(), |
| 1820 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1821 | &net_error_details_, |
| 1822 | failed_on_default_network_callback_, |
| 1823 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1824 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1825 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1826 | EXPECT_TRUE(stream.get()); |
| 1827 | stream.reset(); |
| 1828 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1829 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1830 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1831 | } |
| 1832 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1833 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1834 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1835 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1836 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1837 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1838 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1839 | MockQuicData socket_data; |
| 1840 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1841 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1842 | socket_data.AddWrite( |
| 1843 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1844 | socket_data.AddWrite(SYNCHRONOUS, |
| 1845 | client_maker_.MakeConnectionClosePacket( |
| 1846 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1847 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1848 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1849 | MockQuicData socket_data2; |
| 1850 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1851 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1852 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1853 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1854 | QuicStreamRequest request(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 | request.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 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1864 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1865 | request_info.traffic_annotation = |
| 1866 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1867 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1868 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1869 | |
| 1870 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1871 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1872 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1873 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1874 | stream->ReadResponseHeaders(callback_.callback())); |
| 1875 | |
| 1876 | // Now attempting to request a stream to the same origin should create |
| 1877 | // a new session. |
| 1878 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1879 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1880 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1881 | request2.Request( |
| 1882 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1883 | SocketTag(), |
| 1884 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1885 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1886 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1887 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1888 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1889 | stream.reset(); // Will reset stream 3. |
| 1890 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1891 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1892 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1893 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1894 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1895 | } |
| 1896 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1897 | // Regression test for crbug.com/700617. Test a write error during the |
| 1898 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1899 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1900 | // QuicStreamRequest should succeed without hanging. |
| 1901 | TEST_P(QuicStreamFactoryTest, |
| 1902 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1903 | Initialize(); |
| 1904 | // Use unmocked crypto stream to do crypto connect. |
| 1905 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1906 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1907 | |
| 1908 | MockQuicData socket_data; |
| 1909 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1910 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1911 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1912 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1913 | |
| 1914 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1915 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1916 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1917 | request.Request( |
| 1918 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1919 | SocketTag(), |
| 1920 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1921 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1922 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1923 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1924 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1925 | |
| 1926 | // Verify new requests can be sent normally without hanging. |
| 1927 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1928 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1929 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1930 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1931 | MockQuicData socket_data2; |
| 1932 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1933 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1934 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1935 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1936 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1937 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1938 | request2.Request( |
| 1939 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1940 | SocketTag(), |
| 1941 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1942 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1943 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1944 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1945 | // Run the message loop to complete host resolution. |
| 1946 | base::RunLoop().RunUntilIdle(); |
| 1947 | |
| 1948 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1949 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1950 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1951 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1952 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1953 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1954 | |
| 1955 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1956 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1957 | EXPECT_TRUE(stream.get()); |
| 1958 | stream.reset(); |
| 1959 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1960 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1961 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1962 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1963 | } |
| 1964 | |
| 1965 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1966 | Initialize(); |
| 1967 | // Use unmocked crypto stream to do crypto connect. |
| 1968 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1969 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1970 | host_resolver_->set_synchronous_mode(true); |
| 1971 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1972 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1973 | |
| 1974 | MockQuicData socket_data; |
| 1975 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1976 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1977 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1978 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1979 | |
| 1980 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1981 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1982 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1983 | request.Request( |
| 1984 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1985 | SocketTag(), |
| 1986 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1987 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1988 | // Check no active session, or active jobs left for this server. |
| 1989 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1990 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1991 | |
| 1992 | // Verify new requests can be sent normally without hanging. |
| 1993 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1994 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1995 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1996 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1997 | MockQuicData socket_data2; |
| 1998 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1999 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2000 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2001 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2002 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2003 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2004 | request2.Request( |
| 2005 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2006 | SocketTag(), |
| 2007 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2008 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2009 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2010 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 2011 | |
| 2012 | // Complete handshake. |
| 2013 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2014 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2015 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2016 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2017 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 2018 | |
| 2019 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2020 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 2021 | EXPECT_TRUE(stream.get()); |
| 2022 | stream.reset(); |
| 2023 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2024 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2025 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2026 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2027 | } |
| 2028 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2029 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 2030 | close_sessions_on_ip_change_ = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2031 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2032 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2033 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2034 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2035 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2036 | MockQuicData socket_data; |
| 2037 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2038 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2039 | socket_data.AddWrite( |
| 2040 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2041 | socket_data.AddWrite( |
| 2042 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2043 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2044 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2045 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2046 | MockQuicData socket_data2; |
| 2047 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2048 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2049 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2050 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2051 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2052 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2053 | request.Request( |
| 2054 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2055 | SocketTag(), |
| 2056 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2057 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2058 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2059 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2060 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2061 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2062 | request_info.traffic_annotation = |
| 2063 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2064 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2065 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2066 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2067 | // Check an active session exisits for the destination. |
| 2068 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2069 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2070 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2071 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2072 | IPAddress last_address; |
| 2073 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2074 | // Change the IP address and verify that stream saw the error and the active |
| 2075 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2076 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2077 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2078 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2079 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2080 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2081 | // Check no active session exists for the destination. |
| 2082 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2083 | |
| 2084 | // Now attempting to request a stream to the same origin should create |
| 2085 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2086 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2087 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2088 | request2.Request( |
| 2089 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2090 | SocketTag(), |
| 2091 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2092 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2093 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2094 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2095 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2096 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2097 | // Check a new active session exisits for the destination and the old session |
| 2098 | // is no longer live. |
| 2099 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2100 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2101 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2102 | |
| 2103 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2104 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2105 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2106 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2107 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2108 | } |
| 2109 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2110 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2111 | // as going away on IP address change instead of being closed. New requests will |
| 2112 | // go to a new connection. |
| 2113 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
| 2114 | goaway_sessions_on_ip_change_ = true; |
| 2115 | Initialize(); |
| 2116 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2117 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2118 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2119 | |
| 2120 | MockQuicData quic_data1; |
| 2121 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2122 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2123 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2124 | quic_data1.AddWrite( |
| 2125 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2126 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2127 | true, &header_stream_offset)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2128 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2129 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2130 | ASYNC, |
| 2131 | ConstructOkResponsePacket( |
| 2132 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2133 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2134 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2135 | |
| 2136 | MockQuicData quic_data2; |
| 2137 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2138 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2139 | quic_data2.AddWrite( |
| 2140 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2141 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2142 | |
| 2143 | // Create request and QuicHttpStream. |
| 2144 | QuicStreamRequest request(factory_.get()); |
| 2145 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2146 | request.Request( |
| 2147 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2148 | SocketTag(), |
| 2149 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2150 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2151 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2152 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2153 | EXPECT_TRUE(stream.get()); |
| 2154 | |
| 2155 | // Cause QUIC stream to be created. |
| 2156 | HttpRequestInfo request_info; |
| 2157 | request_info.method = "GET"; |
| 2158 | request_info.url = url_; |
| 2159 | request_info.traffic_annotation = |
| 2160 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2161 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2162 | net_log_, CompletionOnceCallback())); |
| 2163 | |
| 2164 | // Ensure that session is alive and active. |
| 2165 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2166 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2167 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2168 | |
| 2169 | // Send GET request on stream. |
| 2170 | HttpResponseInfo response; |
| 2171 | HttpRequestHeaders request_headers; |
| 2172 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2173 | callback_.callback())); |
| 2174 | |
| 2175 | // Receive an IP address change notification. |
| 2176 | NotifyIPAddressChanged(); |
| 2177 | |
| 2178 | // The connection should still be alive, but marked as going away. |
| 2179 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2180 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2181 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2182 | |
| 2183 | // Resume the data, response should be read from the original connection. |
| 2184 | quic_data1.Resume(); |
| 2185 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2186 | EXPECT_EQ(200, response.headers->response_code()); |
| 2187 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2188 | |
| 2189 | // Second request should be sent on a new connection. |
| 2190 | QuicStreamRequest request2(factory_.get()); |
| 2191 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2192 | request2.Request( |
| 2193 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2194 | SocketTag(), |
| 2195 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2196 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2197 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2198 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2199 | EXPECT_TRUE(stream2.get()); |
| 2200 | |
| 2201 | // Check an active session exisits for the destination. |
| 2202 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2203 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2204 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2205 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2206 | |
| 2207 | stream.reset(); |
| 2208 | stream2.reset(); |
| 2209 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2210 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2211 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2212 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2213 | } |
| 2214 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2215 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2216 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2217 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2218 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2219 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2220 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2221 | |
| 2222 | MockQuicData socket_data; |
| 2223 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2224 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2225 | socket_data.AddWrite( |
| 2226 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2227 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2228 | |
| 2229 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2230 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2231 | request.Request( |
| 2232 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2233 | SocketTag(), |
| 2234 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2235 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2236 | |
| 2237 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2238 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2239 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2240 | request_info.traffic_annotation = |
| 2241 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2242 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2243 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2244 | |
| 2245 | IPAddress last_address; |
| 2246 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2247 | |
| 2248 | // Change the IP address and verify that the connection is unaffected. |
| 2249 | NotifyIPAddressChanged(); |
| 2250 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2251 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2252 | |
| 2253 | // Attempting a new request to the same origin uses the same connection. |
| 2254 | QuicStreamRequest request2(factory_.get()); |
| 2255 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2256 | DEFAULT_PRIORITY, SocketTag(), |
| 2257 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2258 | &net_error_details_, |
| 2259 | failed_on_default_network_callback_, |
| 2260 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2261 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2262 | |
| 2263 | stream.reset(); |
| 2264 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2265 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2266 | } |
| 2267 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2268 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
| 2269 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2270 | } |
| 2271 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2272 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
| 2273 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2274 | } |
| 2275 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2276 | // Sets up a test which attempts connection migration successfully after probing |
| 2277 | // when a new network is made as default and the old default is still available. |
| 2278 | // |write_mode| specifies the write mode for the last write before |
| 2279 | // OnNetworkMadeDefault is delivered to session. |
| 2280 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2281 | IoMode write_mode) { |
| 2282 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2283 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2284 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2285 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2286 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2287 | // Using a testing task runner so that we can control time. |
| 2288 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2289 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2290 | |
| 2291 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2292 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2293 | |
| 2294 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2295 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2296 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2297 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2298 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2299 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2300 | write_mode, ConstructGetRequestPacket( |
| 2301 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2302 | true, &header_stream_offset)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2303 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2304 | |
| 2305 | // Set up the second socket data provider that is used after migration. |
| 2306 | // The response to the earlier request is read on the new socket. |
| 2307 | MockQuicData quic_data2; |
| 2308 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2309 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2310 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2311 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2312 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2313 | quic_data2.AddRead(ASYNC, |
| 2314 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2315 | // Ping packet to send after migration is completed. |
| 2316 | quic_data2.AddWrite(ASYNC, |
| 2317 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2318 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2319 | ASYNC, |
| 2320 | ConstructOkResponsePacket( |
| 2321 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2322 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2323 | quic_data2.AddWrite( |
| 2324 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2325 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2326 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2327 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2328 | |
| 2329 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2330 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2331 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2332 | request.Request( |
| 2333 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2334 | SocketTag(), |
| 2335 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2336 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2337 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2338 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2339 | EXPECT_TRUE(stream.get()); |
| 2340 | |
| 2341 | // Cause QUIC stream to be created. |
| 2342 | HttpRequestInfo request_info; |
| 2343 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2344 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2345 | request_info.traffic_annotation = |
| 2346 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2347 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2348 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2349 | |
| 2350 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2351 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2352 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2353 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2354 | |
| 2355 | // Send GET request on stream. |
| 2356 | HttpResponseInfo response; |
| 2357 | HttpRequestHeaders request_headers; |
| 2358 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2359 | callback_.callback())); |
| 2360 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2361 | // Deliver a signal that a alternate network is connected now, this should |
| 2362 | // cause the connection to start early migration on path degrading. |
| 2363 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2364 | ->SetConnectedNetworksList( |
| 2365 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2366 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2367 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2368 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2369 | // Cause the connection to report path degrading to the session. |
| 2370 | // Due to lack of alternate network, session will not mgirate connection. |
| 2371 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2372 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2373 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2374 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2375 | // A task will be posted to migrate to the new default network. |
| 2376 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2377 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2378 | |
| 2379 | // Execute the posted task to migrate back to the default network. |
| 2380 | task_runner->RunUntilIdle(); |
| 2381 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2382 | // retry migrate back to default network is scheduled. |
| 2383 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2384 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2385 | // kDefaultRTTMilliSecs. |
| 2386 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2387 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2388 | next_task_delay); |
| 2389 | |
| 2390 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2391 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2392 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2393 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2394 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2395 | |
| 2396 | // Resume quic data and a connectivity probe response will be read on the new |
| 2397 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2398 | // will be posted to complete migration. |
| 2399 | quic_data2.Resume(); |
| 2400 | |
| 2401 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2402 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2403 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2404 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2405 | // There should be three pending tasks, the nearest one will complete |
| 2406 | // migration to the new network. |
| 2407 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2408 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2409 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2410 | task_runner->FastForwardBy(next_task_delay); |
| 2411 | |
| 2412 | // Response headers are received over the new network. |
| 2413 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2414 | EXPECT_EQ(200, response.headers->response_code()); |
| 2415 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2416 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2417 | // probe and has been cancelled due to successful migration. |
| 2418 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2419 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2420 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2421 | next_task_delay); |
| 2422 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2423 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2424 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2425 | // is also cancelled due to the success migration on the previous trial. |
| 2426 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2427 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2428 | base::TimeDelta expected_delay = |
| 2429 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2430 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2431 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2432 | task_runner->FastForwardBy(next_task_delay); |
| 2433 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2434 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2435 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2436 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2437 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2438 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2439 | stream.reset(); |
| 2440 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2441 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2442 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2443 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2444 | } |
| 2445 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2446 | // Regression test for http://859674. |
| 2447 | // This test veries that a writer will not attempt to write packets until being |
| 2448 | // unblocked on both socket level and network level. In this test, a probing |
| 2449 | // writer is used to send two connectivity probes to the peer: where the first |
| 2450 | // one completes successfully, while a connectivity response is received before |
| 2451 | // completes sending the second one. The connection migration attempt will |
| 2452 | // proceed while the probing writer is blocked at the socket level, which will |
| 2453 | // block the writer on the network level. Once connection migration completes |
| 2454 | // successfully, the probing writer will be unblocked on the network level, it |
| 2455 | // will not attempt to write new packets until the socket level is unblocked. |
| 2456 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
| 2457 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2458 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2459 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2460 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2461 | |
| 2462 | // Using a testing task runner so that we can control time. |
| 2463 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2464 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2465 | |
| 2466 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2467 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2468 | |
| 2469 | MockQuicData quic_data1; |
| 2470 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2471 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2472 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2473 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2474 | quic_data1.AddWrite( |
| 2475 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 2476 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 2477 | true, &header_stream_offset)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2478 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2479 | |
| 2480 | // Set up the second socket data provider that is used after migration. |
| 2481 | // The response to the earlier request is read on the new socket. |
| 2482 | MockQuicData quic_data2; |
| 2483 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2484 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2485 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2486 | quic_data2.AddRead(ASYNC, |
| 2487 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2488 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2489 | quic_data2.AddRead(ASYNC, |
| 2490 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2491 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2492 | quic_data2.AddWrite(ASYNC, |
| 2493 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2494 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2495 | ASYNC, |
| 2496 | ConstructOkResponsePacket( |
| 2497 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2498 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2499 | quic_data2.AddWrite(ASYNC, |
| 2500 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2501 | quic_data2.AddWrite( |
| 2502 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 2503 | 6, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2504 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2505 | |
| 2506 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2507 | |
| 2508 | // Create request and QuicHttpStream. |
| 2509 | QuicStreamRequest request(factory_.get()); |
| 2510 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2511 | request.Request( |
| 2512 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2513 | SocketTag(), |
| 2514 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2515 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2516 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2517 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2518 | EXPECT_TRUE(stream.get()); |
| 2519 | |
| 2520 | // Cause QUIC stream to be created. |
| 2521 | HttpRequestInfo request_info; |
| 2522 | request_info.method = "GET"; |
| 2523 | request_info.url = url_; |
| 2524 | request_info.traffic_annotation = |
| 2525 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2526 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2527 | net_log_, CompletionOnceCallback())); |
| 2528 | |
| 2529 | // Ensure that session is alive and active. |
| 2530 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2531 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2532 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2533 | |
| 2534 | // Send GET request on stream. |
| 2535 | HttpResponseInfo response; |
| 2536 | HttpRequestHeaders request_headers; |
| 2537 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2538 | callback_.callback())); |
| 2539 | |
| 2540 | // Deliver a signal that a alternate network is connected now, this should |
| 2541 | // cause the connection to start early migration on path degrading. |
| 2542 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2543 | ->SetConnectedNetworksList( |
| 2544 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2545 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2546 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2547 | |
| 2548 | // Cause the connection to report path degrading to the session. |
| 2549 | // Due to lack of alternate network, session will not mgirate connection. |
| 2550 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2551 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2552 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2553 | |
| 2554 | // A task will be posted to migrate to the new default network. |
| 2555 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2556 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2557 | |
| 2558 | // Execute the posted task to migrate back to the default network. |
| 2559 | task_runner->RunUntilIdle(); |
| 2560 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2561 | // retry migrate back to default network is scheduled. |
| 2562 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2563 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2564 | // kDefaultRTTMilliSecs. |
| 2565 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2566 | base::TimeDelta expected_delay = |
| 2567 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2568 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2569 | |
| 2570 | // Fast forward to send the second connectivity probe. The write will be |
| 2571 | // asynchronous and complete after the read completes. |
| 2572 | task_runner->FastForwardBy(next_task_delay); |
| 2573 | |
| 2574 | // Resume quic data and a connectivity probe response will be read on the new |
| 2575 | // socket, declare probing as successful. |
| 2576 | quic_data2.Resume(); |
| 2577 | |
| 2578 | // The connection should still be alive, and not marked as going away. |
| 2579 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2580 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2581 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2582 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2583 | |
| 2584 | // There should be three pending tasks, the nearest one will complete |
| 2585 | // migration to the new network. Second task will retry migrate back to |
| 2586 | // default but cancelled, and the third task will retry send connectivity |
| 2587 | // probe but also cancelled. |
| 2588 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2589 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2590 | task_runner->RunUntilIdle(); |
| 2591 | |
| 2592 | // Response headers are received over the new network. |
| 2593 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2594 | EXPECT_EQ(200, response.headers->response_code()); |
| 2595 | |
| 2596 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2597 | base::RunLoop().RunUntilIdle(); |
| 2598 | |
| 2599 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2600 | // to default network and has been cancelled due to successful migration. |
| 2601 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2602 | expected_delay = |
| 2603 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2604 | expected_delay; |
| 2605 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2606 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2607 | task_runner->FastForwardBy(next_task_delay); |
| 2608 | |
| 2609 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2610 | // also been cancelled due to the successful probing. |
| 2611 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2612 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2613 | expected_delay = |
| 2614 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2615 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2616 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2617 | task_runner->FastForwardBy(next_task_delay); |
| 2618 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2619 | |
| 2620 | // Verify that the session is still alive. |
| 2621 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2622 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2623 | |
| 2624 | stream.reset(); |
| 2625 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2626 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2627 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2628 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2629 | } |
| 2630 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2631 | // This test verifies that session times out connection migration attempt |
| 2632 | // with signals delivered in the following order (no alternate network is |
| 2633 | // available): |
| 2634 | // - default network disconnected is delivered: session attempts connection |
| 2635 | // migration but found not alternate network. Session waits for a new network |
| 2636 | // comes up in the next kWaitTimeForNewNetworkSecs seonds. |
| 2637 | // - no new network is connected, migration times out. Session is closed. |
| 2638 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
| 2639 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2640 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2641 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2642 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2643 | // Using a testing task runner so that we can control time. |
| 2644 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2645 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2646 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2647 | MockQuicData socket_data; |
| 2648 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2649 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2650 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2651 | |
| 2652 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2653 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2654 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2655 | request.Request( |
| 2656 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2657 | SocketTag(), |
| 2658 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2659 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2660 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2661 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2662 | EXPECT_TRUE(stream.get()); |
| 2663 | |
| 2664 | // Cause QUIC stream to be created. |
| 2665 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2666 | request_info.traffic_annotation = |
| 2667 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2668 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2669 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2670 | |
| 2671 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2672 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2673 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2674 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2675 | |
| 2676 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2677 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2678 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2679 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2680 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2681 | // The migration will not fail until the migration alarm timeout. |
| 2682 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2683 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2684 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2685 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2686 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2687 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2688 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2689 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2690 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2691 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2692 | next_task_delay); |
| 2693 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2694 | |
| 2695 | // The connection should now be closed. A request for response |
| 2696 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2697 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2698 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2699 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2700 | |
| 2701 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2702 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2703 | } |
| 2704 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2705 | // This test verifies that connectivity probes will be sent even if there is |
| 2706 | // a non-migratable stream. However, when connection migrates to the |
| 2707 | // successfully probed path, any non-migratable stream will be reset. And if |
| 2708 | // the connection becomes idle then, close the connection. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2709 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2710 | InitializeConnectionMigrationV2Test( |
| 2711 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2712 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2713 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2714 | |
| 2715 | MockQuicData socket_data; |
| 2716 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2717 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2718 | socket_data.AddWrite( |
| 2719 | SYNCHRONOUS, |
| 2720 | client_maker_.MakeRstAckAndConnectionClosePacket( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2721 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Fan Yang | 7c68f63 | 2018-11-06 03:05:38 | [diff] [blame] | 2722 | quic::QUIC_STREAM_CANCELLED, |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2723 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 2724 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
| 2725 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2726 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2727 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2728 | // Set up the second socket data provider that is used for probing. |
| 2729 | MockQuicData quic_data1; |
| 2730 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2731 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2732 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2733 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2734 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2735 | quic_data1.AddRead(ASYNC, |
| 2736 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2737 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2738 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2739 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2740 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2741 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2742 | request.Request( |
| 2743 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2744 | SocketTag(), |
| 2745 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2746 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2747 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2748 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2749 | EXPECT_TRUE(stream.get()); |
| 2750 | |
| 2751 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2752 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2753 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2754 | request_info.traffic_annotation = |
| 2755 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2756 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2757 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2758 | |
| 2759 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2760 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2761 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2762 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2763 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2764 | // Trigger connection migration. Session will start to probe the alternative |
| 2765 | // network. Although there is a non-migratable stream, session will still be |
| 2766 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2767 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2768 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2769 | |
| 2770 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2771 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2772 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2773 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2774 | // Resume data to read a connectivity probing response, which will cause |
| 2775 | // non-migtable streams to be closed. As session becomes idle, connection will |
| 2776 | // be closed. |
| 2777 | quic_data1.Resume(); |
| 2778 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2779 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2780 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2781 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2782 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2783 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2784 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2785 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2786 | } |
| 2787 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2788 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2789 | InitializeConnectionMigrationV2Test( |
| 2790 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2791 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2792 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2793 | |
| 2794 | MockQuicData socket_data; |
| 2795 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2796 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2797 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2798 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2799 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2800 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2801 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2802 | |
| 2803 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2804 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2805 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2806 | request.Request( |
| 2807 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2808 | SocketTag(), |
| 2809 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2810 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2811 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2812 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2813 | EXPECT_TRUE(stream.get()); |
| 2814 | |
| 2815 | // Cause QUIC stream to be created. |
| 2816 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2817 | request_info.traffic_annotation = |
| 2818 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2819 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2820 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2821 | |
| 2822 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2823 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2824 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2825 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2826 | |
| 2827 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2828 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2829 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2830 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2831 | |
| 2832 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2833 | // this should cause session to continue but be marked as going away. |
| 2834 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2835 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2836 | |
| 2837 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2838 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2839 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2840 | |
| 2841 | stream.reset(); |
| 2842 | |
| 2843 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2844 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2845 | } |
| 2846 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2847 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2848 | InitializeConnectionMigrationV2Test( |
| 2849 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2850 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2851 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2852 | |
| 2853 | MockQuicData socket_data; |
| 2854 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2855 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2856 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2857 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2858 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2859 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2860 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2861 | |
| 2862 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2863 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2864 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2865 | request.Request( |
| 2866 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2867 | SocketTag(), |
| 2868 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2869 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2870 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2871 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2872 | EXPECT_TRUE(stream.get()); |
| 2873 | |
| 2874 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2875 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2876 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2877 | request_info.traffic_annotation = |
| 2878 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2879 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2880 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2881 | |
| 2882 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2883 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2884 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2885 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2886 | |
| 2887 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2888 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2889 | // quic::QUIC_STREAM_CANCELLED error code, and the session will be closed. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2890 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2891 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2892 | |
| 2893 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2894 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2895 | |
| 2896 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2897 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2898 | } |
| 2899 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2900 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2901 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2902 | InitializeConnectionMigrationV2Test( |
| 2903 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2904 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2905 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2906 | |
| 2907 | MockQuicData socket_data; |
| 2908 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2909 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2910 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 2911 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 2912 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 2913 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2914 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2915 | |
| 2916 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2917 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2918 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2919 | request.Request( |
| 2920 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2921 | SocketTag(), |
| 2922 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2923 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2924 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2925 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2926 | EXPECT_TRUE(stream.get()); |
| 2927 | |
| 2928 | // Cause QUIC stream to be created. |
| 2929 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2930 | request_info.traffic_annotation = |
| 2931 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2932 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2933 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2934 | |
| 2935 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2936 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2937 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2938 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2939 | |
| 2940 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2941 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2942 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2943 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2944 | |
| 2945 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2946 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2947 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2948 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2949 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2950 | |
| 2951 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2952 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2953 | |
| 2954 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2955 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2956 | } |
| 2957 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2958 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2959 | InitializeConnectionMigrationV2Test( |
| 2960 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2961 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2962 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2963 | |
| 2964 | MockQuicData socket_data; |
| 2965 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2966 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2967 | socket_data.AddWrite( |
| 2968 | SYNCHRONOUS, |
| 2969 | client_maker_.MakeConnectionClosePacket( |
| 2970 | 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 2971 | "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2972 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2973 | |
| 2974 | // Create request and QuicHttpStream. |
| 2975 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2976 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2977 | request.Request( |
| 2978 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2979 | SocketTag(), |
| 2980 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2981 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2982 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2983 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2984 | EXPECT_TRUE(stream.get()); |
| 2985 | |
| 2986 | // Ensure that session is alive and active. |
| 2987 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2988 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2989 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2990 | |
| 2991 | // Trigger connection migration. |
| 2992 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2993 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2994 | |
| 2995 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2996 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2997 | |
| 2998 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2999 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3000 | } |
| 3001 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 3002 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3003 | InitializeConnectionMigrationV2Test( |
| 3004 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3005 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3006 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3007 | |
| 3008 | MockQuicData socket_data; |
| 3009 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3010 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3011 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3012 | |
| 3013 | // Create request and QuicHttpStream. |
| 3014 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3015 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3016 | request.Request( |
| 3017 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3018 | SocketTag(), |
| 3019 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3020 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3021 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3022 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3023 | EXPECT_TRUE(stream.get()); |
| 3024 | |
| 3025 | // Ensure that session is alive and active. |
| 3026 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3027 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3028 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3029 | |
| 3030 | // Trigger connection migration. Since there are no active streams, |
| 3031 | // the session will be closed. |
| 3032 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3033 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3034 | |
| 3035 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3036 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3037 | |
| 3038 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3039 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3040 | } |
| 3041 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3042 | // This test verifies session migrates to the alternate network immediately when |
| 3043 | // default network disconnects with a synchronous write before migration. |
| 3044 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3045 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3046 | } |
| 3047 | |
| 3048 | // This test verifies session migrates to the alternate network immediately when |
| 3049 | // default network disconnects with an asynchronously write before migration. |
| 3050 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3051 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3052 | } |
| 3053 | |
| 3054 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3055 | bool async_write_before) { |
| 3056 | InitializeConnectionMigrationV2Test( |
| 3057 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3058 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3059 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3060 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3061 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3062 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3063 | |
| 3064 | // Use the test task runner. |
| 3065 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3066 | |
| 3067 | int packet_number = 1; |
| 3068 | MockQuicData socket_data; |
| 3069 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3070 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3071 | socket_data.AddWrite( |
| 3072 | SYNCHRONOUS, |
| 3073 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3074 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3075 | SYNCHRONOUS, |
| 3076 | ConstructGetRequestPacket(packet_number++, |
| 3077 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3078 | true, true, &header_stream_offset)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3079 | if (async_write_before) { |
| 3080 | socket_data.AddWrite(ASYNC, OK); |
| 3081 | packet_number++; |
| 3082 | } |
| 3083 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3084 | |
| 3085 | // Create request and QuicHttpStream. |
| 3086 | QuicStreamRequest request(factory_.get()); |
| 3087 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3088 | request.Request( |
| 3089 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3090 | SocketTag(), |
| 3091 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3092 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3093 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3094 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3095 | EXPECT_TRUE(stream.get()); |
| 3096 | |
| 3097 | // Cause QUIC stream to be created. |
| 3098 | HttpRequestInfo request_info; |
| 3099 | request_info.method = "GET"; |
| 3100 | request_info.url = url_; |
| 3101 | request_info.traffic_annotation = |
| 3102 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3103 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3104 | net_log_, CompletionOnceCallback())); |
| 3105 | |
| 3106 | // Ensure that session is alive and active. |
| 3107 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3108 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3109 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3110 | |
| 3111 | // Send GET request on stream. |
| 3112 | HttpResponseInfo response; |
| 3113 | HttpRequestHeaders request_headers; |
| 3114 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3115 | callback_.callback())); |
| 3116 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3117 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3118 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3119 | |
| 3120 | // Set up second socket data provider that is used after migration. |
| 3121 | // The response to the earlier request is read on this new socket. |
| 3122 | MockQuicData socket_data1; |
| 3123 | socket_data1.AddWrite( |
| 3124 | SYNCHRONOUS, |
| 3125 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3126 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3127 | ASYNC, |
| 3128 | ConstructOkResponsePacket( |
| 3129 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3130 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3131 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3132 | SYNCHRONOUS, |
| 3133 | client_maker_.MakeAckAndRstPacket( |
| 3134 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3135 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3136 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3137 | |
| 3138 | // Trigger connection migration. |
| 3139 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3140 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3141 | |
| 3142 | // The connection should still be alive, not marked as going away. |
| 3143 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3144 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3145 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3146 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3147 | |
| 3148 | // Ensure that the session is still alive. |
| 3149 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3150 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3151 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3152 | |
| 3153 | // Run the message loop so that data queued in the new socket is read by the |
| 3154 | // packet reader. |
| 3155 | runner_->RunNextTask(); |
| 3156 | |
| 3157 | // Response headers are received over the new network. |
| 3158 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3159 | EXPECT_EQ(200, response.headers->response_code()); |
| 3160 | |
| 3161 | // Check that the session is still alive. |
| 3162 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3163 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3164 | |
| 3165 | // There should be posted tasks not executed, which is to migrate back to |
| 3166 | // default network. |
| 3167 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3168 | |
| 3169 | // Receive signal to mark new network as default. |
| 3170 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3171 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3172 | |
| 3173 | stream.reset(); |
| 3174 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3175 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3176 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3177 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3178 | } |
| 3179 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3180 | // This test receives NCN signals in the following order: |
| 3181 | // - default network disconnected |
| 3182 | // - after a pause, new network is connected. |
| 3183 | // - new network is made default. |
| 3184 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3185 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3186 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3187 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3188 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3189 | |
| 3190 | // Use the test task runner. |
| 3191 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3192 | |
| 3193 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3194 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3195 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3196 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3197 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3198 | socket_data.AddWrite( |
| 3199 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3200 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3201 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3202 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3203 | |
| 3204 | // Create request and QuicHttpStream. |
| 3205 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3206 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3207 | request.Request( |
| 3208 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3209 | SocketTag(), |
| 3210 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3211 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3212 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3213 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3214 | EXPECT_TRUE(stream.get()); |
| 3215 | |
| 3216 | // Cause QUIC stream to be created. |
| 3217 | HttpRequestInfo request_info; |
| 3218 | request_info.method = "GET"; |
| 3219 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3220 | request_info.traffic_annotation = |
| 3221 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3222 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3223 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3224 | |
| 3225 | // Ensure that session is alive and active. |
| 3226 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3227 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3228 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3229 | |
| 3230 | // Send GET request on stream. |
| 3231 | HttpResponseInfo response; |
| 3232 | HttpRequestHeaders request_headers; |
| 3233 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3234 | callback_.callback())); |
| 3235 | |
| 3236 | // Trigger connection migration. Since there are no networks |
| 3237 | // to migrate to, this should cause the session to wait for a new network. |
| 3238 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3239 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3240 | |
| 3241 | // The connection should still be alive, not marked as going away. |
| 3242 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3243 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3244 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3245 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3246 | |
| 3247 | // Set up second socket data provider that is used after migration. |
| 3248 | // The response to the earlier request is read on this new socket. |
| 3249 | MockQuicData socket_data1; |
| 3250 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3251 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3252 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3253 | ASYNC, |
| 3254 | ConstructOkResponsePacket( |
| 3255 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3256 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3257 | socket_data1.AddWrite( |
| 3258 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3259 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3260 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3261 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3262 | |
| 3263 | // Add a new network and notify the stream factory of a new connected network. |
| 3264 | // This causes a PING packet to be sent over the new network. |
| 3265 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3266 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3267 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3268 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3269 | |
| 3270 | // Ensure that the session is still alive. |
| 3271 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3272 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3273 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3274 | |
| 3275 | // Run the message loop so that data queued in the new socket is read by the |
| 3276 | // packet reader. |
| 3277 | runner_->RunNextTask(); |
| 3278 | |
| 3279 | // Response headers are received over the new network. |
| 3280 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3281 | EXPECT_EQ(200, response.headers->response_code()); |
| 3282 | |
| 3283 | // Check that the session is still alive. |
| 3284 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3285 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3286 | |
| 3287 | // There should posted tasks not executed, which is to migrate back to default |
| 3288 | // network. |
| 3289 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3290 | |
| 3291 | // Receive signal to mark new network as default. |
| 3292 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3293 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3294 | |
| 3295 | stream.reset(); |
| 3296 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3297 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3298 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3299 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3300 | } |
| 3301 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3302 | // Regression test for http://crbug.com/872011. |
| 3303 | // This test verifies that migrate to the probing socket will not trigger |
| 3304 | // new packets being read synchronously and generate ACK frame while |
| 3305 | // processing the initial connectivity probe response, which may cause a |
| 3306 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3307 | // allowed when processing a new packet. |
Zhongyi Shi | 6a7323b | 2018-12-07 01:26:32 | [diff] [blame] | 3308 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3309 | InitializeConnectionMigrationV2Test( |
| 3310 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3311 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3312 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3313 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3314 | |
| 3315 | // Using a testing task runner so that we can control time. |
| 3316 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3317 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3318 | |
| 3319 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3320 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3321 | |
| 3322 | int packet_number = 1; |
| 3323 | MockQuicData quic_data1; |
| 3324 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3325 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3326 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3327 | packet_number++, &header_stream_offset)); |
| 3328 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3329 | SYNCHRONOUS, |
| 3330 | ConstructGetRequestPacket(packet_number++, |
| 3331 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3332 | true, true, &header_stream_offset)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3333 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3334 | |
| 3335 | // Set up the second socket data provider that is used for probing on the |
| 3336 | // alternate network. |
| 3337 | MockQuicData quic_data2; |
| 3338 | // Connectivity probe to be sent on the new path. |
| 3339 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3340 | packet_number++, true)); |
| 3341 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3342 | // First connectivity probe to receive from the server, which will complete |
| 3343 | // connection migraiton on path degrading. |
| 3344 | quic_data2.AddRead(ASYNC, |
| 3345 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3346 | // Read multiple connectivity probes synchronously. |
| 3347 | quic_data2.AddRead(SYNCHRONOUS, |
| 3348 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3349 | quic_data2.AddRead(SYNCHRONOUS, |
| 3350 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3351 | quic_data2.AddRead(SYNCHRONOUS, |
| 3352 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3353 | quic_data2.AddWrite( |
| 3354 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3355 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3356 | ASYNC, |
| 3357 | ConstructOkResponsePacket( |
| 3358 | 5, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3359 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3360 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3361 | SYNCHRONOUS, |
| 3362 | client_maker_.MakeAckAndRstPacket( |
| 3363 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3364 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3365 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3366 | |
| 3367 | // Create request and QuicHttpStream. |
| 3368 | QuicStreamRequest request(factory_.get()); |
| 3369 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3370 | request.Request( |
| 3371 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3372 | SocketTag(), |
| 3373 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3374 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3375 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3376 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3377 | EXPECT_TRUE(stream.get()); |
| 3378 | |
| 3379 | // Cause QUIC stream to be created. |
| 3380 | HttpRequestInfo request_info; |
| 3381 | request_info.method = "GET"; |
| 3382 | request_info.url = url_; |
| 3383 | request_info.traffic_annotation = |
| 3384 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3385 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3386 | net_log_, CompletionOnceCallback())); |
| 3387 | |
| 3388 | // Ensure that session is alive and active. |
| 3389 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3390 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3391 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3392 | |
| 3393 | // Send GET request on stream. |
| 3394 | HttpResponseInfo response; |
| 3395 | HttpRequestHeaders request_headers; |
| 3396 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3397 | callback_.callback())); |
| 3398 | |
| 3399 | // Cause the connection to report path degrading to the session. |
| 3400 | // Session will start to probe the alternate network. |
| 3401 | session->connection()->OnPathDegradingTimeout(); |
| 3402 | |
| 3403 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3404 | // kDefaultRTTMilliSecs. |
| 3405 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3406 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3407 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3408 | next_task_delay); |
| 3409 | |
| 3410 | // The connection should still be alive, and not marked as going away. |
| 3411 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3412 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3413 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3414 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3415 | |
| 3416 | // Resume quic data and a connectivity probe response will be read on the new |
| 3417 | // socket. |
| 3418 | quic_data2.Resume(); |
| 3419 | |
| 3420 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3421 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3422 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3423 | |
| 3424 | // There should be three pending tasks, the nearest one will complete |
| 3425 | // migration to the new network. |
| 3426 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3427 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3428 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3429 | task_runner->FastForwardBy(next_task_delay); |
| 3430 | |
| 3431 | // Response headers are received over the new network. |
| 3432 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3433 | EXPECT_EQ(200, response.headers->response_code()); |
| 3434 | |
| 3435 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3436 | // probe and has been cancelled due to successful migration. |
| 3437 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3438 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3439 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3440 | next_task_delay); |
| 3441 | task_runner->FastForwardBy(next_task_delay); |
| 3442 | |
| 3443 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3444 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3445 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3446 | base::TimeDelta expected_delay = |
| 3447 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3448 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3449 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3450 | |
| 3451 | // Deliver a signal that the alternate network now becomes default to session, |
| 3452 | // this will cancel mgirate back to default network timer. |
| 3453 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3454 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3455 | |
| 3456 | task_runner->FastForwardBy(next_task_delay); |
| 3457 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3458 | |
| 3459 | // Verify that the session is still alive. |
| 3460 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3461 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3462 | |
| 3463 | stream.reset(); |
| 3464 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3465 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3466 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3467 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3468 | } |
| 3469 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3470 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3471 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3472 | // migration. |
| 3473 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
| 3474 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3475 | } |
| 3476 | |
| 3477 | // This test verifies that the connection migrates to the alternate network |
| 3478 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3479 | // migration. |
| 3480 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
| 3481 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3482 | } |
| 3483 | |
| 3484 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3485 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3486 | InitializeConnectionMigrationV2Test( |
| 3487 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3488 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3489 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3490 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3491 | |
| 3492 | // Using a testing task runner so that we can control time. |
| 3493 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3494 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3495 | |
| 3496 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3497 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3498 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3499 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3500 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3501 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3502 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3503 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3504 | packet_number++, &header_stream_offset)); |
| 3505 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3506 | SYNCHRONOUS, |
| 3507 | ConstructGetRequestPacket(packet_number++, |
| 3508 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3509 | true, true, &header_stream_offset)); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3510 | if (async_write_before) { |
| 3511 | quic_data1.AddWrite(ASYNC, OK); |
| 3512 | packet_number++; |
| 3513 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3514 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3515 | |
| 3516 | // Set up the second socket data provider that is used after migration. |
| 3517 | // The response to the earlier request is read on the new socket. |
| 3518 | MockQuicData quic_data2; |
| 3519 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3520 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3521 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3522 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3523 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3524 | quic_data2.AddRead(ASYNC, |
| 3525 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3526 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3527 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3528 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3529 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3530 | ASYNC, |
| 3531 | ConstructOkResponsePacket( |
| 3532 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3533 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3534 | quic_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3535 | SYNCHRONOUS, |
| 3536 | client_maker_.MakeAckAndRstPacket( |
| 3537 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3538 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3539 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3540 | |
| 3541 | // Create request and QuicHttpStream. |
| 3542 | QuicStreamRequest request(factory_.get()); |
| 3543 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3544 | request.Request( |
| 3545 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3546 | SocketTag(), |
| 3547 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3548 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3549 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3550 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3551 | EXPECT_TRUE(stream.get()); |
| 3552 | |
| 3553 | // Cause QUIC stream to be created. |
| 3554 | HttpRequestInfo request_info; |
| 3555 | request_info.method = "GET"; |
| 3556 | request_info.url = url_; |
| 3557 | request_info.traffic_annotation = |
| 3558 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3559 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3560 | net_log_, CompletionOnceCallback())); |
| 3561 | |
| 3562 | // Ensure that session is alive and active. |
| 3563 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3564 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3565 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3566 | |
| 3567 | // Send GET request on stream. |
| 3568 | HttpResponseInfo response; |
| 3569 | HttpRequestHeaders request_headers; |
| 3570 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3571 | callback_.callback())); |
| 3572 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3573 | if (async_write_before) |
| 3574 | session->SendPing(); |
| 3575 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3576 | // Cause the connection to report path degrading to the session. |
| 3577 | // Session will start to probe the alternate network. |
| 3578 | session->connection()->OnPathDegradingTimeout(); |
| 3579 | |
| 3580 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3581 | // kDefaultRTTMilliSecs. |
| 3582 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3583 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3584 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3585 | next_task_delay); |
| 3586 | |
| 3587 | // The connection should still be alive, and not marked as going away. |
| 3588 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3589 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3590 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3591 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3592 | |
| 3593 | // Resume quic data and a connectivity probe response will be read on the new |
| 3594 | // socket. |
| 3595 | quic_data2.Resume(); |
| 3596 | |
| 3597 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3598 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3599 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3600 | |
| 3601 | // There should be three pending tasks, the nearest one will complete |
| 3602 | // migration to the new network. |
| 3603 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3604 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3605 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3606 | task_runner->FastForwardBy(next_task_delay); |
| 3607 | |
| 3608 | // Response headers are received over the new network. |
| 3609 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3610 | EXPECT_EQ(200, response.headers->response_code()); |
| 3611 | |
| 3612 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3613 | // probe and has been cancelled due to successful migration. |
| 3614 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3615 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3616 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3617 | next_task_delay); |
| 3618 | task_runner->FastForwardBy(next_task_delay); |
| 3619 | |
| 3620 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3621 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3622 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3623 | base::TimeDelta expected_delay = |
| 3624 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3625 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3626 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3627 | |
| 3628 | // Deliver a signal that the alternate network now becomes default to session, |
| 3629 | // this will cancel mgirate back to default network timer. |
| 3630 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3631 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3632 | |
| 3633 | task_runner->FastForwardBy(next_task_delay); |
| 3634 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3635 | |
| 3636 | // Verify that the session is still alive. |
| 3637 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3638 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3639 | |
| 3640 | stream.reset(); |
| 3641 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3642 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3643 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3644 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3645 | } |
| 3646 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3647 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3648 | // and it does not receive any new request |
| 3649 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
| 3650 | go_away_on_path_degrading_ = true; |
| 3651 | Initialize(); |
| 3652 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3653 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3654 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3655 | |
| 3656 | MockQuicData quic_data1; |
| 3657 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3658 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3659 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3660 | quic_data1.AddWrite( |
| 3661 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3662 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3663 | true, &header_stream_offset)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3664 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3665 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3666 | ASYNC, |
| 3667 | ConstructOkResponsePacket( |
| 3668 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, true)); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3669 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3670 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3671 | |
| 3672 | MockQuicData quic_data2; |
| 3673 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3674 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3675 | quic_data2.AddWrite( |
| 3676 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3677 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3678 | |
| 3679 | // Creat request and QuicHttpStream. |
| 3680 | QuicStreamRequest request(factory_.get()); |
| 3681 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3682 | request.Request( |
| 3683 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3684 | SocketTag(), |
| 3685 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3686 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3687 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3688 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3689 | EXPECT_TRUE(stream.get()); |
| 3690 | |
| 3691 | // Cause QUIC stream to be created. |
| 3692 | HttpRequestInfo request_info; |
| 3693 | request_info.method = "GET"; |
| 3694 | request_info.url = url_; |
| 3695 | request_info.traffic_annotation = |
| 3696 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3697 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3698 | net_log_, CompletionOnceCallback())); |
| 3699 | |
| 3700 | // Ensure that session is alive and active. |
| 3701 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3702 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3703 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3704 | |
| 3705 | // Send GET request on stream. |
| 3706 | HttpResponseInfo response; |
| 3707 | HttpRequestHeaders request_headers; |
| 3708 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3709 | callback_.callback())); |
| 3710 | |
| 3711 | // Trigger the connection to report path degrading to the session. |
| 3712 | // Session will mark itself GOAWAY. |
| 3713 | session->connection()->OnPathDegradingTimeout(); |
| 3714 | |
| 3715 | // The connection should still be alive, but marked as going away. |
| 3716 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3717 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3718 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3719 | |
| 3720 | // Second request should be sent on a new connection. |
| 3721 | QuicStreamRequest request2(factory_.get()); |
| 3722 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3723 | request2.Request( |
| 3724 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3725 | SocketTag(), |
| 3726 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3727 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3728 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3729 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3730 | EXPECT_TRUE(stream2.get()); |
| 3731 | |
| 3732 | // Resume the data, verify old request can read response on the old session |
| 3733 | // successfully. |
| 3734 | quic_data1.Resume(); |
| 3735 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3736 | EXPECT_EQ(200, response.headers->response_code()); |
| 3737 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3738 | |
| 3739 | // Check an active session exists for the destination. |
| 3740 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3741 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3742 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3743 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3744 | EXPECT_NE(session, session2); |
| 3745 | |
| 3746 | stream.reset(); |
| 3747 | stream2.reset(); |
| 3748 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3749 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3750 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3751 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3752 | } |
| 3753 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3754 | // This test verifies that the connection will not migrate to a bad socket |
| 3755 | // when path degrading is detected. |
| 3756 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3757 | InitializeConnectionMigrationV2Test( |
| 3758 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3759 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3760 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3761 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3762 | |
| 3763 | // Using a testing task runner so that we can control time. |
| 3764 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3765 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3766 | |
| 3767 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3768 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3769 | |
| 3770 | MockQuicData quic_data; |
| 3771 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3772 | quic_data.AddWrite(SYNCHRONOUS, |
| 3773 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3774 | quic_data.AddWrite(SYNCHRONOUS, |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3775 | ConstructGetRequestPacket( |
| 3776 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 3777 | true, &header_stream_offset)); |
| 3778 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3779 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 3780 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3781 | false, false)); |
| 3782 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3783 | quic_data.AddWrite( |
| 3784 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3785 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 3786 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3787 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3788 | |
| 3789 | // Set up second socket that will immediately return disconnected. |
| 3790 | // The stream factory will abort probe the alternate network. |
| 3791 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3792 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3793 | base::span<MockWrite>()); |
| 3794 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3795 | |
| 3796 | // Create request and QuicHttpStream. |
| 3797 | QuicStreamRequest request(factory_.get()); |
| 3798 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3799 | request.Request( |
| 3800 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3801 | SocketTag(), |
| 3802 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3803 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3804 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3805 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3806 | EXPECT_TRUE(stream.get()); |
| 3807 | |
| 3808 | // Cause QUIC stream to be created. |
| 3809 | HttpRequestInfo request_info; |
| 3810 | request_info.method = "GET"; |
| 3811 | request_info.url = url_; |
| 3812 | request_info.traffic_annotation = |
| 3813 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3814 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3815 | net_log_, CompletionOnceCallback())); |
| 3816 | |
| 3817 | // Ensure that session is alive and active. |
| 3818 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3819 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3820 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3821 | |
| 3822 | // Send GET request on stream. |
| 3823 | HttpResponseInfo response; |
| 3824 | HttpRequestHeaders request_headers; |
| 3825 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3826 | callback_.callback())); |
| 3827 | |
| 3828 | // Cause the connection to report path degrading to the session. |
| 3829 | // Session will start to probe the alternate network. |
| 3830 | session->connection()->OnPathDegradingTimeout(); |
| 3831 | |
| 3832 | // The connection should still be alive, and not marked as going away. |
| 3833 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3834 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3835 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3836 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3837 | |
| 3838 | // Resume the data, and response header is received over the original network. |
| 3839 | quic_data.Resume(); |
| 3840 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3841 | EXPECT_EQ(200, response.headers->response_code()); |
| 3842 | |
| 3843 | // Verify there is no pending task as probing alternate network is halted. |
| 3844 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3845 | |
| 3846 | // Verify that the session is still alive. |
| 3847 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3848 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3849 | |
| 3850 | stream.reset(); |
| 3851 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3852 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3853 | } |
| 3854 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3855 | // Regression test for http://crbug.com/847569. |
| 3856 | // This test verifies that the connection migrates to the alternate network |
| 3857 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3858 | // The first packet being written after migration is a synchrnous write, which |
| 3859 | // will cause a PING packet being sent. |
| 3860 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
| 3861 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3862 | } |
| 3863 | |
| 3864 | // Regression test for http://crbug.com/847569. |
| 3865 | // This test verifies that the connection migrates to the alternate network |
| 3866 | // early when there is no active stream but a draining stream. |
| 3867 | // The first packet being written after migration is an asynchronous write, no |
| 3868 | // PING packet will be sent. |
| 3869 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
| 3870 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3871 | } |
| 3872 | |
| 3873 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3874 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3875 | InitializeConnectionMigrationV2Test( |
| 3876 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3877 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3878 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3879 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3880 | |
| 3881 | // Using a testing task runner so that we can control time. |
| 3882 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3883 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3884 | |
| 3885 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3886 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3887 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3888 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3889 | MockQuicData quic_data1; |
| 3890 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3891 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3892 | packet_number++, &header_stream_offset)); |
| 3893 | quic_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3894 | SYNCHRONOUS, |
| 3895 | ConstructGetRequestPacket(packet_number++, |
| 3896 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 3897 | true, true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3898 | // Read an out of order packet with FIN to drain the stream. |
| 3899 | quic_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3900 | ASYNC, ConstructOkResponsePacket( |
| 3901 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, |
| 3902 | true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3903 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3904 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3905 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3906 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3907 | |
| 3908 | // Set up the second socket data provider that is used after migration. |
| 3909 | MockQuicData quic_data2; |
| 3910 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3911 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3912 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3913 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3914 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3915 | quic_data2.AddRead(ASYNC, |
| 3916 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3917 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3918 | quic_data2.AddWrite( |
| 3919 | write_mode_for_queued_packet, |
| 3920 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 3921 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 3922 | quic_data2.AddWrite(ASYNC, |
| 3923 | client_maker_.MakePingPacket(packet_number++, false)); |
| 3924 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3925 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 3926 | ASYNC, |
| 3927 | ConstructOkResponsePacket( |
| 3928 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3929 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3930 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3931 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3932 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3933 | |
| 3934 | // Create request and QuicHttpStream. |
| 3935 | QuicStreamRequest request(factory_.get()); |
| 3936 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3937 | request.Request( |
| 3938 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3939 | SocketTag(), |
| 3940 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3941 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3942 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3943 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3944 | EXPECT_TRUE(stream.get()); |
| 3945 | |
| 3946 | // Cause QUIC stream to be created. |
| 3947 | HttpRequestInfo request_info; |
| 3948 | request_info.method = "GET"; |
| 3949 | request_info.url = url_; |
| 3950 | request_info.traffic_annotation = |
| 3951 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3952 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3953 | net_log_, CompletionOnceCallback())); |
| 3954 | |
| 3955 | // Ensure that session is alive and active. |
| 3956 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3957 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3958 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3959 | |
| 3960 | // Send GET request on stream. |
| 3961 | HttpResponseInfo response; |
| 3962 | HttpRequestHeaders request_headers; |
| 3963 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3964 | callback_.callback())); |
| 3965 | |
| 3966 | // Run the message loop to receive the out of order packet which contains a |
| 3967 | // FIN and drains the stream. |
| 3968 | base::RunLoop().RunUntilIdle(); |
| 3969 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3970 | |
| 3971 | // Cause the connection to report path degrading to the session. |
| 3972 | // Session should still start to probe the alternate network. |
| 3973 | session->connection()->OnPathDegradingTimeout(); |
| 3974 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3975 | |
| 3976 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3977 | // kDefaultRTTMilliSecs. |
| 3978 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3979 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3980 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3981 | next_task_delay); |
| 3982 | |
| 3983 | // The connection should still be alive, and not marked as going away. |
| 3984 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3985 | |
| 3986 | // Resume quic data and a connectivity probe response will be read on the new |
| 3987 | // socket. |
| 3988 | quic_data2.Resume(); |
| 3989 | |
| 3990 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3991 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 3992 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3993 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3994 | |
| 3995 | // There should be three pending tasks, the nearest one will complete |
| 3996 | // migration to the new network. |
| 3997 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3998 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3999 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4000 | task_runner->FastForwardBy(next_task_delay); |
| 4001 | |
| 4002 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4003 | // probe and has been cancelled due to successful migration. |
| 4004 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4005 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4006 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4007 | next_task_delay); |
| 4008 | task_runner->FastForwardBy(next_task_delay); |
| 4009 | |
| 4010 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4011 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4012 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4013 | base::TimeDelta expected_delay = |
| 4014 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4015 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4016 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4017 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 4018 | base::RunLoop().RunUntilIdle(); |
| 4019 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4020 | // Deliver a signal that the alternate network now becomes default to session, |
| 4021 | // this will cancel mgirate back to default network timer. |
| 4022 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4023 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4024 | |
| 4025 | task_runner->FastForwardBy(next_task_delay); |
| 4026 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4027 | |
| 4028 | // Verify that the session is still alive. |
| 4029 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4030 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4031 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4032 | |
| 4033 | stream.reset(); |
| 4034 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4035 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4036 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4037 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4038 | } |
| 4039 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4040 | // Regression test for http://crbug.com/835444. |
| 4041 | // This test verifies that the connection migrates to the alternate network |
| 4042 | // when the alternate network is connected after path has been degrading. |
| 4043 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
| 4044 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4045 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4046 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4047 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4048 | |
| 4049 | // Using a testing task runner so that we can control time. |
| 4050 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4051 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4052 | |
| 4053 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4054 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4055 | |
| 4056 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4057 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4058 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4059 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4060 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4061 | quic_data1.AddWrite( |
| 4062 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4063 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4064 | true, &header_stream_offset)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4065 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4066 | |
| 4067 | // Set up the second socket data provider that is used after migration. |
| 4068 | // The response to the earlier request is read on the new socket. |
| 4069 | MockQuicData quic_data2; |
| 4070 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4071 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4072 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4073 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4074 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4075 | quic_data2.AddRead(ASYNC, |
| 4076 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4077 | // Ping packet to send after migration is completed. |
| 4078 | quic_data2.AddWrite(ASYNC, |
| 4079 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4080 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4081 | ASYNC, |
| 4082 | ConstructOkResponsePacket( |
| 4083 | 2, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4084 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4085 | quic_data2.AddWrite( |
| 4086 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4087 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4088 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4089 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4090 | |
| 4091 | // Create request and QuicHttpStream. |
| 4092 | QuicStreamRequest request(factory_.get()); |
| 4093 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4094 | request.Request( |
| 4095 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4096 | SocketTag(), |
| 4097 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4098 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4099 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4100 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4101 | EXPECT_TRUE(stream.get()); |
| 4102 | |
| 4103 | // Cause QUIC stream to be created. |
| 4104 | HttpRequestInfo request_info; |
| 4105 | request_info.method = "GET"; |
| 4106 | request_info.url = url_; |
| 4107 | request_info.traffic_annotation = |
| 4108 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4109 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4110 | net_log_, CompletionOnceCallback())); |
| 4111 | |
| 4112 | // Ensure that session is alive and active. |
| 4113 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4114 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4115 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4116 | |
| 4117 | // Send GET request on stream. |
| 4118 | HttpResponseInfo response; |
| 4119 | HttpRequestHeaders request_headers; |
| 4120 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4121 | callback_.callback())); |
| 4122 | |
| 4123 | // Cause the connection to report path degrading to the session. |
| 4124 | // Due to lack of alternate network, session will not mgirate connection. |
| 4125 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4126 | session->connection()->OnPathDegradingTimeout(); |
| 4127 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4128 | |
| 4129 | // Deliver a signal that a alternate network is connected now, this should |
| 4130 | // cause the connection to start early migration on path degrading. |
| 4131 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4132 | ->SetConnectedNetworksList( |
| 4133 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4134 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4135 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4136 | |
| 4137 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4138 | // kDefaultRTTMilliSecs. |
| 4139 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4140 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4141 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4142 | next_task_delay); |
| 4143 | |
| 4144 | // The connection should still be alive, and not marked as going away. |
| 4145 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4146 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4147 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4148 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4149 | |
| 4150 | // Resume quic data and a connectivity probe response will be read on the new |
| 4151 | // socket. |
| 4152 | quic_data2.Resume(); |
| 4153 | |
| 4154 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4155 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4156 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4157 | |
| 4158 | // There should be three pending tasks, the nearest one will complete |
| 4159 | // migration to the new network. |
| 4160 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4161 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4162 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4163 | task_runner->FastForwardBy(next_task_delay); |
| 4164 | |
| 4165 | // Response headers are received over the new network. |
| 4166 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4167 | EXPECT_EQ(200, response.headers->response_code()); |
| 4168 | |
| 4169 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4170 | // probe and has been cancelled due to successful migration. |
| 4171 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4172 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4173 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4174 | next_task_delay); |
| 4175 | task_runner->FastForwardBy(next_task_delay); |
| 4176 | |
| 4177 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4178 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4179 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4180 | base::TimeDelta expected_delay = |
| 4181 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4182 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4183 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4184 | |
| 4185 | // Deliver a signal that the alternate network now becomes default to session, |
| 4186 | // this will cancel mgirate back to default network timer. |
| 4187 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4188 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4189 | |
| 4190 | task_runner->FastForwardBy(next_task_delay); |
| 4191 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4192 | |
| 4193 | // Verify that the session is still alive. |
| 4194 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4195 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4196 | |
| 4197 | stream.reset(); |
| 4198 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4199 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4200 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4201 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4202 | } |
| 4203 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4204 | // This test verifies that multiple sessions are migrated on connection |
| 4205 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4206 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4207 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4208 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4209 | |
| 4210 | MockQuicData socket_data1; |
| 4211 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4212 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4213 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4214 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4215 | MockQuicData socket_data2; |
| 4216 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4217 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4218 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4219 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4220 | |
| 4221 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4222 | HostPortPair server2(kServer2HostName, 443); |
| 4223 | |
| 4224 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4225 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4226 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4227 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4228 | host_resolver_->set_synchronous_mode(true); |
| 4229 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4230 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4231 | |
| 4232 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4233 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4234 | EXPECT_EQ(OK, |
| 4235 | request1.Request( |
| 4236 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4237 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4238 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4239 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4240 | EXPECT_TRUE(stream1.get()); |
| 4241 | |
| 4242 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4243 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4244 | EXPECT_EQ(OK, |
| 4245 | request2.Request( |
| 4246 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4247 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4248 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4249 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4250 | EXPECT_TRUE(stream2.get()); |
| 4251 | |
| 4252 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4253 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4254 | EXPECT_NE(session1, session2); |
| 4255 | |
| 4256 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4257 | // stream. |
| 4258 | HttpRequestInfo request_info1; |
| 4259 | request_info1.method = "GET"; |
| 4260 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4261 | request_info1.traffic_annotation = |
| 4262 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4263 | EXPECT_EQ(OK, |
| 4264 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4265 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4266 | HttpResponseInfo response1; |
| 4267 | HttpRequestHeaders request_headers1; |
| 4268 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4269 | callback_.callback())); |
| 4270 | |
| 4271 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4272 | // stream. |
| 4273 | HttpRequestInfo request_info2; |
| 4274 | request_info2.method = "GET"; |
| 4275 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4276 | request_info2.traffic_annotation = |
| 4277 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4278 | EXPECT_EQ(OK, |
| 4279 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4280 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4281 | HttpResponseInfo response2; |
| 4282 | HttpRequestHeaders request_headers2; |
| 4283 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4284 | callback_.callback())); |
| 4285 | |
| 4286 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4287 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4288 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4289 | |
| 4290 | // Ensure that both sessions are paused but alive. |
| 4291 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4292 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4293 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4294 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4295 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4296 | MockConnect connect_result = |
| 4297 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4298 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4299 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4300 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4301 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4302 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4303 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4304 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4305 | // Connect the new network and cause migration to bad sockets, causing |
| 4306 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4307 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4308 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4309 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4310 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4311 | |
| 4312 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4313 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4314 | |
| 4315 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4316 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4317 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4318 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4319 | } |
| 4320 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4321 | // This test verifies that session attempts connection migration with signals |
| 4322 | // delivered in the following order (no alternate network is available): |
| 4323 | // - path degrading is detected: session attempts connection migration but no |
| 4324 | // alternate network is available, session caches path degrading signal in |
| 4325 | // connection and stays on the original network. |
| 4326 | // - original network backs up, request is served in the orignal network, |
| 4327 | // session is not marked as going away. |
| 4328 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4329 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4330 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4331 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4332 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4333 | MockQuicData quic_data; |
| 4334 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4335 | quic_data.AddWrite(SYNCHRONOUS, |
| 4336 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4337 | quic_data.AddWrite(SYNCHRONOUS, |
| 4338 | ConstructGetRequestPacket( |
| 4339 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4340 | true, &header_stream_offset)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4341 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4342 | |
| 4343 | // The rest of the data will still flow in the original socket as there is no |
| 4344 | // new network after path degrading. |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4345 | quic_data.AddRead(ASYNC, ConstructOkResponsePacket( |
| 4346 | 1, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4347 | false, false)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4348 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4349 | quic_data.AddWrite( |
| 4350 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4351 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4352 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4353 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4354 | |
| 4355 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4356 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4357 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4358 | request.Request( |
| 4359 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4360 | SocketTag(), |
| 4361 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4362 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4363 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4364 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4365 | EXPECT_TRUE(stream.get()); |
| 4366 | |
| 4367 | // Cause QUIC stream to be created. |
| 4368 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4369 | request_info.method = "GET"; |
| 4370 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4371 | request_info.traffic_annotation = |
| 4372 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4373 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4374 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4375 | |
| 4376 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4377 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4378 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4379 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4380 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4381 | // Send GET request on stream. |
| 4382 | HttpResponseInfo response; |
| 4383 | HttpRequestHeaders request_headers; |
| 4384 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4385 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4386 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4387 | // Trigger connection migration on path degrading. Since there are no networks |
| 4388 | // to migrate to, the session will remain on the original network, not marked |
| 4389 | // as going away. |
| 4390 | session->connection()->OnPathDegradingTimeout(); |
| 4391 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4392 | |
| 4393 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4394 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4395 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4396 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4397 | |
| 4398 | // Resume so that rest of the data will flow in the original socket. |
| 4399 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4400 | |
| 4401 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4402 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4403 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4404 | |
| 4405 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4406 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4407 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4408 | } |
| 4409 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4410 | // This test verifies that session with non-migratable stream will probe the |
| 4411 | // alternate network on path degrading, and close the non-migratable streams |
| 4412 | // when probe is successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4413 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4414 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4415 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4416 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4417 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4418 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4419 | MockQuicData socket_data; |
| 4420 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4421 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4422 | socket_data.AddWrite( |
| 4423 | SYNCHRONOUS, |
| 4424 | client_maker_.MakeRstAckAndConnectionClosePacket( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4425 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
Fan Yang | 7c68f63 | 2018-11-06 03:05:38 | [diff] [blame] | 4426 | quic::QUIC_STREAM_CANCELLED, |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4427 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 4428 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4429 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4430 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4431 | // Set up the second socket data provider that is used for probing. |
| 4432 | MockQuicData quic_data1; |
| 4433 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4434 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4435 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4436 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4437 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4438 | quic_data1.AddRead(ASYNC, |
| 4439 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4440 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4441 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4442 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4443 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4444 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4445 | request.Request( |
| 4446 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4447 | SocketTag(), |
| 4448 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4449 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4450 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4451 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4452 | EXPECT_TRUE(stream.get()); |
| 4453 | |
| 4454 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4455 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4456 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4457 | request_info.traffic_annotation = |
| 4458 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4459 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4460 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4461 | |
| 4462 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4463 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4464 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4465 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4466 | |
| 4467 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4468 | // this should cause session to be continue without migrating. |
| 4469 | session->OnPathDegrading(); |
| 4470 | |
| 4471 | // Run the message loop so that data queued in the new socket is read by the |
| 4472 | // packet reader. |
| 4473 | base::RunLoop().RunUntilIdle(); |
| 4474 | |
| 4475 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4476 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4477 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4478 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4479 | // Resume the data to read the connectivity probing response to declare probe |
| 4480 | // as successful. Non-migratable streams will be closed. |
| 4481 | quic_data1.Resume(); |
| 4482 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4483 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4484 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4485 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4486 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4487 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4488 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4489 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4490 | } |
| 4491 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4492 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4493 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4494 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4495 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4496 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4497 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4498 | MockQuicData socket_data; |
| 4499 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4500 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4501 | socket_data.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4502 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4503 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4504 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4505 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4506 | |
| 4507 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4508 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4509 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4510 | request.Request( |
| 4511 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4512 | SocketTag(), |
| 4513 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4514 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4515 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4516 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4517 | EXPECT_TRUE(stream.get()); |
| 4518 | |
| 4519 | // Cause QUIC stream to be created. |
| 4520 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4521 | request_info.traffic_annotation = |
| 4522 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4523 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4524 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4525 | |
| 4526 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4527 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4528 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4529 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4530 | |
| 4531 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4532 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4533 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4534 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4535 | |
| 4536 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4537 | // this should cause session to be continue without migrating. |
| 4538 | session->OnPathDegrading(); |
| 4539 | |
| 4540 | // Run the message loop so that data queued in the new socket is read by the |
| 4541 | // packet reader. |
| 4542 | base::RunLoop().RunUntilIdle(); |
| 4543 | |
| 4544 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4545 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4546 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4547 | |
| 4548 | stream.reset(); |
| 4549 | |
| 4550 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4551 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4552 | } |
| 4553 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4554 | // Regression test for http://crbug.com/791886. |
| 4555 | // This test verifies that the old packet writer which encountered an |
| 4556 | // asynchronous write error will be blocked during migration on write error. New |
| 4557 | // packets would not be written until the one with write error is rewritten on |
| 4558 | // the new network. |
| 4559 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4560 | InitializeConnectionMigrationV2Test( |
| 4561 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4562 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4563 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4564 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4565 | |
| 4566 | // Using a testing task runner so that we can control time. |
| 4567 | // base::RunLoop() controls mocked socket writes and reads. |
| 4568 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4569 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4570 | |
| 4571 | MockQuicData socket_data; |
| 4572 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4573 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4574 | socket_data.AddWrite( |
| 4575 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4576 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4577 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4578 | |
| 4579 | // Set up second socket data provider that is used after |
| 4580 | // migration. The request is rewritten to this new socket, and the |
| 4581 | // response to the request is read on this new socket. |
| 4582 | MockQuicData socket_data1; |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4583 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4584 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4585 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4586 | true, &header_stream_offset)); |
| 4587 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4588 | ConstructGetRequestPacket( |
| 4589 | 3, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4590 | GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4591 | true, &header_stream_offset)); |
| 4592 | socket_data1.AddRead( |
| 4593 | ASYNC, |
| 4594 | ConstructOkResponsePacket( |
| 4595 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 4596 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4597 | socket_data1.AddWrite( |
| 4598 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 4599 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4600 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4601 | socket_data1.AddWrite( |
| 4602 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4603 | 5, false, GetNthClientInitiatedBidirectionalStreamId(1), |
| 4604 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4605 | |
| 4606 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4607 | |
| 4608 | // Create request #1 and QuicHttpStream. |
| 4609 | QuicStreamRequest request1(factory_.get()); |
| 4610 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4611 | request1.Request( |
| 4612 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4613 | SocketTag(), |
| 4614 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4615 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4616 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4617 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4618 | EXPECT_TRUE(stream1.get()); |
| 4619 | |
| 4620 | HttpRequestInfo request_info1; |
| 4621 | request_info1.method = "GET"; |
| 4622 | request_info1.url = GURL("https://www.example.org/"); |
| 4623 | request_info1.traffic_annotation = |
| 4624 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4625 | EXPECT_EQ(OK, |
| 4626 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4627 | net_log_, CompletionOnceCallback())); |
| 4628 | |
| 4629 | // Request #2 returns synchronously because it pools to existing session. |
| 4630 | TestCompletionCallback callback2; |
| 4631 | QuicStreamRequest request2(factory_.get()); |
| 4632 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4633 | DEFAULT_PRIORITY, SocketTag(), |
| 4634 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4635 | &net_error_details_, |
| 4636 | failed_on_default_network_callback_, |
| 4637 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4638 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4639 | EXPECT_TRUE(stream2.get()); |
| 4640 | |
| 4641 | HttpRequestInfo request_info2; |
| 4642 | request_info2.method = "GET"; |
| 4643 | request_info2.url = GURL("https://www.example.org/"); |
| 4644 | request_info2.traffic_annotation = |
| 4645 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4646 | EXPECT_EQ(OK, |
| 4647 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4648 | net_log_, CompletionOnceCallback())); |
| 4649 | |
| 4650 | // Ensure that session is alive and active. |
| 4651 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4652 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4653 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4654 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4655 | |
| 4656 | // Send GET request on stream1. This should cause an async write error. |
| 4657 | HttpResponseInfo response; |
| 4658 | HttpRequestHeaders request_headers; |
| 4659 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4660 | callback_.callback())); |
| 4661 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4662 | |
| 4663 | // Run the message loop so that asynchronous write completes and a connection |
| 4664 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4665 | // runner. |
| 4666 | base::RunLoop().RunUntilIdle(); |
| 4667 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4668 | |
| 4669 | // Send GET request on stream. This will cause another write attempt before |
| 4670 | // migration on write error is exectued. |
| 4671 | HttpResponseInfo response2; |
| 4672 | HttpRequestHeaders request_headers2; |
| 4673 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4674 | callback2.callback())); |
| 4675 | |
| 4676 | // Run the task runner so that migration on write error is finally executed. |
| 4677 | task_runner->RunUntilIdle(); |
| 4678 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4679 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4680 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4681 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4682 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4683 | // There should be one task posted to migrate back to the default network in |
| 4684 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4685 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4686 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4687 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4688 | |
| 4689 | // Verify that response headers on the migrated socket were delivered to the |
| 4690 | // stream. |
| 4691 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4692 | EXPECT_EQ(200, response.headers->response_code()); |
| 4693 | |
| 4694 | stream1.reset(); |
| 4695 | stream2.reset(); |
| 4696 | |
| 4697 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4698 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4699 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4700 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4701 | } |
| 4702 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4703 | // Verify session is not marked as going away after connection migration on |
| 4704 | // write error and migrate back to default network logic is applied to bring the |
| 4705 | // migrated session back to the default network. Migration singals delivered |
| 4706 | // in the following order (alternate network is always availabe): |
| 4707 | // - session on the default network encountered a write error; |
| 4708 | // - session successfully migrated to the non-default network; |
| 4709 | // - session attempts to migrate back to default network post migration; |
| 4710 | // - migration back to the default network is successful. |
| 4711 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
| 4712 | InitializeConnectionMigrationV2Test( |
| 4713 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4714 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4715 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4716 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4717 | |
| 4718 | // Using a testing task runner so that we can control time. |
| 4719 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4720 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4721 | |
| 4722 | MockQuicData socket_data; |
| 4723 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4724 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4725 | socket_data.AddWrite( |
| 4726 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4727 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4728 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4729 | |
| 4730 | // Set up second socket data provider that is used after |
| 4731 | // migration. The request is rewritten to this new socket, and the |
| 4732 | // response to the request is read on this new socket. |
| 4733 | MockQuicData quic_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4734 | quic_data2.AddWrite( |
| 4735 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 4736 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 4737 | true, &header_stream_offset)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4738 | quic_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4739 | ASYNC, |
| 4740 | ConstructOkResponsePacket( |
| 4741 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4742 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4743 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4744 | |
| 4745 | // Create request QuicHttpStream. |
| 4746 | QuicStreamRequest request1(factory_.get()); |
| 4747 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4748 | request1.Request( |
| 4749 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4750 | SocketTag(), |
| 4751 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4752 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4753 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4754 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4755 | EXPECT_TRUE(stream1.get()); |
| 4756 | |
| 4757 | HttpRequestInfo request_info1; |
| 4758 | request_info1.method = "GET"; |
| 4759 | request_info1.url = GURL("https://www.example.org/"); |
| 4760 | request_info1.traffic_annotation = |
| 4761 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4762 | EXPECT_EQ(OK, |
| 4763 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4764 | net_log_, CompletionOnceCallback())); |
| 4765 | |
| 4766 | // Ensure that session is alive and active. |
| 4767 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4768 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4769 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4770 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4771 | |
| 4772 | // Send GET request. This should cause an async write error. |
| 4773 | HttpResponseInfo response; |
| 4774 | HttpRequestHeaders request_headers; |
| 4775 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4776 | callback_.callback())); |
| 4777 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4778 | |
| 4779 | // Run the message loop so that asynchronous write completes and a connection |
| 4780 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4781 | // runner. |
| 4782 | base::RunLoop().RunUntilIdle(); |
| 4783 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4784 | |
| 4785 | // Run the task runner so that migration on write error is finally executed. |
| 4786 | task_runner->RunUntilIdle(); |
| 4787 | |
| 4788 | // Verify the session is still alive and not marked as going away. |
| 4789 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4790 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4791 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4792 | // There should be one task posted to migrate back to the default network in |
| 4793 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4794 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4795 | base::TimeDelta expected_delay = |
| 4796 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4797 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4798 | |
| 4799 | // Verify that response headers on the migrated socket were delivered to the |
| 4800 | // stream. |
| 4801 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4802 | EXPECT_EQ(200, response.headers->response_code()); |
| 4803 | |
| 4804 | // Set up the third socket data provider for migrate back to default network. |
| 4805 | MockQuicData quic_data3; |
| 4806 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4807 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4808 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4809 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4810 | quic_data3.AddRead(ASYNC, |
| 4811 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4812 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4813 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4814 | quic_data3.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 4815 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 4816 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 4817 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4818 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4819 | |
| 4820 | // Fast forward to fire the migrate back timer and verify the session |
| 4821 | // successfully migrates back to the default network. |
| 4822 | task_runner->FastForwardBy(expected_delay); |
| 4823 | |
| 4824 | // Verify the session is still alive and not marked as going away. |
| 4825 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4826 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4827 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4828 | |
| 4829 | // There should be one task posted to one will resend a connectivity probe and |
| 4830 | // the other will retry migrate back, both are cancelled. |
| 4831 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4832 | task_runner->FastForwardBy( |
| 4833 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4834 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4835 | |
| 4836 | stream1.reset(); |
| 4837 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4838 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4839 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4840 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4841 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4842 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4843 | } |
| 4844 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4845 | // This test verifies that the connection will not attempt connection migration |
| 4846 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4847 | // and handshake is not confirmed. |
| 4848 | TEST_P(QuicStreamFactoryTest, |
| 4849 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 4850 | InitializeConnectionMigrationV2Test( |
| 4851 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4852 | |
| 4853 | // Using a testing task runner. |
| 4854 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4855 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4856 | |
| 4857 | // Use cold start mode to send crypto message for handshake. |
| 4858 | crypto_client_stream_factory_.set_handshake_mode( |
| 4859 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4860 | |
| 4861 | MockQuicData socket_data; |
| 4862 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4863 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4864 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4865 | |
| 4866 | // Create request and QuicHttpStream. |
| 4867 | QuicStreamRequest request(factory_.get()); |
| 4868 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4869 | request.Request( |
| 4870 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4871 | SocketTag(), |
| 4872 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4873 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4874 | |
| 4875 | base::RunLoop().RunUntilIdle(); |
| 4876 | |
| 4877 | // Ensure that session is alive but not active. |
| 4878 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4879 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4880 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4881 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4882 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4883 | |
| 4884 | // Cause the connection to report path degrading to the session. |
| 4885 | // Session will ignore the signal as handshake is not completed. |
| 4886 | session->connection()->OnPathDegradingTimeout(); |
| 4887 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4888 | |
| 4889 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4890 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4891 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4892 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4893 | } |
| 4894 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4895 | // This test verifies that if a connection is closed with |
| 4896 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 4897 | // alternate network, no new connection will be created. |
| 4898 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 4899 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4900 | } |
| 4901 | |
| 4902 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 4903 | // and there is no alternate network, no new connection will be created. |
| 4904 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 4905 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4906 | } |
| 4907 | |
| 4908 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 4909 | quic::QuicErrorCode quic_error) { |
| 4910 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4911 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4912 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4913 | |
| 4914 | // Using a testing task runner. |
| 4915 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4916 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4917 | |
| 4918 | // Use cold start mode to send crypto message for handshake. |
| 4919 | crypto_client_stream_factory_.set_handshake_mode( |
| 4920 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4921 | |
| 4922 | MockQuicData socket_data; |
| 4923 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4924 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4925 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4926 | |
| 4927 | // Create request. |
| 4928 | QuicStreamRequest request(factory_.get()); |
| 4929 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4930 | request.Request( |
| 4931 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4932 | SocketTag(), |
| 4933 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4934 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4935 | |
| 4936 | base::RunLoop().RunUntilIdle(); |
| 4937 | |
| 4938 | // Ensure that session is alive but not active. |
| 4939 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4940 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4941 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4942 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4943 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4944 | |
| 4945 | // Cause the connection to report path degrading to the session. |
| 4946 | // Session will ignore the signal as handshake is not completed. |
| 4947 | session->connection()->OnPathDegradingTimeout(); |
| 4948 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4949 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4950 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4951 | |
| 4952 | // Cause the connection to close due to |quic_error| before handshake. |
| 4953 | quic::QuicString error_details; |
| 4954 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 4955 | error_details = "No recent network activity."; |
| 4956 | } else { |
| 4957 | error_details = "Handshake timeout expired."; |
| 4958 | } |
| 4959 | session->connection()->CloseConnection( |
| 4960 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 4961 | |
| 4962 | // A task will be posted to clean up the session in the factory. |
| 4963 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4964 | task_runner->FastForwardUntilNoTasksRemain(); |
| 4965 | |
| 4966 | // No new session should be created as there is no alternate network. |
| 4967 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4968 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4969 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4970 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4971 | } |
| 4972 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4973 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
| 4974 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4975 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4976 | } |
| 4977 | |
| 4978 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
| 4979 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4980 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4981 | } |
| 4982 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 4983 | // Sets up a test to verify that a new connection will be created on the |
| 4984 | // alternate network after the initial connection fails before handshake with |
| 4985 | // signals delivered in the following order (alternate network is available): |
| 4986 | // - the default network is not able to complete crypto handshake; |
| 4987 | // - the original connection is closed with |quic_error|; |
| 4988 | // - a new connection is created on the alternate network and is able to finish |
| 4989 | // crypto handshake; |
| 4990 | // - the new session on the alternate network attempts to migrate back to the |
| 4991 | // default network by sending probes; |
| 4992 | // - default network being disconnected is delivered: session will stop probing |
| 4993 | // the original network. |
| 4994 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4995 | void QuicStreamFactoryTestBase:: |
| 4996 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4997 | quic::QuicErrorCode quic_error) { |
| 4998 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4999 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 5000 | InitializeConnectionMigrationV2Test( |
| 5001 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5002 | |
| 5003 | // Using a testing task runner. |
| 5004 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5005 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 5006 | |
| 5007 | // Use cold start mode to send crypto message for handshake. |
| 5008 | crypto_client_stream_factory_.set_handshake_mode( |
| 5009 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 5010 | |
| 5011 | // Socket data for connection on the default network. |
| 5012 | MockQuicData socket_data; |
| 5013 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5014 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 5015 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5016 | |
| 5017 | // Socket data for connection on the alternate network. |
| 5018 | MockQuicData socket_data2; |
| 5019 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5020 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 5021 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 5022 | // Change the encryption level after handshake is confirmed. |
| 5023 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 5024 | socket_data2.AddWrite( |
| 5025 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5026 | socket_data2.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5027 | ASYNC, ConstructGetRequestPacket( |
| 5028 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, true, |
| 5029 | &header_stream_offset)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5030 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5031 | ASYNC, |
| 5032 | ConstructOkResponsePacket( |
| 5033 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5034 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5035 | socket_data2.AddWrite( |
| 5036 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5037 | 5, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5038 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5039 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5040 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5041 | // Socket data for probing on the default network. |
| 5042 | MockQuicData probing_data; |
| 5043 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5044 | probing_data.AddWrite(SYNCHRONOUS, |
| 5045 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5046 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5047 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5048 | // Create request and QuicHttpStream. |
| 5049 | QuicStreamRequest request(factory_.get()); |
| 5050 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5051 | request.Request( |
| 5052 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5053 | SocketTag(), |
| 5054 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5055 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5056 | |
| 5057 | base::RunLoop().RunUntilIdle(); |
| 5058 | |
| 5059 | // Ensure that session is alive but not active. |
| 5060 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5061 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5062 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5063 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5064 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5065 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5066 | |
| 5067 | quic::QuicString error_details; |
| 5068 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5069 | error_details = "No recent network activity."; |
| 5070 | } else { |
| 5071 | error_details = "Handshake timeout expired."; |
| 5072 | } |
| 5073 | session->connection()->CloseConnection( |
| 5074 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5075 | |
| 5076 | // A task will be posted to clean up the session in the factory. |
| 5077 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5078 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5079 | |
| 5080 | // Verify a new session is created on the alternate network. |
| 5081 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5082 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5083 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5084 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5085 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5086 | |
| 5087 | // Confirm the handshake on the alternate network. |
| 5088 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5089 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5090 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5091 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5092 | // Resume the data now so that data can be sent and read. |
| 5093 | socket_data2.Resume(); |
| 5094 | |
| 5095 | // Create the stream. |
| 5096 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5097 | EXPECT_TRUE(stream.get()); |
| 5098 | HttpRequestInfo request_info; |
| 5099 | request_info.method = "GET"; |
| 5100 | request_info.url = GURL("https://www.example.org/"); |
| 5101 | request_info.traffic_annotation = |
| 5102 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5103 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5104 | net_log_, CompletionOnceCallback())); |
| 5105 | // Send the request. |
| 5106 | HttpResponseInfo response; |
| 5107 | HttpRequestHeaders request_headers; |
| 5108 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5109 | callback_.callback())); |
| 5110 | // Run the message loop to finish asynchronous mock write. |
| 5111 | base::RunLoop().RunUntilIdle(); |
| 5112 | // Read the response. |
| 5113 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5114 | EXPECT_EQ(200, response.headers->response_code()); |
| 5115 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5116 | // There should be a new task posted to migrate back to the default network. |
| 5117 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5118 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5119 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5120 | next_task_delay); |
| 5121 | task_runner->FastForwardBy(next_task_delay); |
| 5122 | |
| 5123 | // There should be two tasks posted. One will retry probing and the other |
| 5124 | // will retry migrate back. |
| 5125 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5126 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5127 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5128 | next_task_delay); |
| 5129 | |
| 5130 | // Deliver the signal that the default network is disconnected. |
| 5131 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5132 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5133 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5134 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5135 | // Deliver the signal that the alternate network is made default. |
| 5136 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5137 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5138 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5139 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5140 | stream.reset(); |
| 5141 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5142 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5143 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5144 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5145 | } |
| 5146 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5147 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5148 | // is triggered before handshake is confirmed and connection migration is turned |
| 5149 | // on. |
| 5150 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
| 5151 | InitializeConnectionMigrationV2Test( |
| 5152 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5153 | |
| 5154 | // Use unmocked crypto stream to do crypto connect. |
| 5155 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5156 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5157 | |
| 5158 | MockQuicData socket_data; |
| 5159 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5160 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5161 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5162 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5163 | |
| 5164 | // Create request, should fail after the write of the CHLO fails. |
| 5165 | QuicStreamRequest request(factory_.get()); |
| 5166 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5167 | request.Request( |
| 5168 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5169 | SocketTag(), |
| 5170 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5171 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5172 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5173 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5174 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5175 | |
| 5176 | // Verify new requests can be sent normally. |
| 5177 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5178 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5179 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5180 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5181 | MockQuicData socket_data2; |
| 5182 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5183 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5184 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5185 | |
| 5186 | QuicStreamRequest request2(factory_.get()); |
| 5187 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5188 | request2.Request( |
| 5189 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5190 | SocketTag(), |
| 5191 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5192 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5193 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5194 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5195 | // Run the message loop to complete host resolution. |
| 5196 | base::RunLoop().RunUntilIdle(); |
| 5197 | |
| 5198 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5199 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5200 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5201 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5202 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5203 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5204 | |
| 5205 | // Create QuicHttpStream. |
| 5206 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5207 | EXPECT_TRUE(stream.get()); |
| 5208 | stream.reset(); |
| 5209 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5210 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5211 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5212 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5213 | } |
| 5214 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5215 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5216 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5217 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5218 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5219 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5220 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5221 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5222 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5223 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5224 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5225 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5226 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5227 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5228 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5229 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5230 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5231 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5232 | |
| 5233 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5234 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5235 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5236 | request.Request( |
| 5237 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5238 | SocketTag(), |
| 5239 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5240 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5241 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5242 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5243 | EXPECT_TRUE(stream.get()); |
| 5244 | |
| 5245 | // Cause QUIC stream to be created. |
| 5246 | HttpRequestInfo request_info; |
| 5247 | request_info.method = "GET"; |
| 5248 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5249 | request_info.traffic_annotation = |
| 5250 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5251 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5252 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5253 | |
| 5254 | // Ensure that session is alive and active. |
| 5255 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5256 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5257 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5258 | |
| 5259 | // Set up second socket data provider that is used after |
| 5260 | // migration. The request is rewritten to this new socket, and the |
| 5261 | // response to the request is read on this new socket. |
| 5262 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5263 | socket_data1.AddWrite( |
| 5264 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5265 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5266 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5267 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5268 | ASYNC, |
| 5269 | ConstructOkResponsePacket( |
| 5270 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5271 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5272 | socket_data1.AddWrite( |
| 5273 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5274 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5275 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5276 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5277 | |
| 5278 | // Send GET request on stream. This should cause a write error, which triggers |
| 5279 | // a connection migration attempt. |
| 5280 | HttpResponseInfo response; |
| 5281 | HttpRequestHeaders request_headers; |
| 5282 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5283 | callback_.callback())); |
| 5284 | |
| 5285 | // Run the message loop so that the migration attempt is executed and |
| 5286 | // data queued in the new socket is read by the packet reader. |
| 5287 | base::RunLoop().RunUntilIdle(); |
| 5288 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5289 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5290 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5291 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5292 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5293 | |
| 5294 | // Verify that response headers on the migrated socket were delivered to the |
| 5295 | // stream. |
| 5296 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5297 | EXPECT_EQ(200, response.headers->response_code()); |
| 5298 | |
| 5299 | stream.reset(); |
| 5300 | |
| 5301 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5302 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5303 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5304 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5305 | } |
| 5306 | |
| 5307 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5308 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5309 | } |
| 5310 | |
| 5311 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5312 | TestMigrationOnWriteError(ASYNC); |
| 5313 | } |
| 5314 | |
| 5315 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5316 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5317 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5318 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5319 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5320 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5321 | // Use the test task runner, to force the migration alarm timeout later. |
| 5322 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5323 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5324 | MockQuicData socket_data; |
| 5325 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5326 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5327 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5328 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5329 | |
| 5330 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5331 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5332 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5333 | request.Request( |
| 5334 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5335 | SocketTag(), |
| 5336 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5337 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5338 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5339 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5340 | EXPECT_TRUE(stream.get()); |
| 5341 | |
| 5342 | // Cause QUIC stream to be created. |
| 5343 | HttpRequestInfo request_info; |
| 5344 | request_info.method = "GET"; |
| 5345 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5346 | request_info.traffic_annotation = |
| 5347 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5348 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5349 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5350 | |
| 5351 | // Ensure that session is alive and active. |
| 5352 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5353 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5354 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5355 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5356 | // Send GET request on stream. This causes a write error, which triggers |
| 5357 | // a connection migration attempt. Since there are no networks |
| 5358 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5359 | HttpResponseInfo response; |
| 5360 | HttpRequestHeaders request_headers; |
| 5361 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5362 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5363 | |
| 5364 | // Complete any pending writes. Pending async MockQuicData writes |
| 5365 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5366 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5367 | |
| 5368 | // Write error causes migration task to be posted. Spin the loop. |
| 5369 | if (write_error_mode == ASYNC) |
| 5370 | runner_->RunNextTask(); |
| 5371 | |
| 5372 | // Migration has not yet failed. The session should be alive and active. |
| 5373 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5374 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5375 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5376 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5377 | |
| 5378 | // The migration will not fail until the migration alarm timeout. |
| 5379 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5380 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5381 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5382 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5383 | |
| 5384 | // Force migration alarm timeout to run. |
| 5385 | RunTestLoopUntilIdle(); |
| 5386 | |
| 5387 | // The connection should be closed. A request for response headers |
| 5388 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5389 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5390 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5391 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5392 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5393 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5394 | |
Zhongyi Shi | 59aaf07 | 2019-01-17 03:32:13 | [diff] [blame] | 5395 | NetErrorDetails error_details; |
| 5396 | stream->PopulateNetErrorDetails(&error_details); |
| 5397 | EXPECT_EQ(error_details.quic_connection_error, |
| 5398 | quic::QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
| 5399 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5400 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5401 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5402 | } |
| 5403 | |
| 5404 | TEST_P(QuicStreamFactoryTest, |
| 5405 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5406 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5407 | } |
| 5408 | |
| 5409 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5410 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5411 | } |
| 5412 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5413 | TEST_P(QuicStreamFactoryTest, |
| 5414 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5415 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5416 | } |
| 5417 | |
| 5418 | TEST_P(QuicStreamFactoryTest, |
| 5419 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5420 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5421 | } |
| 5422 | |
| 5423 | // Sets up a test which verifies that connection migration on write error can |
| 5424 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5425 | // migratable streams. |
| 5426 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5427 | IoMode write_error_mode) { |
| 5428 | InitializeConnectionMigrationV2Test( |
| 5429 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5430 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5431 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5432 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5433 | |
| 5434 | MockQuicData socket_data; |
| 5435 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5436 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5437 | socket_data.AddWrite( |
| 5438 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5439 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5440 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5441 | |
| 5442 | // Set up second socket data provider that is used after |
| 5443 | // migration. The request is rewritten to this new socket, and the |
| 5444 | // response to the request is read on this new socket. |
| 5445 | MockQuicData socket_data1; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5446 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5447 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5448 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 5449 | true, &header_stream_offset)); |
| 5450 | socket_data1.AddRead( |
| 5451 | ASYNC, |
| 5452 | ConstructOkResponsePacket( |
| 5453 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
| 5454 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5455 | socket_data1.AddWrite( |
| 5456 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5457 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5458 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5459 | socket_data1.AddWrite( |
| 5460 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 5461 | 4, false, GetNthClientInitiatedBidirectionalStreamId(1), |
| 5462 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5463 | |
| 5464 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5465 | |
| 5466 | // Create request #1 and QuicHttpStream. |
| 5467 | QuicStreamRequest request1(factory_.get()); |
| 5468 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5469 | request1.Request( |
| 5470 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5471 | SocketTag(), |
| 5472 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5473 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5474 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5475 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5476 | EXPECT_TRUE(stream1.get()); |
| 5477 | |
| 5478 | HttpRequestInfo request_info1; |
| 5479 | request_info1.method = "GET"; |
| 5480 | request_info1.url = GURL("https://www.example.org/"); |
| 5481 | request_info1.traffic_annotation = |
| 5482 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5483 | EXPECT_EQ(OK, |
| 5484 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5485 | net_log_, CompletionOnceCallback())); |
| 5486 | |
| 5487 | // Second request returns synchronously because it pools to existing session. |
| 5488 | TestCompletionCallback callback2; |
| 5489 | QuicStreamRequest request2(factory_.get()); |
| 5490 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5491 | DEFAULT_PRIORITY, SocketTag(), |
| 5492 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5493 | &net_error_details_, |
| 5494 | failed_on_default_network_callback_, |
| 5495 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5496 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5497 | EXPECT_TRUE(stream2.get()); |
| 5498 | HttpRequestInfo request_info2; |
| 5499 | request_info2.method = "GET"; |
| 5500 | request_info2.url = GURL("https://www.example.org/"); |
| 5501 | request_info2.traffic_annotation = |
| 5502 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5503 | EXPECT_EQ(OK, |
| 5504 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5505 | net_log_, CompletionOnceCallback())); |
| 5506 | |
| 5507 | // Ensure that session is alive and active. |
| 5508 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5509 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5510 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5511 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5512 | |
| 5513 | // Send GET request on stream. This should cause a write error, which triggers |
| 5514 | // a connection migration attempt. |
| 5515 | HttpResponseInfo response; |
| 5516 | HttpRequestHeaders request_headers; |
| 5517 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5518 | callback_.callback())); |
| 5519 | |
| 5520 | // Run the message loop so that the migration attempt is executed and |
| 5521 | // data queued in the new socket is read by the packet reader. |
| 5522 | base::RunLoop().RunUntilIdle(); |
| 5523 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5524 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5525 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5526 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5527 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5528 | |
| 5529 | // Verify that response headers on the migrated socket were delivered to the |
| 5530 | // stream. |
| 5531 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5532 | EXPECT_EQ(200, response.headers->response_code()); |
| 5533 | |
| 5534 | stream1.reset(); |
| 5535 | stream2.reset(); |
| 5536 | |
| 5537 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5538 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5539 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5540 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5541 | } |
| 5542 | |
| 5543 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5544 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5545 | } |
| 5546 | |
| 5547 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5548 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5549 | } |
| 5550 | |
| 5551 | // Sets up a test that verifies connection migration manages to migrate to |
| 5552 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5553 | // |write_error_mode| on the original network. |
| 5554 | // Note there are mixed types of unfinished requests before migration: one |
| 5555 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5556 | // error. |
| 5557 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5558 | IoMode write_error_mode) { |
| 5559 | InitializeConnectionMigrationV2Test( |
| 5560 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5561 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5562 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5563 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5564 | |
| 5565 | int packet_number = 1; |
| 5566 | MockQuicData socket_data; |
| 5567 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5568 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5569 | socket_data.AddWrite( |
| 5570 | SYNCHRONOUS, |
| 5571 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5572 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5573 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5574 | |
| 5575 | // Set up second socket data provider that is used after |
| 5576 | // migration. The request is rewritten to this new socket, and the |
| 5577 | // response to the request is read on this new socket. |
| 5578 | MockQuicData socket_data1; |
| 5579 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5580 | SYNCHRONOUS, |
| 5581 | ConstructGetRequestPacket(packet_number++, |
| 5582 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5583 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5584 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5585 | SYNCHRONOUS, |
| 5586 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5587 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5588 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5589 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5590 | ASYNC, |
| 5591 | ConstructOkResponsePacket( |
| 5592 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5593 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5594 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5595 | SYNCHRONOUS, |
| 5596 | client_maker_.MakeAckAndRstPacket( |
| 5597 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5598 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5599 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5600 | |
| 5601 | // Create request #1 and QuicHttpStream. |
| 5602 | QuicStreamRequest request1(factory_.get()); |
| 5603 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5604 | request1.Request( |
| 5605 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5606 | SocketTag(), |
| 5607 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5608 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5609 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5610 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5611 | EXPECT_TRUE(stream1.get()); |
| 5612 | |
| 5613 | HttpRequestInfo request_info1; |
| 5614 | request_info1.method = "GET"; |
| 5615 | request_info1.url = GURL("https://www.example.org/"); |
| 5616 | request_info1.traffic_annotation = |
| 5617 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5618 | EXPECT_EQ(OK, |
| 5619 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5620 | net_log_, CompletionOnceCallback())); |
| 5621 | |
| 5622 | // Second request returns synchronously because it pools to existing session. |
| 5623 | TestCompletionCallback callback2; |
| 5624 | QuicStreamRequest request2(factory_.get()); |
| 5625 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5626 | DEFAULT_PRIORITY, SocketTag(), |
| 5627 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5628 | &net_error_details_, |
| 5629 | failed_on_default_network_callback_, |
| 5630 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5631 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5632 | EXPECT_TRUE(stream2.get()); |
| 5633 | |
| 5634 | HttpRequestInfo request_info2; |
| 5635 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5636 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5637 | request_info2.url = GURL("https://www.example.org/"); |
| 5638 | request_info2.traffic_annotation = |
| 5639 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5640 | EXPECT_EQ(OK, |
| 5641 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5642 | net_log_, CompletionOnceCallback())); |
| 5643 | |
| 5644 | // Ensure that session is alive and active. |
| 5645 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5646 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5647 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5648 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5649 | |
| 5650 | // Send GET request on stream 1. This should cause a write error, which |
| 5651 | // triggers a connection migration attempt. |
| 5652 | HttpResponseInfo response; |
| 5653 | HttpRequestHeaders request_headers; |
| 5654 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5655 | callback_.callback())); |
| 5656 | |
| 5657 | // Run the message loop so that the migration attempt is executed and |
| 5658 | // data queued in the new socket is read by the packet reader. |
| 5659 | base::RunLoop().RunUntilIdle(); |
| 5660 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5661 | // Verify that the session is still alive and not marked as going away. |
| 5662 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5663 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5664 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5665 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5666 | |
| 5667 | // Verify that response headers on the migrated socket were delivered to the |
| 5668 | // stream. |
| 5669 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5670 | EXPECT_EQ(200, response.headers->response_code()); |
| 5671 | |
| 5672 | stream1.reset(); |
| 5673 | |
| 5674 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5675 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5676 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5677 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5678 | } |
| 5679 | |
| 5680 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5681 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5682 | } |
| 5683 | |
| 5684 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5685 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5686 | } |
| 5687 | |
| 5688 | // The one triggers write error is a non-migratable stream. |
| 5689 | // Sets up a test that verifies connection migration manages to migrate to |
| 5690 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5691 | // |write_error_mode| on the original network. |
| 5692 | // Note there are mixed types of unfinished requests before migration: one |
| 5693 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5694 | // error. |
| 5695 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5696 | IoMode write_error_mode) { |
| 5697 | InitializeConnectionMigrationV2Test( |
| 5698 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5699 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5700 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5701 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5702 | |
| 5703 | int packet_number = 1; |
| 5704 | MockQuicData socket_data; |
| 5705 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5706 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5707 | socket_data.AddWrite( |
| 5708 | SYNCHRONOUS, |
| 5709 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5710 | socket_data.AddWrite(write_error_mode, |
| 5711 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5712 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5713 | |
| 5714 | // Set up second socket data provider that is used after |
| 5715 | // migration. The request is rewritten to this new socket, and the |
| 5716 | // response to the request is read on this new socket. |
| 5717 | MockQuicData socket_data1; |
| 5718 | // The packet triggered writer error will be sent anyway even if the stream |
| 5719 | // will be cancelled later. |
| 5720 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5721 | SYNCHRONOUS, |
| 5722 | ConstructGetRequestPacket(packet_number++, |
| 5723 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5724 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5725 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5726 | SYNCHRONOUS, |
| 5727 | client_maker_.MakeRstPacket(packet_number++, true, |
| 5728 | GetNthClientInitiatedBidirectionalStreamId(1), |
| 5729 | quic::QUIC_STREAM_CANCELLED, 0)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5730 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5731 | SYNCHRONOUS, |
| 5732 | ConstructGetRequestPacket(packet_number++, |
| 5733 | GetNthClientInitiatedBidirectionalStreamId(0), |
| 5734 | true, true, &header_stream_offset)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5735 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5736 | ASYNC, |
| 5737 | ConstructOkResponsePacket( |
| 5738 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5739 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5740 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 5741 | SYNCHRONOUS, |
| 5742 | client_maker_.MakeAckAndRstPacket( |
| 5743 | packet_number++, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 5744 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5745 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5746 | |
| 5747 | // Create request #1 and QuicHttpStream. |
| 5748 | QuicStreamRequest request1(factory_.get()); |
| 5749 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5750 | request1.Request( |
| 5751 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5752 | SocketTag(), |
| 5753 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5754 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5755 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5756 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5757 | EXPECT_TRUE(stream1.get()); |
| 5758 | |
| 5759 | HttpRequestInfo request_info1; |
| 5760 | request_info1.method = "GET"; |
| 5761 | request_info1.url = GURL("https://www.example.org/"); |
| 5762 | request_info1.traffic_annotation = |
| 5763 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5764 | EXPECT_EQ(OK, |
| 5765 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5766 | net_log_, CompletionOnceCallback())); |
| 5767 | |
| 5768 | // Second request returns synchronously because it pools to existing session. |
| 5769 | TestCompletionCallback callback2; |
| 5770 | QuicStreamRequest request2(factory_.get()); |
| 5771 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5772 | DEFAULT_PRIORITY, SocketTag(), |
| 5773 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5774 | &net_error_details_, |
| 5775 | failed_on_default_network_callback_, |
| 5776 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5777 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5778 | EXPECT_TRUE(stream2.get()); |
| 5779 | |
| 5780 | HttpRequestInfo request_info2; |
| 5781 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5782 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5783 | request_info2.url = GURL("https://www.example.org/"); |
| 5784 | request_info2.traffic_annotation = |
| 5785 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5786 | EXPECT_EQ(OK, |
| 5787 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5788 | net_log_, CompletionOnceCallback())); |
| 5789 | |
| 5790 | // Ensure that session is alive and active. |
| 5791 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5792 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5793 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5794 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5795 | |
| 5796 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 5797 | // write error, which triggers a connection migration attempt. |
| 5798 | HttpResponseInfo response2; |
| 5799 | HttpRequestHeaders request_headers2; |
| 5800 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 5801 | callback2.callback())); |
| 5802 | |
| 5803 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5804 | // data queued in the new socket is read by the packet reader. Session is |
| 5805 | // still alive and not marked as going away, non-migratable stream will be |
| 5806 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5807 | base::RunLoop().RunUntilIdle(); |
| 5808 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5809 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5810 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5811 | |
| 5812 | // Send GET request on stream 1. |
| 5813 | HttpResponseInfo response; |
| 5814 | HttpRequestHeaders request_headers; |
| 5815 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5816 | callback_.callback())); |
| 5817 | |
| 5818 | base::RunLoop().RunUntilIdle(); |
| 5819 | |
| 5820 | // Verify that response headers on the migrated socket were delivered to the |
| 5821 | // stream. |
| 5822 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5823 | EXPECT_EQ(200, response.headers->response_code()); |
| 5824 | |
| 5825 | stream1.reset(); |
| 5826 | |
| 5827 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5828 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5829 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5830 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5831 | } |
| 5832 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5833 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
| 5834 | IoMode write_error_mode) { |
| 5835 | DVLOG(1) << "Mode: " |
| 5836 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5837 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5838 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5839 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5840 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5841 | |
| 5842 | MockQuicData socket_data; |
| 5843 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5844 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5845 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5846 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5847 | |
| 5848 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5849 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5850 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5851 | request.Request( |
| 5852 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5853 | SocketTag(), |
| 5854 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5855 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5856 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5857 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5858 | EXPECT_TRUE(stream.get()); |
| 5859 | |
| 5860 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 5861 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5862 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5863 | request_info.method = "GET"; |
| 5864 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5865 | request_info.traffic_annotation = |
| 5866 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5867 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5868 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5869 | |
| 5870 | // Ensure that session is alive and active. |
| 5871 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5872 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5873 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5874 | |
| 5875 | // Send GET request on stream. This should cause a write error, which triggers |
| 5876 | // a connection migration attempt. |
| 5877 | HttpResponseInfo response; |
| 5878 | HttpRequestHeaders request_headers; |
| 5879 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5880 | callback_.callback())); |
| 5881 | |
| 5882 | // Run message loop to execute migration attempt. |
| 5883 | base::RunLoop().RunUntilIdle(); |
| 5884 | |
| 5885 | // Migration fails, and session is closed and deleted. |
| 5886 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5887 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5888 | |
| 5889 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5890 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5891 | } |
| 5892 | |
| 5893 | TEST_P(QuicStreamFactoryTest, |
| 5894 | MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 5895 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 5896 | } |
| 5897 | |
| 5898 | TEST_P(QuicStreamFactoryTest, |
| 5899 | MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 5900 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC); |
| 5901 | } |
| 5902 | |
| 5903 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 5904 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5905 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5906 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5907 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5908 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5909 | |
| 5910 | MockQuicData socket_data; |
| 5911 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5912 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5913 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5914 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5915 | |
| 5916 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5917 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5918 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5919 | request.Request( |
| 5920 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5921 | SocketTag(), |
| 5922 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5923 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5924 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5925 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5926 | EXPECT_TRUE(stream.get()); |
| 5927 | |
| 5928 | // Cause QUIC stream to be created. |
| 5929 | HttpRequestInfo request_info; |
| 5930 | request_info.method = "GET"; |
| 5931 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5932 | request_info.traffic_annotation = |
| 5933 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5934 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5935 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5936 | |
| 5937 | // Ensure that session is alive and active. |
| 5938 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5939 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5940 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5941 | |
| 5942 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5943 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 5944 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5945 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 5946 | |
| 5947 | // Send GET request on stream. This should cause a write error, which triggers |
| 5948 | // a connection migration attempt. |
| 5949 | HttpResponseInfo response; |
| 5950 | HttpRequestHeaders request_headers; |
| 5951 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5952 | callback_.callback())); |
| 5953 | // Run message loop to execute migration attempt. |
| 5954 | base::RunLoop().RunUntilIdle(); |
| 5955 | // Migration fails, and session is closed and deleted. |
| 5956 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5957 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5958 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5959 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5960 | } |
| 5961 | |
| 5962 | TEST_P(QuicStreamFactoryTest, |
| 5963 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 5964 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 5965 | } |
| 5966 | |
| 5967 | TEST_P(QuicStreamFactoryTest, |
| 5968 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 5969 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 5970 | } |
| 5971 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5972 | // Sets up a test which verifies that connection migration on write error can |
| 5973 | // eventually succeed and rewrite the packet on the new network with singals |
| 5974 | // delivered in the following order (alternate network is always availabe): |
| 5975 | // - original network encounters a SYNC/ASYNC write error based on |
| 5976 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 5977 | // cached, session migrates immediately to the alternate network. |
| 5978 | // - an immediate SYNC/ASYNC write error based on |
| 5979 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 5980 | // alternate network, session migrates immediately to the original network. |
| 5981 | // - an immediate SYNC/ASYNC write error based on |
| 5982 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 5983 | // original network, session migrates immediately to the alternate network. |
| 5984 | // - finally, session successfully sends the packet and reads the response on |
| 5985 | // the alternate network. |
| 5986 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 5987 | // modified to test that session is closed early if hopping between networks |
| 5988 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5989 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5990 | IoMode write_error_mode_on_old_network, |
| 5991 | IoMode write_error_mode_on_new_network) { |
| 5992 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5993 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5994 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5995 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5996 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5997 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5998 | // Set up the socket data used by the original network, which encounters a |
| 5999 | // write erorr. |
| 6000 | MockQuicData socket_data1; |
| 6001 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6002 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6003 | socket_data1.AddWrite( |
| 6004 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6005 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 6006 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 6007 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6008 | |
| 6009 | // Set up the socket data used by the alternate network, which also |
| 6010 | // encounters a write error. |
| 6011 | MockQuicData failed_quic_data2; |
| 6012 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6013 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 6014 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 6015 | |
| 6016 | // Set up the third socket data used by original network, which encounters a |
| 6017 | // write error again. |
| 6018 | MockQuicData failed_quic_data1; |
| 6019 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6020 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 6021 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6022 | |
| 6023 | // Set up the last socket data used by the alternate network, which will |
| 6024 | // finish migration successfully. The request is rewritten to this new socket, |
| 6025 | // and the response to the request is read on this socket. |
| 6026 | MockQuicData socket_data2; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6027 | socket_data2.AddWrite( |
| 6028 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6029 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6030 | true, &header_stream_offset)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6031 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6032 | ASYNC, |
| 6033 | ConstructOkResponsePacket( |
| 6034 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6035 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6036 | socket_data2.AddWrite( |
| 6037 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6038 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6039 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6040 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6041 | |
| 6042 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6043 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6044 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6045 | request.Request( |
| 6046 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6047 | SocketTag(), |
| 6048 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6049 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6050 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6051 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6052 | EXPECT_TRUE(stream.get()); |
| 6053 | |
| 6054 | // Cause QUIC stream to be created. |
| 6055 | HttpRequestInfo request_info; |
| 6056 | request_info.method = "GET"; |
| 6057 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6058 | request_info.traffic_annotation = |
| 6059 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6060 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6061 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6062 | |
| 6063 | // Ensure that session is alive and active. |
| 6064 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6065 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6066 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6067 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6068 | // Send GET request on stream. |
| 6069 | // This should encounter a write error on network 1, |
| 6070 | // then migrate to network 2, which encounters another write error, |
| 6071 | // and migrate again to network 1, which encoutners one more write error. |
| 6072 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6073 | HttpResponseInfo response; |
| 6074 | HttpRequestHeaders request_headers; |
| 6075 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6076 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6077 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6078 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6079 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6080 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6081 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6082 | // Verify that response headers on the migrated socket were delivered to the |
| 6083 | // stream. |
| 6084 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6085 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6086 | |
| 6087 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6088 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6089 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6090 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6091 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6092 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6093 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6094 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6095 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6099 | TestMigrationOnMultipleWriteErrors( |
| 6100 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6101 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6102 | } |
| 6103 | |
| 6104 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6105 | TestMigrationOnMultipleWriteErrors( |
| 6106 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6107 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6111 | TestMigrationOnMultipleWriteErrors( |
| 6112 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6113 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6117 | TestMigrationOnMultipleWriteErrors( |
| 6118 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6119 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6120 | } |
| 6121 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6122 | // Verifies that a connection is closed when connection migration is triggered |
| 6123 | // on network being disconnected and the handshake is not confirmed. |
| 6124 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6125 | InitializeConnectionMigrationV2Test( |
| 6126 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6127 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6128 | // 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] | 6129 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6130 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6131 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6132 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6133 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6134 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6135 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6136 | |
| 6137 | // Create request and QuicHttpStream. |
| 6138 | QuicStreamRequest request(factory_.get()); |
| 6139 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6140 | request.Request( |
| 6141 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6142 | SocketTag(), |
| 6143 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6144 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6145 | // Deliver the network notification, which should cause the connection to be |
| 6146 | // closed. |
| 6147 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6148 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6149 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6150 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6151 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6152 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6153 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6154 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6155 | } |
| 6156 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6157 | // Sets up the connection migration test where network change notification is |
| 6158 | // queued BEFORE connection migration attempt on write error is posted. |
| 6159 | void QuicStreamFactoryTestBase:: |
| 6160 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6161 | bool disconnected) { |
| 6162 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6163 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6164 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6165 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6166 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6167 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6168 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6169 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6170 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6171 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6172 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6173 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6174 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6175 | |
| 6176 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6177 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6178 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6179 | request.Request( |
| 6180 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6181 | SocketTag(), |
| 6182 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6183 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6184 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6185 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6186 | EXPECT_TRUE(stream.get()); |
| 6187 | |
| 6188 | // Cause QUIC stream to be created. |
| 6189 | HttpRequestInfo request_info; |
| 6190 | request_info.method = "GET"; |
| 6191 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6192 | request_info.traffic_annotation = |
| 6193 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6194 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6195 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6196 | |
| 6197 | // Ensure that session is alive and active. |
| 6198 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6199 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6200 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6201 | |
| 6202 | // Set up second socket data provider that is used after |
| 6203 | // migration. The request is rewritten to this new socket, and the |
| 6204 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6205 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6206 | socket_data1.AddWrite( |
| 6207 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6208 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6209 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6210 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6211 | ASYNC, |
| 6212 | ConstructOkResponsePacket( |
| 6213 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6214 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6215 | socket_data1.AddWrite( |
| 6216 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6217 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6218 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6219 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6220 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6221 | // First queue a network change notification in the message loop. |
| 6222 | if (disconnected) { |
| 6223 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6224 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6225 | } else { |
| 6226 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6227 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6228 | } |
| 6229 | // Send GET request on stream. This should cause a write error, |
| 6230 | // which triggers a connection migration attempt. This will queue a |
| 6231 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6232 | HttpResponseInfo response; |
| 6233 | HttpRequestHeaders request_headers; |
| 6234 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6235 | callback_.callback())); |
| 6236 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6237 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6238 | // Verify the session is still alive and not marked as going away post |
| 6239 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6240 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6241 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6242 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6243 | |
| 6244 | // Verify that response headers on the migrated socket were delivered to the |
| 6245 | // stream. |
| 6246 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6247 | EXPECT_EQ(200, response.headers->response_code()); |
| 6248 | |
| 6249 | stream.reset(); |
| 6250 | |
| 6251 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6252 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6253 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6254 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6255 | } |
| 6256 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6257 | // This test verifies that session attempts connection migration successfully |
| 6258 | // with signals delivered in the following order (alternate network is always |
| 6259 | // available): |
| 6260 | // - a notification that default network is disconnected is queued. |
| 6261 | // - write error is triggered: session posts a task to attempt connection |
| 6262 | // migration, |migration_pending_| set to true. |
| 6263 | // - default network disconnected is delivered: session immediately migrates to |
| 6264 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6265 | // - connection migration on write error attempt aborts: writer encountered |
| 6266 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6267 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6268 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6269 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6270 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6271 | } |
| 6272 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6273 | // This test verifies that session attempts connection migration successfully |
| 6274 | // with signals delivered in the following order (alternate network is always |
| 6275 | // available): |
| 6276 | // - a notification that alternate network is made default is queued. |
| 6277 | // - write error is triggered: session posts a task to attempt connection |
| 6278 | // migration, block future migrations. |
| 6279 | // - new default notification is delivered: migrate back timer spins and task is |
| 6280 | // posted to migrate to the new default network. |
| 6281 | // - connection migration on write error attempt proceeds successfully: session |
| 6282 | // is |
| 6283 | // marked as going away, future migrations unblocked. |
| 6284 | // - migrate back to default network task executed: session is already on the |
| 6285 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6286 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6287 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6288 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6289 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6290 | } |
| 6291 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6292 | // Sets up the connection migration test where network change notification is |
| 6293 | // queued AFTER connection migration attempt on write error is posted. |
| 6294 | void QuicStreamFactoryTestBase:: |
| 6295 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6296 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6297 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6298 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6299 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6300 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6301 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6302 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6303 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6304 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6305 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6306 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6307 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6308 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6309 | |
| 6310 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6311 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6312 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6313 | request.Request( |
| 6314 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6315 | SocketTag(), |
| 6316 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6317 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6318 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6319 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6320 | EXPECT_TRUE(stream.get()); |
| 6321 | |
| 6322 | // Cause QUIC stream to be created. |
| 6323 | HttpRequestInfo request_info; |
| 6324 | request_info.method = "GET"; |
| 6325 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6326 | request_info.traffic_annotation = |
| 6327 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6328 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6329 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6330 | |
| 6331 | // Ensure that session is alive and active. |
| 6332 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6333 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6334 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6335 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6336 | // Set up second socket data provider that is used after |
| 6337 | // migration. The request is rewritten to this new socket, and the |
| 6338 | // response to the request is read on this new socket. |
| 6339 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6340 | socket_data1.AddWrite( |
| 6341 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6342 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6343 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6344 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6345 | ASYNC, |
| 6346 | ConstructOkResponsePacket( |
| 6347 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6348 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6349 | socket_data1.AddWrite( |
| 6350 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6351 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6352 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6353 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6354 | |
| 6355 | // Send GET request on stream. This should cause a write error, |
| 6356 | // which triggers a connection migration attempt. This will queue a |
| 6357 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6358 | HttpResponseInfo response; |
| 6359 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6360 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6361 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6362 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6363 | // Now queue a network change notification in the message loop behind |
| 6364 | // the migration attempt. |
| 6365 | if (disconnected) { |
| 6366 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6367 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6368 | } else { |
| 6369 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6370 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6371 | } |
| 6372 | |
| 6373 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6374 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6375 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6376 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6377 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6378 | |
| 6379 | // Verify that response headers on the migrated socket were delivered to the |
| 6380 | // stream. |
| 6381 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6382 | EXPECT_EQ(200, response.headers->response_code()); |
| 6383 | |
| 6384 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6385 | |
| 6386 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6387 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6388 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6389 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6390 | } |
| 6391 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6392 | // This test verifies that session attempts connection migration successfully |
| 6393 | // with signals delivered in the following order (alternate network is always |
| 6394 | // available): |
| 6395 | // - write error is triggered: session posts a task to complete connection |
| 6396 | // migration. |
| 6397 | // - a notification that alternate network is made default is queued. |
| 6398 | // - connection migration attempt proceeds successfully, session is marked as |
| 6399 | // going away. |
| 6400 | // - new default notification is delivered after connection migration has been |
| 6401 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6402 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6403 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6404 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6405 | } |
| 6406 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6407 | // This test verifies that session attempts connection migration successfully |
| 6408 | // with signals delivered in the following order (alternate network is always |
| 6409 | // available): |
| 6410 | // - write error is triggered: session posts a task to complete connection |
| 6411 | // migration. |
| 6412 | // - a notification that default network is diconnected is queued. |
| 6413 | // - connection migration attempt proceeds successfully, session is marked as |
| 6414 | // going away. |
| 6415 | // - disconnect notification is delivered after connection migration has been |
| 6416 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6417 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6418 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6419 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6420 | } |
| 6421 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6422 | // This tests connection migration on write error with signals delivered in the |
| 6423 | // following order: |
| 6424 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6425 | // |write_error_mode|: connection migration attempt is posted. |
| 6426 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6427 | // - after a pause, new network is connected: session will migrate to new |
| 6428 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6429 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6430 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6431 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6432 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6433 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6434 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6435 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6436 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6437 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6438 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6439 | // Use the test task runner. |
| 6440 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6441 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6442 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6443 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6444 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6445 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6446 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6447 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6448 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6449 | |
| 6450 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6451 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6452 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6453 | request.Request( |
| 6454 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6455 | SocketTag(), |
| 6456 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6457 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6458 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6459 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6460 | EXPECT_TRUE(stream.get()); |
| 6461 | |
| 6462 | // Cause QUIC stream to be created. |
| 6463 | HttpRequestInfo request_info; |
| 6464 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6465 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6466 | request_info.traffic_annotation = |
| 6467 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6468 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6469 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6470 | |
| 6471 | // Ensure that session is alive and active. |
| 6472 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6473 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6474 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6475 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6476 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6477 | HttpResponseInfo response; |
| 6478 | HttpRequestHeaders request_headers; |
| 6479 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6480 | callback_.callback())); |
| 6481 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6482 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6483 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6484 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6485 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6486 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6487 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6488 | // Set up second socket data provider that is used after migration. |
| 6489 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6490 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6491 | socket_data1.AddWrite( |
| 6492 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6493 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6494 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6495 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6496 | ASYNC, |
| 6497 | ConstructOkResponsePacket( |
| 6498 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6499 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6500 | socket_data1.AddWrite( |
| 6501 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6502 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6503 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6504 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6505 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6506 | // On a DISCONNECTED notification, nothing happens. |
| 6507 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6508 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6509 | // Add a new network and notify the stream factory of a new connected network. |
| 6510 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6511 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6512 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6513 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6514 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6515 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6516 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6517 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6518 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6519 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6520 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6521 | // Run the message loop migration for write error can finish. |
| 6522 | runner_->RunUntilIdle(); |
| 6523 | |
| 6524 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6525 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6526 | EXPECT_EQ(200, response.headers->response_code()); |
| 6527 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6528 | // Check that the session is still alive. |
| 6529 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6530 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6531 | |
| 6532 | // There should be no posted tasks not executed, no way to migrate back to |
| 6533 | // default network. |
| 6534 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6535 | |
| 6536 | // Receive signal to mark new network as default. |
| 6537 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6538 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6539 | |
| 6540 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6541 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6542 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6543 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6544 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6545 | } |
| 6546 | |
| 6547 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6548 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6549 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6550 | } |
| 6551 | |
| 6552 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6553 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6554 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6555 | } |
| 6556 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6557 | // This test verifies that when session successfully migrate to the alternate |
| 6558 | // network, packet write error on the old writer will be ignored and will not |
| 6559 | // trigger connection migration on write error. |
| 6560 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6561 | InitializeConnectionMigrationV2Test( |
| 6562 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6563 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6564 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6565 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6566 | |
| 6567 | // Using a testing task runner so that we can verify whether the migrate on |
| 6568 | // write error task is posted. |
| 6569 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6570 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6571 | |
| 6572 | MockQuicData socket_data; |
| 6573 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6574 | socket_data.AddWrite( |
| 6575 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6576 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6577 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6578 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6579 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6580 | |
| 6581 | // Create request and QuicHttpStream. |
| 6582 | QuicStreamRequest request(factory_.get()); |
| 6583 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6584 | request.Request( |
| 6585 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6586 | SocketTag(), |
| 6587 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6588 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6589 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6590 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6591 | EXPECT_TRUE(stream.get()); |
| 6592 | |
| 6593 | // Cause QUIC stream to be created. |
| 6594 | HttpRequestInfo request_info; |
| 6595 | request_info.method = "GET"; |
| 6596 | request_info.url = GURL("https://www.example.org/"); |
| 6597 | request_info.traffic_annotation = |
| 6598 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6599 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6600 | net_log_, CompletionOnceCallback())); |
| 6601 | |
| 6602 | // Ensure that session is alive and active. |
| 6603 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6604 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6605 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6606 | |
| 6607 | // Set up second socket data provider that is used after |
| 6608 | // migration. The response to the request is read on this new socket. |
| 6609 | MockQuicData socket_data1; |
| 6610 | socket_data1.AddWrite( |
| 6611 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6612 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6613 | ASYNC, |
| 6614 | ConstructOkResponsePacket( |
| 6615 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6616 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6617 | socket_data1.AddWrite( |
| 6618 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6619 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6620 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6621 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6622 | |
| 6623 | // Send GET request on stream. |
| 6624 | HttpResponseInfo response; |
| 6625 | HttpRequestHeaders request_headers; |
| 6626 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6627 | callback_.callback())); |
| 6628 | |
| 6629 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6630 | // Now notify network is disconnected, cause the migration to complete |
| 6631 | // immediately. |
| 6632 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6633 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6634 | // There will be two pending task, one will complete migration with no delay |
| 6635 | // and the other will attempt to migrate back to the default network with |
| 6636 | // delay. |
| 6637 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6638 | |
| 6639 | // Complete migration. |
| 6640 | task_runner->RunUntilIdle(); |
| 6641 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6642 | |
| 6643 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6644 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6645 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6646 | |
| 6647 | // Verify that response headers on the migrated socket were delivered to the |
| 6648 | // stream. |
| 6649 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6650 | EXPECT_EQ(200, response.headers->response_code()); |
| 6651 | |
| 6652 | // Resume the old socket data, a write error will be delivered to the old |
| 6653 | // packet writer. Verify no additional task is posted. |
| 6654 | socket_data.Resume(); |
| 6655 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6656 | |
| 6657 | stream.reset(); |
| 6658 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6659 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6660 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6661 | } |
| 6662 | |
| 6663 | // This test verifies that when session successfully migrate to the alternate |
| 6664 | // network, packet read error on the old reader will be ignored and will not |
| 6665 | // close the connection. |
| 6666 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6667 | InitializeConnectionMigrationV2Test( |
| 6668 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6669 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6670 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6671 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6672 | |
| 6673 | // Using a testing task runner. |
| 6674 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6675 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6676 | |
| 6677 | MockQuicData socket_data; |
| 6678 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6679 | socket_data.AddWrite( |
| 6680 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6681 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6682 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6683 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6684 | |
| 6685 | // Create request and QuicHttpStream. |
| 6686 | QuicStreamRequest request(factory_.get()); |
| 6687 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6688 | request.Request( |
| 6689 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6690 | SocketTag(), |
| 6691 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6692 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6693 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6694 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6695 | EXPECT_TRUE(stream.get()); |
| 6696 | |
| 6697 | // Cause QUIC stream to be created. |
| 6698 | HttpRequestInfo request_info; |
| 6699 | request_info.method = "GET"; |
| 6700 | request_info.url = GURL("https://www.example.org/"); |
| 6701 | request_info.traffic_annotation = |
| 6702 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6703 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6704 | net_log_, CompletionOnceCallback())); |
| 6705 | |
| 6706 | // Ensure that session is alive and active. |
| 6707 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6708 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6709 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6710 | |
| 6711 | // Set up second socket data provider that is used after |
| 6712 | // migration. The request is written to this new socket, and the |
| 6713 | // response to the request is read on this new socket. |
| 6714 | MockQuicData socket_data1; |
| 6715 | socket_data1.AddWrite( |
| 6716 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6717 | socket_data1.AddWrite( |
| 6718 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6719 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6720 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6721 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6722 | ASYNC, |
| 6723 | ConstructOkResponsePacket( |
| 6724 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6725 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6726 | socket_data1.AddWrite( |
| 6727 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6728 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6729 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6730 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6731 | |
| 6732 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6733 | // Now notify network is disconnected, cause the migration to complete |
| 6734 | // immediately. |
| 6735 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6736 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6737 | // There will be two pending task, one will complete migration with no delay |
| 6738 | // and the other will attempt to migrate back to the default network with |
| 6739 | // delay. |
| 6740 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6741 | |
| 6742 | // Complete migration. |
| 6743 | task_runner->RunUntilIdle(); |
| 6744 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6745 | |
| 6746 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6747 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6748 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6749 | |
| 6750 | // Send GET request on stream. |
| 6751 | HttpResponseInfo response; |
| 6752 | HttpRequestHeaders request_headers; |
| 6753 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6754 | callback_.callback())); |
| 6755 | |
| 6756 | // Verify that response headers on the migrated socket were delivered to the |
| 6757 | // stream. |
| 6758 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6759 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6760 | EXPECT_EQ(200, response.headers->response_code()); |
| 6761 | |
| 6762 | // Resume the old socket data, a read error will be delivered to the old |
| 6763 | // packet reader. Verify that the session is not affected. |
| 6764 | socket_data.Resume(); |
| 6765 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6766 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6767 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6768 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6769 | |
| 6770 | stream.reset(); |
| 6771 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6772 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6773 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6774 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6775 | } |
| 6776 | |
| 6777 | // This test verifies that after migration on network is executed, packet |
| 6778 | // read error on the old reader will be ignored and will not close the |
| 6779 | // connection. |
| 6780 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 6781 | InitializeConnectionMigrationV2Test( |
| 6782 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6783 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6784 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6785 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6786 | |
| 6787 | // Using a testing task runner. |
| 6788 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6789 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6790 | |
| 6791 | MockQuicData socket_data; |
| 6792 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6793 | socket_data.AddWrite( |
| 6794 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6795 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6796 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6797 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6798 | |
| 6799 | // Create request and QuicHttpStream. |
| 6800 | QuicStreamRequest request(factory_.get()); |
| 6801 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6802 | request.Request( |
| 6803 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6804 | SocketTag(), |
| 6805 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6806 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6807 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6808 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6809 | EXPECT_TRUE(stream.get()); |
| 6810 | |
| 6811 | // Cause QUIC stream to be created. |
| 6812 | HttpRequestInfo request_info; |
| 6813 | request_info.method = "GET"; |
| 6814 | request_info.url = GURL("https://www.example.org/"); |
| 6815 | request_info.traffic_annotation = |
| 6816 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6817 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6818 | net_log_, CompletionOnceCallback())); |
| 6819 | |
| 6820 | // Ensure that session is alive and active. |
| 6821 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6822 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6823 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6824 | |
| 6825 | // Set up second socket data provider that is used after |
| 6826 | // migration. The request is written to this new socket, and the |
| 6827 | // response to the request is read on this new socket. |
| 6828 | MockQuicData socket_data1; |
| 6829 | socket_data1.AddWrite( |
| 6830 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6831 | socket_data1.AddWrite( |
| 6832 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6833 | 3, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6834 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6835 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6836 | ASYNC, |
| 6837 | ConstructOkResponsePacket( |
| 6838 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6839 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6840 | socket_data1.AddWrite( |
| 6841 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 6842 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 6843 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6844 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6845 | |
| 6846 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6847 | // Now notify network is disconnected, cause the migration to complete |
| 6848 | // immediately. |
| 6849 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6850 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6851 | // There will be two pending task, one will complete migration with no delay |
| 6852 | // and the other will attempt to migrate back to the default network with |
| 6853 | // delay. |
| 6854 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6855 | |
| 6856 | // Resume the old socket data, a read error will be delivered to the old |
| 6857 | // packet reader. Verify that the session is not affected. |
| 6858 | socket_data.Resume(); |
| 6859 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6860 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6861 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6862 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6863 | |
| 6864 | // Complete migration. |
| 6865 | task_runner->RunUntilIdle(); |
| 6866 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6867 | |
| 6868 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6869 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6870 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6871 | |
| 6872 | // Send GET request on stream. |
| 6873 | HttpResponseInfo response; |
| 6874 | HttpRequestHeaders request_headers; |
| 6875 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6876 | callback_.callback())); |
| 6877 | |
| 6878 | // Verify that response headers on the migrated socket were delivered to the |
| 6879 | // stream. |
| 6880 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6881 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6882 | EXPECT_EQ(200, response.headers->response_code()); |
| 6883 | |
| 6884 | stream.reset(); |
| 6885 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6886 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6887 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6888 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6889 | } |
| 6890 | |
| 6891 | // This test verifies that after migration on write error is posted, packet |
| 6892 | // read error on the old reader will be ignored and will not close the |
| 6893 | // connection. |
| 6894 | TEST_P(QuicStreamFactoryTest, |
| 6895 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 6896 | InitializeConnectionMigrationV2Test( |
| 6897 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6898 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6899 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6900 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6901 | |
| 6902 | // Using a testing task runner. |
| 6903 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6904 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6905 | |
| 6906 | MockQuicData socket_data; |
| 6907 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6908 | socket_data.AddWrite( |
| 6909 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6910 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 6911 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 6912 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6913 | |
| 6914 | // Create request and QuicHttpStream. |
| 6915 | QuicStreamRequest request(factory_.get()); |
| 6916 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6917 | request.Request( |
| 6918 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6919 | SocketTag(), |
| 6920 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6921 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6922 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6923 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6924 | EXPECT_TRUE(stream.get()); |
| 6925 | |
| 6926 | // Cause QUIC stream to be created. |
| 6927 | HttpRequestInfo request_info; |
| 6928 | request_info.method = "GET"; |
| 6929 | request_info.url = GURL("https://www.example.org/"); |
| 6930 | request_info.traffic_annotation = |
| 6931 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6932 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6933 | net_log_, CompletionOnceCallback())); |
| 6934 | |
| 6935 | // Ensure that session is alive and active. |
| 6936 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6937 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6938 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6939 | |
| 6940 | // Set up second socket data provider that is used after |
| 6941 | // migration. The request is written to this new socket, and the |
| 6942 | // response to the request is read on this new socket. |
| 6943 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6944 | socket_data1.AddWrite( |
| 6945 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 6946 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 6947 | true, &header_stream_offset)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6948 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 6949 | ASYNC, |
| 6950 | ConstructOkResponsePacket( |
| 6951 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6952 | |
| 6953 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 6954 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 6955 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6956 | |
| 6957 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6958 | // Send GET request on stream. |
| 6959 | HttpResponseInfo response; |
| 6960 | HttpRequestHeaders request_headers; |
| 6961 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6962 | callback_.callback())); |
| 6963 | // Run the message loop to complete asynchronous write and read with errors. |
| 6964 | base::RunLoop().RunUntilIdle(); |
| 6965 | // There will be one pending task to complete migration on write error. |
| 6966 | // Verify session is not closed with read error. |
| 6967 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6968 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6969 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6970 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6971 | |
| 6972 | // Complete migration. |
| 6973 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6974 | // There will be one more task posted attempting to migrate back to the |
| 6975 | // default network. |
| 6976 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6977 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6978 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6979 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6980 | |
| 6981 | // Verify that response headers on the migrated socket were delivered to the |
| 6982 | // stream. |
| 6983 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6984 | EXPECT_EQ(200, response.headers->response_code()); |
| 6985 | |
| 6986 | // Resume to consume the read error on new socket, which will close |
| 6987 | // the connection. |
| 6988 | socket_data1.Resume(); |
| 6989 | |
| 6990 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6991 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6992 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6993 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6994 | } |
| 6995 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6996 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 6997 | // network connects. |
| 6998 | TEST_P(QuicStreamFactoryTest, |
| 6999 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 7000 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7001 | ASYNC, /*disconnect_before_connect*/ false); |
| 7002 | } |
| 7003 | |
| 7004 | // Migrate on synchronous write error, old network disconnects after alternate |
| 7005 | // network connects. |
| 7006 | TEST_P(QuicStreamFactoryTest, |
| 7007 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 7008 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7009 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 7010 | } |
| 7011 | |
| 7012 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 7013 | // network connects. |
| 7014 | TEST_P(QuicStreamFactoryTest, |
| 7015 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 7016 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7017 | ASYNC, /*disconnect_before_connect*/ true); |
| 7018 | } |
| 7019 | |
| 7020 | // Migrate on synchronous write error, old network disconnects before alternate |
| 7021 | // network connects. |
| 7022 | TEST_P(QuicStreamFactoryTest, |
| 7023 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 7024 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 7025 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 7026 | } |
| 7027 | |
| 7028 | // Setps up test which verifies that session successfully migrate to alternate |
| 7029 | // network with signals delivered in the following order: |
| 7030 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 7031 | // |disconnect_before_connect|. |
| 7032 | // - (No alternate network is connected) session connects to |
| 7033 | // kDefaultNetworkForTests. |
| 7034 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 7035 | // session posted task to migrate session on write error. |
| 7036 | // - Posted task is executed, miration moves to pending state due to lack of |
| 7037 | // alternate network. |
| 7038 | // - (A) An alternate network is connected, pending migration completes. |
| 7039 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7040 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7041 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7042 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7043 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7044 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7045 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7046 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7047 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7048 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7049 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7050 | |
| 7051 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7052 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7053 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7054 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7055 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7056 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7057 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7058 | |
| 7059 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7060 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7061 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7062 | request.Request( |
| 7063 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7064 | SocketTag(), |
| 7065 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7066 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7067 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7068 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7069 | EXPECT_TRUE(stream.get()); |
| 7070 | |
| 7071 | // Cause QUIC stream to be created. |
| 7072 | HttpRequestInfo request_info; |
| 7073 | request_info.method = "GET"; |
| 7074 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7075 | request_info.traffic_annotation = |
| 7076 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7077 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7078 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7079 | |
| 7080 | // Ensure that session is alive and active. |
| 7081 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7082 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7083 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7084 | |
| 7085 | // Send GET request on stream. This should cause a write error, which triggers |
| 7086 | // a connection migration attempt. |
| 7087 | HttpResponseInfo response; |
| 7088 | HttpRequestHeaders request_headers; |
| 7089 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7090 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7091 | // Run the message loop so that posted task to migrate to socket will be |
| 7092 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7093 | base::RunLoop().RunUntilIdle(); |
| 7094 | |
| 7095 | // In this particular code path, the network will not yet be marked |
| 7096 | // as going away and the session will still be alive. |
| 7097 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7098 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7099 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7100 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7101 | |
| 7102 | // Set up second socket data provider that is used after |
| 7103 | // migration. The request is rewritten to this new socket, and the |
| 7104 | // response to the request is read on this new socket. |
| 7105 | MockQuicData socket_data1; |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7106 | socket_data1.AddWrite( |
| 7107 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7108 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7109 | true, &header_stream_offset)); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7110 | socket_data1.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7111 | ASYNC, |
| 7112 | ConstructOkResponsePacket( |
| 7113 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7114 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7115 | socket_data1.AddWrite( |
| 7116 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7117 | 3, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7118 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7119 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7120 | |
| 7121 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7122 | ->SetConnectedNetworksList( |
| 7123 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7124 | if (disconnect_before_connect) { |
| 7125 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7126 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7127 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7128 | |
| 7129 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7130 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7131 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7132 | } else { |
| 7133 | // Now deliver a CONNECTED notification and completes migration. |
| 7134 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7135 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7136 | |
| 7137 | // Now deliver a DISCONNECT notification. |
| 7138 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7139 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7140 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7141 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7142 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7143 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7144 | |
| 7145 | // This is the callback for the response headers that returned |
| 7146 | // pending previously, because no result was available. Check that |
| 7147 | // the result is now available due to the successful migration. |
| 7148 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7149 | EXPECT_EQ(200, response.headers->response_code()); |
| 7150 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7151 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7152 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7153 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7154 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7155 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7156 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7157 | DEFAULT_PRIORITY, SocketTag(), |
| 7158 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7159 | &net_error_details_, |
| 7160 | failed_on_default_network_callback_, |
| 7161 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7162 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7163 | EXPECT_TRUE(stream2.get()); |
| 7164 | |
| 7165 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7166 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7167 | |
| 7168 | stream.reset(); |
| 7169 | stream2.reset(); |
| 7170 | |
| 7171 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7172 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7173 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7174 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7175 | } |
| 7176 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7177 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
| 7178 | allow_server_migration_ = true; |
| 7179 | Initialize(); |
| 7180 | |
| 7181 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7182 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7183 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7184 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7185 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7186 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7187 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7188 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7189 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7190 | socket_data1.AddWrite( |
| 7191 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 7192 | 2, GetNthClientInitiatedBidirectionalStreamId(0), true, |
| 7193 | true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7194 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7195 | |
| 7196 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7197 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7198 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7199 | request.Request( |
| 7200 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7201 | SocketTag(), |
| 7202 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7203 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7204 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7205 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7206 | EXPECT_TRUE(stream.get()); |
| 7207 | |
| 7208 | // Cause QUIC stream to be created. |
| 7209 | HttpRequestInfo request_info; |
| 7210 | request_info.method = "GET"; |
| 7211 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7212 | request_info.traffic_annotation = |
| 7213 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7214 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7215 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7216 | |
| 7217 | // Ensure that session is alive and active. |
| 7218 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7219 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7220 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7221 | |
| 7222 | // Send GET request on stream. |
| 7223 | HttpResponseInfo response; |
| 7224 | HttpRequestHeaders request_headers; |
| 7225 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7226 | callback_.callback())); |
| 7227 | |
| 7228 | IPEndPoint ip; |
| 7229 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7230 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7231 | << ip.port(); |
| 7232 | |
| 7233 | // Set up second socket data provider that is used after |
| 7234 | // migration. The request is rewritten to this new socket, and the |
| 7235 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7236 | MockQuicData socket_data2; |
| 7237 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7238 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7239 | socket_data2.AddRead( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7240 | ASYNC, |
| 7241 | ConstructOkResponsePacket( |
| 7242 | 1, GetNthClientInitiatedBidirectionalStreamId(0), false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7243 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7244 | socket_data2.AddWrite( |
| 7245 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 7246 | 4, false, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7247 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7248 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7249 | |
| 7250 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7251 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7252 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7253 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7254 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7255 | |
| 7256 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7257 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7258 | << ip.port(); |
| 7259 | |
| 7260 | // The session should be alive and active. |
| 7261 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7262 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7263 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7264 | |
| 7265 | // Run the message loop so that data queued in the new socket is read by the |
| 7266 | // packet reader. |
| 7267 | base::RunLoop().RunUntilIdle(); |
| 7268 | |
| 7269 | // Verify that response headers on the migrated socket were delivered to the |
| 7270 | // stream. |
| 7271 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7272 | EXPECT_EQ(200, response.headers->response_code()); |
| 7273 | |
| 7274 | stream.reset(); |
| 7275 | |
| 7276 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7277 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7278 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7279 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7280 | } |
| 7281 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7282 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7283 | // Add alternate IPv4 server address to config. |
| 7284 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7285 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7286 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7287 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7288 | VerifyServerMigration(config, alt_address); |
| 7289 | } |
| 7290 | |
| 7291 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7292 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7293 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7294 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7295 | // Add alternate IPv6 server address to config. |
| 7296 | IPEndPoint alt_address = IPEndPoint( |
| 7297 | 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] | 7298 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7299 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7300 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7301 | VerifyServerMigration(config, alt_address); |
| 7302 | } |
| 7303 | |
| 7304 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7305 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7306 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7307 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7308 | // Add alternate IPv4 server address to config. |
| 7309 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7310 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7311 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7312 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7313 | IPEndPoint expected_address( |
| 7314 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7315 | VerifyServerMigration(config, expected_address); |
| 7316 | } |
| 7317 | |
| 7318 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
| 7319 | allow_server_migration_ = true; |
| 7320 | Initialize(); |
| 7321 | |
| 7322 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7323 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7324 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7325 | // Add alternate IPv6 server address to config. |
| 7326 | IPEndPoint alt_address = IPEndPoint( |
| 7327 | 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] | 7328 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7329 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7330 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7331 | |
| 7332 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7333 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7334 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7335 | |
| 7336 | crypto_client_stream_factory_.SetConfig(config); |
| 7337 | |
| 7338 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7339 | MockQuicData socket_data1; |
| 7340 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7341 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7342 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7343 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7344 | 2, true, GetNthClientInitiatedBidirectionalStreamId(0), |
| 7345 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7346 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7347 | |
| 7348 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7349 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7350 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7351 | request.Request( |
| 7352 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7353 | SocketTag(), |
| 7354 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7355 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7356 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7357 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7358 | EXPECT_TRUE(stream.get()); |
| 7359 | |
| 7360 | // Cause QUIC stream to be created. |
| 7361 | HttpRequestInfo request_info; |
| 7362 | request_info.method = "GET"; |
| 7363 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7364 | request_info.traffic_annotation = |
| 7365 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7366 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7367 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7368 | |
| 7369 | // Ensure that session is alive and active. |
| 7370 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7371 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7372 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7373 | |
| 7374 | IPEndPoint actual_address; |
| 7375 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7376 | // No migration should have happened. |
| 7377 | IPEndPoint expected_address = |
| 7378 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7379 | EXPECT_EQ(actual_address, expected_address); |
| 7380 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7381 | << " " << actual_address.port(); |
| 7382 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7383 | << " " << expected_address.port(); |
| 7384 | |
| 7385 | stream.reset(); |
| 7386 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7387 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7388 | } |
| 7389 | |
rsleevi | 1778469 | 2016-10-12 01:36:20 | [diff] [blame] | 7390 | TEST_P(QuicStreamFactoryTest, OnCertDBChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7391 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7392 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7393 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7394 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7395 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7396 | MockQuicData socket_data; |
| 7397 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7398 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7399 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7400 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7401 | MockQuicData socket_data2; |
| 7402 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7403 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7404 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7405 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7406 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7407 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7408 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7409 | request.Request( |
| 7410 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7411 | SocketTag(), |
| 7412 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7413 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7414 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7415 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7416 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7417 | EXPECT_TRUE(stream); |
| 7418 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7419 | |
| 7420 | // Change the CA cert and verify that stream saw the event. |
mattm | fd05a1f | 2017-02-18 06:18:44 | [diff] [blame] | 7421 | factory_->OnCertDBChanged(); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7422 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7423 | EXPECT_FALSE(factory_->require_confirmation()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7424 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7425 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7426 | |
| 7427 | // Now attempting to request a stream to the same origin should create |
| 7428 | // a new session. |
| 7429 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7430 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7431 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7432 | request2.Request( |
| 7433 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7434 | SocketTag(), |
| 7435 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7436 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7437 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7438 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Charles 'Buck' Krasic | 71763c9f | 2018-02-16 02:37:28 | [diff] [blame] | 7439 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 7440 | EXPECT_TRUE(stream2); |
| 7441 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 7442 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7443 | EXPECT_NE(session, session2); |
| 7444 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7445 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 7446 | |
| 7447 | stream2.reset(); |
| 7448 | stream.reset(); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7449 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7450 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7451 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7452 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7453 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | d7d1e50b | 2013-11-25 22:08:09 | [diff] [blame] | 7454 | } |
| 7455 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7456 | TEST_P(QuicStreamFactoryTest, SharedCryptoConfig) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7457 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7458 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7459 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7460 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7461 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7462 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7463 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7464 | string r1_host_name("r1"); |
| 7465 | string r2_host_name("r2"); |
| 7466 | r1_host_name.append(cannoncial_suffixes[i]); |
| 7467 | r2_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7468 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7469 | HostPortPair host_port_pair1(r1_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7470 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7471 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7472 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7473 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7474 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7475 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7476 | EXPECT_FALSE(cached1->proof_valid()); |
| 7477 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7478 | |
| 7479 | // Mutate the cached1 to have different data. |
| 7480 | // TODO(rtenneti): mutate other members of CachedState. |
| 7481 | cached1->set_source_address_token(r1_host_name); |
| 7482 | cached1->SetProofValid(); |
| 7483 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7484 | HostPortPair host_port_pair2(r2_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7485 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7486 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7487 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7488 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7489 | EXPECT_EQ(cached1->source_address_token(), cached2->source_address_token()); |
| 7490 | EXPECT_TRUE(cached2->proof_valid()); |
| 7491 | } |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7492 | } |
| 7493 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 7494 | TEST_P(QuicStreamFactoryTest, CryptoConfigWhenProofIsInvalid) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7495 | Initialize(); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 7496 | std::vector<string> cannoncial_suffixes; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7497 | cannoncial_suffixes.push_back(string(".c.youtube.com")); |
| 7498 | cannoncial_suffixes.push_back(string(".googlevideo.com")); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7499 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7500 | for (unsigned i = 0; i < cannoncial_suffixes.size(); ++i) { |
| 7501 | string r3_host_name("r3"); |
| 7502 | string r4_host_name("r4"); |
| 7503 | r3_host_name.append(cannoncial_suffixes[i]); |
| 7504 | r4_host_name.append(cannoncial_suffixes[i]); |
[email protected] | b70fdb79 | 2013-10-25 19:04:14 | [diff] [blame] | 7505 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7506 | HostPortPair host_port_pair1(r3_host_name, 80); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7507 | quic::QuicCryptoClientConfig* crypto_config = |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7508 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7509 | quic::QuicServerId server_id1(host_port_pair1.host(), |
| 7510 | host_port_pair1.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7511 | quic::QuicCryptoClientConfig::CachedState* cached1 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7512 | crypto_config->LookupOrCreate(server_id1); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7513 | EXPECT_FALSE(cached1->proof_valid()); |
| 7514 | EXPECT_TRUE(cached1->source_address_token().empty()); |
| 7515 | |
| 7516 | // Mutate the cached1 to have different data. |
| 7517 | // TODO(rtenneti): mutate other members of CachedState. |
| 7518 | cached1->set_source_address_token(r3_host_name); |
| 7519 | cached1->SetProofInvalid(); |
| 7520 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 7521 | HostPortPair host_port_pair2(r4_host_name, 80); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7522 | quic::QuicServerId server_id2(host_port_pair2.host(), |
| 7523 | host_port_pair2.port(), privacy_mode_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7524 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 7525 | crypto_config->LookupOrCreate(server_id2); |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 7526 | EXPECT_NE(cached1->source_address_token(), cached2->source_address_token()); |
| 7527 | EXPECT_TRUE(cached2->source_address_token().empty()); |
| 7528 | EXPECT_FALSE(cached2->proof_valid()); |
| 7529 | } |
[email protected] | c49ff18 | 2013-09-28 08:33:26 | [diff] [blame] | 7530 | } |
| 7531 | |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7532 | TEST_P(QuicStreamFactoryTest, EnableNotLoadFromDiskCache) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7533 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7534 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7535 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7536 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7537 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7538 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7539 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7540 | MockQuicData socket_data; |
| 7541 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7542 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7543 | |
| 7544 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7545 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7546 | host_resolver_->set_synchronous_mode(true); |
| 7547 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7548 | "192.168.0.1", ""); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7549 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7550 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7551 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7552 | DEFAULT_PRIORITY, SocketTag(), |
| 7553 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7554 | &net_error_details_, |
| 7555 | failed_on_default_network_callback_, |
| 7556 | callback_.callback())); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7557 | |
| 7558 | // If we are waiting for disk cache, we would have posted a task. Verify that |
| 7559 | // the CancelWaitForDataReady task hasn't been posted. |
| 7560 | ASSERT_EQ(0u, runner_->GetPostedTasks().size()); |
| 7561 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7562 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7563 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 7564 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7565 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
rtenneti | 34dffe75 | 2015-02-24 23:27:32 | [diff] [blame] | 7566 | } |
| 7567 | |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7568 | TEST_P(QuicStreamFactoryTest, ReducePingTimeoutOnConnectionTimeOutOpenStreams) { |
| 7569 | reduced_ping_timeout_seconds_ = 10; |
dmurph | 44ca4f4 | 2016-09-09 20:39:09 | [diff] [blame] | 7570 | Initialize(); |
| 7571 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7572 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7573 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7574 | |
| 7575 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7576 | |
| 7577 | MockQuicData socket_data; |
| 7578 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7579 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7580 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7581 | |
| 7582 | MockQuicData socket_data2; |
| 7583 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7584 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7585 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7586 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7587 | |
| 7588 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
| 7589 | |
| 7590 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7591 | MockCryptoClientStream::CONFIRM_HANDSHAKE); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7592 | host_resolver_->set_synchronous_mode(true); |
| 7593 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7594 | "192.168.0.1", ""); |
| 7595 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7596 | |
| 7597 | // Quic should use default PING timeout when no previous connection times out |
| 7598 | // with open stream. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7599 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7600 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7601 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7602 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7603 | DEFAULT_PRIORITY, SocketTag(), |
| 7604 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7605 | &net_error_details_, |
| 7606 | failed_on_default_network_callback_, |
| 7607 | callback_.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7608 | |
| 7609 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7610 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(quic::kPingTimeoutSecs), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7611 | session->connection()->ping_timeout()); |
| 7612 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7613 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7614 | EXPECT_TRUE(stream.get()); |
| 7615 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7616 | request_info.traffic_annotation = |
| 7617 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7618 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7619 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7620 | |
| 7621 | DVLOG(1) |
| 7622 | << "Created 1st session and initialized a stream. Now trigger timeout"; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7623 | session->connection()->CloseConnection( |
| 7624 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7625 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7626 | // Need to spin the loop now to ensure that |
| 7627 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7628 | base::RunLoop run_loop; |
| 7629 | run_loop.RunUntilIdle(); |
| 7630 | |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7631 | // The first connection times out with open stream, QUIC should reduce initial |
| 7632 | // PING time for subsequent connections. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7633 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7634 | QuicStreamFactoryPeer::GetPingTimeout(factory_.get())); |
| 7635 | |
| 7636 | // Test two-in-a-row timeouts with open streams. |
| 7637 | DVLOG(1) << "Create 2nd session and timeout with open stream"; |
| 7638 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7639 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7640 | EXPECT_EQ(OK, |
| 7641 | request2.Request( |
| 7642 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 7643 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 7644 | failed_on_default_network_callback_, callback2.callback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7645 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7646 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(10), |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7647 | session2->connection()->ping_timeout()); |
| 7648 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7649 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7650 | EXPECT_TRUE(stream2.get()); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7651 | EXPECT_EQ(OK, |
| 7652 | stream2->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7653 | net_log_, CompletionOnceCallback())); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7654 | session2->connection()->CloseConnection( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7655 | quic::QUIC_NETWORK_IDLE_TIMEOUT, "test", |
| 7656 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7657 | // Need to spin the loop now to ensure that |
| 7658 | // QuicStreamFactory::OnSessionClosed() runs. |
| 7659 | base::RunLoop run_loop2; |
| 7660 | run_loop2.RunUntilIdle(); |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 7661 | |
| 7662 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7663 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7664 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7665 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7666 | } |
| 7667 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 7668 | // Verifies that the QUIC stream factory is initialized correctly. |
rtenneti | cd2aaa15b | 2015-10-10 20:29:33 | [diff] [blame] | 7669 | TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 7670 | VerifyInitialization(); |
rtenneti | 8a80a6dc | 2015-09-21 19:51:13 | [diff] [blame] | 7671 | } |
| 7672 | |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7673 | TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 7674 | Initialize(); |
| 7675 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7676 | MockQuicData socket_data; |
| 7677 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7678 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7679 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7680 | |
| 7681 | // Save current state of |race_cert_verification|. |
| 7682 | bool race_cert_verification = |
| 7683 | QuicStreamFactoryPeer::GetRaceCertVerification(factory_.get()); |
| 7684 | |
| 7685 | // Load server config. |
| 7686 | HostPortPair host_port_pair(kDefaultServerHostName, kDefaultServerPort); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7687 | quic::QuicServerId quic_server_id(host_port_pair_.host(), |
| 7688 | host_port_pair_.port(), |
| 7689 | privacy_mode_ == PRIVACY_MODE_ENABLED); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7690 | QuicStreamFactoryPeer::CacheDummyServerConfig(factory_.get(), quic_server_id); |
| 7691 | |
| 7692 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), true); |
| 7693 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7694 | |
| 7695 | // Start CertVerifyJob. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7696 | quic::QuicAsyncStatus status = QuicStreamFactoryPeer::StartCertVerifyJob( |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7697 | factory_.get(), quic_server_id, /*cert_verify_flags=*/0, net_log_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7698 | if (status == quic::QUIC_PENDING) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7699 | // Verify CertVerifierJob has started. |
| 7700 | EXPECT_TRUE(HasActiveCertVerifierJob(quic_server_id)); |
| 7701 | |
| 7702 | while (HasActiveCertVerifierJob(quic_server_id)) { |
| 7703 | base::RunLoop().RunUntilIdle(); |
| 7704 | } |
| 7705 | } |
| 7706 | // Verify CertVerifierJob has finished. |
| 7707 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7708 | |
| 7709 | // Start a QUIC request. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7710 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7711 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7712 | request.Request( |
| 7713 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7714 | SocketTag(), |
| 7715 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7716 | failed_on_default_network_callback_, callback_.callback())); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7717 | |
| 7718 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 7719 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7720 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 7721 | EXPECT_TRUE(stream.get()); |
| 7722 | |
| 7723 | // Restore |race_cert_verification|. |
| 7724 | QuicStreamFactoryPeer::SetRaceCertVerification(factory_.get(), |
| 7725 | race_cert_verification); |
| 7726 | |
| 7727 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7728 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7729 | |
| 7730 | // Verify there are no outstanding CertVerifierJobs after request has |
| 7731 | // finished. |
| 7732 | EXPECT_FALSE(HasActiveCertVerifierJob(quic_server_id)); |
| 7733 | } |
| 7734 | |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7735 | TEST_P(QuicStreamFactoryTest, YieldAfterPackets) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7736 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7737 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7738 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7739 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7740 | QuicStreamFactoryPeer::SetYieldAfterPackets(factory_.get(), 0); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7741 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7742 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7743 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(0)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7744 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7745 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7746 | |
| 7747 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7748 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7749 | host_resolver_->set_synchronous_mode(true); |
| 7750 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7751 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7752 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7753 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7754 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7755 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7756 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7757 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7758 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7759 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7760 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7761 | DEFAULT_PRIORITY, SocketTag(), |
| 7762 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7763 | &net_error_details_, |
| 7764 | failed_on_default_network_callback_, |
| 7765 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7766 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7767 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7768 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7769 | base::RunLoop run_loop; |
| 7770 | run_loop.RunUntilIdle(); |
| 7771 | |
| 7772 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7773 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7774 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7775 | EXPECT_EQ(1u, observer.executed_count()); |
| 7776 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7777 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7778 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7779 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7780 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7781 | } |
| 7782 | |
| 7783 | TEST_P(QuicStreamFactoryTest, YieldAfterDuration) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7784 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 7785 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7786 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7787 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7788 | QuicStreamFactoryPeer::SetYieldAfterDuration( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7789 | factory_.get(), quic::QuicTime::Delta::FromMilliseconds(-1)); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7790 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7791 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7792 | socket_data.AddRead(SYNCHRONOUS, ConstructClientConnectionClosePacket(0)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7793 | socket_data.AddRead(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7794 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7795 | |
| 7796 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 7797 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7798 | host_resolver_->set_synchronous_mode(true); |
| 7799 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7800 | "192.168.0.1", ""); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7801 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7802 | // Set up the TaskObserver to verify QuicChromiumPacketReader::StartReading |
| 7803 | // posts a task. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7804 | // TODO(rtenneti): Change SpdySessionTestTaskObserver to NetTestTaskObserver?? |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7805 | SpdySessionTestTaskObserver observer("quic_chromium_packet_reader.cc", |
| 7806 | "StartReading"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7807 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7808 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7809 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 7810 | DEFAULT_PRIORITY, SocketTag(), |
| 7811 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7812 | &net_error_details_, |
| 7813 | failed_on_default_network_callback_, |
| 7814 | callback_.callback())); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7815 | |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7816 | // Call run_loop so that QuicChromiumPacketReader::OnReadComplete() gets |
| 7817 | // called. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7818 | base::RunLoop run_loop; |
| 7819 | run_loop.RunUntilIdle(); |
| 7820 | |
| 7821 | // Verify task that the observer's executed_count is 1, which indicates |
rch | a02807b4 | 2016-01-29 21:56:15 | [diff] [blame] | 7822 | // QuicChromiumPacketReader::StartReading() has posted only one task and |
| 7823 | // yielded the read. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7824 | EXPECT_EQ(1u, observer.executed_count()); |
| 7825 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7826 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
xunjieli | 2608f9b | 2016-03-14 13:39:23 | [diff] [blame] | 7827 | EXPECT_FALSE(stream.get()); // Session is already closed. |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 7828 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7829 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7830 | } |
| 7831 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7832 | TEST_P(QuicStreamFactoryTest, ServerPushSessionAffinity) { |
| 7833 | Initialize(); |
| 7834 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7835 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7836 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7837 | MockQuicData socket_data; |
| 7838 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7839 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7840 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7841 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7842 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7843 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7844 | request.Request( |
| 7845 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7846 | SocketTag(), |
| 7847 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7848 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7849 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7850 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7851 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7852 | EXPECT_TRUE(stream.get()); |
| 7853 | |
| 7854 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7855 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7856 | string url = "https://www.example.org/"; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7857 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7858 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7859 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7860 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7861 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7862 | (*QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()) |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7863 | ->promised_by_url())[kDefaultUrl] = &promised; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7864 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7865 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 7866 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7867 | DEFAULT_PRIORITY, SocketTag(), |
| 7868 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7869 | &net_error_details_, |
| 7870 | failed_on_default_network_callback_, |
| 7871 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7872 | |
| 7873 | EXPECT_EQ(1, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7874 | } |
| 7875 | |
| 7876 | TEST_P(QuicStreamFactoryTest, ServerPushPrivacyModeMismatch) { |
| 7877 | Initialize(); |
| 7878 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7879 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7880 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7881 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7882 | MockQuicData socket_data1; |
| 7883 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7884 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7885 | socket_data1.AddWrite( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7886 | SYNCHRONOUS, client_maker_.MakeRstPacket( |
| 7887 | 2, true, GetNthServerInitiatedUnidirectionalStreamId(0), |
| 7888 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7889 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7890 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7891 | MockQuicData socket_data2; |
| 7892 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7893 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7894 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7895 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7896 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7897 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7898 | request.Request( |
| 7899 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7900 | SocketTag(), |
| 7901 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7902 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7903 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7904 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7905 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7906 | EXPECT_TRUE(stream.get()); |
| 7907 | |
| 7908 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
| 7909 | |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 7910 | string url = "https://www.example.org/"; |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 7911 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7912 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7913 | quic::QuicClientPromisedInfo promised( |
Fan Yang | 32c5a11 | 2018-12-10 20:06:33 | [diff] [blame] | 7914 | session, GetNthServerInitiatedUnidirectionalStreamId(0), kDefaultUrl); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7915 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7916 | quic::QuicClientPushPromiseIndex* index = |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7917 | QuicStreamFactoryPeer::GetPushPromiseIndex(factory_.get()); |
| 7918 | |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7919 | (*index->promised_by_url())[kDefaultUrl] = &promised; |
| 7920 | EXPECT_EQ(index->GetPromised(kDefaultUrl), &promised); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7921 | |
| 7922 | // Doing the request should not use the push stream, but rather |
| 7923 | // cancel it because the privacy modes do not match. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7924 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7925 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7926 | request2.Request( |
| 7927 | host_port_pair_, version_, PRIVACY_MODE_ENABLED, |
| 7928 | DEFAULT_PRIORITY, SocketTag(), |
| 7929 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7930 | failed_on_default_network_callback_, callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7931 | |
| 7932 | EXPECT_EQ(0, QuicStreamFactoryPeer::GetNumPushStreamsCreated(factory_.get())); |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 7933 | EXPECT_EQ(index->GetPromised(kDefaultUrl), nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7934 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7935 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7936 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 7937 | EXPECT_TRUE(stream2.get()); |
| 7938 | |
| 7939 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7940 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7941 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7942 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7943 | } |
| 7944 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7945 | // Pool to existing session with matching quic::QuicServerId |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7946 | // even if destination is different. |
| 7947 | TEST_P(QuicStreamFactoryTest, PoolByOrigin) { |
| 7948 | Initialize(); |
| 7949 | |
| 7950 | HostPortPair destination1("first.example.com", 443); |
| 7951 | HostPortPair destination2("second.example.com", 443); |
| 7952 | |
| 7953 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7954 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7955 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7956 | MockQuicData socket_data; |
| 7957 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7958 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7959 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7960 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7961 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7962 | EXPECT_EQ( |
| 7963 | ERR_IO_PENDING, |
| 7964 | request1.Request( |
| 7965 | destination1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 7966 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7967 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7968 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7969 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7970 | EXPECT_TRUE(stream1.get()); |
| 7971 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7972 | |
| 7973 | // Second request returns synchronously because it pools to existing session. |
| 7974 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7975 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 7976 | EXPECT_EQ(OK, request2.Request(destination2, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7977 | DEFAULT_PRIORITY, SocketTag(), |
| 7978 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7979 | &net_error_details_, |
| 7980 | failed_on_default_network_callback_, |
| 7981 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7982 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7983 | EXPECT_TRUE(stream2.get()); |
| 7984 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 7985 | QuicChromiumClientSession::Handle* session1 = |
| 7986 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 7987 | QuicChromiumClientSession::Handle* session2 = |
| 7988 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 7989 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 7990 | EXPECT_EQ(quic::QuicServerId(host_port_pair_.host(), host_port_pair_.port(), |
| 7991 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 7992 | session1->server_id()); |
| 7993 | |
| 7994 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7995 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7996 | } |
| 7997 | |
| 7998 | class QuicStreamFactoryWithDestinationTest |
| 7999 | : public QuicStreamFactoryTestBase, |
| 8000 | public ::testing::TestWithParam<PoolingTestParams> { |
| 8001 | protected: |
| 8002 | QuicStreamFactoryWithDestinationTest() |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 8003 | : QuicStreamFactoryTestBase( |
| 8004 | GetParam().version, |
| 8005 | GetParam().client_headers_include_h2_stream_dependency), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8006 | destination_type_(GetParam().destination_type), |
| 8007 | hanging_read_(SYNCHRONOUS, ERR_IO_PENDING, 0) {} |
| 8008 | |
| 8009 | HostPortPair GetDestination() { |
| 8010 | switch (destination_type_) { |
| 8011 | case SAME_AS_FIRST: |
| 8012 | return origin1_; |
| 8013 | case SAME_AS_SECOND: |
| 8014 | return origin2_; |
| 8015 | case DIFFERENT: |
| 8016 | return HostPortPair(kDifferentHostname, 443); |
| 8017 | default: |
| 8018 | NOTREACHED(); |
| 8019 | return HostPortPair(); |
| 8020 | } |
| 8021 | } |
| 8022 | |
| 8023 | void AddHangingSocketData() { |
| 8024 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8025 | new SequencedSocketData(base::make_span(&hanging_read_, 1), |
| 8026 | base::span<MockWrite>())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8027 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8028 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8029 | } |
| 8030 | |
| 8031 | bool AllDataConsumed() { |
| 8032 | for (const auto& socket_data_ptr : sequenced_socket_data_vector_) { |
| 8033 | if (!socket_data_ptr->AllReadDataConsumed() || |
| 8034 | !socket_data_ptr->AllWriteDataConsumed()) { |
| 8035 | return false; |
| 8036 | } |
| 8037 | } |
| 8038 | return true; |
| 8039 | } |
| 8040 | |
| 8041 | DestinationType destination_type_; |
| 8042 | HostPortPair origin1_; |
| 8043 | HostPortPair origin2_; |
| 8044 | MockRead hanging_read_; |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8045 | std::vector<std::unique_ptr<SequencedSocketData>> |
| 8046 | sequenced_socket_data_vector_; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8047 | }; |
| 8048 | |
Victor Costan | e635086f | 2019-01-27 05:20:30 | [diff] [blame^] | 8049 | INSTANTIATE_TEST_SUITE_P(VersionIncludeStreamDependencySequence, |
| 8050 | QuicStreamFactoryWithDestinationTest, |
| 8051 | ::testing::ValuesIn(GetPoolingTestParams())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8052 | |
| 8053 | // A single QUIC request fails because the certificate does not match the origin |
| 8054 | // hostname, regardless of whether it matches the alternative service hostname. |
| 8055 | TEST_P(QuicStreamFactoryWithDestinationTest, InvalidCertificate) { |
| 8056 | if (destination_type_ == DIFFERENT) |
| 8057 | return; |
| 8058 | |
| 8059 | Initialize(); |
| 8060 | |
| 8061 | GURL url("https://mail.example.com/"); |
| 8062 | origin1_ = HostPortPair::FromURL(url); |
| 8063 | |
| 8064 | // Not used for requests, but this provides a test case where the certificate |
| 8065 | // is valid for the hostname of the alternative service. |
| 8066 | origin2_ = HostPortPair("mail.example.org", 433); |
| 8067 | |
| 8068 | HostPortPair destination = GetDestination(); |
| 8069 | |
| 8070 | scoped_refptr<X509Certificate> cert( |
| 8071 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8072 | ASSERT_FALSE(cert->VerifyNameMatch(origin1_.host())); |
| 8073 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8074 | |
| 8075 | ProofVerifyDetailsChromium verify_details; |
| 8076 | verify_details.cert_verify_result.verified_cert = cert; |
| 8077 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8078 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8079 | |
| 8080 | AddHangingSocketData(); |
| 8081 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8082 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8083 | EXPECT_EQ( |
| 8084 | ERR_IO_PENDING, |
| 8085 | request.Request( |
| 8086 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8087 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 8088 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8089 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8090 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_QUIC_HANDSHAKE_FAILED)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8091 | |
| 8092 | EXPECT_TRUE(AllDataConsumed()); |
| 8093 | } |
| 8094 | |
| 8095 | // QuicStreamRequest is pooled based on |destination| if certificate matches. |
| 8096 | TEST_P(QuicStreamFactoryWithDestinationTest, SharedCertificate) { |
| 8097 | Initialize(); |
| 8098 | |
| 8099 | GURL url1("https://www.example.org/"); |
| 8100 | GURL url2("https://mail.example.org/"); |
| 8101 | origin1_ = HostPortPair::FromURL(url1); |
| 8102 | origin2_ = HostPortPair::FromURL(url2); |
| 8103 | |
| 8104 | HostPortPair destination = GetDestination(); |
| 8105 | |
| 8106 | scoped_refptr<X509Certificate> cert( |
| 8107 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8108 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8109 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8110 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8111 | |
| 8112 | ProofVerifyDetailsChromium verify_details; |
| 8113 | verify_details.cert_verify_result.verified_cert = cert; |
| 8114 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 8115 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8116 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8117 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8118 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8119 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8120 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8121 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8122 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8123 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8124 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8125 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8126 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8127 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8128 | EXPECT_EQ( |
| 8129 | ERR_IO_PENDING, |
| 8130 | request1.Request( |
| 8131 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8132 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8133 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8134 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8135 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8136 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8137 | EXPECT_TRUE(stream1.get()); |
| 8138 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8139 | |
| 8140 | // Second request returns synchronously because it pools to existing session. |
| 8141 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8142 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 8143 | EXPECT_EQ(OK, request2.Request(destination, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8144 | DEFAULT_PRIORITY, SocketTag(), |
| 8145 | /*cert_verify_flags=*/0, url2, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8146 | &net_error_details_, |
| 8147 | failed_on_default_network_callback_, |
| 8148 | callback2.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8149 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8150 | EXPECT_TRUE(stream2.get()); |
| 8151 | |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8152 | QuicChromiumClientSession::Handle* session1 = |
| 8153 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8154 | QuicChromiumClientSession::Handle* session2 = |
| 8155 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8156 | EXPECT_TRUE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8157 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8158 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8159 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8160 | session1->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8161 | |
| 8162 | EXPECT_TRUE(AllDataConsumed()); |
| 8163 | } |
| 8164 | |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8165 | // QuicStreamRequest is not pooled if PrivacyMode differs. |
| 8166 | TEST_P(QuicStreamFactoryWithDestinationTest, DifferentPrivacyMode) { |
| 8167 | Initialize(); |
| 8168 | |
| 8169 | GURL url1("https://www.example.org/"); |
| 8170 | GURL url2("https://mail.example.org/"); |
| 8171 | origin1_ = HostPortPair::FromURL(url1); |
| 8172 | origin2_ = HostPortPair::FromURL(url2); |
| 8173 | |
| 8174 | HostPortPair destination = GetDestination(); |
| 8175 | |
| 8176 | scoped_refptr<X509Certificate> cert( |
| 8177 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8178 | ASSERT_TRUE(cert->VerifyNameMatch(origin1_.host())); |
| 8179 | ASSERT_TRUE(cert->VerifyNameMatch(origin2_.host())); |
| 8180 | ASSERT_FALSE(cert->VerifyNameMatch(kDifferentHostname)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8181 | |
| 8182 | ProofVerifyDetailsChromium verify_details1; |
| 8183 | verify_details1.cert_verify_result.verified_cert = cert; |
| 8184 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8185 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8186 | |
| 8187 | ProofVerifyDetailsChromium verify_details2; |
| 8188 | verify_details2.cert_verify_result.verified_cert = cert; |
| 8189 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8190 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8191 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8192 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8193 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8194 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8195 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8196 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8197 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8198 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8199 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8200 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8201 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8202 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8203 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8204 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8205 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8206 | QuicStreamRequest request1(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8207 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8208 | request1.Request( |
| 8209 | destination, version_, PRIVACY_MODE_DISABLED, DEFAULT_PRIORITY, |
| 8210 | SocketTag(), |
| 8211 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8212 | failed_on_default_network_callback_, callback_.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8213 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8214 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8215 | EXPECT_TRUE(stream1.get()); |
| 8216 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8217 | |
| 8218 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8219 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8220 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8221 | request2.Request( |
| 8222 | destination, version_, PRIVACY_MODE_ENABLED, DEFAULT_PRIORITY, |
| 8223 | SocketTag(), |
| 8224 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8225 | failed_on_default_network_callback_, callback2.callback())); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8226 | EXPECT_EQ(OK, callback2.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8227 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8228 | EXPECT_TRUE(stream2.get()); |
| 8229 | |
| 8230 | // |request2| does not pool to the first session, because PrivacyMode does not |
| 8231 | // match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8232 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8233 | QuicChromiumClientSession::Handle* session1 = |
| 8234 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8235 | QuicChromiumClientSession::Handle* session2 = |
| 8236 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8237 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8238 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8239 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), false), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8240 | session1->server_id()); |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8241 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), true), |
bnc | 47eba7d | 2016-07-01 00:43:38 | [diff] [blame] | 8242 | session2->server_id()); |
| 8243 | |
| 8244 | EXPECT_TRUE(AllDataConsumed()); |
| 8245 | } |
| 8246 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8247 | // QuicStreamRequest is not pooled if certificate does not match its origin. |
| 8248 | TEST_P(QuicStreamFactoryWithDestinationTest, DisjointCertificate) { |
| 8249 | Initialize(); |
| 8250 | |
| 8251 | GURL url1("https://news.example.org/"); |
| 8252 | GURL url2("https://mail.example.com/"); |
| 8253 | origin1_ = HostPortPair::FromURL(url1); |
| 8254 | origin2_ = HostPortPair::FromURL(url2); |
| 8255 | |
| 8256 | HostPortPair destination = GetDestination(); |
| 8257 | |
| 8258 | scoped_refptr<X509Certificate> cert1( |
| 8259 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8260 | ASSERT_TRUE(cert1->VerifyNameMatch(origin1_.host())); |
| 8261 | ASSERT_FALSE(cert1->VerifyNameMatch(origin2_.host())); |
| 8262 | ASSERT_FALSE(cert1->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8263 | |
| 8264 | ProofVerifyDetailsChromium verify_details1; |
| 8265 | verify_details1.cert_verify_result.verified_cert = cert1; |
| 8266 | verify_details1.cert_verify_result.is_issued_by_known_root = true; |
| 8267 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 8268 | |
| 8269 | scoped_refptr<X509Certificate> cert2( |
| 8270 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
Ryan Sleevi | def35f6 | 2018-01-23 21:12:24 | [diff] [blame] | 8271 | ASSERT_TRUE(cert2->VerifyNameMatch(origin2_.host())); |
| 8272 | ASSERT_FALSE(cert2->VerifyNameMatch(kDifferentHostname)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8273 | |
| 8274 | ProofVerifyDetailsChromium verify_details2; |
| 8275 | verify_details2.cert_verify_result.verified_cert = cert2; |
| 8276 | verify_details2.cert_verify_result.is_issued_by_known_root = true; |
| 8277 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
| 8278 | |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8279 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8280 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 8281 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 8282 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 8283 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8284 | std::unique_ptr<SequencedSocketData> sequenced_socket_data( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8285 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8286 | socket_factory_->AddSocketDataProvider(sequenced_socket_data.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8287 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data)); |
| 8288 | std::unique_ptr<SequencedSocketData> sequenced_socket_data1( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8289 | new SequencedSocketData(reads, writes)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8290 | socket_factory_->AddSocketDataProvider(sequenced_socket_data1.get()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 8291 | sequenced_socket_data_vector_.push_back(std::move(sequenced_socket_data1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8292 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8293 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8294 | EXPECT_EQ( |
| 8295 | ERR_IO_PENDING, |
| 8296 | request1.Request( |
| 8297 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8298 | /*cert_verify_flags=*/0, url1, net_log_, &net_error_details_, |
| 8299 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8300 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8301 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8302 | EXPECT_TRUE(stream1.get()); |
| 8303 | EXPECT_TRUE(HasActiveSession(origin1_)); |
| 8304 | |
| 8305 | TestCompletionCallback callback2; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 8306 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8307 | EXPECT_EQ( |
| 8308 | ERR_IO_PENDING, |
| 8309 | request2.Request( |
| 8310 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 8311 | /*cert_verify_flags=*/0, url2, net_log_, &net_error_details_, |
| 8312 | failed_on_default_network_callback_, callback2.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8313 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 8314 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8315 | EXPECT_TRUE(stream2.get()); |
| 8316 | |
| 8317 | // |request2| does not pool to the first session, because the certificate does |
| 8318 | // not match. Instead, another session is opened to the same destination, but |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8319 | // with a different quic::QuicServerId. |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 8320 | QuicChromiumClientSession::Handle* session1 = |
| 8321 | QuicHttpStreamPeer::GetSessionHandle(stream1.get()); |
| 8322 | QuicChromiumClientSession::Handle* session2 = |
| 8323 | QuicHttpStreamPeer::GetSessionHandle(stream2.get()); |
| 8324 | EXPECT_FALSE(session1->SharesSameSession(*session2)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8325 | |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 8326 | EXPECT_EQ(quic::QuicServerId(origin1_.host(), origin1_.port(), |
| 8327 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8328 | session1->server_id()); |
| 8329 | EXPECT_EQ(quic::QuicServerId(origin2_.host(), origin2_.port(), |
| 8330 | privacy_mode_ == PRIVACY_MODE_ENABLED), |
| 8331 | session2->server_id()); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8332 | |
| 8333 | EXPECT_TRUE(AllDataConsumed()); |
| 8334 | } |
| 8335 | |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8336 | // This test verifies that QuicStreamFactory::ClearCachedStatesInCryptoConfig |
| 8337 | // correctly transform an origin filter to a ServerIdFilter. Whether the |
| 8338 | // deletion itself works correctly is tested in QuicCryptoClientConfigTest. |
| 8339 | TEST_P(QuicStreamFactoryTest, ClearCachedStatesInCryptoConfig) { |
| 8340 | Initialize(); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8341 | quic::QuicCryptoClientConfig* crypto_config = |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8342 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 8343 | |
| 8344 | struct TestCase { |
| 8345 | TestCase(const std::string& host, |
| 8346 | int port, |
| 8347 | PrivacyMode privacy_mode, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8348 | quic::QuicCryptoClientConfig* crypto_config) |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8349 | : server_id(host, port, privacy_mode), |
| 8350 | state(crypto_config->LookupOrCreate(server_id)) { |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 8351 | std::vector<string> certs(1); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8352 | certs[0] = "cert"; |
| 8353 | state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 8354 | state->set_source_address_token("TOKEN"); |
| 8355 | state->SetProofValid(); |
| 8356 | |
| 8357 | EXPECT_FALSE(state->certs().empty()); |
| 8358 | } |
| 8359 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8360 | quic::QuicServerId server_id; |
| 8361 | quic::QuicCryptoClientConfig::CachedState* state; |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8362 | } test_cases[] = { |
| 8363 | TestCase("www.google.com", 443, privacy_mode_, crypto_config), |
| 8364 | TestCase("www.example.com", 443, privacy_mode_, crypto_config), |
| 8365 | TestCase("www.example.com", 4433, privacy_mode_, crypto_config)}; |
| 8366 | |
| 8367 | // Clear cached states for the origin https://www.example.com:4433. |
| 8368 | GURL origin("https://www.example.com:4433"); |
csharrison | ebeca8e | 2016-10-18 02:35:36 | [diff] [blame] | 8369 | factory_->ClearCachedStatesInCryptoConfig(base::Bind( |
| 8370 | static_cast<bool (*)(const GURL&, const GURL&)>(::operator==), origin)); |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 8371 | EXPECT_FALSE(test_cases[0].state->certs().empty()); |
| 8372 | EXPECT_FALSE(test_cases[1].state->certs().empty()); |
| 8373 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8374 | |
| 8375 | // Clear all cached states. |
| 8376 | factory_->ClearCachedStatesInCryptoConfig( |
| 8377 | base::Callback<bool(const GURL&)>()); |
| 8378 | EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 8379 | EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 8380 | EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 8381 | } |
| 8382 | |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8383 | // Passes connection options and client connection options to QuicStreamFactory, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8384 | // then checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8385 | TEST_P(QuicStreamFactoryTest, ConfigConnectionOptions) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8386 | connection_options_.push_back(quic::kTIME); |
| 8387 | connection_options_.push_back(quic::kTBBR); |
| 8388 | connection_options_.push_back(quic::kREJ); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8389 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8390 | client_connection_options_.push_back(quic::kTBBR); |
| 8391 | client_connection_options_.push_back(quic::k1RTT); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8392 | |
| 8393 | Initialize(); |
| 8394 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8395 | const quic::QuicConfig* config = |
| 8396 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8397 | EXPECT_EQ(connection_options_, config->SendConnectionOptions()); |
| 8398 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8399 | quic::kTBBR, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8400 | EXPECT_TRUE(config->HasClientRequestedIndependentOption( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8401 | quic::k1RTT, quic::Perspective::IS_CLIENT)); |
Yixin Wang | 46a425f | 2017-08-10 23:02:20 | [diff] [blame] | 8402 | } |
| 8403 | |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8404 | // Verifies that the host resolver uses the request priority passed to |
| 8405 | // QuicStreamRequest::Request(). |
| 8406 | TEST_P(QuicStreamFactoryTest, HostResolverUsesRequestPriority) { |
| 8407 | Initialize(); |
| 8408 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8409 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8410 | |
| 8411 | MockQuicData socket_data; |
| 8412 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 8413 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 8414 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8415 | |
| 8416 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8417 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8418 | request.Request( |
| 8419 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8420 | SocketTag(), |
| 8421 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8422 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8423 | |
| 8424 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8425 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8426 | EXPECT_TRUE(stream.get()); |
| 8427 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8428 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 8429 | |
| 8430 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 8431 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 8432 | } |
| 8433 | |
Lily Chen | f11e129 | 2018-11-29 16:42:09 | [diff] [blame] | 8434 | TEST_P(QuicStreamFactoryTest, HostResolverRequestReprioritizedOnSetPriority) { |
| 8435 | Initialize(); |
| 8436 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8437 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8438 | |
| 8439 | MockQuicData socket_data; |
| 8440 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8441 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8442 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8443 | |
| 8444 | QuicStreamRequest request(factory_.get()); |
| 8445 | EXPECT_EQ(ERR_IO_PENDING, |
| 8446 | request.Request( |
| 8447 | host_port_pair_, version_, privacy_mode_, MAXIMUM_PRIORITY, |
| 8448 | SocketTag(), |
| 8449 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8450 | failed_on_default_network_callback_, callback_.callback())); |
| 8451 | |
| 8452 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->last_request_priority()); |
| 8453 | EXPECT_EQ(MAXIMUM_PRIORITY, host_resolver_->request_priority(1)); |
| 8454 | |
| 8455 | QuicStreamRequest request2(factory_.get()); |
| 8456 | EXPECT_EQ(ERR_IO_PENDING, |
| 8457 | request2.Request( |
| 8458 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8459 | SocketTag(), |
| 8460 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 8461 | failed_on_default_network_callback_, callback_.callback())); |
| 8462 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
| 8463 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8464 | |
| 8465 | request.SetPriority(LOWEST); |
| 8466 | EXPECT_EQ(LOWEST, host_resolver_->request_priority(1)); |
| 8467 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->request_priority(2)); |
| 8468 | } |
| 8469 | |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8470 | // Passes |max_time_before_crypto_handshake_seconds| and |
| 8471 | // |max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, then |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8472 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8473 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
| 8474 | max_time_before_crypto_handshake_seconds_ = 11; |
| 8475 | max_idle_time_before_crypto_handshake_seconds_ = 13; |
| 8476 | |
| 8477 | Initialize(); |
| 8478 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8479 | const quic::QuicConfig* config = |
| 8480 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 8481 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8482 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8483 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8484 | config->max_idle_time_before_crypto_handshake()); |
| 8485 | } |
| 8486 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8487 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8488 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 8489 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 8490 | Initialize(); |
| 8491 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8492 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8493 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8494 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8495 | |
| 8496 | MockQuicData socket_data; |
| 8497 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8498 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8499 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8500 | |
| 8501 | QuicStreamRequest request(factory_.get()); |
| 8502 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8503 | request.Request( |
| 8504 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8505 | SocketTag(), |
| 8506 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8507 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8508 | |
| 8509 | TestCompletionCallback host_resolution_callback; |
| 8510 | EXPECT_TRUE( |
| 8511 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8512 | |
| 8513 | // |host_resolver_| has not finished host resolution at this point, so |
| 8514 | // |host_resolution_callback| should not have a result. |
| 8515 | base::RunLoop().RunUntilIdle(); |
| 8516 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8517 | |
| 8518 | // Allow |host_resolver_| to finish host resolution. |
| 8519 | // Since the request fails immediately after host resolution (getting |
| 8520 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 8521 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 8522 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8523 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8524 | base::RunLoop().RunUntilIdle(); |
| 8525 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8526 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 8527 | |
| 8528 | // Calling WaitForHostResolution() a second time should return |
| 8529 | // false since host resolution has finished already. |
| 8530 | EXPECT_FALSE( |
| 8531 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8532 | |
| 8533 | EXPECT_TRUE(callback_.have_result()); |
| 8534 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8535 | } |
| 8536 | |
| 8537 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8538 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 8539 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 8540 | Initialize(); |
| 8541 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8542 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8543 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8544 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8545 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8546 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8547 | factory_->set_require_confirmation(true); |
| 8548 | |
| 8549 | MockQuicData socket_data; |
| 8550 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8551 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8552 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8553 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8554 | |
| 8555 | QuicStreamRequest request(factory_.get()); |
| 8556 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8557 | request.Request( |
| 8558 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8559 | SocketTag(), |
| 8560 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8561 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8562 | |
| 8563 | TestCompletionCallback host_resolution_callback; |
| 8564 | EXPECT_TRUE( |
| 8565 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8566 | |
| 8567 | // |host_resolver_| has not finished host resolution at this point, so |
| 8568 | // |host_resolution_callback| should not have a result. |
| 8569 | base::RunLoop().RunUntilIdle(); |
| 8570 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8571 | |
| 8572 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 8573 | // will hang after host resolution, |host_resolution_callback| should run with |
| 8574 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8575 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8576 | base::RunLoop().RunUntilIdle(); |
| 8577 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8578 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 8579 | |
| 8580 | // Calling WaitForHostResolution() a second time should return |
| 8581 | // false since host resolution has finished already. |
| 8582 | EXPECT_FALSE( |
| 8583 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8584 | |
| 8585 | EXPECT_FALSE(callback_.have_result()); |
| 8586 | socket_data.GetSequencedSocketData()->Resume(); |
| 8587 | base::RunLoop().RunUntilIdle(); |
| 8588 | EXPECT_TRUE(callback_.have_result()); |
| 8589 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8590 | } |
| 8591 | |
| 8592 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8593 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 8594 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 8595 | Initialize(); |
| 8596 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8597 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8598 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8599 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8600 | |
| 8601 | MockQuicData socket_data; |
| 8602 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8603 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8604 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8605 | |
| 8606 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8607 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8608 | request.Request( |
| 8609 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8610 | SocketTag(), |
| 8611 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8612 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8613 | |
| 8614 | // WaitForHostResolution() should return false since host |
| 8615 | // resolution has finished already. |
| 8616 | TestCompletionCallback host_resolution_callback; |
| 8617 | EXPECT_FALSE( |
| 8618 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8619 | base::RunLoop().RunUntilIdle(); |
| 8620 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8621 | EXPECT_FALSE(callback_.have_result()); |
| 8622 | } |
| 8623 | |
| 8624 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8625 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 8626 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 8627 | Initialize(); |
| 8628 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8629 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8630 | |
| 8631 | // Host resolution will succeed synchronously, but Request() as a whole |
| 8632 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8633 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8634 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8635 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8636 | factory_->set_require_confirmation(true); |
| 8637 | |
| 8638 | MockQuicData socket_data; |
| 8639 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8640 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8641 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8642 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8643 | |
| 8644 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8645 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8646 | request.Request( |
| 8647 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8648 | SocketTag(), |
| 8649 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8650 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8651 | |
| 8652 | // WaitForHostResolution() should return false since host |
| 8653 | // resolution has finished already. |
| 8654 | TestCompletionCallback host_resolution_callback; |
| 8655 | EXPECT_FALSE( |
| 8656 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8657 | base::RunLoop().RunUntilIdle(); |
| 8658 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8659 | |
| 8660 | EXPECT_FALSE(callback_.have_result()); |
| 8661 | socket_data.GetSequencedSocketData()->Resume(); |
| 8662 | base::RunLoop().RunUntilIdle(); |
| 8663 | EXPECT_TRUE(callback_.have_result()); |
| 8664 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8665 | } |
| 8666 | |
| 8667 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8668 | // synchronously. |
| 8669 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 8670 | Initialize(); |
| 8671 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8672 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8673 | |
| 8674 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8675 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 8676 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8677 | |
| 8678 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8679 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8680 | request.Request( |
| 8681 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8682 | SocketTag(), |
| 8683 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8684 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8685 | |
| 8686 | // WaitForHostResolution() should return false since host |
| 8687 | // resolution has failed already. |
| 8688 | TestCompletionCallback host_resolution_callback; |
| 8689 | EXPECT_FALSE( |
| 8690 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8691 | base::RunLoop().RunUntilIdle(); |
| 8692 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8693 | } |
| 8694 | |
| 8695 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8696 | // asynchronously. |
| 8697 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 8698 | Initialize(); |
| 8699 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8700 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8701 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8702 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8703 | |
| 8704 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8705 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8706 | request.Request( |
| 8707 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8708 | SocketTag(), |
| 8709 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8710 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8711 | |
| 8712 | TestCompletionCallback host_resolution_callback; |
| 8713 | EXPECT_TRUE( |
| 8714 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8715 | |
| 8716 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 8717 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 8718 | // resolution failed with. |
| 8719 | base::RunLoop().RunUntilIdle(); |
| 8720 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8721 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 8722 | |
| 8723 | EXPECT_TRUE(callback_.have_result()); |
| 8724 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 8725 | } |
| 8726 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8727 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 8728 | // the final connection is established through the resolved DNS. No racing |
| 8729 | // connection. |
| 8730 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
| 8731 | race_stale_dns_on_connection_ = true; |
| 8732 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8733 | Initialize(); |
| 8734 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8735 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8736 | |
| 8737 | // Set an address in resolver for synchronous return. |
| 8738 | host_resolver_->set_synchronous_mode(true); |
| 8739 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8740 | kNonCachedIPAddress, ""); |
| 8741 | |
| 8742 | // Set up a different address in stale resolver cache. |
| 8743 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8744 | HostCache::Entry entry(OK, |
| 8745 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8746 | HostCache::Entry::SOURCE_DNS); |
| 8747 | base::TimeDelta zero; |
| 8748 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8749 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8750 | // Expire the cache |
| 8751 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 8752 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8753 | MockQuicData quic_data; |
| 8754 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8755 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8756 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8757 | |
| 8758 | QuicStreamRequest request(factory_.get()); |
| 8759 | EXPECT_THAT(request.Request( |
| 8760 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8761 | SocketTag(), |
| 8762 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8763 | failed_on_default_network_callback_, callback_.callback()), |
| 8764 | IsOk()); |
| 8765 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8766 | EXPECT_TRUE(stream.get()); |
| 8767 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8768 | EXPECT_EQ( |
| 8769 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8770 | kNonCachedIPAddress); |
| 8771 | |
| 8772 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8773 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8774 | } |
| 8775 | |
| 8776 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 8777 | // host resolver, connection should be successful and through resolved DNS. No |
| 8778 | // racing connection. |
| 8779 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
| 8780 | race_stale_dns_on_connection_ = true; |
| 8781 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8782 | Initialize(); |
| 8783 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8784 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8785 | |
| 8786 | // Set an address in resolver for asynchronous return. |
| 8787 | host_resolver_->set_ondemand_mode(true); |
| 8788 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8789 | kNonCachedIPAddress, ""); |
| 8790 | |
| 8791 | MockQuicData quic_data; |
| 8792 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8793 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8794 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8795 | |
| 8796 | QuicStreamRequest request(factory_.get()); |
| 8797 | EXPECT_EQ(ERR_IO_PENDING, |
| 8798 | request.Request( |
| 8799 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8800 | SocketTag(), |
| 8801 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8802 | failed_on_default_network_callback_, callback_.callback())); |
| 8803 | TestCompletionCallback host_resolution_callback; |
| 8804 | EXPECT_TRUE( |
| 8805 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8806 | base::RunLoop().RunUntilIdle(); |
| 8807 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8808 | |
| 8809 | // Cause the host resolution to return. |
| 8810 | host_resolver_->ResolveAllPending(); |
| 8811 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 8812 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8813 | |
| 8814 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8815 | EXPECT_TRUE(stream.get()); |
| 8816 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8817 | |
| 8818 | EXPECT_EQ( |
| 8819 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8820 | kNonCachedIPAddress); |
| 8821 | |
| 8822 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8823 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8824 | } |
| 8825 | |
| 8826 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 8827 | // connects synchrounously, and then the resolved DNS matches. |
| 8828 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
| 8829 | race_stale_dns_on_connection_ = true; |
| 8830 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8831 | Initialize(); |
| 8832 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8833 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8834 | |
| 8835 | // Set an address in resolver for asynchronous return. |
| 8836 | host_resolver_->set_ondemand_mode(true); |
| 8837 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8838 | kCachedIPAddress.ToString(), ""); |
| 8839 | |
| 8840 | // Set up the same address in the stale resolver cache. |
| 8841 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8842 | HostCache::Entry entry(OK, |
| 8843 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8844 | HostCache::Entry::SOURCE_DNS); |
| 8845 | base::TimeDelta zero; |
| 8846 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8847 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8848 | // Expire the cache |
| 8849 | cache->OnNetworkChange(); |
| 8850 | |
| 8851 | MockQuicData quic_data; |
| 8852 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8853 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8854 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8855 | |
| 8856 | QuicStreamRequest request(factory_.get()); |
| 8857 | EXPECT_EQ(ERR_IO_PENDING, |
| 8858 | request.Request( |
| 8859 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8860 | SocketTag(), |
| 8861 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8862 | failed_on_default_network_callback_, callback_.callback())); |
| 8863 | |
| 8864 | // Check that the racing job is running. |
| 8865 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8866 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8867 | |
| 8868 | // Resolve dns and return. |
| 8869 | host_resolver_->ResolveAllPending(); |
| 8870 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8871 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8872 | EXPECT_TRUE(stream.get()); |
| 8873 | |
| 8874 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8875 | |
| 8876 | EXPECT_EQ( |
| 8877 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8878 | kCachedIPAddress.ToString()); |
| 8879 | |
| 8880 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8881 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8882 | } |
| 8883 | |
| 8884 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 8885 | // async, and then the result matches. |
| 8886 | TEST_P(QuicStreamFactoryTest, |
| 8887 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
| 8888 | race_stale_dns_on_connection_ = true; |
| 8889 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8890 | Initialize(); |
| 8891 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8892 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8893 | |
| 8894 | // Set an address in resolver for asynchronous return. |
| 8895 | host_resolver_->set_ondemand_mode(true); |
| 8896 | factory_->set_require_confirmation(true); |
| 8897 | crypto_client_stream_factory_.set_handshake_mode( |
| 8898 | MockCryptoClientStream::ZERO_RTT); |
| 8899 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8900 | kCachedIPAddress.ToString(), ""); |
| 8901 | |
| 8902 | // Set up the same address in the stale resolver cache. |
| 8903 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8904 | HostCache::Entry entry(OK, |
| 8905 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8906 | HostCache::Entry::SOURCE_DNS); |
| 8907 | base::TimeDelta zero; |
| 8908 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8909 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8910 | // Expire the cache |
| 8911 | cache->OnNetworkChange(); |
| 8912 | |
| 8913 | MockQuicData quic_data; |
| 8914 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8915 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8916 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8917 | |
| 8918 | QuicStreamRequest request(factory_.get()); |
| 8919 | EXPECT_EQ(ERR_IO_PENDING, |
| 8920 | request.Request( |
| 8921 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8922 | SocketTag(), |
| 8923 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8924 | failed_on_default_network_callback_, callback_.callback())); |
| 8925 | |
| 8926 | // Send Crypto handshake so connect will call back. |
| 8927 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 8928 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 8929 | base::RunLoop().RunUntilIdle(); |
| 8930 | |
| 8931 | // Check that the racing job is running. |
| 8932 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8933 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8934 | |
| 8935 | // Resolve dns and call back, make sure job finishes. |
| 8936 | host_resolver_->ResolveAllPending(); |
| 8937 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8938 | |
| 8939 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8940 | EXPECT_TRUE(stream.get()); |
| 8941 | |
| 8942 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8943 | |
| 8944 | EXPECT_EQ( |
| 8945 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8946 | kCachedIPAddress.ToString()); |
| 8947 | |
| 8948 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8949 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8950 | } |
| 8951 | |
| 8952 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 8953 | // return, then connection finishes and matches with the result. |
| 8954 | TEST_P(QuicStreamFactoryTest, |
| 8955 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
| 8956 | race_stale_dns_on_connection_ = true; |
| 8957 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8958 | Initialize(); |
| 8959 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8960 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8961 | |
| 8962 | // Set an address in resolver for asynchronous return. |
| 8963 | host_resolver_->set_ondemand_mode(true); |
| 8964 | factory_->set_require_confirmation(true); |
| 8965 | crypto_client_stream_factory_.set_handshake_mode( |
| 8966 | MockCryptoClientStream::ZERO_RTT); |
| 8967 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8968 | kCachedIPAddress.ToString(), ""); |
| 8969 | |
| 8970 | // Set up the same address in the stale resolver cache. |
| 8971 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8972 | HostCache::Entry entry(OK, |
| 8973 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8974 | HostCache::Entry::SOURCE_DNS); |
| 8975 | base::TimeDelta zero; |
| 8976 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8977 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8978 | // Expire the cache |
| 8979 | cache->OnNetworkChange(); |
| 8980 | |
| 8981 | MockQuicData quic_data; |
| 8982 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8983 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8984 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8985 | |
| 8986 | QuicStreamRequest request(factory_.get()); |
| 8987 | EXPECT_EQ(ERR_IO_PENDING, |
| 8988 | request.Request( |
| 8989 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8990 | SocketTag(), |
| 8991 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8992 | failed_on_default_network_callback_, callback_.callback())); |
| 8993 | |
| 8994 | // Finish dns async, check we still need to wait for stale connection async. |
| 8995 | host_resolver_->ResolveAllPending(); |
| 8996 | base::RunLoop().RunUntilIdle(); |
| 8997 | EXPECT_FALSE(callback_.have_result()); |
| 8998 | |
| 8999 | // Finish stale connection async, and the stale connection should pass dns |
| 9000 | // validation. |
| 9001 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9002 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9003 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9004 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9005 | EXPECT_TRUE(stream.get()); |
| 9006 | |
| 9007 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9008 | EXPECT_EQ( |
| 9009 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9010 | kCachedIPAddress.ToString()); |
| 9011 | |
| 9012 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9013 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9014 | } |
| 9015 | |
| 9016 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9017 | // sync, but dns no match |
| 9018 | TEST_P(QuicStreamFactoryTest, |
| 9019 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
| 9020 | race_stale_dns_on_connection_ = true; |
| 9021 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9022 | Initialize(); |
| 9023 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9024 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9025 | |
| 9026 | // Set an address in resolver for asynchronous return. |
| 9027 | host_resolver_->set_ondemand_mode(true); |
| 9028 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9029 | kNonCachedIPAddress, ""); |
| 9030 | |
| 9031 | // Set up a different address in the stale resolver cache. |
| 9032 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9033 | HostCache::Entry entry(OK, |
| 9034 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9035 | HostCache::Entry::SOURCE_DNS); |
| 9036 | base::TimeDelta zero; |
| 9037 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9038 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9039 | // Expire the cache |
| 9040 | cache->OnNetworkChange(); |
| 9041 | |
| 9042 | // Socket for the stale connection which will invoke connection closure. |
| 9043 | MockQuicData quic_data; |
| 9044 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9045 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9046 | quic_data.AddWrite( |
| 9047 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9048 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9049 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9050 | |
| 9051 | // Socket for the new connection. |
| 9052 | MockQuicData quic_data2; |
| 9053 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9054 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9055 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9056 | |
| 9057 | QuicStreamRequest request(factory_.get()); |
| 9058 | EXPECT_EQ(ERR_IO_PENDING, |
| 9059 | request.Request( |
| 9060 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9061 | SocketTag(), |
| 9062 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9063 | failed_on_default_network_callback_, callback_.callback())); |
| 9064 | |
| 9065 | // Check the stale connection is running. |
| 9066 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9067 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9068 | |
| 9069 | // Finish dns resolution and check the job has finished. |
| 9070 | host_resolver_->ResolveAllPending(); |
| 9071 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9072 | |
| 9073 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9074 | EXPECT_TRUE(stream.get()); |
| 9075 | |
| 9076 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9077 | |
| 9078 | EXPECT_EQ( |
| 9079 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9080 | kNonCachedIPAddress); |
| 9081 | |
| 9082 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9083 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9084 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9085 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9086 | } |
| 9087 | |
| 9088 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9089 | // async, finishes before dns, but no match |
| 9090 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
| 9091 | race_stale_dns_on_connection_ = true; |
| 9092 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9093 | Initialize(); |
| 9094 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9095 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9096 | |
| 9097 | // Set an address in resolver for asynchronous return. |
| 9098 | host_resolver_->set_ondemand_mode(true); |
| 9099 | factory_->set_require_confirmation(true); |
| 9100 | crypto_client_stream_factory_.set_handshake_mode( |
| 9101 | MockCryptoClientStream::ZERO_RTT); |
| 9102 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9103 | kNonCachedIPAddress, ""); |
| 9104 | |
| 9105 | // Set up a different address in the stale resolvercache. |
| 9106 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9107 | HostCache::Entry entry(OK, |
| 9108 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9109 | HostCache::Entry::SOURCE_DNS); |
| 9110 | base::TimeDelta zero; |
| 9111 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9112 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9113 | // Expire the cache |
| 9114 | cache->OnNetworkChange(); |
| 9115 | |
| 9116 | MockQuicData quic_data; |
| 9117 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9118 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9119 | quic_data.AddWrite( |
| 9120 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9121 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9122 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9123 | |
| 9124 | MockQuicData quic_data2; |
| 9125 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9126 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9127 | |
| 9128 | QuicStreamRequest request(factory_.get()); |
| 9129 | EXPECT_EQ(ERR_IO_PENDING, |
| 9130 | request.Request( |
| 9131 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9132 | SocketTag(), |
| 9133 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9134 | failed_on_default_network_callback_, callback_.callback())); |
| 9135 | |
| 9136 | // Finish the stale connection. |
| 9137 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9138 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9139 | base::RunLoop().RunUntilIdle(); |
| 9140 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9141 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9142 | |
| 9143 | // Finish host resolution and check the job is done. |
| 9144 | host_resolver_->ResolveAllPending(); |
| 9145 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9146 | |
| 9147 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9148 | EXPECT_TRUE(stream.get()); |
| 9149 | |
| 9150 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 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, dns finishes first, but no match |
| 9163 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
| 9164 | race_stale_dns_on_connection_ = true; |
| 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 resolver cache. |
| 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); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9191 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9192 | quic_data.AddWrite( |
| 9193 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9194 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9195 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9196 | |
| 9197 | MockQuicData quic_data2; |
| 9198 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9199 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9200 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9201 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9202 | |
| 9203 | QuicStreamRequest request(factory_.get()); |
| 9204 | EXPECT_EQ(ERR_IO_PENDING, |
| 9205 | request.Request( |
| 9206 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9207 | SocketTag(), |
| 9208 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9209 | failed_on_default_network_callback_, callback_.callback())); |
| 9210 | // Finish dns resolution, but need to wait for stale connection. |
| 9211 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9212 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9213 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9214 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9215 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9216 | |
| 9217 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9218 | EXPECT_TRUE(stream.get()); |
| 9219 | |
| 9220 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9221 | EXPECT_EQ( |
| 9222 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9223 | kNonCachedIPAddress); |
| 9224 | |
| 9225 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9226 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9227 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9228 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9229 | } |
| 9230 | |
| 9231 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9232 | // as experiment is not on |
| 9233 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
| 9234 | race_stale_dns_on_connection_ = true; |
| 9235 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9236 | Initialize(); |
| 9237 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9238 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9239 | |
| 9240 | // Set synchronous failure in resolver. |
| 9241 | host_resolver_->set_synchronous_mode(true); |
| 9242 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9243 | |
| 9244 | MockQuicData quic_data; |
| 9245 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9246 | QuicStreamRequest request(factory_.get()); |
| 9247 | |
| 9248 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9249 | request.Request( |
| 9250 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9251 | SocketTag(), |
| 9252 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9253 | failed_on_default_network_callback_, callback_.callback())); |
| 9254 | } |
| 9255 | |
| 9256 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9257 | // async |
| 9258 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
| 9259 | race_stale_dns_on_connection_ = true; |
| 9260 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9261 | Initialize(); |
| 9262 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9263 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9264 | |
| 9265 | // Set asynchronous failure in resolver. |
| 9266 | host_resolver_->set_ondemand_mode(true); |
| 9267 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9268 | |
| 9269 | MockQuicData quic_data; |
| 9270 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9271 | QuicStreamRequest request(factory_.get()); |
| 9272 | |
| 9273 | EXPECT_EQ(ERR_IO_PENDING, |
| 9274 | request.Request( |
| 9275 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9276 | SocketTag(), |
| 9277 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9278 | failed_on_default_network_callback_, callback_.callback())); |
| 9279 | |
| 9280 | // Resolve and expect result that shows the resolution error. |
| 9281 | host_resolver_->ResolveAllPending(); |
| 9282 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9283 | } |
| 9284 | |
| 9285 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9286 | // sync, dns returns error and no connection is established. |
| 9287 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
| 9288 | race_stale_dns_on_connection_ = true; |
| 9289 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9290 | Initialize(); |
| 9291 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9292 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9293 | |
| 9294 | // Set asynchronous failure in resolver. |
| 9295 | host_resolver_->set_ondemand_mode(true); |
| 9296 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9297 | |
| 9298 | // Set up an address in the stale cache. |
| 9299 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9300 | HostCache::Entry entry(OK, |
| 9301 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9302 | HostCache::Entry::SOURCE_DNS); |
| 9303 | base::TimeDelta zero; |
| 9304 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9305 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9306 | // Expire the cache |
| 9307 | cache->OnNetworkChange(); |
| 9308 | |
| 9309 | // Socket for the stale connection which is supposed to disconnect. |
| 9310 | MockQuicData quic_data; |
| 9311 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9312 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9313 | quic_data.AddWrite( |
| 9314 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9315 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9316 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9317 | |
| 9318 | QuicStreamRequest request(factory_.get()); |
| 9319 | EXPECT_EQ(ERR_IO_PENDING, |
| 9320 | request.Request( |
| 9321 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9322 | SocketTag(), |
| 9323 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9324 | failed_on_default_network_callback_, callback_.callback())); |
| 9325 | |
| 9326 | // Check that the stale connection is running. |
| 9327 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9328 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9329 | |
| 9330 | // Finish host resolution. |
| 9331 | host_resolver_->ResolveAllPending(); |
| 9332 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9333 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9334 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9335 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9336 | } |
| 9337 | |
| 9338 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9339 | // return error, then dns matches |
| 9340 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
| 9341 | race_stale_dns_on_connection_ = true; |
| 9342 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9343 | Initialize(); |
| 9344 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9345 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9346 | |
| 9347 | // Set an address in host resolver for asynchronous return. |
| 9348 | host_resolver_->set_ondemand_mode(true); |
| 9349 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9350 | kCachedIPAddress.ToString(), ""); |
| 9351 | |
| 9352 | // Set up the same address in the stale resolver cache. |
| 9353 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9354 | HostCache::Entry entry(OK, |
| 9355 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9356 | HostCache::Entry::SOURCE_DNS); |
| 9357 | base::TimeDelta zero; |
| 9358 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9359 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9360 | // Expire the cache |
| 9361 | cache->OnNetworkChange(); |
| 9362 | |
| 9363 | // Simulate synchronous connect failure. |
| 9364 | MockQuicData quic_data; |
| 9365 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9366 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9367 | |
| 9368 | MockQuicData quic_data2; |
| 9369 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9370 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9371 | |
| 9372 | QuicStreamRequest request(factory_.get()); |
| 9373 | EXPECT_EQ(ERR_IO_PENDING, |
| 9374 | request.Request( |
| 9375 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9376 | SocketTag(), |
| 9377 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9378 | failed_on_default_network_callback_, callback_.callback())); |
| 9379 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9380 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9381 | |
| 9382 | host_resolver_->ResolveAllPending(); |
| 9383 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9384 | } |
| 9385 | |
| 9386 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9387 | // returns error, dns no match, new connection is established |
| 9388 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
| 9389 | race_stale_dns_on_connection_ = true; |
| 9390 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9391 | Initialize(); |
| 9392 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9393 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9394 | |
| 9395 | // Set an address in host resolver. |
| 9396 | host_resolver_->set_ondemand_mode(true); |
| 9397 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9398 | kNonCachedIPAddress, ""); |
| 9399 | |
| 9400 | // Set up a different address in stale resolver cache. |
| 9401 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9402 | HostCache::Entry entry(OK, |
| 9403 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9404 | HostCache::Entry::SOURCE_DNS); |
| 9405 | base::TimeDelta zero; |
| 9406 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9407 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9408 | // Expire the cache |
| 9409 | cache->OnNetworkChange(); |
| 9410 | |
| 9411 | // Add failure for the stale connection. |
| 9412 | MockQuicData quic_data; |
| 9413 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9414 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9415 | |
| 9416 | MockQuicData quic_data2; |
| 9417 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9418 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9419 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9420 | |
| 9421 | QuicStreamRequest request(factory_.get()); |
| 9422 | EXPECT_EQ(ERR_IO_PENDING, |
| 9423 | request.Request( |
| 9424 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9425 | SocketTag(), |
| 9426 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9427 | failed_on_default_network_callback_, callback_.callback())); |
| 9428 | |
| 9429 | // Check that the stale connection fails. |
| 9430 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9431 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9432 | |
| 9433 | // Finish host resolution and check the job finishes ok. |
| 9434 | host_resolver_->ResolveAllPending(); |
| 9435 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9436 | |
| 9437 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9438 | EXPECT_TRUE(stream.get()); |
| 9439 | |
| 9440 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9441 | |
| 9442 | EXPECT_EQ( |
| 9443 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9444 | kNonCachedIPAddress); |
| 9445 | |
| 9446 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9447 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9448 | } |
| 9449 | |
| 9450 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9451 | // returns error, dns no match, new connection error |
| 9452 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
| 9453 | race_stale_dns_on_connection_ = true; |
| 9454 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9455 | Initialize(); |
| 9456 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9457 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9458 | |
| 9459 | // Set an address in host resolver asynchronously. |
| 9460 | host_resolver_->set_ondemand_mode(true); |
| 9461 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9462 | kNonCachedIPAddress, ""); |
| 9463 | |
| 9464 | // Set up a different address in the stale cache. |
| 9465 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9466 | HostCache::Entry entry(OK, |
| 9467 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9468 | HostCache::Entry::SOURCE_DNS); |
| 9469 | base::TimeDelta zero; |
| 9470 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9471 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9472 | // Expire the cache |
| 9473 | cache->OnNetworkChange(); |
| 9474 | |
| 9475 | // Add failure for stale connection. |
| 9476 | MockQuicData quic_data; |
| 9477 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9478 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9479 | |
| 9480 | // Add failure for resolved dns connection. |
| 9481 | MockQuicData quic_data2; |
| 9482 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9483 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9484 | |
| 9485 | QuicStreamRequest request(factory_.get()); |
| 9486 | EXPECT_EQ(ERR_IO_PENDING, |
| 9487 | request.Request( |
| 9488 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9489 | SocketTag(), |
| 9490 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9491 | failed_on_default_network_callback_, callback_.callback())); |
| 9492 | |
| 9493 | // Check the stale connection fails. |
| 9494 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9495 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9496 | |
| 9497 | // Check the resolved dns connection fails. |
| 9498 | host_resolver_->ResolveAllPending(); |
| 9499 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9500 | } |
| 9501 | |
| 9502 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 9503 | // resolve returns error and then preconnect finishes |
| 9504 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
| 9505 | race_stale_dns_on_connection_ = true; |
| 9506 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9507 | Initialize(); |
| 9508 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9509 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9510 | |
| 9511 | // Add asynchronous failure in host resolver. |
| 9512 | host_resolver_->set_ondemand_mode(true); |
| 9513 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9514 | factory_->set_require_confirmation(true); |
| 9515 | crypto_client_stream_factory_.set_handshake_mode( |
| 9516 | MockCryptoClientStream::ZERO_RTT); |
| 9517 | |
| 9518 | // Set up an address in stale resolver cache. |
| 9519 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9520 | HostCache::Entry entry(OK, |
| 9521 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9522 | HostCache::Entry::SOURCE_DNS); |
| 9523 | base::TimeDelta zero; |
| 9524 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9525 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9526 | // Expire the cache |
| 9527 | cache->OnNetworkChange(); |
| 9528 | |
| 9529 | // Socket data for stale connection which is supposed to disconnect. |
| 9530 | MockQuicData quic_data; |
| 9531 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9532 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9533 | quic_data.AddWrite( |
| 9534 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9535 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9536 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9537 | |
| 9538 | QuicStreamRequest request(factory_.get()); |
| 9539 | EXPECT_EQ(ERR_IO_PENDING, |
| 9540 | request.Request( |
| 9541 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9542 | SocketTag(), |
| 9543 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9544 | failed_on_default_network_callback_, callback_.callback())); |
| 9545 | |
| 9546 | // host resolution returned but stale connection hasn't finished yet. |
| 9547 | host_resolver_->ResolveAllPending(); |
| 9548 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9549 | |
| 9550 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9551 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9552 | } |
| 9553 | |
| 9554 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9555 | // resolve returns error and then preconnect fails. |
| 9556 | TEST_P(QuicStreamFactoryTest, |
| 9557 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
| 9558 | race_stale_dns_on_connection_ = true; |
| 9559 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9560 | Initialize(); |
| 9561 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9562 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9563 | |
| 9564 | // Add asynchronous failure to host resolver. |
| 9565 | host_resolver_->set_ondemand_mode(true); |
| 9566 | factory_->set_require_confirmation(true); |
| 9567 | crypto_client_stream_factory_.set_handshake_mode( |
| 9568 | MockCryptoClientStream::ZERO_RTT); |
| 9569 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9570 | |
| 9571 | // Set up an address in stale resolver cache. |
| 9572 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9573 | HostCache::Entry entry(OK, |
| 9574 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9575 | HostCache::Entry::SOURCE_DNS); |
| 9576 | base::TimeDelta zero; |
| 9577 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9578 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9579 | // Expire the cache |
| 9580 | cache->OnNetworkChange(); |
| 9581 | |
| 9582 | MockQuicData quic_data; |
| 9583 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9584 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9585 | quic_data.AddWrite( |
| 9586 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9587 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9588 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9589 | |
| 9590 | QuicStreamRequest request(factory_.get()); |
| 9591 | EXPECT_EQ(ERR_IO_PENDING, |
| 9592 | request.Request( |
| 9593 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9594 | SocketTag(), |
| 9595 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9596 | failed_on_default_network_callback_, callback_.callback())); |
| 9597 | |
| 9598 | // Host Resolution returns failure but stale connection hasn't finished. |
| 9599 | host_resolver_->ResolveAllPending(); |
| 9600 | |
| 9601 | // Check that the final error is on resolution failure. |
| 9602 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9603 | |
| 9604 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9605 | } |
| 9606 | |
| 9607 | // With dns race experiment on, test that host resolution callback behaves |
| 9608 | // normal as experiment is not on |
| 9609 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
| 9610 | race_stale_dns_on_connection_ = true; |
| 9611 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9612 | Initialize(); |
| 9613 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9614 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9615 | |
| 9616 | host_resolver_->set_ondemand_mode(true); |
| 9617 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9618 | kNonCachedIPAddress, ""); |
| 9619 | |
| 9620 | MockQuicData quic_data; |
| 9621 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9622 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9623 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9624 | |
| 9625 | QuicStreamRequest request(factory_.get()); |
| 9626 | EXPECT_EQ(ERR_IO_PENDING, |
| 9627 | request.Request( |
| 9628 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9629 | SocketTag(), |
| 9630 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9631 | failed_on_default_network_callback_, callback_.callback())); |
| 9632 | |
| 9633 | // Check that expect_on_host_resolution_ is properlly set. |
| 9634 | TestCompletionCallback host_resolution_callback; |
| 9635 | EXPECT_TRUE( |
| 9636 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9637 | base::RunLoop().RunUntilIdle(); |
| 9638 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9639 | |
| 9640 | host_resolver_->ResolveAllPending(); |
| 9641 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9642 | |
| 9643 | // Check that expect_on_host_resolution_ is flipped back. |
| 9644 | EXPECT_FALSE( |
| 9645 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9646 | |
| 9647 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9648 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9649 | } |
| 9650 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9651 | // Test that QuicStreamRequests with similar and different tags results in |
| 9652 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 9653 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 9654 | MockTaggingClientSocketFactory* socket_factory = |
| 9655 | new MockTaggingClientSocketFactory(); |
| 9656 | socket_factory_.reset(socket_factory); |
| 9657 | Initialize(); |
| 9658 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9659 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9660 | |
| 9661 | // Prepare to establish two QUIC sessions. |
| 9662 | MockQuicData socket_data; |
| 9663 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9664 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9665 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9666 | MockQuicData socket_data2; |
| 9667 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9668 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9669 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9670 | |
| 9671 | #if defined(OS_ANDROID) |
| 9672 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 9673 | SocketTag tag2(getuid(), 0x87654321); |
| 9674 | #else |
| 9675 | // On non-Android platforms we can only use the default constructor. |
| 9676 | SocketTag tag1, tag2; |
| 9677 | #endif |
| 9678 | |
| 9679 | // Request a stream with |tag1|. |
| 9680 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9681 | int rv = request1.Request( |
| 9682 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9683 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9684 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9685 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9686 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 9687 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9688 | ->tagged_before_data_transferred()); |
| 9689 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 9690 | request1.ReleaseSessionHandle(); |
| 9691 | EXPECT_TRUE(stream1); |
| 9692 | EXPECT_TRUE(stream1->IsConnected()); |
| 9693 | |
| 9694 | // Request a stream with |tag1| and verify underlying session is reused. |
| 9695 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9696 | rv = request2.Request( |
| 9697 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9698 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9699 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9700 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9701 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 9702 | request2.ReleaseSessionHandle(); |
| 9703 | EXPECT_TRUE(stream2); |
| 9704 | EXPECT_TRUE(stream2->IsConnected()); |
| 9705 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 9706 | |
| 9707 | // Request a stream with |tag2| and verify a new session is created. |
| 9708 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9709 | rv = request3.Request( |
| 9710 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 9711 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9712 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9713 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9714 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 9715 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9716 | ->tagged_before_data_transferred()); |
| 9717 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 9718 | request3.ReleaseSessionHandle(); |
| 9719 | EXPECT_TRUE(stream3); |
| 9720 | EXPECT_TRUE(stream3->IsConnected()); |
| 9721 | #if defined(OS_ANDROID) |
| 9722 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 9723 | #else |
| 9724 | // Same tag should reuse session. |
| 9725 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 9726 | #endif |
| 9727 | } |
| 9728 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9729 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9730 | } // namespace net |