[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" |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 28 | #include "net/quic/crypto/proof_verifier_chromium.h" |
| 29 | #include "net/quic/mock_crypto_client_stream_factory.h" |
| 30 | #include "net/quic/mock_quic_data.h" |
| 31 | #include "net/quic/properties_based_quic_server_info.h" |
| 32 | #include "net/quic/quic_http_stream.h" |
| 33 | #include "net/quic/quic_http_utils.h" |
| 34 | #include "net/quic/quic_server_info.h" |
| 35 | #include "net/quic/quic_stream_factory_peer.h" |
| 36 | #include "net/quic/quic_test_packet_maker.h" |
| 37 | #include "net/quic/test_task_runner.h" |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 38 | #include "net/socket/next_proto.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 39 | #include "net/socket/socket_test_util.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 40 | #include "net/spdy/spdy_session_test_util.h" |
| 41 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 42 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 43 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 44 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 45 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 46 | #include "net/third_party/quic/core/crypto/crypto_handshake.h" |
| 47 | #include "net/third_party/quic/core/crypto/quic_crypto_client_config.h" |
| 48 | #include "net/third_party/quic/core/crypto/quic_decrypter.h" |
| 49 | #include "net/third_party/quic/core/crypto/quic_encrypter.h" |
Victor Vasiliev | c5b409c2 | 2018-07-24 12:23:46 | [diff] [blame] | 50 | #include "net/third_party/quic/core/http/quic_client_promised_info.h" |
Ryan Hamilton | 56b10c5d | 2018-05-11 13:40:16 | [diff] [blame] | 51 | #include "net/third_party/quic/platform/api/quic_test.h" |
| 52 | #include "net/third_party/quic/test_tools/mock_clock.h" |
| 53 | #include "net/third_party/quic/test_tools/mock_random.h" |
| 54 | #include "net/third_party/quic/test_tools/quic_config_peer.h" |
| 55 | #include "net/third_party/quic/test_tools/quic_spdy_session_peer.h" |
| 56 | #include "net/third_party/quic/test_tools/quic_test_utils.h" |
Ryan Hamilton | 2e003eea | 2018-05-02 00:24:29 | [diff] [blame] | 57 | #include "net/third_party/spdy/core/spdy_test_utils.h" |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 58 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 59 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 60 | #include "testing/gtest/include/gtest/gtest.h" |
msramek | 992625ec | 2016-08-04 18:33:58 | [diff] [blame] | 61 | #include "url/gurl.h" |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 62 | |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 63 | using std::string; |
[email protected] | 6e12d70 | 2013-11-13 00:17:17 | [diff] [blame] | 64 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 65 | namespace net { |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 66 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 67 | namespace { |
| 68 | |
| 69 | class MockSSLConfigService : public SSLConfigService { |
| 70 | public: |
| 71 | MockSSLConfigService() {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 72 | ~MockSSLConfigService() override {} |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 73 | |
| 74 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 75 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 76 | bool CanShareConnectionWithClientCerts( |
| 77 | const std::string& hostname) const override { |
| 78 | return false; |
| 79 | } |
| 80 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 81 | private: |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 82 | SSLConfig config_; |
| 83 | }; |
| 84 | |
| 85 | } // namespace |
| 86 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 87 | namespace test { |
| 88 | |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 89 | namespace { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 90 | |
| 91 | enum DestinationType { |
| 92 | // In pooling tests with two requests for different origins to the same |
| 93 | // destination, the destination should be |
| 94 | SAME_AS_FIRST, // the same as the first origin, |
| 95 | SAME_AS_SECOND, // the same as the second origin, or |
| 96 | DIFFERENT, // different from both. |
| 97 | }; |
| 98 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 99 | const char kDefaultServerHostName[] = "www.example.org"; |
| 100 | const char kServer2HostName[] = "mail.example.org"; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 101 | const char kDifferentHostname[] = "different.example.com"; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 102 | const int kDefaultServerPort = 443; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 103 | const char kDefaultUrl[] = "https://www.example.org/"; |
| 104 | const char kServer2Url[] = "https://mail.example.org/"; |
| 105 | const char kServer3Url[] = "https://docs.example.org/"; |
| 106 | const char kServer4Url[] = "https://images.example.org/"; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 107 | const int kDefaultRTTMilliSecs = 300; |
| 108 | const size_t kMinRetryTimeForDefaultNetworkSecs = 1; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 109 | const size_t kWaitTimeForNewNetworkSecs = 10; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 110 | const IPAddress kCachedIPAddress = IPAddress(192, 168, 0, 2); |
| 111 | const char kNonCachedIPAddress[] = "192.168.0.1"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 112 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 113 | // Run QuicStreamFactoryTest instances with all value combinations of version |
| 114 | // and enable_connection_racting. |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 115 | struct TestParams { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 116 | friend std::ostream& operator<<(std::ostream& os, const TestParams& p) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 117 | os << "{ version: " << QuicVersionToString(p.version) |
| 118 | << ", client_headers_include_h2_stream_dependency: " |
| 119 | << p.client_headers_include_h2_stream_dependency << " }"; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 120 | return os; |
| 121 | } |
| 122 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 123 | quic::QuicTransportVersion version; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 124 | bool client_headers_include_h2_stream_dependency; |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 125 | }; |
| 126 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 127 | std::vector<TestParams> GetTestParams() { |
| 128 | std::vector<TestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 129 | quic::QuicTransportVersionVector all_supported_versions = |
| 130 | quic::AllSupportedTransportVersions(); |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 131 | for (const auto& version : all_supported_versions) { |
| 132 | params.push_back(TestParams{version, false}); |
| 133 | params.push_back(TestParams{version, true}); |
| 134 | } |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 135 | return params; |
| 136 | } |
| 137 | |
| 138 | // Run QuicStreamFactoryWithDestinationTest instances with all value |
| 139 | // combinations of version, enable_connection_racting, and destination_type. |
| 140 | struct PoolingTestParams { |
| 141 | friend std::ostream& operator<<(std::ostream& os, |
| 142 | const PoolingTestParams& p) { |
| 143 | os << "{ version: " << QuicVersionToString(p.version) |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 144 | << ", destination_type: "; |
| 145 | switch (p.destination_type) { |
| 146 | case SAME_AS_FIRST: |
| 147 | os << "SAME_AS_FIRST"; |
| 148 | break; |
| 149 | case SAME_AS_SECOND: |
| 150 | os << "SAME_AS_SECOND"; |
| 151 | break; |
| 152 | case DIFFERENT: |
| 153 | os << "DIFFERENT"; |
| 154 | break; |
| 155 | } |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 156 | os << ", client_headers_include_h2_stream_dependency: " |
| 157 | << p.client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 158 | os << " }"; |
| 159 | return os; |
| 160 | } |
| 161 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 162 | quic::QuicTransportVersion version; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 163 | DestinationType destination_type; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 164 | bool client_headers_include_h2_stream_dependency; |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 165 | }; |
| 166 | |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 167 | std::vector<PoolingTestParams> GetPoolingTestParams() { |
| 168 | std::vector<PoolingTestParams> params; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 169 | quic::QuicTransportVersionVector all_supported_versions = |
| 170 | quic::AllSupportedTransportVersions(); |
| 171 | for (const quic::QuicTransportVersion version : all_supported_versions) { |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 172 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, false}); |
| 173 | params.push_back(PoolingTestParams{version, SAME_AS_FIRST, true}); |
| 174 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, false}); |
| 175 | params.push_back(PoolingTestParams{version, SAME_AS_SECOND, true}); |
| 176 | params.push_back(PoolingTestParams{version, DIFFERENT, false}); |
| 177 | params.push_back(PoolingTestParams{version, DIFFERENT, true}); |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 178 | } |
| 179 | return params; |
| 180 | } |
| 181 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 182 | } // namespace |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 183 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 184 | class QuicHttpStreamPeer { |
| 185 | public: |
rch | f0b18c8a | 2017-05-05 19:31:57 | [diff] [blame] | 186 | static QuicChromiumClientSession::Handle* GetSessionHandle( |
| 187 | HttpStream* stream) { |
| 188 | return static_cast<QuicHttpStream*>(stream)->quic_session(); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 189 | } |
| 190 | }; |
| 191 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 192 | // TestConnectionMigrationSocketFactory will vend sockets with incremental port |
| 193 | // number. |
| 194 | class TestConnectionMigrationSocketFactory : public MockClientSocketFactory { |
| 195 | public: |
| 196 | TestConnectionMigrationSocketFactory() : next_source_port_num_(1u) {} |
| 197 | ~TestConnectionMigrationSocketFactory() override {} |
| 198 | |
| 199 | std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 200 | DatagramSocket::BindType bind_type, |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 201 | NetLog* net_log, |
| 202 | const NetLogSource& source) override { |
| 203 | SocketDataProvider* data_provider = mock_data().GetNext(); |
| 204 | std::unique_ptr<MockUDPClientSocket> socket( |
| 205 | new MockUDPClientSocket(data_provider, net_log)); |
| 206 | socket->set_source_port(next_source_port_num_++); |
| 207 | return std::move(socket); |
| 208 | } |
| 209 | |
| 210 | private: |
| 211 | uint16_t next_source_port_num_; |
| 212 | |
| 213 | DISALLOW_COPY_AND_ASSIGN(TestConnectionMigrationSocketFactory); |
| 214 | }; |
| 215 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 216 | class QuicStreamFactoryTestBase : public WithScopedTaskEnvironment { |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 217 | protected: |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 218 | QuicStreamFactoryTestBase(quic::QuicTransportVersion version, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 219 | bool client_headers_include_h2_stream_dependency) |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 220 | : host_resolver_(new MockHostResolver), |
| 221 | ssl_config_service_(new MockSSLConfigService), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 222 | socket_factory_(new MockClientSocketFactory), |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 223 | random_generator_(0), |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 224 | runner_(new TestTaskRunner(&clock_)), |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 225 | version_(version), |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 226 | client_headers_include_h2_stream_dependency_( |
| 227 | client_headers_include_h2_stream_dependency), |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 228 | client_maker_(version_, |
| 229 | 0, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 230 | &clock_, |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 231 | kDefaultServerHostName, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 232 | quic::Perspective::IS_CLIENT, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 233 | client_headers_include_h2_stream_dependency_), |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 234 | server_maker_(version_, |
| 235 | 0, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 236 | &clock_, |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 237 | kDefaultServerHostName, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 238 | quic::Perspective::IS_SERVER, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 239 | false), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 240 | cert_verifier_(std::make_unique<MockCertVerifier>()), |
Ryan Sleevi | 987d2d9 | 2017-12-19 19:22:14 | [diff] [blame] | 241 | cert_transparency_verifier_(std::make_unique<DoNothingCTVerifier>()), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 242 | scoped_mock_network_change_notifier_(nullptr), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 243 | factory_(nullptr), |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 244 | host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 245 | url_(kDefaultUrl), |
| 246 | url2_(kServer2Url), |
| 247 | url3_(kServer3Url), |
| 248 | url4_(kServer4Url), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 249 | privacy_mode_(PRIVACY_MODE_DISABLED), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 250 | failed_on_default_network_callback_(base::BindRepeating( |
| 251 | &QuicStreamFactoryTestBase::OnFailedOnDefaultNetwork, |
| 252 | base::Unretained(this))), |
| 253 | failed_on_default_network_(false), |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 254 | store_server_configs_in_properties_(false), |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 255 | close_sessions_on_ip_change_(false), |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 256 | goaway_sessions_on_ip_change_(false), |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 257 | idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 258 | reduced_ping_timeout_seconds_(quic::kPingTimeoutSecs), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 259 | max_time_before_crypto_handshake_seconds_( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 260 | quic::kMaxTimeForCryptoHandshakeSecs), |
| 261 | max_idle_time_before_crypto_handshake_seconds_( |
| 262 | quic::kInitialIdleTimeoutSecs), |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 263 | migrate_sessions_on_network_change_v2_(false), |
| 264 | migrate_sessions_early_v2_(false), |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 265 | retry_on_alternate_network_before_handshake_(false), |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 266 | race_stale_dns_on_connection_(false), |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 267 | go_away_on_path_degrading_(false), |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 268 | allow_server_migration_(false), |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 269 | race_cert_verification_(false), |
| 270 | estimate_initial_rtt_(false) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 271 | clock_.AdvanceTime(quic::QuicTime::Delta::FromSeconds(1)); |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 272 | } |
| 273 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 274 | void Initialize() { |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 275 | DCHECK(!factory_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 276 | factory_.reset(new QuicStreamFactory( |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 277 | net_log_.net_log(), host_resolver_.get(), ssl_config_service_.get(), |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 278 | socket_factory_.get(), &http_server_properties_, cert_verifier_.get(), |
Nick Harper | ecf319d | 2018-10-16 07:58:54 | [diff] [blame] | 279 | &ct_policy_enforcer_, &transport_security_state_, |
| 280 | cert_transparency_verifier_.get(), |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 281 | /*SocketPerformanceWatcherFactory*/ nullptr, |
rch | bf4c26d | 2017-04-16 23:17:55 | [diff] [blame] | 282 | &crypto_client_stream_factory_, &random_generator_, &clock_, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 283 | quic::kDefaultMaxPacketSize, string(), |
| 284 | store_server_configs_in_properties_, close_sessions_on_ip_change_, |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 285 | goaway_sessions_on_ip_change_, |
rch | 9ecde09b | 2017-04-08 00:18:23 | [diff] [blame] | 286 | /*mark_quic_broken_when_network_blackholes*/ false, |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 287 | idle_connection_timeout_seconds_, reduced_ping_timeout_seconds_, |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 288 | max_time_before_crypto_handshake_seconds_, |
| 289 | max_idle_time_before_crypto_handshake_seconds_, |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 290 | migrate_sessions_on_network_change_v2_, migrate_sessions_early_v2_, |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 291 | retry_on_alternate_network_before_handshake_, |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 292 | race_stale_dns_on_connection_, go_away_on_path_degrading_, |
Zhongyi Shi | 73f23ca87 | 2017-12-13 18:37:13 | [diff] [blame] | 293 | base::TimeDelta::FromSeconds(kMaxTimeOnNonDefaultNetworkSecs), |
Zhongyi Shi | ee76076 | 2018-08-01 00:54:29 | [diff] [blame] | 294 | kMaxMigrationsToNonDefaultNetworkOnWriteError, |
Zhongyi Shi | 8b1e43f | 2017-12-13 20:46:30 | [diff] [blame] | 295 | kMaxMigrationsToNonDefaultNetworkOnPathDegrading, |
Charles 'Buck' Krasic | 0c346c9 | 2017-09-14 18:17:37 | [diff] [blame] | 296 | allow_server_migration_, race_cert_verification_, estimate_initial_rtt_, |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 297 | client_headers_include_h2_stream_dependency_, connection_options_, |
Nick Harper | 2243e800 | 2018-09-28 20:33:26 | [diff] [blame] | 298 | client_connection_options_, |
kapishnikov | 7f8dd1e | 2018-01-24 06:10:49 | [diff] [blame] | 299 | /*enable_socket_recv_optimization*/ false)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 300 | } |
| 301 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 302 | void InitializeConnectionMigrationV2Test( |
| 303 | NetworkChangeNotifier::NetworkList connected_networks) { |
| 304 | scoped_mock_network_change_notifier_.reset( |
| 305 | new ScopedMockNetworkChangeNotifier()); |
| 306 | MockNetworkChangeNotifier* mock_ncn = |
| 307 | scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 308 | mock_ncn->ForceNetworkHandlesSupported(); |
| 309 | mock_ncn->SetConnectedNetworksList(connected_networks); |
| 310 | migrate_sessions_on_network_change_v2_ = true; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 311 | migrate_sessions_early_v2_ = true; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 312 | retry_on_alternate_network_before_handshake_ = true; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 313 | socket_factory_.reset(new TestConnectionMigrationSocketFactory); |
| 314 | Initialize(); |
| 315 | } |
| 316 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 317 | std::unique_ptr<HttpStream> CreateStream(QuicStreamRequest* request) { |
| 318 | std::unique_ptr<QuicChromiumClientSession::Handle> session = |
| 319 | request->ReleaseSessionHandle(); |
| 320 | if (!session || !session->IsConnected()) |
| 321 | return nullptr; |
| 322 | |
| 323 | return std::make_unique<QuicHttpStream>(std::move(session)); |
| 324 | } |
| 325 | |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 326 | bool HasActiveSession(const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 327 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 328 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 329 | return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), server_id); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 330 | } |
| 331 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 332 | bool HasLiveSession(const HostPortPair& host_port_pair) { |
| 333 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 334 | false); |
| 335 | return QuicStreamFactoryPeer::HasLiveSession(factory_.get(), host_port_pair, |
| 336 | server_id); |
| 337 | } |
| 338 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 339 | bool HasActiveJob(const HostPortPair& host_port_pair, |
| 340 | const PrivacyMode privacy_mode) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 341 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 342 | privacy_mode == PRIVACY_MODE_ENABLED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 343 | return QuicStreamFactoryPeer::HasActiveJob(factory_.get(), server_id); |
| 344 | } |
| 345 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 346 | bool HasActiveCertVerifierJob(const quic::QuicServerId& server_id) { |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 347 | return QuicStreamFactoryPeer::HasActiveCertVerifierJob(factory_.get(), |
| 348 | server_id); |
| 349 | } |
| 350 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 351 | // Get the pending, not activated session, if there is only one session alive. |
| 352 | QuicChromiumClientSession* GetPendingSession( |
| 353 | const HostPortPair& host_port_pair) { |
| 354 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 355 | false); |
| 356 | return QuicStreamFactoryPeer::GetPendingSession(factory_.get(), server_id, |
| 357 | host_port_pair); |
| 358 | } |
| 359 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 360 | QuicChromiumClientSession* GetActiveSession( |
| 361 | const HostPortPair& host_port_pair) { |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 362 | quic::QuicServerId server_id(host_port_pair.host(), host_port_pair.port(), |
| 363 | false); |
bnc | 5fdc0716 | 2016-05-23 17:36:03 | [diff] [blame] | 364 | return QuicStreamFactoryPeer::GetActiveSession(factory_.get(), server_id); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 367 | int GetSourcePortForNewSession(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 368 | return GetSourcePortForNewSessionInner(destination, false); |
| 369 | } |
| 370 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 371 | int GetSourcePortForNewSessionAndGoAway(const HostPortPair& destination) { |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 372 | return GetSourcePortForNewSessionInner(destination, true); |
| 373 | } |
| 374 | |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 375 | int GetSourcePortForNewSessionInner(const HostPortPair& destination, |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 376 | bool goaway_received) { |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 377 | // Should only be called if there is no active session for this destination. |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 378 | EXPECT_FALSE(HasActiveSession(destination)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 379 | size_t socket_count = socket_factory_->udp_client_socket_ports().size(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 380 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 381 | MockQuicData socket_data; |
| 382 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 383 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 384 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 385 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 386 | QuicStreamRequest request(factory_.get()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 387 | GURL url("https://" + destination.host() + "/"); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 388 | EXPECT_EQ( |
| 389 | ERR_IO_PENDING, |
| 390 | request.Request( |
| 391 | destination, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 392 | /*cert_verify_flags=*/0, url, net_log_, &net_error_details_, |
| 393 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 394 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 395 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 396 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 397 | EXPECT_TRUE(stream.get()); |
| 398 | stream.reset(); |
| 399 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 400 | QuicChromiumClientSession* session = GetActiveSession(destination); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 401 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 402 | if (socket_count + 1 != socket_factory_->udp_client_socket_ports().size()) { |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 403 | ADD_FAILURE(); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 407 | if (goaway_received) { |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 408 | quic::QuicGoAwayFrame goaway(quic::kInvalidControlFrameId, |
| 409 | quic::QUIC_NO_ERROR, 1, ""); |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 410 | session->connection()->OnGoAwayFrame(goaway); |
[email protected] | d8e2abf8 | 2014-03-06 10:30:10 | [diff] [blame] | 411 | } |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 412 | |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 413 | factory_->OnSessionClosed(session); |
bnc | cb7ff3c | 2015-05-21 20:51:55 | [diff] [blame] | 414 | EXPECT_FALSE(HasActiveSession(destination)); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 415 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 416 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 417 | return socket_factory_->udp_client_socket_ports()[socket_count]; |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 418 | } |
| 419 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 420 | std::unique_ptr<quic::QuicEncryptedPacket> |
| 421 | ConstructClientConnectionClosePacket(quic::QuicPacketNumber num) { |
Bin Wu | 5311aca | 2018-01-22 01:19:03 | [diff] [blame] | 422 | return client_maker_.MakeConnectionClosePacket( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 423 | num, false, quic::QUIC_CRYPTO_VERSION_NOT_SUPPORTED, "Time to panic!"); |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 424 | } |
| 425 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 426 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructClientRstPacket( |
| 427 | quic::QuicPacketNumber packet_number, |
| 428 | quic::QuicRstStreamErrorCode error_code) { |
| 429 | quic::QuicStreamId stream_id = GetNthClientInitiatedStreamId(0); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 430 | return client_maker_.MakeRstPacket(packet_number, true, stream_id, |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 431 | error_code); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 432 | } |
| 433 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 434 | static ProofVerifyDetailsChromium DefaultProofVerifyDetails() { |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 435 | // Load a certificate that is valid for *.example.org |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 436 | scoped_refptr<X509Certificate> test_cert( |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 437 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 438 | EXPECT_TRUE(test_cert.get()); |
| 439 | ProofVerifyDetailsChromium verify_details; |
| 440 | verify_details.cert_verify_result.verified_cert = test_cert; |
| 441 | verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 442 | return verify_details; |
| 443 | } |
| 444 | |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 445 | void NotifyIPAddressChanged() { |
| 446 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 447 | // Spin the message loop so the notification is delivered. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 448 | base::RunLoop().RunUntilIdle(); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 449 | } |
| 450 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 451 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 452 | quic::QuicPacketNumber packet_number, |
| 453 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 454 | bool should_include_version, |
| 455 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 456 | spdy::SpdyHeaderBlock headers = |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 457 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 458 | spdy::SpdyPriority priority = |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 459 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 460 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 461 | return client_maker_.MakeRequestHeadersPacket( |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 462 | packet_number, stream_id, should_include_version, fin, priority, |
Yixin Wang | 7a3f1b8d | 2018-01-17 21:40:48 | [diff] [blame] | 463 | std::move(headers), 0, &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 464 | } |
| 465 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 466 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 467 | quic::QuicPacketNumber packet_number, |
| 468 | quic::QuicStreamId stream_id, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 469 | quic::QuicStreamId parent_stream_id, |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 470 | bool should_include_version, |
| 471 | bool fin, |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 472 | quic::QuicStreamOffset* offset) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 473 | spdy::SpdyHeaderBlock headers = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 474 | client_maker_.GetRequestHeaders("GET", "https", "/"); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 475 | spdy::SpdyPriority priority = |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 476 | ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 477 | size_t spdy_headers_frame_len; |
| 478 | return client_maker_.MakeRequestHeadersPacket( |
| 479 | packet_number, stream_id, should_include_version, fin, priority, |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 480 | std::move(headers), parent_stream_id, &spdy_headers_frame_len, offset); |
| 481 | } |
| 482 | |
| 483 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructGetRequestPacket( |
| 484 | quic::QuicPacketNumber packet_number, |
| 485 | quic::QuicStreamId stream_id, |
| 486 | bool should_include_version, |
| 487 | bool fin, |
| 488 | quic::QuicStreamOffset* offset) { |
| 489 | return ConstructGetRequestPacket(packet_number, stream_id, |
| 490 | /*parent_stream_id=*/0, |
| 491 | should_include_version, fin, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 492 | } |
| 493 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 494 | std::unique_ptr<quic::QuicEncryptedPacket> ConstructOkResponsePacket( |
| 495 | quic::QuicPacketNumber packet_number, |
| 496 | quic::QuicStreamId stream_id, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 497 | bool should_include_version, |
| 498 | bool fin) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 499 | spdy::SpdyHeaderBlock headers = server_maker_.GetResponseHeaders("200 OK"); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 500 | size_t spdy_headers_frame_len; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 501 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 502 | packet_number, stream_id, should_include_version, fin, |
| 503 | std::move(headers), &spdy_headers_frame_len); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 504 | } |
| 505 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 506 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket() { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 507 | return client_maker_.MakeInitialSettingsPacket(1, nullptr); |
| 508 | } |
| 509 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 510 | std::unique_ptr<quic::QuicReceivedPacket> ConstructInitialSettingsPacket( |
| 511 | quic::QuicPacketNumber packet_number, |
| 512 | quic::QuicStreamOffset* offset) { |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 513 | return client_maker_.MakeInitialSettingsPacket(packet_number, offset); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 514 | } |
| 515 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 516 | // Helper method for server migration tests. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 517 | void VerifyServerMigration(const quic::QuicConfig& config, |
bnc | 6a0348c | 2017-05-22 18:56:19 | [diff] [blame] | 518 | IPEndPoint expected_address) { |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 519 | allow_server_migration_ = true; |
| 520 | Initialize(); |
| 521 | |
| 522 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 523 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 524 | crypto_client_stream_factory_.SetConfig(config); |
| 525 | |
| 526 | // Set up first socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 527 | MockQuicData socket_data1; |
| 528 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 529 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 530 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 531 | // Set up second socket data provider that is used after |
| 532 | // migration. |
| 533 | MockQuicData socket_data2; |
| 534 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 535 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 536 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 537 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 538 | socket_data2.AddWrite( |
| 539 | SYNCHRONOUS, |
| 540 | client_maker_.MakeRstPacket(3, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 541 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 542 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 543 | |
| 544 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 545 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 546 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 547 | request.Request( |
| 548 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 549 | SocketTag(), |
| 550 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 551 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 552 | EXPECT_EQ(OK, callback_.WaitForResult()); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 553 | |
| 554 | // Run QuicChromiumClientSession::WriteToNewSocket() |
| 555 | // posted by QuicChromiumClientSession::MigrateToSocket(). |
| 556 | base::RunLoop().RunUntilIdle(); |
| 557 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 558 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 559 | EXPECT_TRUE(stream.get()); |
| 560 | |
| 561 | // Cause QUIC stream to be created. |
| 562 | HttpRequestInfo request_info; |
| 563 | request_info.method = "GET"; |
| 564 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 565 | request_info.traffic_annotation = |
| 566 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 567 | EXPECT_EQ(OK, |
| 568 | stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 569 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 570 | // Ensure that session is alive and active. |
| 571 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 572 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 573 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 574 | |
| 575 | IPEndPoint actual_address; |
| 576 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 577 | EXPECT_EQ(actual_address, expected_address); |
| 578 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 579 | << " " << actual_address.port(); |
| 580 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 581 | << " " << expected_address.port(); |
| 582 | |
| 583 | stream.reset(); |
| 584 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 585 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 586 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 587 | } |
| 588 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 589 | // Verifies that the QUIC stream factory is initialized correctly. |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 590 | void VerifyInitialization() { |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 591 | store_server_configs_in_properties_ = true; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 592 | idle_connection_timeout_seconds_ = 500; |
| 593 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 594 | factory_->set_require_confirmation(false); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 595 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 596 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 597 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 598 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 599 | MockCryptoClientStream::ZERO_RTT); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 600 | const quic::QuicConfig* config = |
| 601 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
ckrasic | 32b17dcd | 2016-10-31 06:15:35 | [diff] [blame] | 602 | EXPECT_EQ(500, config->IdleNetworkTimeout().ToSeconds()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 603 | |
| 604 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 605 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 606 | const AlternativeService alternative_service1( |
| 607 | kProtoQUIC, host_port_pair_.host(), host_port_pair_.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 608 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 609 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 610 | alternative_service_info_vector.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 611 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 612 | alternative_service1, expiration, {version_})); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 613 | http_server_properties_.SetAlternativeServices( |
| 614 | url::SchemeHostPort(url_), alternative_service_info_vector); |
| 615 | |
| 616 | HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 617 | url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 618 | const AlternativeService alternative_service2( |
| 619 | kProtoQUIC, host_port_pair2.host(), host_port_pair2.port()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 620 | AlternativeServiceInfoVector alternative_service_info_vector2; |
| 621 | alternative_service_info_vector2.push_back( |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 622 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 623 | alternative_service2, expiration, {version_})); |
tbansal | 9b1cdf3 | 2017-05-10 17:28:39 | [diff] [blame] | 624 | |
| 625 | http_server_properties_.SetAlternativeServices( |
| 626 | server2, alternative_service_info_vector2); |
| 627 | // Verify that the properties of both QUIC servers are stored in the |
| 628 | // HTTP properties map. |
| 629 | EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 630 | |
| 631 | http_server_properties_.SetMaxServerConfigsStoredInProperties( |
Yixin Wang | 4a227aa2 | 2017-11-30 21:33:01 | [diff] [blame] | 632 | kDefaultMaxQuicServerEntries); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 633 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 634 | quic::QuicServerId quic_server_id(kDefaultServerHostName, 443, |
| 635 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 636 | std::unique_ptr<QuicServerInfo> quic_server_info = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 637 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 638 | quic_server_id, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 639 | |
| 640 | // Update quic_server_info's server_config and persist it. |
| 641 | QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 642 | // Minimum SCFG that passes config validation checks. |
| 643 | const char scfg[] = {// SCFG |
| 644 | 0x53, 0x43, 0x46, 0x47, |
| 645 | // num entries |
| 646 | 0x01, 0x00, |
| 647 | // padding |
| 648 | 0x00, 0x00, |
| 649 | // EXPY |
| 650 | 0x45, 0x58, 0x50, 0x59, |
| 651 | // EXPY end offset |
| 652 | 0x08, 0x00, 0x00, 0x00, |
| 653 | // Value |
| 654 | '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 655 | |
| 656 | // Create temporary strings becasue Persist() clears string data in |state|. |
| 657 | string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 658 | string source_address_token("test_source_address_token"); |
| 659 | string cert_sct("test_cert_sct"); |
| 660 | string chlo_hash("test_chlo_hash"); |
| 661 | string signature("test_signature"); |
| 662 | string test_cert("test_cert"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 663 | std::vector<string> certs; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 664 | certs.push_back(test_cert); |
| 665 | state->server_config = server_config; |
| 666 | state->source_address_token = source_address_token; |
| 667 | state->cert_sct = cert_sct; |
| 668 | state->chlo_hash = chlo_hash; |
| 669 | state->server_config_sig = signature; |
| 670 | state->certs = certs; |
| 671 | |
| 672 | quic_server_info->Persist(); |
| 673 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 674 | quic::QuicServerId quic_server_id2(kServer2HostName, 443, |
| 675 | PRIVACY_MODE_DISABLED); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 676 | std::unique_ptr<QuicServerInfo> quic_server_info2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 677 | std::make_unique<PropertiesBasedQuicServerInfo>( |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 678 | quic_server_id2, &http_server_properties_); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 679 | // Update quic_server_info2's server_config and persist it. |
| 680 | QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 681 | |
| 682 | // Minimum SCFG that passes config validation checks. |
| 683 | const char scfg2[] = {// SCFG |
| 684 | 0x53, 0x43, 0x46, 0x47, |
| 685 | // num entries |
| 686 | 0x01, 0x00, |
| 687 | // padding |
| 688 | 0x00, 0x00, |
| 689 | // EXPY |
| 690 | 0x45, 0x58, 0x50, 0x59, |
| 691 | // EXPY end offset |
| 692 | 0x08, 0x00, 0x00, 0x00, |
| 693 | // Value |
| 694 | '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 695 | |
| 696 | // Create temporary strings becasue Persist() clears string data in |
| 697 | // |state2|. |
| 698 | string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 699 | string source_address_token2("test_source_address_token2"); |
| 700 | string cert_sct2("test_cert_sct2"); |
| 701 | string chlo_hash2("test_chlo_hash2"); |
| 702 | string signature2("test_signature2"); |
| 703 | string test_cert2("test_cert2"); |
rch | 872e00e | 2016-12-02 02:48:18 | [diff] [blame] | 704 | std::vector<string> certs2; |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 705 | certs2.push_back(test_cert2); |
| 706 | state2->server_config = server_config2; |
| 707 | state2->source_address_token = source_address_token2; |
| 708 | state2->cert_sct = cert_sct2; |
| 709 | state2->chlo_hash = chlo_hash2; |
| 710 | state2->server_config_sig = signature2; |
| 711 | state2->certs = certs2; |
| 712 | |
| 713 | quic_server_info2->Persist(); |
| 714 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 715 | // Verify the MRU order is maintained. |
| 716 | const QuicServerInfoMap& quic_server_info_map = |
| 717 | http_server_properties_.quic_server_info_map(); |
| 718 | EXPECT_EQ(2u, quic_server_info_map.size()); |
jdoerrie | 22a91d8b9 | 2018-10-05 08:43:26 | [diff] [blame] | 719 | auto quic_server_info_map_it = quic_server_info_map.begin(); |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 720 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 721 | ++quic_server_info_map_it; |
| 722 | EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 723 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 724 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 725 | "192.168.0.1", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 726 | |
| 727 | // Create a session and verify that the cached state is loaded. |
| 728 | MockQuicData socket_data; |
| 729 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 730 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 731 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 732 | QuicStreamRequest request(factory_.get()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 733 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 734 | request.Request( |
| 735 | HostPortPair(quic_server_id.host(), quic_server_id.port()), |
| 736 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 737 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 738 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 739 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 740 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 741 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 742 | factory_.get(), quic_server_id)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 743 | quic::QuicCryptoClientConfig* crypto_config = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 744 | QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 745 | quic::QuicCryptoClientConfig::CachedState* cached = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 746 | crypto_config->LookupOrCreate(quic_server_id); |
| 747 | EXPECT_FALSE(cached->server_config().empty()); |
| 748 | EXPECT_TRUE(cached->GetServerConfig()); |
| 749 | EXPECT_EQ(server_config, cached->server_config()); |
| 750 | EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 751 | EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 752 | EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 753 | EXPECT_EQ(signature, cached->signature()); |
| 754 | ASSERT_EQ(1U, cached->certs().size()); |
| 755 | EXPECT_EQ(test_cert, cached->certs()[0]); |
| 756 | |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 757 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 758 | |
| 759 | // Create a session and verify that the cached state is loaded. |
| 760 | MockQuicData socket_data2; |
| 761 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 762 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 763 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 764 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 765 | "192.168.0.2", ""); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 766 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 767 | QuicStreamRequest request2(factory_.get()); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 768 | EXPECT_EQ(ERR_IO_PENDING, |
Ryan Hamilton | 4f0b26e | 2018-06-27 23:52:32 | [diff] [blame] | 769 | request2.Request( |
| 770 | HostPortPair(quic_server_id2.host(), quic_server_id2.port()), |
| 771 | version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 772 | /*cert_verify_flags=*/0, GURL("https://mail.example.org/"), |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 773 | net_log_, &net_error_details_, |
| 774 | failed_on_default_network_callback_, callback_.callback())); |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 775 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 776 | |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 777 | EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 778 | factory_.get(), quic_server_id2)); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 779 | quic::QuicCryptoClientConfig::CachedState* cached2 = |
tbansal | 3b96695 | 2016-10-25 23:25:14 | [diff] [blame] | 780 | crypto_config->LookupOrCreate(quic_server_id2); |
| 781 | EXPECT_FALSE(cached2->server_config().empty()); |
| 782 | EXPECT_TRUE(cached2->GetServerConfig()); |
| 783 | EXPECT_EQ(server_config2, cached2->server_config()); |
| 784 | EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 785 | EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 786 | EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 787 | EXPECT_EQ(signature2, cached2->signature()); |
| 788 | ASSERT_EQ(1U, cached->certs().size()); |
| 789 | EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 790 | } |
| 791 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 792 | void RunTestLoopUntilIdle() { |
| 793 | while (!runner_->GetPostedTasks().empty()) |
| 794 | runner_->RunNextTask(); |
| 795 | } |
| 796 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 797 | quic::QuicStreamId GetNthClientInitiatedStreamId(int n) { |
| 798 | return quic::test::GetNthClientInitiatedStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 799 | } |
| 800 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 801 | quic::QuicStreamId GetNthServerInitiatedStreamId(int n) { |
| 802 | return quic::test::GetNthServerInitiatedStreamId(version_, n); |
ckrasic | bf2f59c | 2017-05-04 23:54:36 | [diff] [blame] | 803 | } |
| 804 | |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 805 | void OnFailedOnDefaultNetwork(int rv) { failed_on_default_network_ = true; } |
| 806 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 807 | // Helper methods for tests of connection migration on write error. |
| 808 | void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 809 | // Migratable stream triggers write error. |
| 810 | void TestMigrationOnWriteErrorMixedStreams(IoMode write_error_mode); |
| 811 | // Non-migratable stream triggers write error. |
| 812 | void TestMigrationOnWriteErrorMixedStreams2(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 813 | void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 814 | void TestMigrationOnWriteError(IoMode write_error_mode); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 815 | void TestMigrationOnWriteErrorWithMultipleRequests(IoMode write_error_mode); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 816 | void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 817 | void TestMigrationOnMultipleWriteErrors( |
| 818 | IoMode write_error_mode_on_old_network, |
| 819 | IoMode write_error_mode_on_new_network); |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 820 | void TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 821 | bool disconnected); |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 822 | void TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 823 | void TestMigrationOnNetworkDisconnected(bool async_write_before); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 824 | void TestMigrationOnNetworkMadeDefault(IoMode write_mode); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 825 | void TestMigrationOnPathDegrading(bool async_write_before); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 826 | void TestMigrateSessionWithDrainingStream( |
| 827 | IoMode write_mode_for_queued_packet); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 828 | void TestMigrationOnWriteErrorPauseBeforeConnected(IoMode write_error_mode); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 829 | void TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 830 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 831 | bool disconnect_before_connect); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 832 | void TestNoAlternateNetworkBeforeHandshake(quic::QuicErrorCode error); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 833 | void TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 834 | quic::QuicErrorCode error); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 835 | |
Jana Iyengar | f6b13d8 | 2017-09-04 02:09:10 | [diff] [blame] | 836 | QuicFlagSaver flags_; // Save/restore all QUIC flag values. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 837 | std::unique_ptr<MockHostResolverBase> host_resolver_; |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 838 | std::unique_ptr<SSLConfigService> ssl_config_service_; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 839 | std::unique_ptr<MockClientSocketFactory> socket_factory_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 840 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 841 | quic::test::MockRandom random_generator_; |
| 842 | quic::MockClock clock_; |
rtenneti | 38f5cd5 | 2014-10-28 20:28:28 | [diff] [blame] | 843 | scoped_refptr<TestTaskRunner> runner_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 844 | const quic::QuicTransportVersion version_; |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 845 | const bool client_headers_include_h2_stream_dependency_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 846 | QuicTestPacketMaker client_maker_; |
| 847 | QuicTestPacketMaker server_maker_; |
rtenneti | ccab42b | 2015-10-09 06:38:16 | [diff] [blame] | 848 | HttpServerPropertiesImpl http_server_properties_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 849 | std::unique_ptr<CertVerifier> cert_verifier_; |
[email protected] | 080b7793 | 2014-08-04 01:22:46 | [diff] [blame] | 850 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 851 | std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
Ryan Sleevi | 8a9c9c1 | 2018-05-09 02:36:23 | [diff] [blame] | 852 | DefaultCTPolicyEnforcer ct_policy_enforcer_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 853 | std::unique_ptr<ScopedMockNetworkChangeNotifier> |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 854 | scoped_mock_network_change_notifier_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 855 | std::unique_ptr<QuicStreamFactory> factory_; |
[email protected] | bf4ea2f | 2014-03-10 22:57:53 | [diff] [blame] | 856 | HostPortPair host_port_pair_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 857 | GURL url_; |
| 858 | GURL url2_; |
| 859 | GURL url3_; |
| 860 | GURL url4_; |
| 861 | |
[email protected] | 9dd3ff0f | 2014-03-26 09:51:28 | [diff] [blame] | 862 | PrivacyMode privacy_mode_; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 863 | NetLogWithSource net_log_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 864 | TestCompletionCallback callback_; |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 865 | const CompletionRepeatingCallback failed_on_default_network_callback_; |
| 866 | bool failed_on_default_network_; |
Ryan Hamilton | 75f19726 | 2017-08-17 14:00:07 | [diff] [blame] | 867 | NetErrorDetails net_error_details_; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 868 | |
| 869 | // Variables to configure QuicStreamFactory. |
rch | 431dd445 | 2017-04-19 15:22:35 | [diff] [blame] | 870 | bool store_server_configs_in_properties_; |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 871 | bool close_sessions_on_ip_change_; |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 872 | bool goaway_sessions_on_ip_change_; |
rtenneti | 41c0999 | 2015-11-30 18:24:01 | [diff] [blame] | 873 | int idle_connection_timeout_seconds_; |
zhongyi | dd1439f6 | 2016-09-02 02:02:26 | [diff] [blame] | 874 | int reduced_ping_timeout_seconds_; |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 875 | int max_time_before_crypto_handshake_seconds_; |
| 876 | int max_idle_time_before_crypto_handshake_seconds_; |
Zhongyi Shi | f4683a3 | 2017-12-01 00:03:28 | [diff] [blame] | 877 | bool migrate_sessions_on_network_change_v2_; |
| 878 | bool migrate_sessions_early_v2_; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 879 | bool retry_on_alternate_network_before_handshake_; |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 880 | bool race_stale_dns_on_connection_; |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 881 | bool go_away_on_path_degrading_; |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 882 | bool allow_server_migration_; |
rtenneti | d073dd2 | 2016-08-04 01:58:33 | [diff] [blame] | 883 | bool race_cert_verification_; |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 884 | bool estimate_initial_rtt_; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 885 | quic::QuicTagVector connection_options_; |
| 886 | quic::QuicTagVector client_connection_options_; |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 887 | }; |
| 888 | |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 889 | class QuicStreamFactoryTest : public QuicStreamFactoryTestBase, |
| 890 | public ::testing::TestWithParam<TestParams> { |
| 891 | protected: |
Yixin Wang | 079ad54 | 2018-01-11 04:06:05 | [diff] [blame] | 892 | QuicStreamFactoryTest() |
| 893 | : QuicStreamFactoryTestBase( |
| 894 | GetParam().version, |
| 895 | GetParam().client_headers_include_h2_stream_dependency) {} |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 896 | }; |
| 897 | |
Bence Béky | ce380cb | 2018-04-26 23:39:55 | [diff] [blame] | 898 | INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 899 | QuicStreamFactoryTest, |
| 900 | ::testing::ValuesIn(GetTestParams())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 901 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 902 | TEST_P(QuicStreamFactoryTest, Create) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 903 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 904 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 905 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 906 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 907 | MockQuicData socket_data; |
| 908 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 909 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 910 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 911 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 912 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 913 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 914 | request.Request( |
| 915 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 916 | SocketTag(), |
| 917 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 918 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 919 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 920 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 921 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0edce6a | 2013-05-08 18:02:40 | [diff] [blame] | 922 | EXPECT_TRUE(stream.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 923 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 924 | EXPECT_EQ(DEFAULT_PRIORITY, host_resolver_->last_request_priority()); |
Yixin Wang | 247ea64 | 2017-11-15 01:15:50 | [diff] [blame] | 925 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 926 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 927 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 928 | DEFAULT_PRIORITY, SocketTag(), |
| 929 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 930 | &net_error_details_, |
| 931 | failed_on_default_network_callback_, |
| 932 | callback_.callback())); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 933 | // Will reset stream 3. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 934 | stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 935 | |
| 936 | EXPECT_TRUE(stream.get()); |
| 937 | |
| 938 | // TODO(rtenneti): We should probably have a tests that HTTP and HTTPS result |
| 939 | // in streams on different sessions. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 940 | QuicStreamRequest request3(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 941 | EXPECT_EQ(OK, request3.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 942 | DEFAULT_PRIORITY, SocketTag(), |
| 943 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 944 | &net_error_details_, |
| 945 | failed_on_default_network_callback_, |
| 946 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 947 | stream = CreateStream(&request3); // Will reset stream 5. |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 948 | stream.reset(); // Will reset stream 7. |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 949 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 950 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 951 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 952 | } |
| 953 | |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 954 | TEST_P(QuicStreamFactoryTest, CreateZeroRtt) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 955 | Initialize(); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 956 | factory_->set_require_confirmation(false); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 957 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 958 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 959 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 960 | MockQuicData socket_data; |
| 961 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 962 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 963 | |
| 964 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 965 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 966 | host_resolver_->set_synchronous_mode(true); |
| 967 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 968 | "192.168.0.1", ""); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 969 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 970 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 971 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 972 | DEFAULT_PRIORITY, SocketTag(), |
| 973 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 974 | &net_error_details_, |
| 975 | failed_on_default_network_callback_, |
| 976 | callback_.callback())); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 977 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 978 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 979 | EXPECT_TRUE(stream.get()); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 980 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 981 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 8bd2b81 | 2014-03-26 04:01:17 | [diff] [blame] | 982 | } |
| 983 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 984 | TEST_P(QuicStreamFactoryTest, DefaultInitialRtt) { |
| 985 | Initialize(); |
| 986 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 987 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 988 | |
| 989 | MockQuicData socket_data; |
| 990 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 991 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 992 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 993 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 994 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 995 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 996 | request.Request( |
| 997 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 998 | SocketTag(), |
| 999 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1000 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1001 | |
| 1002 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1003 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1004 | EXPECT_TRUE(stream.get()); |
| 1005 | |
| 1006 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1007 | EXPECT_TRUE(session->require_confirmation()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1008 | EXPECT_EQ(100000u, session->connection()->GetStats().srtt_us); |
| 1009 | ASSERT_FALSE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1010 | } |
| 1011 | |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1012 | TEST_P(QuicStreamFactoryTest, FactoryDestroyedWhenJobPending) { |
| 1013 | Initialize(); |
| 1014 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1015 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1016 | |
| 1017 | MockQuicData socket_data; |
| 1018 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1019 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1020 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1021 | |
| 1022 | auto request = std::make_unique<QuicStreamRequest>(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1023 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1024 | request->Request( |
| 1025 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1026 | SocketTag(), |
| 1027 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1028 | failed_on_default_network_callback_, callback_.callback())); |
Helen Li | 0e82391 | 2017-09-25 19:48:30 | [diff] [blame] | 1029 | request.reset(); |
| 1030 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1031 | // Tearing down a QuicStreamFactory with a pending Job should not cause any |
| 1032 | // crash. crbug.com/768343. |
| 1033 | factory_.reset(); |
| 1034 | } |
| 1035 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1036 | TEST_P(QuicStreamFactoryTest, RequireConfirmation) { |
| 1037 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1038 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1039 | host_resolver_->set_synchronous_mode(true); |
| 1040 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1041 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1042 | Initialize(); |
| 1043 | factory_->set_require_confirmation(true); |
| 1044 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1045 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1046 | |
| 1047 | MockQuicData socket_data; |
| 1048 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1049 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1050 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1051 | |
| 1052 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1053 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1054 | request.Request( |
| 1055 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1056 | SocketTag(), |
| 1057 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1058 | failed_on_default_network_callback_, callback_.callback())); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1059 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1060 | IPAddress last_address; |
| 1061 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1062 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1063 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1064 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1065 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1066 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1067 | |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1068 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1069 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1070 | EXPECT_TRUE(stream.get()); |
| 1071 | |
| 1072 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1073 | EXPECT_TRUE(session->require_confirmation()); |
| 1074 | } |
| 1075 | |
| 1076 | TEST_P(QuicStreamFactoryTest, DontRequireConfirmationFromSameIP) { |
| 1077 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1078 | MockCryptoClientStream::ZERO_RTT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1079 | host_resolver_->set_synchronous_mode(true); |
| 1080 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1081 | "192.168.0.1", ""); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1082 | Initialize(); |
| 1083 | factory_->set_require_confirmation(true); |
| 1084 | http_server_properties_.SetSupportsQuic(IPAddress(192, 0, 2, 33)); |
| 1085 | |
| 1086 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1087 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1088 | |
| 1089 | MockQuicData socket_data; |
| 1090 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1091 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1092 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1093 | |
| 1094 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1095 | EXPECT_THAT(request.Request( |
| 1096 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1097 | SocketTag(), |
| 1098 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1099 | failed_on_default_network_callback_, callback_.callback()), |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1100 | IsOk()); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1101 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1102 | IPAddress last_address; |
| 1103 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 1104 | |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1105 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1106 | EXPECT_TRUE(stream.get()); |
| 1107 | |
| 1108 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1109 | EXPECT_FALSE(session->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1110 | |
| 1111 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1112 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 1113 | |
| 1114 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Ryan Hamilton | a12722b | 2017-08-12 02:23:20 | [diff] [blame] | 1115 | } |
| 1116 | |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1117 | TEST_P(QuicStreamFactoryTest, CachedInitialRtt) { |
| 1118 | ServerNetworkStats stats; |
| 1119 | stats.srtt = base::TimeDelta::FromMilliseconds(10); |
| 1120 | http_server_properties_.SetServerNetworkStats(url::SchemeHostPort(url_), |
| 1121 | stats); |
| 1122 | estimate_initial_rtt_ = true; |
| 1123 | |
| 1124 | Initialize(); |
| 1125 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1126 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1127 | |
| 1128 | MockQuicData socket_data; |
| 1129 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1130 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1131 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1132 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1133 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1134 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1135 | request.Request( |
| 1136 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1137 | SocketTag(), |
| 1138 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1139 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1140 | |
| 1141 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1142 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1143 | EXPECT_TRUE(stream.get()); |
| 1144 | |
| 1145 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1146 | EXPECT_EQ(10000u, session->connection()->GetStats().srtt_us); |
| 1147 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1148 | EXPECT_EQ(10000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1149 | } |
| 1150 | |
| 1151 | TEST_P(QuicStreamFactoryTest, 2gInitialRtt) { |
| 1152 | ScopedMockNetworkChangeNotifier notifier; |
| 1153 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1154 | NetworkChangeNotifier::CONNECTION_2G); |
| 1155 | estimate_initial_rtt_ = true; |
| 1156 | |
| 1157 | Initialize(); |
| 1158 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1159 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1160 | |
| 1161 | MockQuicData socket_data; |
| 1162 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1163 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1164 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1165 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1166 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1167 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1168 | request.Request( |
| 1169 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1170 | SocketTag(), |
| 1171 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1172 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1173 | |
| 1174 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1175 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1176 | EXPECT_TRUE(stream.get()); |
| 1177 | |
| 1178 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1179 | EXPECT_EQ(1200000u, session->connection()->GetStats().srtt_us); |
| 1180 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1181 | EXPECT_EQ(1200000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1182 | } |
| 1183 | |
| 1184 | TEST_P(QuicStreamFactoryTest, 3gInitialRtt) { |
| 1185 | ScopedMockNetworkChangeNotifier notifier; |
| 1186 | notifier.mock_network_change_notifier()->SetConnectionType( |
| 1187 | NetworkChangeNotifier::CONNECTION_3G); |
| 1188 | estimate_initial_rtt_ = true; |
| 1189 | |
| 1190 | Initialize(); |
| 1191 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1192 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1193 | |
| 1194 | MockQuicData socket_data; |
| 1195 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1196 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1197 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1198 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1199 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1200 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1201 | request.Request( |
| 1202 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1203 | SocketTag(), |
| 1204 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1205 | failed_on_default_network_callback_, callback_.callback())); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1206 | |
| 1207 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1208 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | d6163f3 | 2017-01-30 23:50:38 | [diff] [blame] | 1209 | EXPECT_TRUE(stream.get()); |
| 1210 | |
| 1211 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 1212 | EXPECT_EQ(400000u, session->connection()->GetStats().srtt_us); |
| 1213 | ASSERT_TRUE(session->config()->HasInitialRoundTripTimeUsToSend()); |
| 1214 | EXPECT_EQ(400000u, session->config()->GetInitialRoundTripTimeUsToSend()); |
| 1215 | } |
| 1216 | |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1217 | TEST_P(QuicStreamFactoryTest, GoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1218 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1219 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1220 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1221 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1222 | MockQuicData socket_data; |
| 1223 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1224 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1225 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1226 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1227 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1228 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1229 | request.Request( |
| 1230 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1231 | SocketTag(), |
| 1232 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1233 | failed_on_default_network_callback_, callback_.callback())); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1234 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1235 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1236 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1237 | EXPECT_TRUE(stream.get()); |
| 1238 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1239 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1240 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1241 | session->OnGoAway(quic::QuicGoAwayFrame()); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1242 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1243 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
rch | 6895548 | 2015-09-24 00:14:39 | [diff] [blame] | 1244 | |
| 1245 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1246 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1247 | } |
| 1248 | |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1249 | TEST_P(QuicStreamFactoryTest, GoAwayForConnectionMigrationWithPortOnly) { |
| 1250 | Initialize(); |
| 1251 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1252 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1253 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1254 | MockQuicData socket_data; |
| 1255 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1256 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1257 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1258 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1259 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1260 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1261 | request.Request( |
| 1262 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1263 | SocketTag(), |
| 1264 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1265 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1266 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1267 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1268 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1269 | EXPECT_TRUE(stream.get()); |
| 1270 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1271 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1272 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1273 | session->OnGoAway(quic::QuicGoAwayFrame( |
| 1274 | quic::kInvalidControlFrameId, quic::QUIC_ERROR_MIGRATING_PORT, 0, |
| 1275 | "peer connection migration due to port change only")); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1276 | NetErrorDetails details; |
| 1277 | EXPECT_FALSE(details.quic_port_migration_detected); |
| 1278 | session->PopulateNetErrorDetails(&details); |
| 1279 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1280 | details.quic_port_migration_detected = false; |
| 1281 | stream->PopulateNetErrorDetails(&details); |
| 1282 | EXPECT_TRUE(details.quic_port_migration_detected); |
| 1283 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1284 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
zhongyi | 6b5a389 | 2016-03-12 04:46:20 | [diff] [blame] | 1285 | |
| 1286 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1287 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1288 | } |
| 1289 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1290 | TEST_P(QuicStreamFactoryTest, Pooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1291 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1292 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1293 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1294 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1295 | MockQuicData socket_data; |
| 1296 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1297 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1298 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1299 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1300 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1301 | host_resolver_->set_synchronous_mode(true); |
| 1302 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1303 | "192.168.0.1", ""); |
| 1304 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1305 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1306 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1307 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1308 | DEFAULT_PRIORITY, SocketTag(), |
| 1309 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1310 | &net_error_details_, |
| 1311 | failed_on_default_network_callback_, |
| 1312 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1313 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1314 | EXPECT_TRUE(stream.get()); |
| 1315 | |
| 1316 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1317 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1318 | EXPECT_EQ(OK, |
| 1319 | request2.Request( |
| 1320 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1321 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1322 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1323 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1324 | EXPECT_TRUE(stream2.get()); |
| 1325 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1326 | EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1327 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1328 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1329 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1330 | } |
| 1331 | |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1332 | TEST_P(QuicStreamFactoryTest, PoolingWithServerMigration) { |
| 1333 | // Set up session to migrate. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1334 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1335 | "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1336 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 443); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1337 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 1338 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1339 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1340 | |
| 1341 | VerifyServerMigration(config, alt_address); |
| 1342 | |
| 1343 | // Close server-migrated session. |
| 1344 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1345 | session->CloseSessionOnError(0u, quic::QUIC_NO_ERROR, |
| 1346 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1347 | |
| 1348 | // Set up server IP, socket, proof, and config for new session. |
| 1349 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1350 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1351 | |
| 1352 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1353 | std::unique_ptr<quic::QuicEncryptedPacket> settings_packet( |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 1354 | client_maker_.MakeInitialSettingsPacket(1, nullptr)); |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 1355 | MockWrite writes[] = {MockWrite(SYNCHRONOUS, settings_packet->data(), |
| 1356 | settings_packet->length(), 1)}; |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1357 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1358 | SequencedSocketData socket_data(reads, writes); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1359 | socket_factory_->AddSocketDataProvider(&socket_data); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1360 | |
| 1361 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1362 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1363 | quic::QuicConfig config2; |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1364 | crypto_client_stream_factory_.SetConfig(config2); |
| 1365 | |
| 1366 | // Create new request to cause new session creation. |
| 1367 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1368 | QuicStreamRequest request2(factory_.get()); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1369 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1370 | request2.Request( |
| 1371 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1372 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1373 | failed_on_default_network_callback_, callback.callback())); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1374 | EXPECT_EQ(OK, callback.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1375 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 94ddc314 | 2016-08-26 01:32:43 | [diff] [blame] | 1376 | EXPECT_TRUE(stream2.get()); |
| 1377 | |
| 1378 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1379 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1380 | // EXPECT_EQ(GetActiveSession(host_port_pair_), GetActiveSession(server2)); |
| 1381 | } |
| 1382 | |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1383 | TEST_P(QuicStreamFactoryTest, NoPoolingAfterGoAway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1384 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1385 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1386 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1387 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1388 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1389 | MockQuicData socket_data1; |
| 1390 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1391 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1392 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1393 | MockQuicData socket_data2; |
| 1394 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1395 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1396 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1397 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1398 | HostPortPair server2(kServer2HostName, kDefaultServerPort); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1399 | host_resolver_->set_synchronous_mode(true); |
| 1400 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1401 | "192.168.0.1", ""); |
| 1402 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1403 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1404 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1405 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1406 | DEFAULT_PRIORITY, SocketTag(), |
| 1407 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1408 | &net_error_details_, |
| 1409 | failed_on_default_network_callback_, |
| 1410 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1411 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1412 | EXPECT_TRUE(stream.get()); |
| 1413 | |
| 1414 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1415 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1416 | EXPECT_EQ(OK, |
| 1417 | request2.Request( |
| 1418 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1419 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1420 | failed_on_default_network_callback_, callback.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1421 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1422 | EXPECT_TRUE(stream2.get()); |
| 1423 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1424 | factory_->OnSessionGoingAway(GetActiveSession(host_port_pair_)); |
| 1425 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1426 | EXPECT_FALSE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1427 | |
| 1428 | TestCompletionCallback callback3; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1429 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1430 | EXPECT_EQ(OK, |
| 1431 | request3.Request( |
| 1432 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1433 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1434 | failed_on_default_network_callback_, callback3.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1435 | std::unique_ptr<HttpStream> stream3 = CreateStream(&request3); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1436 | EXPECT_TRUE(stream3.get()); |
| 1437 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1438 | EXPECT_TRUE(HasActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1439 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1440 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1441 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1442 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1443 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1444 | } |
| 1445 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1446 | TEST_P(QuicStreamFactoryTest, HttpsPooling) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1447 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1448 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1449 | MockQuicData socket_data; |
| 1450 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1451 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1452 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1453 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1454 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1455 | HostPortPair server2(kServer2HostName, 443); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1456 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1457 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1458 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1459 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1460 | host_resolver_->set_synchronous_mode(true); |
| 1461 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1462 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1463 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1464 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1465 | EXPECT_EQ(OK, |
| 1466 | request.Request( |
| 1467 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1468 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1469 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1470 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1471 | EXPECT_TRUE(stream.get()); |
| 1472 | |
| 1473 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1474 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1475 | EXPECT_EQ(OK, |
| 1476 | request2.Request( |
| 1477 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1478 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1479 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1480 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1481 | EXPECT_TRUE(stream2.get()); |
| 1482 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1483 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1484 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1485 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1486 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | eed749f9 | 2013-12-23 18:57:38 | [diff] [blame] | 1487 | } |
| 1488 | |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1489 | TEST_P(QuicStreamFactoryTest, HttpsPoolingWithMatchingPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1490 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1491 | MockQuicData socket_data; |
| 1492 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1493 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1494 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1495 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1496 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1497 | HostPortPair server2(kServer2HostName, 443); |
Hiroki Nakagawa | 4e4967bcb | 2018-10-11 04:09:51 | [diff] [blame] | 1498 | uint8_t primary_pin = 1; |
| 1499 | uint8_t backup_pin = 2; |
| 1500 | test::AddPin(&transport_security_state_, kServer2HostName, primary_pin, |
| 1501 | backup_pin); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1502 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1503 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
Hiroki Nakagawa | 4e4967bcb | 2018-10-11 04:09:51 | [diff] [blame] | 1504 | verify_details.cert_verify_result.public_key_hashes.push_back( |
| 1505 | test::GetTestHashValue(primary_pin)); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1506 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1507 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1508 | host_resolver_->set_synchronous_mode(true); |
| 1509 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1510 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1511 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1512 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1513 | EXPECT_EQ(OK, |
| 1514 | request.Request( |
| 1515 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1516 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1517 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1518 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1519 | EXPECT_TRUE(stream.get()); |
| 1520 | |
| 1521 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1522 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1523 | EXPECT_EQ(OK, |
| 1524 | request2.Request( |
| 1525 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1526 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1527 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1528 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1529 | EXPECT_TRUE(stream2.get()); |
| 1530 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1531 | EXPECT_EQ(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1532 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1533 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1534 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | TEST_P(QuicStreamFactoryTest, NoHttpsPoolingWithDifferentPins) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1538 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1539 | |
| 1540 | MockQuicData socket_data1; |
| 1541 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1542 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1543 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1544 | MockQuicData socket_data2; |
| 1545 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1546 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1547 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1548 | |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1549 | HostPortPair server1(kDefaultServerHostName, 443); |
| 1550 | HostPortPair server2(kServer2HostName, 443); |
Hiroki Nakagawa | 4e4967bcb | 2018-10-11 04:09:51 | [diff] [blame] | 1551 | uint8_t primary_pin = 1; |
| 1552 | uint8_t backup_pin = 2; |
| 1553 | uint8_t bad_pin = 3; |
| 1554 | test::AddPin(&transport_security_state_, kServer2HostName, primary_pin, |
| 1555 | backup_pin); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1556 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1557 | ProofVerifyDetailsChromium verify_details1 = DefaultProofVerifyDetails(); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1558 | verify_details1.cert_verify_result.public_key_hashes.push_back( |
| 1559 | test::GetTestHashValue(bad_pin)); |
| 1560 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details1); |
| 1561 | |
bnc | f8bf072 | 2015-05-19 20:04:13 | [diff] [blame] | 1562 | ProofVerifyDetailsChromium verify_details2 = DefaultProofVerifyDetails(); |
Hiroki Nakagawa | 4e4967bcb | 2018-10-11 04:09:51 | [diff] [blame] | 1563 | verify_details2.cert_verify_result.public_key_hashes.push_back( |
| 1564 | test::GetTestHashValue(primary_pin)); |
bnc | 20daf9a | 2015-05-15 17:11:01 | [diff] [blame] | 1565 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1566 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1567 | host_resolver_->set_synchronous_mode(true); |
| 1568 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 1569 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.1", ""); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1570 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1571 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1572 | EXPECT_EQ(OK, |
| 1573 | request.Request( |
| 1574 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1575 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1576 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1577 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1578 | EXPECT_TRUE(stream.get()); |
| 1579 | |
| 1580 | TestCompletionCallback callback; |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1581 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1582 | EXPECT_EQ(OK, |
| 1583 | request2.Request( |
| 1584 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1585 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 1586 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1587 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1588 | EXPECT_TRUE(stream2.get()); |
| 1589 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1590 | EXPECT_NE(GetActiveSession(server1), GetActiveSession(server2)); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1591 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1592 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1593 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1594 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1595 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 1596 | } |
| 1597 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1598 | TEST_P(QuicStreamFactoryTest, Goaway) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1599 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1600 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1601 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1602 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1603 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1604 | MockQuicData socket_data; |
| 1605 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1606 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1607 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1608 | MockQuicData socket_data2; |
| 1609 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1610 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1611 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1612 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1613 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1614 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1615 | request.Request( |
| 1616 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1617 | SocketTag(), |
| 1618 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1619 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1620 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1621 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1622 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1623 | EXPECT_TRUE(stream.get()); |
| 1624 | |
| 1625 | // Mark the session as going away. Ensure that while it is still alive |
| 1626 | // that it is no longer active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1627 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1628 | factory_->OnSessionGoingAway(session); |
| 1629 | EXPECT_EQ(true, |
| 1630 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1631 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1632 | |
| 1633 | // Create a new request for the same destination and verify that a |
| 1634 | // new session is created. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1635 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1636 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1637 | request2.Request( |
| 1638 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1639 | SocketTag(), |
| 1640 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1641 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1642 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1643 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1644 | EXPECT_TRUE(stream2.get()); |
| 1645 | |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1646 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1647 | EXPECT_NE(session, GetActiveSession(host_port_pair_)); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1648 | EXPECT_EQ(true, |
| 1649 | QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1650 | |
| 1651 | stream2.reset(); |
| 1652 | stream.reset(); |
| 1653 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1654 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1655 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1656 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1657 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1660 | TEST_P(QuicStreamFactoryTest, MaxOpenStream) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1661 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1662 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1663 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1664 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1665 | quic::QuicStreamId stream_id = GetNthClientInitiatedStreamId(0); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1666 | MockQuicData socket_data; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1667 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
fayang | 3bcb8b50 | 2016-12-07 21:44:37 | [diff] [blame] | 1668 | socket_data.AddWrite( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1669 | SYNCHRONOUS, client_maker_.MakeRstPacket(2, true, stream_id, |
| 1670 | quic::QUIC_STREAM_CANCELLED)); |
| 1671 | socket_data.AddRead(ASYNC, |
| 1672 | server_maker_.MakeRstPacket(1, false, stream_id, |
| 1673 | quic::QUIC_STREAM_CANCELLED)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1674 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1675 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1676 | |
| 1677 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1678 | request_info.traffic_annotation = |
| 1679 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1680 | |
xunjieli | 1d2b427 | 2017-04-25 22:37:17 | [diff] [blame] | 1681 | std::vector<std::unique_ptr<HttpStream>> streams; |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1682 | // The MockCryptoClientStream sets max_open_streams to be |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1683 | // quic::kDefaultMaxStreamsPerConnection / 2. |
| 1684 | for (size_t i = 0; i < quic::kDefaultMaxStreamsPerConnection / 2; i++) { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1685 | QuicStreamRequest request(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1686 | int rv = request.Request( |
| 1687 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 1688 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1689 | failed_on_default_network_callback_, callback_.callback()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1690 | if (i == 0) { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1691 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1692 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1693 | } else { |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1694 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1695 | } |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1696 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1697 | EXPECT_TRUE(stream); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1698 | EXPECT_EQ(OK, |
| 1699 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1700 | net_log_, CompletionOnceCallback())); |
avi | b363545 | 2016-10-21 18:33:53 | [diff] [blame] | 1701 | streams.push_back(std::move(stream)); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1702 | } |
| 1703 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1704 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1705 | EXPECT_EQ(OK, request.Request(host_port_pair_, version_, privacy_mode_, |
| 1706 | DEFAULT_PRIORITY, SocketTag(), |
| 1707 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1708 | &net_error_details_, |
| 1709 | failed_on_default_network_callback_, |
| 1710 | CompletionOnceCallback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1711 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1712 | EXPECT_TRUE(stream); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1713 | EXPECT_EQ(ERR_IO_PENDING, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1714 | stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
| 1715 | net_log_, callback_.callback())); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1716 | |
| 1717 | // Close the first stream. |
| 1718 | streams.front()->Close(false); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1719 | // Trigger exchange of RSTs that in turn allow progress for the last |
| 1720 | // stream. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1721 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1722 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1723 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1724 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 1725 | |
| 1726 | // Force close of the connection to suppress the generation of RST |
| 1727 | // packets when streams are torn down, which wouldn't be relevant to |
| 1728 | // this test anyway. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 1729 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1730 | session->connection()->CloseConnection( |
| 1731 | quic::QUIC_PUBLIC_RESET, "test", |
| 1732 | quic::ConnectionCloseBehavior::SILENT_CLOSE); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1733 | } |
| 1734 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1735 | TEST_P(QuicStreamFactoryTest, ResolutionErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1736 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1737 | MockQuicData socket_data; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1738 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1739 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1740 | host_resolver_->rules()->AddSimulatedFailure(kDefaultServerHostName); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1741 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1742 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1743 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1744 | request.Request( |
| 1745 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1746 | SocketTag(), |
| 1747 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1748 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1749 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1750 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1751 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1752 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1753 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1754 | } |
| 1755 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1756 | TEST_P(QuicStreamFactoryTest, ConnectErrorInCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1757 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1758 | |
| 1759 | MockQuicData socket_data; |
| 1760 | socket_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1761 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1762 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1763 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1764 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1765 | request.Request( |
| 1766 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1767 | SocketTag(), |
| 1768 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1769 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1770 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1771 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1772 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1773 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1774 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | 3c77240 | 2013-12-18 21:38:11 | [diff] [blame] | 1775 | } |
| 1776 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1777 | TEST_P(QuicStreamFactoryTest, CancelCreate) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1778 | Initialize(); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1779 | MockQuicData socket_data; |
| 1780 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1781 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1782 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1783 | { |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1784 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1785 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1786 | request.Request( |
| 1787 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1788 | SocketTag(), |
| 1789 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1790 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1791 | } |
| 1792 | |
mmenke | 651bae7f | 2015-12-18 21:26:45 | [diff] [blame] | 1793 | base::RunLoop().RunUntilIdle(); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1794 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1795 | QuicStreamRequest request2(factory_.get()); |
zhongyi | a00ca01 | 2017-07-06 23:36:39 | [diff] [blame] | 1796 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1797 | DEFAULT_PRIORITY, SocketTag(), |
| 1798 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1799 | &net_error_details_, |
| 1800 | failed_on_default_network_callback_, |
| 1801 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1802 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
rch | 68a80eb | 2017-04-25 05:24:24 | [diff] [blame] | 1803 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1804 | EXPECT_TRUE(stream.get()); |
| 1805 | stream.reset(); |
| 1806 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1807 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1808 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 1809 | } |
| 1810 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1811 | TEST_P(QuicStreamFactoryTest, CloseAllSessions) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 1812 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 1813 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1814 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1815 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1816 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1817 | MockQuicData socket_data; |
| 1818 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1819 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1820 | socket_data.AddWrite( |
| 1821 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 1822 | socket_data.AddWrite(SYNCHRONOUS, |
| 1823 | client_maker_.MakeConnectionClosePacket( |
| 1824 | 3, true, quic::QUIC_INTERNAL_ERROR, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1825 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1826 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 1827 | MockQuicData socket_data2; |
| 1828 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1829 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1830 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1831 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1832 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1833 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1834 | request.Request( |
| 1835 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1836 | SocketTag(), |
| 1837 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1838 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1839 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1840 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1841 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 1842 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 1843 | request_info.traffic_annotation = |
| 1844 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 1845 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 1846 | net_log_, CompletionOnceCallback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1847 | |
| 1848 | // Close the session and verify that stream saw the error. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1849 | factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, |
| 1850 | quic::QUIC_INTERNAL_ERROR); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1851 | EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1852 | stream->ReadResponseHeaders(callback_.callback())); |
| 1853 | |
| 1854 | // Now attempting to request a stream to the same origin should create |
| 1855 | // a new session. |
| 1856 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1857 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1858 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1859 | request2.Request( |
| 1860 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1861 | SocketTag(), |
| 1862 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1863 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1864 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1865 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1866 | stream = CreateStream(&request2); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1867 | stream.reset(); // Will reset stream 3. |
| 1868 | |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 1869 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1870 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1871 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1872 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | 56dfb90 | 2013-01-03 23:17:55 | [diff] [blame] | 1873 | } |
| 1874 | |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1875 | // Regression test for crbug.com/700617. Test a write error during the |
| 1876 | // crypto handshake will not hang QuicStreamFactory::Job and should |
| 1877 | // report QUIC_HANDSHAKE_FAILED to upper layers. Subsequent |
| 1878 | // QuicStreamRequest should succeed without hanging. |
| 1879 | TEST_P(QuicStreamFactoryTest, |
| 1880 | WriteErrorInCryptoConnectWithAsyncHostResolution) { |
| 1881 | Initialize(); |
| 1882 | // Use unmocked crypto stream to do crypto connect. |
| 1883 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1884 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1885 | |
| 1886 | MockQuicData socket_data; |
| 1887 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1888 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1889 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1890 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1891 | |
| 1892 | // Create request, should fail after the write of the CHLO fails. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1893 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1894 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1895 | request.Request( |
| 1896 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1897 | SocketTag(), |
| 1898 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1899 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1900 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 1901 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1902 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1903 | |
| 1904 | // Verify new requests can be sent normally without hanging. |
| 1905 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1906 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1907 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1908 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1909 | MockQuicData socket_data2; |
| 1910 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1911 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1912 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1913 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1914 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1915 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1916 | request2.Request( |
| 1917 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1918 | SocketTag(), |
| 1919 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1920 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1921 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1922 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1923 | // Run the message loop to complete host resolution. |
| 1924 | base::RunLoop().RunUntilIdle(); |
| 1925 | |
| 1926 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 1927 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1928 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1929 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1930 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1931 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1932 | |
| 1933 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1934 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1935 | EXPECT_TRUE(stream.get()); |
| 1936 | stream.reset(); |
| 1937 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1938 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1939 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1940 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1941 | } |
| 1942 | |
| 1943 | TEST_P(QuicStreamFactoryTest, WriteErrorInCryptoConnectWithSyncHostResolution) { |
| 1944 | Initialize(); |
| 1945 | // Use unmocked crypto stream to do crypto connect. |
| 1946 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 1947 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 1948 | host_resolver_->set_synchronous_mode(true); |
| 1949 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 1950 | "192.168.0.1", ""); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1951 | |
| 1952 | MockQuicData socket_data; |
| 1953 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 1954 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 1955 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1956 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1957 | |
| 1958 | // Create request, should fail immediately. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1959 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1960 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1961 | request.Request( |
| 1962 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1963 | SocketTag(), |
| 1964 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1965 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1966 | // Check no active session, or active jobs left for this server. |
| 1967 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1968 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1969 | |
| 1970 | // Verify new requests can be sent normally without hanging. |
| 1971 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 1972 | MockCryptoClientStream::COLD_START); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1973 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1974 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1975 | MockQuicData socket_data2; |
| 1976 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 1977 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 1978 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1979 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 1980 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 1981 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 1982 | request2.Request( |
| 1983 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 1984 | SocketTag(), |
| 1985 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 1986 | failed_on_default_network_callback_, callback_.callback())); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1987 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1988 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1989 | |
| 1990 | // Complete handshake. |
| 1991 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 1992 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1993 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 1994 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1995 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 1996 | |
| 1997 | // Create QuicHttpStream. |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 1998 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
zhongyi | 363c91c | 2017-03-23 23:16:08 | [diff] [blame] | 1999 | EXPECT_TRUE(stream.get()); |
| 2000 | stream.reset(); |
| 2001 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2002 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2003 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2004 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 2005 | } |
| 2006 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2007 | TEST_P(QuicStreamFactoryTest, CloseSessionsOnIPAddressChanged) { |
Jana Iyengar | 903dec2 | 2017-11-28 00:44:23 | [diff] [blame] | 2008 | close_sessions_on_ip_change_ = true; |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2009 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 2010 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2011 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2012 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2013 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2014 | MockQuicData socket_data; |
| 2015 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2016 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2017 | socket_data.AddWrite( |
| 2018 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2019 | socket_data.AddWrite( |
| 2020 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 2021 | 3, true, quic::QUIC_IP_ADDRESS_CHANGED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2022 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2023 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2024 | MockQuicData socket_data2; |
| 2025 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2026 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2027 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2028 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2029 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2030 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2031 | request.Request( |
| 2032 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2033 | SocketTag(), |
| 2034 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2035 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2036 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2037 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2038 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 2039 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2040 | request_info.traffic_annotation = |
| 2041 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2042 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2043 | net_log_, CompletionOnceCallback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2044 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2045 | // Check an active session exisits for the destination. |
| 2046 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2047 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2048 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2049 | |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2050 | IPAddress last_address; |
| 2051 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2052 | // Change the IP address and verify that stream saw the error and the active |
| 2053 | // session is closed. |
jri | 8c44d69 | 2015-10-23 23:53:41 | [diff] [blame] | 2054 | NotifyIPAddressChanged(); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2055 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 2056 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 2057 | EXPECT_TRUE(factory_->require_confirmation()); |
Ryan Hamilton | 8e32a2b | 2017-08-28 20:06:52 | [diff] [blame] | 2058 | EXPECT_FALSE(http_server_properties_.GetSupportsQuic(&last_address)); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2059 | // Check no active session exists for the destination. |
| 2060 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2061 | |
| 2062 | // Now attempting to request a stream to the same origin should create |
| 2063 | // a new session. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2064 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2065 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2066 | request2.Request( |
| 2067 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2068 | SocketTag(), |
| 2069 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2070 | failed_on_default_network_callback_, callback_.callback())); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2071 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2072 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2073 | stream = CreateStream(&request2); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2074 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2075 | // Check a new active session exisits for the destination and the old session |
| 2076 | // is no longer live. |
| 2077 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2078 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2079 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2080 | |
| 2081 | stream.reset(); // Will reset stream 3. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2082 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2083 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2084 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 2085 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
[email protected] | f698a01 | 2013-05-06 20:18:59 | [diff] [blame] | 2086 | } |
| 2087 | |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2088 | // Test that if goaway_session_on_ip_change is set, old sessions will be marked |
| 2089 | // as going away on IP address change instead of being closed. New requests will |
| 2090 | // go to a new connection. |
| 2091 | TEST_P(QuicStreamFactoryTest, GoAwaySessionsOnIPAddressChanged) { |
| 2092 | goaway_sessions_on_ip_change_ = true; |
| 2093 | Initialize(); |
| 2094 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2095 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2096 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2097 | |
| 2098 | MockQuicData quic_data1; |
| 2099 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2100 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2101 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2102 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 2103 | 2, GetNthClientInitiatedStreamId(0), |
| 2104 | true, true, &header_stream_offset)); |
| 2105 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2106 | quic_data1.AddRead( |
| 2107 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 2108 | false, true)); |
| 2109 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2110 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2111 | |
| 2112 | MockQuicData quic_data2; |
| 2113 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 2114 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 2115 | quic_data2.AddWrite( |
| 2116 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 2117 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2118 | |
| 2119 | // Create request and QuicHttpStream. |
| 2120 | QuicStreamRequest request(factory_.get()); |
| 2121 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2122 | request.Request( |
| 2123 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2124 | SocketTag(), |
| 2125 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2126 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2127 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2128 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2129 | EXPECT_TRUE(stream.get()); |
| 2130 | |
| 2131 | // Cause QUIC stream to be created. |
| 2132 | HttpRequestInfo request_info; |
| 2133 | request_info.method = "GET"; |
| 2134 | request_info.url = url_; |
| 2135 | request_info.traffic_annotation = |
| 2136 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2137 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2138 | net_log_, CompletionOnceCallback())); |
| 2139 | |
| 2140 | // Ensure that session is alive and active. |
| 2141 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2142 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2143 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2144 | |
| 2145 | // Send GET request on stream. |
| 2146 | HttpResponseInfo response; |
| 2147 | HttpRequestHeaders request_headers; |
| 2148 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2149 | callback_.callback())); |
| 2150 | |
| 2151 | // Receive an IP address change notification. |
| 2152 | NotifyIPAddressChanged(); |
| 2153 | |
| 2154 | // The connection should still be alive, but marked as going away. |
| 2155 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2156 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2157 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2158 | |
| 2159 | // Resume the data, response should be read from the original connection. |
| 2160 | quic_data1.Resume(); |
| 2161 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 2162 | EXPECT_EQ(200, response.headers->response_code()); |
| 2163 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 2164 | |
| 2165 | // Second request should be sent on a new connection. |
| 2166 | QuicStreamRequest request2(factory_.get()); |
| 2167 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2168 | request2.Request( |
| 2169 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2170 | SocketTag(), |
| 2171 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2172 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 63574b7 | 2018-06-01 20:22:25 | [diff] [blame] | 2173 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2174 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 2175 | EXPECT_TRUE(stream2.get()); |
| 2176 | |
| 2177 | // Check an active session exisits for the destination. |
| 2178 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2179 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2180 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 2181 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 2182 | |
| 2183 | stream.reset(); |
| 2184 | stream2.reset(); |
| 2185 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2186 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2187 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2188 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2189 | } |
| 2190 | |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2191 | TEST_P(QuicStreamFactoryTest, OnIPAddressChangedWithConnectionMigration) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 2192 | InitializeConnectionMigrationV2Test( |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2193 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2194 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2195 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2196 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2197 | |
| 2198 | MockQuicData socket_data; |
| 2199 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2200 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2201 | socket_data.AddWrite( |
| 2202 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2203 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2204 | |
| 2205 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2206 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2207 | request.Request( |
| 2208 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2209 | SocketTag(), |
| 2210 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2211 | failed_on_default_network_callback_, callback_.callback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2212 | |
| 2213 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2214 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2215 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2216 | request_info.traffic_annotation = |
| 2217 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2218 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2219 | net_log_, CompletionOnceCallback())); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2220 | |
| 2221 | IPAddress last_address; |
| 2222 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2223 | |
| 2224 | // Change the IP address and verify that the connection is unaffected. |
| 2225 | NotifyIPAddressChanged(); |
| 2226 | EXPECT_FALSE(factory_->require_confirmation()); |
| 2227 | EXPECT_TRUE(http_server_properties_.GetSupportsQuic(&last_address)); |
| 2228 | |
| 2229 | // Attempting a new request to the same origin uses the same connection. |
| 2230 | QuicStreamRequest request2(factory_.get()); |
| 2231 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2232 | DEFAULT_PRIORITY, SocketTag(), |
| 2233 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2234 | &net_error_details_, |
| 2235 | failed_on_default_network_callback_, |
| 2236 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2237 | stream = CreateStream(&request2); |
Jana Iyengar | ba35577 | 2017-09-21 22:03:21 | [diff] [blame] | 2238 | |
| 2239 | stream.reset(); |
| 2240 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2241 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2242 | } |
| 2243 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2244 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithSynchronousWrite) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 2245 | if (version_ == quic::QUIC_VERSION_99) |
| 2246 | return; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2247 | TestMigrationOnNetworkMadeDefault(SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2248 | } |
| 2249 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2250 | TEST_P(QuicStreamFactoryTest, MigrateOnNetworkMadeDefaultWithAsyncWrite) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 2251 | if (version_ == quic::QUIC_VERSION_99) |
| 2252 | return; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2253 | TestMigrationOnNetworkMadeDefault(ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2254 | } |
| 2255 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2256 | // Sets up a test which attempts connection migration successfully after probing |
| 2257 | // when a new network is made as default and the old default is still available. |
| 2258 | // |write_mode| specifies the write mode for the last write before |
| 2259 | // OnNetworkMadeDefault is delivered to session. |
| 2260 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkMadeDefault( |
| 2261 | IoMode write_mode) { |
| 2262 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2263 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2264 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2265 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2266 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2267 | // Using a testing task runner so that we can control time. |
| 2268 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2269 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2270 | |
| 2271 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2272 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2273 | |
| 2274 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2275 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2276 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2277 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2278 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2279 | quic_data1.AddWrite( |
| 2280 | write_mode, ConstructGetRequestPacket(2, GetNthClientInitiatedStreamId(0), |
| 2281 | true, true, &header_stream_offset)); |
| 2282 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2283 | |
| 2284 | // Set up the second socket data provider that is used after migration. |
| 2285 | // The response to the earlier request is read on the new socket. |
| 2286 | MockQuicData quic_data2; |
| 2287 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2288 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2289 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2290 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2291 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2292 | quic_data2.AddRead(ASYNC, |
| 2293 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2294 | // Ping packet to send after migration is completed. |
| 2295 | quic_data2.AddWrite(ASYNC, |
| 2296 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 2297 | quic_data2.AddRead( |
| 2298 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 2299 | false, false)); |
| 2300 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2301 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2302 | client_maker_.MakeAckAndRstPacket( |
| 2303 | 5, false, GetNthClientInitiatedStreamId(0), |
| 2304 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
| 2305 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2306 | |
| 2307 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2308 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2309 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2310 | request.Request( |
| 2311 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2312 | SocketTag(), |
| 2313 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2314 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2315 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2316 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2317 | EXPECT_TRUE(stream.get()); |
| 2318 | |
| 2319 | // Cause QUIC stream to be created. |
| 2320 | HttpRequestInfo request_info; |
| 2321 | request_info.method = "GET"; |
bnc | 3d9035b3 | 2016-06-30 18:18:48 | [diff] [blame] | 2322 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2323 | request_info.traffic_annotation = |
| 2324 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2325 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2326 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2327 | |
| 2328 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2329 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2330 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2331 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2332 | |
| 2333 | // Send GET request on stream. |
| 2334 | HttpResponseInfo response; |
| 2335 | HttpRequestHeaders request_headers; |
| 2336 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2337 | callback_.callback())); |
| 2338 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2339 | // Deliver a signal that a alternate network is connected now, this should |
| 2340 | // cause the connection to start early migration on path degrading. |
| 2341 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2342 | ->SetConnectedNetworksList( |
| 2343 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2344 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2345 | ->NotifyNetworkConnected(kNewNetworkForTests); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2346 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2347 | // Cause the connection to report path degrading to the session. |
| 2348 | // Due to lack of alternate network, session will not mgirate connection. |
| 2349 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2350 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2351 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2352 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2353 | // A task will be posted to migrate to the new default network. |
| 2354 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2355 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2356 | |
| 2357 | // Execute the posted task to migrate back to the default network. |
| 2358 | task_runner->RunUntilIdle(); |
| 2359 | // Another task to try send a new connectivity probe is posted. And a task to |
| 2360 | // retry migrate back to default network is scheduled. |
| 2361 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2362 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2363 | // kDefaultRTTMilliSecs. |
| 2364 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2365 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2366 | next_task_delay); |
| 2367 | |
| 2368 | // The connection should still be alive, and not marked as going away. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2369 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2370 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2371 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2372 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2373 | |
| 2374 | // Resume quic data and a connectivity probe response will be read on the new |
| 2375 | // socket, declare probing as successful. And a new task to WriteToNewSocket |
| 2376 | // will be posted to complete migration. |
| 2377 | quic_data2.Resume(); |
| 2378 | |
| 2379 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2380 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2381 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2382 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2383 | // There should be three pending tasks, the nearest one will complete |
| 2384 | // migration to the new network. |
| 2385 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2386 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2387 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 2388 | task_runner->FastForwardBy(next_task_delay); |
| 2389 | |
| 2390 | // Response headers are received over the new network. |
| 2391 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2392 | EXPECT_EQ(200, response.headers->response_code()); |
| 2393 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2394 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 2395 | // probe and has been cancelled due to successful migration. |
| 2396 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2397 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2398 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 2399 | next_task_delay); |
| 2400 | task_runner->FastForwardBy(next_task_delay); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2401 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2402 | // There's one more task to mgirate back to the default network in 0.4s, which |
| 2403 | // is also cancelled due to the success migration on the previous trial. |
| 2404 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2405 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2406 | base::TimeDelta expected_delay = |
| 2407 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2408 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2409 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2410 | task_runner->FastForwardBy(next_task_delay); |
| 2411 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2412 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2413 | // Verify that the session is still alive. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2414 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2415 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2416 | |
Zhongyi Shi | a0644e3 | 2018-06-21 05:19:52 | [diff] [blame] | 2417 | stream.reset(); |
| 2418 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2419 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2420 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2421 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2422 | } |
| 2423 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2424 | // Regression test for http://859674. |
| 2425 | // This test veries that a writer will not attempt to write packets until being |
| 2426 | // unblocked on both socket level and network level. In this test, a probing |
| 2427 | // writer is used to send two connectivity probes to the peer: where the first |
| 2428 | // one completes successfully, while a connectivity response is received before |
| 2429 | // completes sending the second one. The connection migration attempt will |
| 2430 | // proceed while the probing writer is blocked at the socket level, which will |
| 2431 | // block the writer on the network level. Once connection migration completes |
| 2432 | // successfully, the probing writer will be unblocked on the network level, it |
| 2433 | // will not attempt to write new packets until the socket level is unblocked. |
| 2434 | TEST_P(QuicStreamFactoryTest, MigratedToBlockedSocketAfterProbing) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 2435 | if (version_ == quic::QUIC_VERSION_99) |
| 2436 | return; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2437 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 2438 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2439 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2440 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2441 | |
| 2442 | // Using a testing task runner so that we can control time. |
| 2443 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2444 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 2445 | |
| 2446 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2447 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 2448 | |
| 2449 | MockQuicData quic_data1; |
| 2450 | quic::QuicStreamOffset header_stream_offset = 0; |
| 2451 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 2452 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2453 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 2454 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 2455 | 2, GetNthClientInitiatedStreamId(0), |
| 2456 | true, true, &header_stream_offset)); |
| 2457 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2458 | |
| 2459 | // Set up the second socket data provider that is used after migration. |
| 2460 | // The response to the earlier request is read on the new socket. |
| 2461 | MockQuicData quic_data2; |
| 2462 | // First connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2463 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2464 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2465 | quic_data2.AddRead(ASYNC, |
| 2466 | ERR_IO_PENDING); // Pause so that we can control time. |
| 2467 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2468 | quic_data2.AddRead(ASYNC, |
| 2469 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2470 | // Second connectivity probe which will complete asynchronously. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2471 | quic_data2.AddWrite(ASYNC, |
| 2472 | client_maker_.MakeConnectivityProbingPacket(4, true)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2473 | quic_data2.AddRead( |
| 2474 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 2475 | false, false)); |
| 2476 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 2477 | quic_data2.AddWrite(ASYNC, |
| 2478 | client_maker_.MakeAckAndPingPacket(5, false, 1, 1, 1)); |
| 2479 | quic_data2.AddWrite(SYNCHRONOUS, |
| 2480 | client_maker_.MakeAckAndRstPacket( |
| 2481 | 6, false, GetNthClientInitiatedStreamId(0), |
| 2482 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
| 2483 | |
| 2484 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 2485 | |
| 2486 | // Create request and QuicHttpStream. |
| 2487 | QuicStreamRequest request(factory_.get()); |
| 2488 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2489 | request.Request( |
| 2490 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2491 | SocketTag(), |
| 2492 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2493 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 2494 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2495 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2496 | EXPECT_TRUE(stream.get()); |
| 2497 | |
| 2498 | // Cause QUIC stream to be created. |
| 2499 | HttpRequestInfo request_info; |
| 2500 | request_info.method = "GET"; |
| 2501 | request_info.url = url_; |
| 2502 | request_info.traffic_annotation = |
| 2503 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2504 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 2505 | net_log_, CompletionOnceCallback())); |
| 2506 | |
| 2507 | // Ensure that session is alive and active. |
| 2508 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2509 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2510 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2511 | |
| 2512 | // Send GET request on stream. |
| 2513 | HttpResponseInfo response; |
| 2514 | HttpRequestHeaders request_headers; |
| 2515 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 2516 | callback_.callback())); |
| 2517 | |
| 2518 | // Deliver a signal that a alternate network is connected now, this should |
| 2519 | // cause the connection to start early migration on path degrading. |
| 2520 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2521 | ->SetConnectedNetworksList( |
| 2522 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2523 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2524 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 2525 | |
| 2526 | // Cause the connection to report path degrading to the session. |
| 2527 | // Due to lack of alternate network, session will not mgirate connection. |
| 2528 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2529 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2530 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2531 | |
| 2532 | // A task will be posted to migrate to the new default network. |
| 2533 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2534 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2535 | |
| 2536 | // Execute the posted task to migrate back to the default network. |
| 2537 | task_runner->RunUntilIdle(); |
| 2538 | // Another task to resend a new connectivity probe is posted. And a task to |
| 2539 | // retry migrate back to default network is scheduled. |
| 2540 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2541 | // Next connectivity probe is scheduled to be sent in 2 * |
| 2542 | // kDefaultRTTMilliSecs. |
| 2543 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2544 | base::TimeDelta expected_delay = |
| 2545 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 2546 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2547 | |
| 2548 | // Fast forward to send the second connectivity probe. The write will be |
| 2549 | // asynchronous and complete after the read completes. |
| 2550 | task_runner->FastForwardBy(next_task_delay); |
| 2551 | |
| 2552 | // Resume quic data and a connectivity probe response will be read on the new |
| 2553 | // socket, declare probing as successful. |
| 2554 | quic_data2.Resume(); |
| 2555 | |
| 2556 | // The connection should still be alive, and not marked as going away. |
| 2557 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2558 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2559 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2560 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2561 | |
| 2562 | // There should be three pending tasks, the nearest one will complete |
| 2563 | // migration to the new network. Second task will retry migrate back to |
| 2564 | // default but cancelled, and the third task will retry send connectivity |
| 2565 | // probe but also cancelled. |
| 2566 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 2567 | EXPECT_EQ(base::TimeDelta(), task_runner->NextPendingTaskDelay()); |
| 2568 | task_runner->RunUntilIdle(); |
| 2569 | |
| 2570 | // Response headers are received over the new network. |
| 2571 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2572 | EXPECT_EQ(200, response.headers->response_code()); |
| 2573 | |
| 2574 | // Run the message loop to complete the asynchronous write of ack and ping. |
| 2575 | base::RunLoop().RunUntilIdle(); |
| 2576 | |
| 2577 | // Now there are two pending tasks, the nearest one was to retry migrate back |
| 2578 | // to default network and has been cancelled due to successful migration. |
| 2579 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 2580 | expected_delay = |
| 2581 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 2582 | expected_delay; |
| 2583 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2584 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2585 | task_runner->FastForwardBy(next_task_delay); |
| 2586 | |
| 2587 | // There's one more task to retry sending connectivity probe in 0.4s and has |
| 2588 | // also been cancelled due to the successful probing. |
| 2589 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2590 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2591 | expected_delay = |
| 2592 | base::TimeDelta::FromMilliseconds(3 * 2 * kDefaultRTTMilliSecs) - |
| 2593 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 2594 | EXPECT_EQ(expected_delay, next_task_delay); |
| 2595 | task_runner->FastForwardBy(next_task_delay); |
| 2596 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 2597 | |
| 2598 | // Verify that the session is still alive. |
| 2599 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2600 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2601 | |
| 2602 | stream.reset(); |
| 2603 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2604 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 2605 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 2606 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 2607 | } |
| 2608 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2609 | // This test verifies that session times out connection migration attempt |
| 2610 | // with signals delivered in the following order (no alternate network is |
| 2611 | // available): |
| 2612 | // - default network disconnected is delivered: session attempts connection |
| 2613 | // migration but found not alternate network. Session waits for a new network |
| 2614 | // comes up in the next kWaitTimeForNewNetworkSecs seonds. |
| 2615 | // - no new network is connected, migration times out. Session is closed. |
| 2616 | TEST_P(QuicStreamFactoryTest, MigrationTimeoutWithNoNewNetwork) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 2617 | if (version_ == quic::QUIC_VERSION_99) |
| 2618 | return; |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2619 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2620 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2621 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2622 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2623 | // Using a testing task runner so that we can control time. |
| 2624 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 2625 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2626 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 2627 | MockQuicData socket_data; |
| 2628 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2629 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2630 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2631 | |
| 2632 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2633 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2634 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2635 | request.Request( |
| 2636 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2637 | SocketTag(), |
| 2638 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2639 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2640 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2641 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2642 | EXPECT_TRUE(stream.get()); |
| 2643 | |
| 2644 | // Cause QUIC stream to be created. |
| 2645 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2646 | request_info.traffic_annotation = |
| 2647 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2648 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2649 | net_log_, CompletionOnceCallback())); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2650 | |
| 2651 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2652 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2653 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2654 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2655 | |
| 2656 | // Trigger connection migration. Since there are no networks |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2657 | // to migrate to, this should cause the session to wait for a new network. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2658 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2659 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2660 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2661 | // The migration will not fail until the migration alarm timeout. |
| 2662 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2663 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2664 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2665 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 2666 | EXPECT_EQ(true, session->connection()->writer()->IsWriteBlocked()); |
| 2667 | |
Zhongyi Shi | b1b1fa4 | 2018-06-19 23:13:47 | [diff] [blame] | 2668 | // Migration will be timed out after kWaitTimeForNewNetwokSecs. |
| 2669 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 2670 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 2671 | EXPECT_EQ(base::TimeDelta::FromSeconds(kWaitTimeForNewNetworkSecs), |
| 2672 | next_task_delay); |
| 2673 | task_runner->FastForwardBy(next_task_delay); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2674 | |
| 2675 | // The connection should now be closed. A request for response |
| 2676 | // headers should fail. |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2677 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2678 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 2679 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 2680 | |
| 2681 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2682 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2683 | } |
| 2684 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2685 | // This test verifies that connectivity probes will be sent even if there is |
| 2686 | // a non-migratable stream. However, when connection migrates to the |
| 2687 | // successfully probed path, any non-migratable stream will be reset. And if |
| 2688 | // the connection becomes idle then, close the connection. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2689 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNonMigratableStream) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 2690 | if (version_ == quic::QUIC_VERSION_99) |
| 2691 | return; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2692 | InitializeConnectionMigrationV2Test( |
| 2693 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2694 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2695 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2696 | |
| 2697 | MockQuicData socket_data; |
| 2698 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2699 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2700 | socket_data.AddWrite( |
| 2701 | SYNCHRONOUS, |
| 2702 | client_maker_.MakeRstAckAndConnectionClosePacket( |
| 2703 | 3, false, 5, quic::QUIC_STREAM_CANCELLED, |
| 2704 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 2705 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
| 2706 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2707 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2708 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2709 | // Set up the second socket data provider that is used for probing. |
| 2710 | MockQuicData quic_data1; |
| 2711 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2712 | quic_data1.AddWrite(SYNCHRONOUS, |
| 2713 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2714 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 2715 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 2716 | quic_data1.AddRead(ASYNC, |
| 2717 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2718 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 2719 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2720 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2721 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2722 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2723 | request.Request( |
| 2724 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2725 | SocketTag(), |
| 2726 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2727 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2728 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2729 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2730 | EXPECT_TRUE(stream.get()); |
| 2731 | |
| 2732 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2733 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2734 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2735 | request_info.traffic_annotation = |
| 2736 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2737 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2738 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2739 | |
| 2740 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2741 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2742 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2743 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2744 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2745 | // Trigger connection migration. Session will start to probe the alternative |
| 2746 | // network. Although there is a non-migratable stream, session will still be |
| 2747 | // active until probing is declared as successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2748 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2749 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2750 | |
| 2751 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2752 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2753 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2754 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2755 | // Resume data to read a connectivity probing response, which will cause |
| 2756 | // non-migtable streams to be closed. As session becomes idle, connection will |
| 2757 | // be closed. |
| 2758 | quic_data1.Resume(); |
| 2759 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2760 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2761 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2762 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 2763 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 2764 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2765 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2766 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2767 | } |
| 2768 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2769 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2770 | InitializeConnectionMigrationV2Test( |
| 2771 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2772 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2773 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2774 | |
| 2775 | MockQuicData socket_data; |
| 2776 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2777 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2778 | socket_data.AddWrite( |
| 2779 | SYNCHRONOUS, |
| 2780 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2781 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2782 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2783 | |
| 2784 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2785 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2786 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2787 | request.Request( |
| 2788 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2789 | SocketTag(), |
| 2790 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2791 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2792 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2793 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2794 | EXPECT_TRUE(stream.get()); |
| 2795 | |
| 2796 | // Cause QUIC stream to be created. |
| 2797 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2798 | request_info.traffic_annotation = |
| 2799 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2800 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2801 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2802 | |
| 2803 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2804 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2805 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2806 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2807 | |
| 2808 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2809 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2810 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2811 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2812 | |
| 2813 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2814 | // this should cause session to continue but be marked as going away. |
| 2815 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
jri | e266198 | 2016-08-20 08:24:34 | [diff] [blame] | 2816 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2817 | |
| 2818 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2819 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2820 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 2821 | |
| 2822 | stream.reset(); |
| 2823 | |
| 2824 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2825 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2826 | } |
| 2827 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2828 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNonMigratableStream) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2829 | InitializeConnectionMigrationV2Test( |
| 2830 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2831 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2832 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2833 | |
| 2834 | MockQuicData socket_data; |
| 2835 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2836 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2837 | socket_data.AddWrite( |
| 2838 | SYNCHRONOUS, |
| 2839 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2840 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2841 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2842 | |
| 2843 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2844 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2845 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2846 | request.Request( |
| 2847 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2848 | SocketTag(), |
| 2849 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2850 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2851 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2852 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2853 | EXPECT_TRUE(stream.get()); |
| 2854 | |
| 2855 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 2856 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 2857 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2858 | request_info.traffic_annotation = |
| 2859 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2860 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2861 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2862 | |
| 2863 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2864 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2865 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2866 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2867 | |
| 2868 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2869 | // this should cause a RST_STREAM frame to be emitted with |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 2870 | // quic::QUIC_STREAM_CANCELLED error code, and the session will be closed. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 2871 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2872 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2873 | |
| 2874 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2875 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2876 | |
| 2877 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2878 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2879 | } |
| 2880 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2881 | TEST_P(QuicStreamFactoryTest, |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2882 | OnNetworkDisconnectedConnectionMigrationDisabled) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2883 | InitializeConnectionMigrationV2Test( |
| 2884 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2885 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2886 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2887 | |
| 2888 | MockQuicData socket_data; |
| 2889 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2890 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 2891 | socket_data.AddWrite( |
| 2892 | SYNCHRONOUS, |
| 2893 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2894 | quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2895 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2896 | |
| 2897 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 2898 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2899 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2900 | request.Request( |
| 2901 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2902 | SocketTag(), |
| 2903 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2904 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2905 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 2906 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2907 | EXPECT_TRUE(stream.get()); |
| 2908 | |
| 2909 | // Cause QUIC stream to be created. |
| 2910 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 2911 | request_info.traffic_annotation = |
| 2912 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 2913 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 2914 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2915 | |
| 2916 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 2917 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2918 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2919 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2920 | |
| 2921 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2922 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 2923 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2924 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 2925 | |
| 2926 | // Trigger connection migration. Since there is a non-migratable stream, |
| 2927 | // this should cause a RST_STREAM frame to be emitted with |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 2928 | // quic::QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 2929 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2930 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 2931 | |
| 2932 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2933 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2934 | |
| 2935 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2936 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2937 | } |
| 2938 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2939 | TEST_P(QuicStreamFactoryTest, OnNetworkMadeDefaultNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2940 | InitializeConnectionMigrationV2Test( |
| 2941 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2942 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2943 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2944 | |
| 2945 | MockQuicData socket_data; |
| 2946 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2947 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 2948 | socket_data.AddWrite( |
| 2949 | SYNCHRONOUS, |
| 2950 | client_maker_.MakeConnectionClosePacket( |
| 2951 | 2, true, quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, |
| 2952 | "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2953 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2954 | |
| 2955 | // Create request and QuicHttpStream. |
| 2956 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2957 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2958 | request.Request( |
| 2959 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2960 | SocketTag(), |
| 2961 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 2962 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2963 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 2964 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 2965 | EXPECT_TRUE(stream.get()); |
| 2966 | |
| 2967 | // Ensure that session is alive and active. |
| 2968 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 2969 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2970 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 2971 | |
| 2972 | // Trigger connection migration. |
| 2973 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 2974 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 2975 | |
| 2976 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 2977 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 2978 | |
| 2979 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2980 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2981 | } |
| 2982 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 2983 | TEST_P(QuicStreamFactoryTest, OnNetworkDisconnectedNoOpenStreams) { |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2984 | InitializeConnectionMigrationV2Test( |
| 2985 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 2986 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 2987 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 2988 | |
| 2989 | MockQuicData socket_data; |
| 2990 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 2991 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 2992 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 2993 | |
| 2994 | // Create request and QuicHttpStream. |
| 2995 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 2996 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 2997 | request.Request( |
| 2998 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 2999 | SocketTag(), |
| 3000 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3001 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3002 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3003 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3004 | EXPECT_TRUE(stream.get()); |
| 3005 | |
| 3006 | // Ensure that session is alive and active. |
| 3007 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3008 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3009 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3010 | |
| 3011 | // Trigger connection migration. Since there are no active streams, |
| 3012 | // the session will be closed. |
| 3013 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3014 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3015 | |
| 3016 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3017 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3018 | |
| 3019 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3020 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3021 | } |
| 3022 | |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3023 | // This test verifies session migrates to the alternate network immediately when |
| 3024 | // default network disconnects with a synchronous write before migration. |
| 3025 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedSync) { |
| 3026 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ false); |
| 3027 | } |
| 3028 | |
| 3029 | // This test verifies session migrates to the alternate network immediately when |
| 3030 | // default network disconnects with an asynchronously write before migration. |
| 3031 | TEST_P(QuicStreamFactoryTest, MigrateOnDefaultNetworkDisconnectedAsync) { |
| 3032 | TestMigrationOnNetworkDisconnected(/*async_write_before*/ true); |
| 3033 | } |
| 3034 | |
| 3035 | void QuicStreamFactoryTestBase::TestMigrationOnNetworkDisconnected( |
| 3036 | bool async_write_before) { |
| 3037 | InitializeConnectionMigrationV2Test( |
| 3038 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3039 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3040 | ->NotifyNetworkMadeDefault(kDefaultNetworkForTests); |
| 3041 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3042 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3043 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3044 | |
| 3045 | // Use the test task runner. |
| 3046 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3047 | |
| 3048 | int packet_number = 1; |
| 3049 | MockQuicData socket_data; |
| 3050 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3051 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3052 | socket_data.AddWrite( |
| 3053 | SYNCHRONOUS, |
| 3054 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 3055 | socket_data.AddWrite( |
| 3056 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3057 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3058 | true, &header_stream_offset)); |
| 3059 | if (async_write_before) { |
| 3060 | socket_data.AddWrite(ASYNC, OK); |
| 3061 | packet_number++; |
| 3062 | } |
| 3063 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3064 | |
| 3065 | // Create request and QuicHttpStream. |
| 3066 | QuicStreamRequest request(factory_.get()); |
| 3067 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3068 | request.Request( |
| 3069 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3070 | SocketTag(), |
| 3071 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3072 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3073 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3074 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3075 | EXPECT_TRUE(stream.get()); |
| 3076 | |
| 3077 | // Cause QUIC stream to be created. |
| 3078 | HttpRequestInfo request_info; |
| 3079 | request_info.method = "GET"; |
| 3080 | request_info.url = url_; |
| 3081 | request_info.traffic_annotation = |
| 3082 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3083 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3084 | net_log_, CompletionOnceCallback())); |
| 3085 | |
| 3086 | // Ensure that session is alive and active. |
| 3087 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3088 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3089 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3090 | |
| 3091 | // Send GET request on stream. |
| 3092 | HttpResponseInfo response; |
| 3093 | HttpRequestHeaders request_headers; |
| 3094 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3095 | callback_.callback())); |
| 3096 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3097 | if (async_write_before) |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3098 | session->SendPing(); |
Zhongyi Shi | 9f316b26 | 2018-06-18 22:01:16 | [diff] [blame] | 3099 | |
| 3100 | // Set up second socket data provider that is used after migration. |
| 3101 | // The response to the earlier request is read on this new socket. |
| 3102 | MockQuicData socket_data1; |
| 3103 | socket_data1.AddWrite( |
| 3104 | SYNCHRONOUS, |
| 3105 | client_maker_.MakePingPacket(packet_number++, /*include_version=*/true)); |
| 3106 | socket_data1.AddRead( |
| 3107 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3108 | false, false)); |
| 3109 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3110 | socket_data1.AddWrite( |
| 3111 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3112 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 3113 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 3114 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3115 | |
| 3116 | // Trigger connection migration. |
| 3117 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3118 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3119 | |
| 3120 | // The connection should still be alive, not marked as going away. |
| 3121 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3122 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3123 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3124 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3125 | |
| 3126 | // Ensure that the session is still alive. |
| 3127 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3128 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3129 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3130 | |
| 3131 | // Run the message loop so that data queued in the new socket is read by the |
| 3132 | // packet reader. |
| 3133 | runner_->RunNextTask(); |
| 3134 | |
| 3135 | // Response headers are received over the new network. |
| 3136 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3137 | EXPECT_EQ(200, response.headers->response_code()); |
| 3138 | |
| 3139 | // Check that the session is still alive. |
| 3140 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3141 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3142 | |
| 3143 | // There should be posted tasks not executed, which is to migrate back to |
| 3144 | // default network. |
| 3145 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3146 | |
| 3147 | // Receive signal to mark new network as default. |
| 3148 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3149 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3150 | |
| 3151 | stream.reset(); |
| 3152 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3153 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3154 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3155 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3156 | } |
| 3157 | |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3158 | // This test receives NCN signals in the following order: |
| 3159 | // - default network disconnected |
| 3160 | // - after a pause, new network is connected. |
| 3161 | // - new network is made default. |
| 3162 | TEST_P(QuicStreamFactoryTest, NewNetworkConnectedAfterNoNetwork) { |
| 3163 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 3164 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3165 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3166 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3167 | |
| 3168 | // Use the test task runner. |
| 3169 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 3170 | |
| 3171 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3172 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3173 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3174 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3175 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 3176 | socket_data.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 3177 | 2, GetNthClientInitiatedStreamId(0), |
| 3178 | true, true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3179 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3180 | |
| 3181 | // Create request and QuicHttpStream. |
| 3182 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 3183 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3184 | request.Request( |
| 3185 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3186 | SocketTag(), |
| 3187 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3188 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3189 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3190 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3191 | EXPECT_TRUE(stream.get()); |
| 3192 | |
| 3193 | // Cause QUIC stream to be created. |
| 3194 | HttpRequestInfo request_info; |
| 3195 | request_info.method = "GET"; |
| 3196 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 3197 | request_info.traffic_annotation = |
| 3198 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 3199 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 3200 | net_log_, CompletionOnceCallback())); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3201 | |
| 3202 | // Ensure that session is alive and active. |
| 3203 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3204 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3205 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3206 | |
| 3207 | // Send GET request on stream. |
| 3208 | HttpResponseInfo response; |
| 3209 | HttpRequestHeaders request_headers; |
| 3210 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3211 | callback_.callback())); |
| 3212 | |
| 3213 | // Trigger connection migration. Since there are no networks |
| 3214 | // to migrate to, this should cause the session to wait for a new network. |
| 3215 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3216 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 3217 | |
| 3218 | // The connection should still be alive, not marked as going away. |
| 3219 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3220 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3221 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3222 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3223 | |
| 3224 | // Set up second socket data provider that is used after migration. |
| 3225 | // The response to the earlier request is read on this new socket. |
| 3226 | MockQuicData socket_data1; |
| 3227 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3228 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 3229 | socket_data1.AddRead( |
| 3230 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3231 | false, false)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3232 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 3233 | socket_data1.AddWrite(SYNCHRONOUS, |
| 3234 | client_maker_.MakeAckAndRstPacket( |
| 3235 | 4, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3236 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 3237 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3238 | |
| 3239 | // Add a new network and notify the stream factory of a new connected network. |
| 3240 | // This causes a PING packet to be sent over the new network. |
| 3241 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3242 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 3243 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3244 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 3245 | |
| 3246 | // Ensure that the session is still alive. |
| 3247 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3248 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3249 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3250 | |
| 3251 | // Run the message loop so that data queued in the new socket is read by the |
| 3252 | // packet reader. |
| 3253 | runner_->RunNextTask(); |
| 3254 | |
| 3255 | // Response headers are received over the new network. |
| 3256 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3257 | EXPECT_EQ(200, response.headers->response_code()); |
| 3258 | |
| 3259 | // Check that the session is still alive. |
| 3260 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3261 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3262 | |
| 3263 | // There should posted tasks not executed, which is to migrate back to default |
| 3264 | // network. |
| 3265 | EXPECT_FALSE(runner_->GetPostedTasks().empty()); |
| 3266 | |
| 3267 | // Receive signal to mark new network as default. |
| 3268 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3269 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3270 | |
| 3271 | stream.reset(); |
| 3272 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 3273 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 3274 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 3275 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 3276 | } |
| 3277 | |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3278 | // Regression test for http://crbug.com/872011. |
| 3279 | // This test verifies that migrate to the probing socket will not trigger |
| 3280 | // new packets being read synchronously and generate ACK frame while |
| 3281 | // processing the initial connectivity probe response, which may cause a |
| 3282 | // connection being closed with INTERNAL_ERROR as pending ACK frame is not |
| 3283 | // allowed when processing a new packet. |
| 3284 | TEST_P(QuicStreamFactoryTest, MigrateToProbingSocket) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 3285 | if (version_ == quic::QUIC_VERSION_99) |
| 3286 | return; |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3287 | InitializeConnectionMigrationV2Test( |
| 3288 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3289 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3290 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3291 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3292 | |
| 3293 | // Using a testing task runner so that we can control time. |
| 3294 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3295 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3296 | |
| 3297 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3298 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3299 | |
| 3300 | int packet_number = 1; |
| 3301 | MockQuicData quic_data1; |
| 3302 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3303 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 3304 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3305 | packet_number++, &header_stream_offset)); |
| 3306 | quic_data1.AddWrite( |
| 3307 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3308 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3309 | true, &header_stream_offset)); |
| 3310 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3311 | |
| 3312 | // Set up the second socket data provider that is used for probing on the |
| 3313 | // alternate network. |
| 3314 | MockQuicData quic_data2; |
| 3315 | // Connectivity probe to be sent on the new path. |
| 3316 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
| 3317 | packet_number++, true)); |
| 3318 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3319 | // First connectivity probe to receive from the server, which will complete |
| 3320 | // connection migraiton on path degrading. |
| 3321 | quic_data2.AddRead(ASYNC, |
| 3322 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
| 3323 | // Read multiple connectivity probes synchronously. |
| 3324 | quic_data2.AddRead(SYNCHRONOUS, |
| 3325 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
| 3326 | quic_data2.AddRead(SYNCHRONOUS, |
| 3327 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
| 3328 | quic_data2.AddRead(SYNCHRONOUS, |
| 3329 | server_maker_.MakeConnectivityProbingPacket(4, false)); |
| 3330 | quic_data2.AddWrite( |
| 3331 | ASYNC, client_maker_.MakeAckPacket(packet_number++, 1, 4, 1, 1, true)); |
| 3332 | quic_data2.AddRead( |
| 3333 | ASYNC, ConstructOkResponsePacket(5, GetNthClientInitiatedStreamId(0), |
| 3334 | false, false)); |
| 3335 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3336 | quic_data2.AddWrite( |
| 3337 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3338 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 3339 | quic::QUIC_STREAM_CANCELLED, 5, 1, 1, true)); |
| 3340 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3341 | |
| 3342 | // Create request and QuicHttpStream. |
| 3343 | QuicStreamRequest request(factory_.get()); |
| 3344 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3345 | request.Request( |
| 3346 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3347 | SocketTag(), |
| 3348 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3349 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | d3d5f50 | 2018-08-10 00:22:22 | [diff] [blame] | 3350 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3351 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3352 | EXPECT_TRUE(stream.get()); |
| 3353 | |
| 3354 | // Cause QUIC stream to be created. |
| 3355 | HttpRequestInfo request_info; |
| 3356 | request_info.method = "GET"; |
| 3357 | request_info.url = url_; |
| 3358 | request_info.traffic_annotation = |
| 3359 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3360 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3361 | net_log_, CompletionOnceCallback())); |
| 3362 | |
| 3363 | // Ensure that session is alive and active. |
| 3364 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3365 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3366 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3367 | |
| 3368 | // Send GET request on stream. |
| 3369 | HttpResponseInfo response; |
| 3370 | HttpRequestHeaders request_headers; |
| 3371 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3372 | callback_.callback())); |
| 3373 | |
| 3374 | // Cause the connection to report path degrading to the session. |
| 3375 | // Session will start to probe the alternate network. |
| 3376 | session->connection()->OnPathDegradingTimeout(); |
| 3377 | |
| 3378 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3379 | // kDefaultRTTMilliSecs. |
| 3380 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3381 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3382 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3383 | next_task_delay); |
| 3384 | |
| 3385 | // The connection should still be alive, and not marked as going away. |
| 3386 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3387 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3388 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3389 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3390 | |
| 3391 | // Resume quic data and a connectivity probe response will be read on the new |
| 3392 | // socket. |
| 3393 | quic_data2.Resume(); |
| 3394 | |
| 3395 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3396 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3397 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3398 | |
| 3399 | // There should be three pending tasks, the nearest one will complete |
| 3400 | // migration to the new network. |
| 3401 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3402 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3403 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3404 | task_runner->FastForwardBy(next_task_delay); |
| 3405 | |
| 3406 | // Response headers are received over the new network. |
| 3407 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3408 | EXPECT_EQ(200, response.headers->response_code()); |
| 3409 | |
| 3410 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3411 | // probe and has been cancelled due to successful migration. |
| 3412 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3413 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3414 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3415 | next_task_delay); |
| 3416 | task_runner->FastForwardBy(next_task_delay); |
| 3417 | |
| 3418 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3419 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3420 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3421 | base::TimeDelta expected_delay = |
| 3422 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3423 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3424 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3425 | |
| 3426 | // Deliver a signal that the alternate network now becomes default to session, |
| 3427 | // this will cancel mgirate back to default network timer. |
| 3428 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3429 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3430 | |
| 3431 | task_runner->FastForwardBy(next_task_delay); |
| 3432 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3433 | |
| 3434 | // Verify that the session is still alive. |
| 3435 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3436 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3437 | |
| 3438 | stream.reset(); |
| 3439 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3440 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3441 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3442 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3443 | } |
| 3444 | |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3445 | // This test verifies that the connection migrates to the alternate network |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3446 | // early when path degrading is detected with an ASYNCHRONOUS write before |
| 3447 | // migration. |
| 3448 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingAysnc) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 3449 | if (version_ == quic::QUIC_VERSION_99) |
| 3450 | return; |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3451 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ true); |
| 3452 | } |
| 3453 | |
| 3454 | // This test verifies that the connection migrates to the alternate network |
| 3455 | // early when path degrading is detected with a SYNCHRONOUS write before |
| 3456 | // migration. |
| 3457 | TEST_P(QuicStreamFactoryTest, MigrateEarlyOnPathDegradingSync) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 3458 | if (version_ == quic::QUIC_VERSION_99) |
| 3459 | return; |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3460 | TestMigrationOnPathDegrading(/*async_write_before_migration*/ false); |
| 3461 | } |
| 3462 | |
| 3463 | void QuicStreamFactoryTestBase::TestMigrationOnPathDegrading( |
| 3464 | bool async_write_before) { |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3465 | InitializeConnectionMigrationV2Test( |
| 3466 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3467 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3468 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3469 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3470 | |
| 3471 | // Using a testing task runner so that we can control time. |
| 3472 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3473 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3474 | |
| 3475 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3476 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3477 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3478 | int packet_number = 1; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3479 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 3480 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3481 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3482 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3483 | packet_number++, &header_stream_offset)); |
| 3484 | quic_data1.AddWrite( |
| 3485 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3486 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3487 | true, &header_stream_offset)); |
| 3488 | if (async_write_before) { |
| 3489 | quic_data1.AddWrite(ASYNC, OK); |
| 3490 | packet_number++; |
| 3491 | } |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3492 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3493 | |
| 3494 | // Set up the second socket data provider that is used after migration. |
| 3495 | // The response to the earlier request is read on the new socket. |
| 3496 | MockQuicData quic_data2; |
| 3497 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3498 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3499 | packet_number++, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3500 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3501 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3502 | quic_data2.AddRead(ASYNC, |
| 3503 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3504 | // Ping packet to send after migration is completed. |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3505 | quic_data2.AddWrite(ASYNC, client_maker_.MakeAckAndPingPacket( |
| 3506 | packet_number++, false, 1, 1, 1)); |
Ryan Hamilton | a3ee93a7 | 2018-08-01 22:03:08 | [diff] [blame] | 3507 | quic_data2.AddRead( |
| 3508 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 3509 | false, false)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3510 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3511 | quic_data2.AddWrite( |
| 3512 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 3513 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 3514 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3515 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3516 | |
| 3517 | // Create request and QuicHttpStream. |
| 3518 | QuicStreamRequest request(factory_.get()); |
| 3519 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3520 | request.Request( |
| 3521 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3522 | SocketTag(), |
| 3523 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3524 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 3525 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3526 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3527 | EXPECT_TRUE(stream.get()); |
| 3528 | |
| 3529 | // Cause QUIC stream to be created. |
| 3530 | HttpRequestInfo request_info; |
| 3531 | request_info.method = "GET"; |
| 3532 | request_info.url = url_; |
| 3533 | request_info.traffic_annotation = |
| 3534 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3535 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3536 | net_log_, CompletionOnceCallback())); |
| 3537 | |
| 3538 | // Ensure that session is alive and active. |
| 3539 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3540 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3541 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3542 | |
| 3543 | // Send GET request on stream. |
| 3544 | HttpResponseInfo response; |
| 3545 | HttpRequestHeaders request_headers; |
| 3546 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3547 | callback_.callback())); |
| 3548 | |
Zhongyi Shi | 22fd5f5 | 2018-06-20 17:39:09 | [diff] [blame] | 3549 | if (async_write_before) |
| 3550 | session->SendPing(); |
| 3551 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 3552 | // Cause the connection to report path degrading to the session. |
| 3553 | // Session will start to probe the alternate network. |
| 3554 | session->connection()->OnPathDegradingTimeout(); |
| 3555 | |
| 3556 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3557 | // kDefaultRTTMilliSecs. |
| 3558 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3559 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3560 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3561 | next_task_delay); |
| 3562 | |
| 3563 | // The connection should still be alive, and not marked as going away. |
| 3564 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3565 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3566 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3567 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3568 | |
| 3569 | // Resume quic data and a connectivity probe response will be read on the new |
| 3570 | // socket. |
| 3571 | quic_data2.Resume(); |
| 3572 | |
| 3573 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3574 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3575 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3576 | |
| 3577 | // There should be three pending tasks, the nearest one will complete |
| 3578 | // migration to the new network. |
| 3579 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3580 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3581 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3582 | task_runner->FastForwardBy(next_task_delay); |
| 3583 | |
| 3584 | // Response headers are received over the new network. |
| 3585 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3586 | EXPECT_EQ(200, response.headers->response_code()); |
| 3587 | |
| 3588 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3589 | // probe and has been cancelled due to successful migration. |
| 3590 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3591 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3592 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3593 | next_task_delay); |
| 3594 | task_runner->FastForwardBy(next_task_delay); |
| 3595 | |
| 3596 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3597 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3598 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3599 | base::TimeDelta expected_delay = |
| 3600 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3601 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3602 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3603 | |
| 3604 | // Deliver a signal that the alternate network now becomes default to session, |
| 3605 | // this will cancel mgirate back to default network timer. |
| 3606 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3607 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3608 | |
| 3609 | task_runner->FastForwardBy(next_task_delay); |
| 3610 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3611 | |
| 3612 | // Verify that the session is still alive. |
| 3613 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3614 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3615 | |
| 3616 | stream.reset(); |
| 3617 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3618 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3619 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3620 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3621 | } |
| 3622 | |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3623 | // This test verifies that the session marks itself GOAWAY on path degrading |
| 3624 | // and it does not receive any new request |
| 3625 | TEST_P(QuicStreamFactoryTest, GoawayOnPathDegrading) { |
| 3626 | go_away_on_path_degrading_ = true; |
| 3627 | Initialize(); |
| 3628 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3629 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3630 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3631 | |
| 3632 | MockQuicData quic_data1; |
| 3633 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3634 | quic_data1.AddWrite(SYNCHRONOUS, |
| 3635 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 3636 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 3637 | 2, GetNthClientInitiatedStreamId(0), |
| 3638 | true, true, &header_stream_offset)); |
| 3639 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3640 | quic_data1.AddRead( |
| 3641 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3642 | false, true)); |
| 3643 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3644 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3645 | |
| 3646 | MockQuicData quic_data2; |
| 3647 | quic::QuicStreamOffset header_stream_offset2 = 0; |
| 3648 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 3649 | quic_data2.AddWrite( |
| 3650 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset2)); |
| 3651 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3652 | |
| 3653 | // Creat request and QuicHttpStream. |
| 3654 | QuicStreamRequest request(factory_.get()); |
| 3655 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3656 | request.Request( |
| 3657 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3658 | SocketTag(), |
| 3659 | /*cerf_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3660 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3661 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3662 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3663 | EXPECT_TRUE(stream.get()); |
| 3664 | |
| 3665 | // Cause QUIC stream to be created. |
| 3666 | HttpRequestInfo request_info; |
| 3667 | request_info.method = "GET"; |
| 3668 | request_info.url = url_; |
| 3669 | request_info.traffic_annotation = |
| 3670 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3671 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3672 | net_log_, CompletionOnceCallback())); |
| 3673 | |
| 3674 | // Ensure that session is alive and active. |
| 3675 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3676 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3677 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3678 | |
| 3679 | // Send GET request on stream. |
| 3680 | HttpResponseInfo response; |
| 3681 | HttpRequestHeaders request_headers; |
| 3682 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3683 | callback_.callback())); |
| 3684 | |
| 3685 | // Trigger the connection to report path degrading to the session. |
| 3686 | // Session will mark itself GOAWAY. |
| 3687 | session->connection()->OnPathDegradingTimeout(); |
| 3688 | |
| 3689 | // The connection should still be alive, but marked as going away. |
| 3690 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 3691 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3692 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3693 | |
| 3694 | // Second request should be sent on a new connection. |
| 3695 | QuicStreamRequest request2(factory_.get()); |
| 3696 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3697 | request2.Request( |
| 3698 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3699 | SocketTag(), |
| 3700 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3701 | failed_on_default_network_callback_, callback_.callback())); |
Renjie | a5722ccf | 2018-08-10 00:18:49 | [diff] [blame] | 3702 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3703 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 3704 | EXPECT_TRUE(stream2.get()); |
| 3705 | |
| 3706 | // Resume the data, verify old request can read response on the old session |
| 3707 | // successfully. |
| 3708 | quic_data1.Resume(); |
| 3709 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 3710 | EXPECT_EQ(200, response.headers->response_code()); |
| 3711 | EXPECT_EQ(0U, session->GetNumActiveStreams()); |
| 3712 | |
| 3713 | // Check an active session exists for the destination. |
| 3714 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3715 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3716 | QuicChromiumClientSession* session2 = GetActiveSession(host_port_pair_); |
| 3717 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 3718 | EXPECT_NE(session, session2); |
| 3719 | |
| 3720 | stream.reset(); |
| 3721 | stream2.reset(); |
| 3722 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 3723 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 3724 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 3725 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 3726 | } |
| 3727 | |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3728 | // This test verifies that the connection will not migrate to a bad socket |
| 3729 | // when path degrading is detected. |
| 3730 | TEST_P(QuicStreamFactoryTest, DoNotMigrateToBadSocketOnPathDegrading) { |
| 3731 | InitializeConnectionMigrationV2Test( |
| 3732 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3733 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3734 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3735 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3736 | |
| 3737 | // Using a testing task runner so that we can control time. |
| 3738 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3739 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3740 | |
| 3741 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3742 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3743 | |
| 3744 | MockQuicData quic_data; |
| 3745 | quic::QuicStreamOffset header_stream_offset = 0; |
| 3746 | quic_data.AddWrite(SYNCHRONOUS, |
| 3747 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 3748 | quic_data.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 3749 | 2, GetNthClientInitiatedStreamId(0), true, |
| 3750 | true, &header_stream_offset)); |
| 3751 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3752 | quic_data.AddRead( |
| 3753 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3754 | false, false)); |
| 3755 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3756 | quic_data.AddWrite(SYNCHRONOUS, |
| 3757 | client_maker_.MakeAckAndRstPacket( |
| 3758 | 3, false, GetNthClientInitiatedStreamId(0), |
| 3759 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 3760 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 3761 | |
| 3762 | // Set up second socket that will immediately return disconnected. |
| 3763 | // The stream factory will abort probe the alternate network. |
| 3764 | MockConnect bad_connect = MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
| 3765 | SequencedSocketData socket_data(bad_connect, base::span<MockRead>(), |
| 3766 | base::span<MockWrite>()); |
| 3767 | socket_factory_->AddSocketDataProvider(&socket_data); |
| 3768 | |
| 3769 | // Create request and QuicHttpStream. |
| 3770 | QuicStreamRequest request(factory_.get()); |
| 3771 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3772 | request.Request( |
| 3773 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3774 | SocketTag(), |
| 3775 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3776 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | bb770d9 | 2018-06-16 02:07:00 | [diff] [blame] | 3777 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3778 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3779 | EXPECT_TRUE(stream.get()); |
| 3780 | |
| 3781 | // Cause QUIC stream to be created. |
| 3782 | HttpRequestInfo request_info; |
| 3783 | request_info.method = "GET"; |
| 3784 | request_info.url = url_; |
| 3785 | request_info.traffic_annotation = |
| 3786 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3787 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3788 | net_log_, CompletionOnceCallback())); |
| 3789 | |
| 3790 | // Ensure that session is alive and active. |
| 3791 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3792 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3793 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3794 | |
| 3795 | // Send GET request on stream. |
| 3796 | HttpResponseInfo response; |
| 3797 | HttpRequestHeaders request_headers; |
| 3798 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3799 | callback_.callback())); |
| 3800 | |
| 3801 | // Cause the connection to report path degrading to the session. |
| 3802 | // Session will start to probe the alternate network. |
| 3803 | session->connection()->OnPathDegradingTimeout(); |
| 3804 | |
| 3805 | // The connection should still be alive, and not marked as going away. |
| 3806 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3807 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3808 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 3809 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 3810 | |
| 3811 | // Resume the data, and response header is received over the original network. |
| 3812 | quic_data.Resume(); |
| 3813 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3814 | EXPECT_EQ(200, response.headers->response_code()); |
| 3815 | |
| 3816 | // Verify there is no pending task as probing alternate network is halted. |
| 3817 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 3818 | |
| 3819 | // Verify that the session is still alive. |
| 3820 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3821 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3822 | |
| 3823 | stream.reset(); |
| 3824 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 3825 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 3826 | } |
| 3827 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3828 | // Regression test for http://crbug.com/847569. |
| 3829 | // This test verifies that the connection migrates to the alternate network |
| 3830 | // early when there is no active stream but a draining stream. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3831 | // The first packet being written after migration is a synchrnous write, which |
| 3832 | // will cause a PING packet being sent. |
| 3833 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamSync) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 3834 | if (version_ == quic::QUIC_VERSION_99) |
| 3835 | return; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3836 | TestMigrateSessionWithDrainingStream(SYNCHRONOUS); |
| 3837 | } |
| 3838 | |
| 3839 | // Regression test for http://crbug.com/847569. |
| 3840 | // This test verifies that the connection migrates to the alternate network |
| 3841 | // early when there is no active stream but a draining stream. |
| 3842 | // The first packet being written after migration is an asynchronous write, no |
| 3843 | // PING packet will be sent. |
| 3844 | TEST_P(QuicStreamFactoryTest, MigrateSessionWithDrainingStreamAsync) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 3845 | if (version_ == quic::QUIC_VERSION_99) |
| 3846 | return; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3847 | TestMigrateSessionWithDrainingStream(ASYNC); |
| 3848 | } |
| 3849 | |
| 3850 | void QuicStreamFactoryTestBase::TestMigrateSessionWithDrainingStream( |
| 3851 | IoMode write_mode_for_queued_packet) { |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3852 | InitializeConnectionMigrationV2Test( |
| 3853 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 3854 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 3855 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3856 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 3857 | |
| 3858 | // Using a testing task runner so that we can control time. |
| 3859 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 3860 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 3861 | |
| 3862 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3863 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 3864 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3865 | int packet_number = 1; |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3866 | MockQuicData quic_data1; |
| 3867 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3868 | quic_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket( |
| 3869 | packet_number++, &header_stream_offset)); |
| 3870 | quic_data1.AddWrite( |
| 3871 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 3872 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 3873 | true, &header_stream_offset)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3874 | // Read an out of order packet with FIN to drain the stream. |
| 3875 | quic_data1.AddRead( |
| 3876 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 3877 | false, true)); // keep sending version. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3878 | quic_data1.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3879 | packet_number++, 2, 2, 2, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3880 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3881 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 3882 | |
| 3883 | // Set up the second socket data provider that is used after migration. |
| 3884 | MockQuicData quic_data2; |
| 3885 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3886 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeConnectivityProbingPacket( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3887 | packet_number++, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3888 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 3889 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 3890 | quic_data2.AddRead(ASYNC, |
| 3891 | server_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3892 | // Ping packet to send after migration is completed. |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3893 | quic_data2.AddWrite( |
| 3894 | write_mode_for_queued_packet, |
| 3895 | client_maker_.MakeAckPacket(packet_number++, 2, 3, 3, 1, true)); |
| 3896 | if (write_mode_for_queued_packet == SYNCHRONOUS) { |
| 3897 | quic_data2.AddWrite(ASYNC, |
| 3898 | client_maker_.MakePingPacket(packet_number++, false)); |
| 3899 | } |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3900 | quic_data2.AddRead( |
| 3901 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 3902 | false, false)); |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3903 | quic_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeAckPacket( |
| 3904 | packet_number++, 1, 3, 1, 1, true)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3905 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 3906 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 3907 | |
| 3908 | // Create request and QuicHttpStream. |
| 3909 | QuicStreamRequest request(factory_.get()); |
| 3910 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 3911 | request.Request( |
| 3912 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 3913 | SocketTag(), |
| 3914 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 3915 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3916 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 3917 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 3918 | EXPECT_TRUE(stream.get()); |
| 3919 | |
| 3920 | // Cause QUIC stream to be created. |
| 3921 | HttpRequestInfo request_info; |
| 3922 | request_info.method = "GET"; |
| 3923 | request_info.url = url_; |
| 3924 | request_info.traffic_annotation = |
| 3925 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 3926 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 3927 | net_log_, CompletionOnceCallback())); |
| 3928 | |
| 3929 | // Ensure that session is alive and active. |
| 3930 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 3931 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3932 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3933 | |
| 3934 | // Send GET request on stream. |
| 3935 | HttpResponseInfo response; |
| 3936 | HttpRequestHeaders request_headers; |
| 3937 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 3938 | callback_.callback())); |
| 3939 | |
| 3940 | // Run the message loop to receive the out of order packet which contains a |
| 3941 | // FIN and drains the stream. |
| 3942 | base::RunLoop().RunUntilIdle(); |
| 3943 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3944 | |
| 3945 | // Cause the connection to report path degrading to the session. |
| 3946 | // Session should still start to probe the alternate network. |
| 3947 | session->connection()->OnPathDegradingTimeout(); |
| 3948 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 3949 | |
| 3950 | // Next connectivity probe is scheduled to be sent in 2 * |
| 3951 | // kDefaultRTTMilliSecs. |
| 3952 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3953 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3954 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3955 | next_task_delay); |
| 3956 | |
| 3957 | // The connection should still be alive, and not marked as going away. |
| 3958 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3959 | |
| 3960 | // Resume quic data and a connectivity probe response will be read on the new |
| 3961 | // socket. |
| 3962 | quic_data2.Resume(); |
| 3963 | |
| 3964 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 3965 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 3966 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
| 3967 | EXPECT_EQ(1u, session->GetNumDrainingStreams()); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3968 | |
| 3969 | // There should be three pending tasks, the nearest one will complete |
| 3970 | // migration to the new network. |
| 3971 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 3972 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3973 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 3974 | task_runner->FastForwardBy(next_task_delay); |
| 3975 | |
| 3976 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 3977 | // probe and has been cancelled due to successful migration. |
| 3978 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 3979 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3980 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 3981 | next_task_delay); |
| 3982 | task_runner->FastForwardBy(next_task_delay); |
| 3983 | |
| 3984 | // There's one more task to mgirate back to the default network in 0.4s. |
| 3985 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 3986 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 3987 | base::TimeDelta expected_delay = |
| 3988 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 3989 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 3990 | EXPECT_EQ(expected_delay, next_task_delay); |
| 3991 | |
Zhongyi Shi | b3bc982c | 2018-07-10 19:59:24 | [diff] [blame] | 3992 | base::RunLoop().RunUntilIdle(); |
| 3993 | |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 3994 | // Deliver a signal that the alternate network now becomes default to session, |
| 3995 | // this will cancel mgirate back to default network timer. |
| 3996 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 3997 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 3998 | |
| 3999 | task_runner->FastForwardBy(next_task_delay); |
| 4000 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4001 | |
| 4002 | // Verify that the session is still alive. |
| 4003 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4004 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 4005 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
Zhongyi Shi | f5cc3039 | 2018-05-30 18:25:15 | [diff] [blame] | 4006 | |
| 4007 | stream.reset(); |
| 4008 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4009 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4010 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4011 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4012 | } |
| 4013 | |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4014 | // Regression test for http://crbug.com/835444. |
| 4015 | // This test verifies that the connection migrates to the alternate network |
| 4016 | // when the alternate network is connected after path has been degrading. |
| 4017 | TEST_P(QuicStreamFactoryTest, MigrateOnNewNetworkConnectAfterPathDegrading) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 4018 | if (version_ == quic::QUIC_VERSION_99) |
| 4019 | return; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4020 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4021 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4022 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4023 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4024 | |
| 4025 | // Using a testing task runner so that we can control time. |
| 4026 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4027 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4028 | |
| 4029 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4030 | ->QueueNetworkMadeDefault(kDefaultNetworkForTests); |
| 4031 | |
| 4032 | MockQuicData quic_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4033 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4034 | quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging Read. |
| 4035 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4036 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4037 | quic_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4038 | 2, GetNthClientInitiatedStreamId(0), |
| 4039 | true, true, &header_stream_offset)); |
| 4040 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4041 | |
| 4042 | // Set up the second socket data provider that is used after migration. |
| 4043 | // The response to the earlier request is read on the new socket. |
| 4044 | MockQuicData quic_data2; |
| 4045 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4046 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4047 | client_maker_.MakeConnectivityProbingPacket(3, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4048 | quic_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4049 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4050 | quic_data2.AddRead(ASYNC, |
| 4051 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4052 | // Ping packet to send after migration is completed. |
| 4053 | quic_data2.AddWrite(ASYNC, |
| 4054 | client_maker_.MakeAckAndPingPacket(4, false, 1, 1, 1)); |
| 4055 | quic_data2.AddRead( |
| 4056 | ASYNC, ConstructOkResponsePacket(2, GetNthClientInitiatedStreamId(0), |
| 4057 | false, false)); |
| 4058 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4059 | quic_data2.AddWrite(SYNCHRONOUS, |
| 4060 | client_maker_.MakeAckAndRstPacket( |
| 4061 | 5, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4062 | quic::QUIC_STREAM_CANCELLED, 2, 2, 1, true)); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4063 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4064 | |
| 4065 | // Create request and QuicHttpStream. |
| 4066 | QuicStreamRequest request(factory_.get()); |
| 4067 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4068 | request.Request( |
| 4069 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4070 | SocketTag(), |
| 4071 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4072 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | aba4a83 | 2018-04-30 20:29:08 | [diff] [blame] | 4073 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4074 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 4075 | EXPECT_TRUE(stream.get()); |
| 4076 | |
| 4077 | // Cause QUIC stream to be created. |
| 4078 | HttpRequestInfo request_info; |
| 4079 | request_info.method = "GET"; |
| 4080 | request_info.url = url_; |
| 4081 | request_info.traffic_annotation = |
| 4082 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4083 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 4084 | net_log_, CompletionOnceCallback())); |
| 4085 | |
| 4086 | // Ensure that session is alive and active. |
| 4087 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4088 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4089 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4090 | |
| 4091 | // Send GET request on stream. |
| 4092 | HttpResponseInfo response; |
| 4093 | HttpRequestHeaders request_headers; |
| 4094 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4095 | callback_.callback())); |
| 4096 | |
| 4097 | // Cause the connection to report path degrading to the session. |
| 4098 | // Due to lack of alternate network, session will not mgirate connection. |
| 4099 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4100 | session->connection()->OnPathDegradingTimeout(); |
| 4101 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4102 | |
| 4103 | // Deliver a signal that a alternate network is connected now, this should |
| 4104 | // cause the connection to start early migration on path degrading. |
| 4105 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4106 | ->SetConnectedNetworksList( |
| 4107 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4108 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4109 | ->NotifyNetworkConnected(kNewNetworkForTests); |
Zhongyi Shi | c4823bd | 2018-04-27 00:49:19 | [diff] [blame] | 4110 | |
| 4111 | // Next connectivity probe is scheduled to be sent in 2 * |
| 4112 | // kDefaultRTTMilliSecs. |
| 4113 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4114 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4115 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4116 | next_task_delay); |
| 4117 | |
| 4118 | // The connection should still be alive, and not marked as going away. |
| 4119 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4120 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4121 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4122 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4123 | |
| 4124 | // Resume quic data and a connectivity probe response will be read on the new |
| 4125 | // socket. |
| 4126 | quic_data2.Resume(); |
| 4127 | |
| 4128 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4129 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4130 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4131 | |
| 4132 | // There should be three pending tasks, the nearest one will complete |
| 4133 | // migration to the new network. |
| 4134 | EXPECT_EQ(3u, task_runner->GetPendingTaskCount()); |
| 4135 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4136 | EXPECT_EQ(base::TimeDelta(), next_task_delay); |
| 4137 | task_runner->FastForwardBy(next_task_delay); |
| 4138 | |
| 4139 | // Response headers are received over the new network. |
| 4140 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4141 | EXPECT_EQ(200, response.headers->response_code()); |
| 4142 | |
| 4143 | // Now there are two pending tasks, the nearest one was to send connectivity |
| 4144 | // probe and has been cancelled due to successful migration. |
| 4145 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4146 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4147 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 4148 | next_task_delay); |
| 4149 | task_runner->FastForwardBy(next_task_delay); |
| 4150 | |
| 4151 | // There's one more task to mgirate back to the default network in 0.4s. |
| 4152 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4153 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 4154 | base::TimeDelta expected_delay = |
| 4155 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs) - |
| 4156 | base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs); |
| 4157 | EXPECT_EQ(expected_delay, next_task_delay); |
| 4158 | |
| 4159 | // Deliver a signal that the alternate network now becomes default to session, |
| 4160 | // this will cancel mgirate back to default network timer. |
| 4161 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4162 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 4163 | |
| 4164 | task_runner->FastForwardBy(next_task_delay); |
| 4165 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4166 | |
| 4167 | // Verify that the session is still alive. |
| 4168 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4169 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4170 | |
| 4171 | stream.reset(); |
| 4172 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4173 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
| 4174 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4175 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4176 | } |
| 4177 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4178 | // This test verifies that multiple sessions are migrated on connection |
| 4179 | // migration signal. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4180 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4181 | MigrateMultipleSessionsToBadSocketsAfterDisconnected) { |
| 4182 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4183 | |
| 4184 | MockQuicData socket_data1; |
| 4185 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4186 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4187 | socket_data1.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4188 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4189 | MockQuicData socket_data2; |
| 4190 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4191 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4192 | socket_data2.AddWrite(ASYNC, OK); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4193 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4194 | |
| 4195 | HostPortPair server1(kDefaultServerHostName, 443); |
| 4196 | HostPortPair server2(kServer2HostName, 443); |
| 4197 | |
| 4198 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4199 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4200 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4201 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 4202 | host_resolver_->set_synchronous_mode(true); |
| 4203 | host_resolver_->rules()->AddIPLiteralRule(server1.host(), "192.168.0.1", ""); |
| 4204 | host_resolver_->rules()->AddIPLiteralRule(server2.host(), "192.168.0.2", ""); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4205 | |
| 4206 | // Create request and QuicHttpStream to create session1. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4207 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4208 | EXPECT_EQ(OK, |
| 4209 | request1.Request( |
| 4210 | server1, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4211 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4212 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4213 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4214 | EXPECT_TRUE(stream1.get()); |
| 4215 | |
| 4216 | // Create request and QuicHttpStream to create session2. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4217 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4218 | EXPECT_EQ(OK, |
| 4219 | request2.Request( |
| 4220 | server2, version_, privacy_mode_, DEFAULT_PRIORITY, SocketTag(), |
| 4221 | /*cert_verify_flags=*/0, url2_, net_log_, &net_error_details_, |
| 4222 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4223 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4224 | EXPECT_TRUE(stream2.get()); |
| 4225 | |
| 4226 | QuicChromiumClientSession* session1 = GetActiveSession(server1); |
| 4227 | QuicChromiumClientSession* session2 = GetActiveSession(server2); |
| 4228 | EXPECT_NE(session1, session2); |
| 4229 | |
| 4230 | // Cause QUIC stream to be created and send GET so session1 has an open |
| 4231 | // stream. |
| 4232 | HttpRequestInfo request_info1; |
| 4233 | request_info1.method = "GET"; |
| 4234 | request_info1.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4235 | request_info1.traffic_annotation = |
| 4236 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4237 | EXPECT_EQ(OK, |
| 4238 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4239 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4240 | HttpResponseInfo response1; |
| 4241 | HttpRequestHeaders request_headers1; |
| 4242 | EXPECT_EQ(OK, stream1->SendRequest(request_headers1, &response1, |
| 4243 | callback_.callback())); |
| 4244 | |
| 4245 | // Cause QUIC stream to be created and send GET so session2 has an open |
| 4246 | // stream. |
| 4247 | HttpRequestInfo request_info2; |
| 4248 | request_info2.method = "GET"; |
| 4249 | request_info2.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4250 | request_info2.traffic_annotation = |
| 4251 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4252 | EXPECT_EQ(OK, |
| 4253 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4254 | net_log_, CompletionOnceCallback())); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4255 | HttpResponseInfo response2; |
| 4256 | HttpRequestHeaders request_headers2; |
| 4257 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4258 | callback_.callback())); |
| 4259 | |
| 4260 | // Cause both sessions to be paused due to DISCONNECTED. |
| 4261 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4262 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 4263 | |
| 4264 | // Ensure that both sessions are paused but alive. |
| 4265 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4266 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4267 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4268 | // Add new sockets to use post migration. Those are bad sockets and will cause |
| 4269 | // migration to fail. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4270 | MockConnect connect_result = |
| 4271 | MockConnect(SYNCHRONOUS, ERR_INTERNET_DISCONNECTED); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4272 | SequencedSocketData socket_data3(connect_result, base::span<MockRead>(), |
| 4273 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4274 | socket_factory_->AddSocketDataProvider(&socket_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4275 | SequencedSocketData socket_data4(connect_result, base::span<MockRead>(), |
| 4276 | base::span<MockWrite>()); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4277 | socket_factory_->AddSocketDataProvider(&socket_data4); |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4278 | |
Zhongyi Shi | 28f6e35 | 2018-06-20 21:15:43 | [diff] [blame] | 4279 | // Connect the new network and cause migration to bad sockets, causing |
| 4280 | // sessions to close. |
jri | e3d187c | 2016-09-16 14:29:17 | [diff] [blame] | 4281 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4282 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 4283 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 4284 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 4285 | |
| 4286 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session1)); |
| 4287 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session2)); |
| 4288 | |
| 4289 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4290 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4291 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 4292 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 4293 | } |
| 4294 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4295 | // This test verifies that session attempts connection migration with signals |
| 4296 | // delivered in the following order (no alternate network is available): |
| 4297 | // - path degrading is detected: session attempts connection migration but no |
| 4298 | // alternate network is available, session caches path degrading signal in |
| 4299 | // connection and stays on the original network. |
| 4300 | // - original network backs up, request is served in the orignal network, |
| 4301 | // session is not marked as going away. |
| 4302 | TEST_P(QuicStreamFactoryTest, MigrateOnPathDegradingWithNoNewNetwork) { |
| 4303 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4304 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4305 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4306 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4307 | MockQuicData quic_data; |
| 4308 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4309 | quic_data.AddWrite(SYNCHRONOUS, |
| 4310 | ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4311 | quic_data.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4312 | 2, GetNthClientInitiatedStreamId(0), true, |
| 4313 | true, &header_stream_offset)); |
| 4314 | quic_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause for path degrading signal. |
| 4315 | |
| 4316 | // The rest of the data will still flow in the original socket as there is no |
| 4317 | // new network after path degrading. |
| 4318 | quic_data.AddRead( |
| 4319 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 4320 | false, false)); |
| 4321 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4322 | quic_data.AddWrite(SYNCHRONOUS, |
| 4323 | client_maker_.MakeAckAndRstPacket( |
| 4324 | 3, false, GetNthClientInitiatedStreamId(0), |
| 4325 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4326 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4327 | |
| 4328 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4329 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4330 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4331 | request.Request( |
| 4332 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4333 | SocketTag(), |
| 4334 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4335 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4336 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4337 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4338 | EXPECT_TRUE(stream.get()); |
| 4339 | |
| 4340 | // Cause QUIC stream to be created. |
| 4341 | HttpRequestInfo request_info; |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4342 | request_info.method = "GET"; |
| 4343 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4344 | request_info.traffic_annotation = |
| 4345 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4346 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4347 | net_log_, CompletionOnceCallback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4348 | |
| 4349 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4350 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4351 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4352 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4353 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4354 | // Send GET request on stream. |
| 4355 | HttpResponseInfo response; |
| 4356 | HttpRequestHeaders request_headers; |
| 4357 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 4358 | callback_.callback())); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4359 | |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4360 | // Trigger connection migration on path degrading. Since there are no networks |
| 4361 | // to migrate to, the session will remain on the original network, not marked |
| 4362 | // as going away. |
| 4363 | session->connection()->OnPathDegradingTimeout(); |
| 4364 | EXPECT_TRUE(session->connection()->IsPathDegrading()); |
| 4365 | |
| 4366 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4367 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4368 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4369 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 4370 | |
| 4371 | // Resume so that rest of the data will flow in the original socket. |
| 4372 | quic_data.Resume(); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4373 | |
| 4374 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4375 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4376 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4377 | |
| 4378 | stream.reset(); |
Zhongyi Shi | 6ec9b36e | 2018-06-20 20:32:54 | [diff] [blame] | 4379 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 4380 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
jri | d36ada6 | 2016-02-06 02:42:08 | [diff] [blame] | 4381 | } |
| 4382 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4383 | // This test verifies that session with non-migratable stream will probe the |
| 4384 | // alternate network on path degrading, and close the non-migratable streams |
| 4385 | // when probe is successful. |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4386 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyNonMigratableStream) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 4387 | if (version_ == quic::QUIC_VERSION_99) |
| 4388 | return; |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4389 | InitializeConnectionMigrationV2Test( |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4390 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4391 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4392 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4393 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4394 | MockQuicData socket_data; |
| 4395 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4396 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 4397 | socket_data.AddWrite( |
| 4398 | SYNCHRONOUS, |
| 4399 | client_maker_.MakeRstAckAndConnectionClosePacket( |
| 4400 | 3, false, 5, quic::QUIC_STREAM_CANCELLED, |
| 4401 | quic::QuicTime::Delta::FromMilliseconds(0), 1, 1, 1, |
| 4402 | quic::QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4403 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4404 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4405 | // Set up the second socket data provider that is used for probing. |
| 4406 | MockQuicData quic_data1; |
| 4407 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4408 | quic_data1.AddWrite(SYNCHRONOUS, |
| 4409 | client_maker_.MakeConnectivityProbingPacket(2, true)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4410 | quic_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 4411 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4412 | quic_data1.AddRead(ASYNC, |
| 4413 | server_maker_.MakeConnectivityProbingPacket(1, false)); |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4414 | quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4415 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4416 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4417 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4418 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4419 | request.Request( |
| 4420 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4421 | SocketTag(), |
| 4422 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4423 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4424 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4425 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4426 | EXPECT_TRUE(stream.get()); |
| 4427 | |
| 4428 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 4429 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 4430 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4431 | request_info.traffic_annotation = |
| 4432 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4433 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4434 | net_log_, CompletionOnceCallback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4435 | |
| 4436 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4437 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4438 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4439 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4440 | |
| 4441 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4442 | // this should cause session to be continue without migrating. |
| 4443 | session->OnPathDegrading(); |
| 4444 | |
| 4445 | // Run the message loop so that data queued in the new socket is read by the |
| 4446 | // packet reader. |
| 4447 | base::RunLoop().RunUntilIdle(); |
| 4448 | |
| 4449 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4450 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4451 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4452 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4453 | // Resume the data to read the connectivity probing response to declare probe |
| 4454 | // as successful. Non-migratable streams will be closed. |
| 4455 | quic_data1.Resume(); |
| 4456 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4457 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4458 | EXPECT_EQ(0u, session->GetNumActiveStreams()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4459 | |
Zhongyi Shi | 21e9953 | 2018-07-17 22:23:07 | [diff] [blame] | 4460 | EXPECT_TRUE(quic_data1.AllReadDataConsumed()); |
| 4461 | EXPECT_TRUE(quic_data1.AllWriteDataConsumed()); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 4462 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4463 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4464 | } |
| 4465 | |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4466 | TEST_P(QuicStreamFactoryTest, MigrateSessionEarlyConnectionMigrationDisabled) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 4467 | InitializeConnectionMigrationV2Test( |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4468 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4469 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4470 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4471 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 4472 | MockQuicData socket_data; |
| 4473 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 4474 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 4475 | socket_data.AddWrite( |
| 4476 | SYNCHRONOUS, |
| 4477 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4478 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 4479 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4480 | |
| 4481 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 4482 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 4483 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4484 | request.Request( |
| 4485 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4486 | SocketTag(), |
| 4487 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4488 | failed_on_default_network_callback_, callback_.callback())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4489 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 4490 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4491 | EXPECT_TRUE(stream.get()); |
| 4492 | |
| 4493 | // Cause QUIC stream to be created. |
| 4494 | HttpRequestInfo request_info; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 4495 | request_info.traffic_annotation = |
| 4496 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 4497 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 4498 | net_log_, CompletionOnceCallback())); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4499 | |
| 4500 | // Ensure that session is alive and active. |
bnc | 912a04b | 2016-04-20 14:19:50 | [diff] [blame] | 4501 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4502 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4503 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4504 | |
| 4505 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 4506 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 4507 | session->config()); |
jri | 9c54157 | 2016-03-29 17:51:48 | [diff] [blame] | 4508 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 4509 | |
| 4510 | // Trigger connection migration. Since there is a non-migratable stream, |
| 4511 | // this should cause session to be continue without migrating. |
| 4512 | session->OnPathDegrading(); |
| 4513 | |
| 4514 | // Run the message loop so that data queued in the new socket is read by the |
| 4515 | // packet reader. |
| 4516 | base::RunLoop().RunUntilIdle(); |
| 4517 | |
| 4518 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4519 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4520 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4521 | |
| 4522 | stream.reset(); |
| 4523 | |
| 4524 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4525 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4526 | } |
| 4527 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4528 | // Regression test for http://crbug.com/791886. |
| 4529 | // This test verifies that the old packet writer which encountered an |
| 4530 | // asynchronous write error will be blocked during migration on write error. New |
| 4531 | // packets would not be written until the one with write error is rewritten on |
| 4532 | // the new network. |
| 4533 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnAysncWriteError) { |
| 4534 | InitializeConnectionMigrationV2Test( |
| 4535 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4536 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4537 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4538 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4539 | |
| 4540 | // Using a testing task runner so that we can control time. |
| 4541 | // base::RunLoop() controls mocked socket writes and reads. |
| 4542 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4543 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4544 | |
| 4545 | MockQuicData socket_data; |
| 4546 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4547 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4548 | socket_data.AddWrite( |
| 4549 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4550 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4551 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4552 | |
| 4553 | // Set up second socket data provider that is used after |
| 4554 | // migration. The request is rewritten to this new socket, and the |
| 4555 | // response to the request is read on this new socket. |
| 4556 | MockQuicData socket_data1; |
| 4557 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4558 | 2, GetNthClientInitiatedStreamId(0), |
| 4559 | true, true, &header_stream_offset)); |
| 4560 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4561 | 3, GetNthClientInitiatedStreamId(1), |
| 4562 | GetNthClientInitiatedStreamId(0), true, |
| 4563 | true, &header_stream_offset)); |
| 4564 | socket_data1.AddRead( |
| 4565 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 4566 | false, false)); |
| 4567 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4568 | socket_data1.AddWrite(SYNCHRONOUS, |
| 4569 | client_maker_.MakeAckAndRstPacket( |
| 4570 | 4, false, GetNthClientInitiatedStreamId(0), |
| 4571 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 4572 | socket_data1.AddWrite( |
| 4573 | SYNCHRONOUS, |
| 4574 | client_maker_.MakeRstPacket(5, false, GetNthClientInitiatedStreamId(1), |
| 4575 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 4576 | |
| 4577 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 4578 | |
| 4579 | // Create request #1 and QuicHttpStream. |
| 4580 | QuicStreamRequest request1(factory_.get()); |
| 4581 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4582 | request1.Request( |
| 4583 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4584 | SocketTag(), |
| 4585 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4586 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4587 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4588 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4589 | EXPECT_TRUE(stream1.get()); |
| 4590 | |
| 4591 | HttpRequestInfo request_info1; |
| 4592 | request_info1.method = "GET"; |
| 4593 | request_info1.url = GURL("https://www.example.org/"); |
| 4594 | request_info1.traffic_annotation = |
| 4595 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4596 | EXPECT_EQ(OK, |
| 4597 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4598 | net_log_, CompletionOnceCallback())); |
| 4599 | |
| 4600 | // Request #2 returns synchronously because it pools to existing session. |
| 4601 | TestCompletionCallback callback2; |
| 4602 | QuicStreamRequest request2(factory_.get()); |
| 4603 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 4604 | DEFAULT_PRIORITY, SocketTag(), |
| 4605 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4606 | &net_error_details_, |
| 4607 | failed_on_default_network_callback_, |
| 4608 | callback2.callback())); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4609 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 4610 | EXPECT_TRUE(stream2.get()); |
| 4611 | |
| 4612 | HttpRequestInfo request_info2; |
| 4613 | request_info2.method = "GET"; |
| 4614 | request_info2.url = GURL("https://www.example.org/"); |
| 4615 | request_info2.traffic_annotation = |
| 4616 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4617 | EXPECT_EQ(OK, |
| 4618 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 4619 | net_log_, CompletionOnceCallback())); |
| 4620 | |
| 4621 | // Ensure that session is alive and active. |
| 4622 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4623 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4624 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4625 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 4626 | |
| 4627 | // Send GET request on stream1. This should cause an async write error. |
| 4628 | HttpResponseInfo response; |
| 4629 | HttpRequestHeaders request_headers; |
| 4630 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4631 | callback_.callback())); |
| 4632 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4633 | |
| 4634 | // Run the message loop so that asynchronous write completes and a connection |
| 4635 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4636 | // runner. |
| 4637 | base::RunLoop().RunUntilIdle(); |
| 4638 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4639 | |
| 4640 | // Send GET request on stream. This will cause another write attempt before |
| 4641 | // migration on write error is exectued. |
| 4642 | HttpResponseInfo response2; |
| 4643 | HttpRequestHeaders request_headers2; |
| 4644 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 4645 | callback2.callback())); |
| 4646 | |
| 4647 | // Run the task runner so that migration on write error is finally executed. |
| 4648 | task_runner->RunUntilIdle(); |
| 4649 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4650 | // Verify the session is still alive and not marked as going away. |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4651 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4652 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4653 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4654 | // There should be one task posted to migrate back to the default network in |
| 4655 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4656 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4657 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 4658 | task_runner->NextPendingTaskDelay()); |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 4659 | |
| 4660 | // Verify that response headers on the migrated socket were delivered to the |
| 4661 | // stream. |
| 4662 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4663 | EXPECT_EQ(200, response.headers->response_code()); |
| 4664 | |
| 4665 | stream1.reset(); |
| 4666 | stream2.reset(); |
| 4667 | |
| 4668 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4669 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4670 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 4671 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 4672 | } |
| 4673 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4674 | // Verify session is not marked as going away after connection migration on |
| 4675 | // write error and migrate back to default network logic is applied to bring the |
| 4676 | // migrated session back to the default network. Migration singals delivered |
| 4677 | // in the following order (alternate network is always availabe): |
| 4678 | // - session on the default network encountered a write error; |
| 4679 | // - session successfully migrated to the non-default network; |
| 4680 | // - session attempts to migrate back to default network post migration; |
| 4681 | // - migration back to the default network is successful. |
| 4682 | TEST_P(QuicStreamFactoryTest, MigrateBackToDefaultPostMigrationOnWriteError) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 4683 | if (version_ == quic::QUIC_VERSION_99) |
| 4684 | return; |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4685 | InitializeConnectionMigrationV2Test( |
| 4686 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4687 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 4688 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4689 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 4690 | |
| 4691 | // Using a testing task runner so that we can control time. |
| 4692 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4693 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4694 | |
| 4695 | MockQuicData socket_data; |
| 4696 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4697 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4698 | socket_data.AddWrite( |
| 4699 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 4700 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 4701 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4702 | |
| 4703 | // Set up second socket data provider that is used after |
| 4704 | // migration. The request is rewritten to this new socket, and the |
| 4705 | // response to the request is read on this new socket. |
| 4706 | MockQuicData quic_data2; |
| 4707 | quic_data2.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 4708 | 2, GetNthClientInitiatedStreamId(0), |
| 4709 | true, true, &header_stream_offset)); |
| 4710 | quic_data2.AddRead( |
| 4711 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 4712 | false, false)); |
| 4713 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4714 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 4715 | |
| 4716 | // Create request QuicHttpStream. |
| 4717 | QuicStreamRequest request1(factory_.get()); |
| 4718 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4719 | request1.Request( |
| 4720 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4721 | SocketTag(), |
| 4722 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4723 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4724 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4725 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 4726 | EXPECT_TRUE(stream1.get()); |
| 4727 | |
| 4728 | HttpRequestInfo request_info1; |
| 4729 | request_info1.method = "GET"; |
| 4730 | request_info1.url = GURL("https://www.example.org/"); |
| 4731 | request_info1.traffic_annotation = |
| 4732 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4733 | EXPECT_EQ(OK, |
| 4734 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 4735 | net_log_, CompletionOnceCallback())); |
| 4736 | |
| 4737 | // Ensure that session is alive and active. |
| 4738 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 4739 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4740 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4741 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4742 | |
| 4743 | // Send GET request. This should cause an async write error. |
| 4744 | HttpResponseInfo response; |
| 4745 | HttpRequestHeaders request_headers; |
| 4746 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 4747 | callback_.callback())); |
| 4748 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4749 | |
| 4750 | // Run the message loop so that asynchronous write completes and a connection |
| 4751 | // migration on write error attempt is posted in QuicStreamFactory's task |
| 4752 | // runner. |
| 4753 | base::RunLoop().RunUntilIdle(); |
| 4754 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4755 | |
| 4756 | // Run the task runner so that migration on write error is finally executed. |
| 4757 | task_runner->RunUntilIdle(); |
| 4758 | |
| 4759 | // Verify the session is still alive and not marked as going away. |
| 4760 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4761 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4762 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4763 | // There should be one task posted to migrate back to the default network in |
| 4764 | // kMinRetryTimeForDefaultNetworkSecs. |
| 4765 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4766 | base::TimeDelta expected_delay = |
| 4767 | base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs); |
| 4768 | EXPECT_EQ(expected_delay, task_runner->NextPendingTaskDelay()); |
| 4769 | |
| 4770 | // Verify that response headers on the migrated socket were delivered to the |
| 4771 | // stream. |
| 4772 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 4773 | EXPECT_EQ(200, response.headers->response_code()); |
| 4774 | |
| 4775 | // Set up the third socket data provider for migrate back to default network. |
| 4776 | MockQuicData quic_data3; |
| 4777 | // Connectivity probe to be sent on the new path. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4778 | quic_data3.AddWrite(SYNCHRONOUS, |
| 4779 | client_maker_.MakeConnectivityProbingPacket(3, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4780 | // Connectivity probe to receive from the server. |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 4781 | quic_data3.AddRead(ASYNC, |
| 4782 | server_maker_.MakeConnectivityProbingPacket(2, false)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 4783 | quic_data3.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4784 | quic_data3.AddWrite(ASYNC, client_maker_.MakeAckPacket(4, 1, 2, 1, 1, true)); |
| 4785 | quic_data3.AddWrite( |
| 4786 | SYNCHRONOUS, |
| 4787 | client_maker_.MakeRstPacket(5, false, GetNthClientInitiatedStreamId(0), |
| 4788 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 4789 | quic_data3.AddSocketDataToFactory(socket_factory_.get()); |
| 4790 | |
| 4791 | // Fast forward to fire the migrate back timer and verify the session |
| 4792 | // successfully migrates back to the default network. |
| 4793 | task_runner->FastForwardBy(expected_delay); |
| 4794 | |
| 4795 | // Verify the session is still alive and not marked as going away. |
| 4796 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4797 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 4798 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 4799 | |
| 4800 | // There should be one task posted to one will resend a connectivity probe and |
| 4801 | // the other will retry migrate back, both are cancelled. |
| 4802 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 4803 | task_runner->FastForwardBy( |
| 4804 | base::TimeDelta::FromSeconds(2 * kMinRetryTimeForDefaultNetworkSecs)); |
| 4805 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4806 | |
| 4807 | stream1.reset(); |
| 4808 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4809 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4810 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 4811 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 4812 | EXPECT_TRUE(quic_data3.AllReadDataConsumed()); |
| 4813 | EXPECT_TRUE(quic_data3.AllWriteDataConsumed()); |
| 4814 | } |
| 4815 | |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4816 | // This test verifies that the connection will not attempt connection migration |
| 4817 | // (send connectivity probes on alternate path) when path degrading is detected |
| 4818 | // and handshake is not confirmed. |
| 4819 | TEST_P(QuicStreamFactoryTest, |
| 4820 | NoMigrationOnPathDegradingBeforeHandshakeConfirmed) { |
| 4821 | InitializeConnectionMigrationV2Test( |
| 4822 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4823 | |
| 4824 | // Using a testing task runner. |
| 4825 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4826 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4827 | |
| 4828 | // Use cold start mode to send crypto message for handshake. |
| 4829 | crypto_client_stream_factory_.set_handshake_mode( |
| 4830 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4831 | |
| 4832 | MockQuicData socket_data; |
| 4833 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4834 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4835 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4836 | |
| 4837 | // Create request and QuicHttpStream. |
| 4838 | QuicStreamRequest request(factory_.get()); |
| 4839 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4840 | request.Request( |
| 4841 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4842 | SocketTag(), |
| 4843 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4844 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4845 | |
| 4846 | base::RunLoop().RunUntilIdle(); |
| 4847 | |
| 4848 | // Ensure that session is alive but not active. |
| 4849 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4850 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4851 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4852 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4853 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4854 | |
| 4855 | // Cause the connection to report path degrading to the session. |
| 4856 | // Session will ignore the signal as handshake is not completed. |
| 4857 | session->connection()->OnPathDegradingTimeout(); |
| 4858 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4859 | |
| 4860 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4861 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | c144937 | 2018-08-09 09:58:58 | [diff] [blame] | 4862 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4863 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4864 | } |
| 4865 | |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4866 | // This test verifies that if a connection is closed with |
| 4867 | // QUIC_NETWORK_IDLE_TIMEOUT before handshake is completed and there is no |
| 4868 | // alternate network, no new connection will be created. |
| 4869 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkBeforeHandshakeOnIdleTimeout) { |
| 4870 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4871 | } |
| 4872 | |
| 4873 | // This test verifies that if a connection is closed with QUIC_HANDSHAKE_TIMEOUT |
| 4874 | // and there is no alternate network, no new connection will be created. |
| 4875 | TEST_P(QuicStreamFactoryTest, NoAlternateNetworkOnHandshakeTimeout) { |
| 4876 | TestNoAlternateNetworkBeforeHandshake(quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4877 | } |
| 4878 | |
| 4879 | void QuicStreamFactoryTestBase::TestNoAlternateNetworkBeforeHandshake( |
| 4880 | quic::QuicErrorCode quic_error) { |
| 4881 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4882 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4883 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
| 4884 | |
| 4885 | // Using a testing task runner. |
| 4886 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4887 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4888 | |
| 4889 | // Use cold start mode to send crypto message for handshake. |
| 4890 | crypto_client_stream_factory_.set_handshake_mode( |
| 4891 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4892 | |
| 4893 | MockQuicData socket_data; |
| 4894 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4895 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4896 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4897 | |
| 4898 | // Create request. |
| 4899 | QuicStreamRequest request(factory_.get()); |
| 4900 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 4901 | request.Request( |
| 4902 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 4903 | SocketTag(), |
| 4904 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 4905 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 634c188 | 2018-08-16 04:05:59 | [diff] [blame] | 4906 | |
| 4907 | base::RunLoop().RunUntilIdle(); |
| 4908 | |
| 4909 | // Ensure that session is alive but not active. |
| 4910 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4911 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4912 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 4913 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 4914 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4915 | |
| 4916 | // Cause the connection to report path degrading to the session. |
| 4917 | // Session will ignore the signal as handshake is not completed. |
| 4918 | session->connection()->OnPathDegradingTimeout(); |
| 4919 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 4920 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4921 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4922 | |
| 4923 | // Cause the connection to close due to |quic_error| before handshake. |
| 4924 | quic::QuicString error_details; |
| 4925 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 4926 | error_details = "No recent network activity."; |
| 4927 | } else { |
| 4928 | error_details = "Handshake timeout expired."; |
| 4929 | } |
| 4930 | session->connection()->CloseConnection( |
| 4931 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 4932 | |
| 4933 | // A task will be posted to clean up the session in the factory. |
| 4934 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 4935 | task_runner->FastForwardUntilNoTasksRemain(); |
| 4936 | |
| 4937 | // No new session should be created as there is no alternate network. |
| 4938 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 4939 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 4940 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4941 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4942 | } |
| 4943 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4944 | TEST_P(QuicStreamFactoryTest, NewConnectionBeforeHandshakeAfterIdleTimeout) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 4945 | if (version_ == quic::QUIC_VERSION_99) |
| 4946 | return; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4947 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4948 | quic::QUIC_NETWORK_IDLE_TIMEOUT); |
| 4949 | } |
| 4950 | |
| 4951 | TEST_P(QuicStreamFactoryTest, NewConnectionAfterHandshakeTimeout) { |
Ryan Hamilton | 14d6a89 | 2018-10-18 19:03:42 | [diff] [blame^] | 4952 | if (version_ == quic::QUIC_VERSION_99) |
| 4953 | return; |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4954 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4955 | quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4956 | } |
| 4957 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 4958 | // Sets up a test to verify that a new connection will be created on the |
| 4959 | // alternate network after the initial connection fails before handshake with |
| 4960 | // signals delivered in the following order (alternate network is available): |
| 4961 | // - the default network is not able to complete crypto handshake; |
| 4962 | // - the original connection is closed with |quic_error|; |
| 4963 | // - a new connection is created on the alternate network and is able to finish |
| 4964 | // crypto handshake; |
| 4965 | // - the new session on the alternate network attempts to migrate back to the |
| 4966 | // default network by sending probes; |
| 4967 | // - default network being disconnected is delivered: session will stop probing |
| 4968 | // the original network. |
| 4969 | // - alternate network is made by default. |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 4970 | void QuicStreamFactoryTestBase:: |
| 4971 | TestNewConnectionOnAlternateNetworkBeforeHandshake( |
| 4972 | quic::QuicErrorCode quic_error) { |
| 4973 | DCHECK(quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT || |
| 4974 | quic_error == quic::QUIC_HANDSHAKE_TIMEOUT); |
| 4975 | InitializeConnectionMigrationV2Test( |
| 4976 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 4977 | |
| 4978 | // Using a testing task runner. |
| 4979 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 4980 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 4981 | |
| 4982 | // Use cold start mode to send crypto message for handshake. |
| 4983 | crypto_client_stream_factory_.set_handshake_mode( |
| 4984 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
| 4985 | |
| 4986 | // Socket data for connection on the default network. |
| 4987 | MockQuicData socket_data; |
| 4988 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4989 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
| 4990 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 4991 | |
| 4992 | // Socket data for connection on the alternate network. |
| 4993 | MockQuicData socket_data2; |
| 4994 | quic::QuicStreamOffset header_stream_offset = 0; |
| 4995 | socket_data2.AddWrite(SYNCHRONOUS, client_maker_.MakeDummyCHLOPacket(1)); |
| 4996 | socket_data2.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 4997 | // Change the encryption level after handshake is confirmed. |
| 4998 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 4999 | socket_data2.AddWrite( |
| 5000 | ASYNC, ConstructInitialSettingsPacket(2, &header_stream_offset)); |
| 5001 | socket_data2.AddWrite( |
| 5002 | ASYNC, ConstructGetRequestPacket(3, GetNthClientInitiatedStreamId(0), |
| 5003 | true, true, &header_stream_offset)); |
| 5004 | socket_data2.AddRead( |
| 5005 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5006 | false, false)); |
| 5007 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5008 | socket_data2.AddWrite(SYNCHRONOUS, |
| 5009 | client_maker_.MakeAckAndRstPacket( |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5010 | 5, false, GetNthClientInitiatedStreamId(0), |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5011 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5012 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5013 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5014 | // Socket data for probing on the default network. |
| 5015 | MockQuicData probing_data; |
| 5016 | probing_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
| 5017 | probing_data.AddWrite(SYNCHRONOUS, |
| 5018 | client_maker_.MakeConnectivityProbingPacket(4, false)); |
| 5019 | probing_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5020 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5021 | // Create request and QuicHttpStream. |
| 5022 | QuicStreamRequest request(factory_.get()); |
| 5023 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5024 | request.Request( |
| 5025 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5026 | SocketTag(), |
| 5027 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5028 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5029 | |
| 5030 | base::RunLoop().RunUntilIdle(); |
| 5031 | |
| 5032 | // Ensure that session is alive but not active. |
| 5033 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5034 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5035 | QuicChromiumClientSession* session = GetPendingSession(host_port_pair_); |
| 5036 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5037 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5038 | EXPECT_FALSE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5039 | |
| 5040 | quic::QuicString error_details; |
| 5041 | if (quic_error == quic::QUIC_NETWORK_IDLE_TIMEOUT) { |
| 5042 | error_details = "No recent network activity."; |
| 5043 | } else { |
| 5044 | error_details = "Handshake timeout expired."; |
| 5045 | } |
| 5046 | session->connection()->CloseConnection( |
| 5047 | quic_error, error_details, quic::ConnectionCloseBehavior::SILENT_CLOSE); |
| 5048 | |
| 5049 | // A task will be posted to clean up the session in the factory. |
| 5050 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5051 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5052 | |
| 5053 | // Verify a new session is created on the alternate network. |
| 5054 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5055 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5056 | QuicChromiumClientSession* session2 = GetPendingSession(host_port_pair_); |
| 5057 | EXPECT_NE(session, session2); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5058 | EXPECT_TRUE(failed_on_default_network_); |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5059 | |
| 5060 | // Confirm the handshake on the alternate network. |
| 5061 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5062 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5063 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5064 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5065 | // Resume the data now so that data can be sent and read. |
| 5066 | socket_data2.Resume(); |
| 5067 | |
| 5068 | // Create the stream. |
| 5069 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 5070 | EXPECT_TRUE(stream.get()); |
| 5071 | HttpRequestInfo request_info; |
| 5072 | request_info.method = "GET"; |
| 5073 | request_info.url = GURL("https://www.example.org/"); |
| 5074 | request_info.traffic_annotation = |
| 5075 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5076 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 5077 | net_log_, CompletionOnceCallback())); |
| 5078 | // Send the request. |
| 5079 | HttpResponseInfo response; |
| 5080 | HttpRequestHeaders request_headers; |
| 5081 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5082 | callback_.callback())); |
| 5083 | // Run the message loop to finish asynchronous mock write. |
| 5084 | base::RunLoop().RunUntilIdle(); |
| 5085 | // Read the response. |
| 5086 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5087 | EXPECT_EQ(200, response.headers->response_code()); |
| 5088 | |
Zhongyi Shi | f3fcbbe6 | 2018-08-16 22:52:08 | [diff] [blame] | 5089 | // There should be a new task posted to migrate back to the default network. |
| 5090 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 5091 | base::TimeDelta next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5092 | EXPECT_EQ(base::TimeDelta::FromSeconds(kMinRetryTimeForDefaultNetworkSecs), |
| 5093 | next_task_delay); |
| 5094 | task_runner->FastForwardBy(next_task_delay); |
| 5095 | |
| 5096 | // There should be two tasks posted. One will retry probing and the other |
| 5097 | // will retry migrate back. |
| 5098 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 5099 | next_task_delay = task_runner->NextPendingTaskDelay(); |
| 5100 | EXPECT_EQ(base::TimeDelta::FromMilliseconds(2 * kDefaultRTTMilliSecs), |
| 5101 | next_task_delay); |
| 5102 | |
| 5103 | // Deliver the signal that the default network is disconnected. |
| 5104 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5105 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 5106 | // Verify no connectivity probes will be sent as probing will be cancelled. |
| 5107 | task_runner->FastForwardUntilNoTasksRemain(); |
| 5108 | // Deliver the signal that the alternate network is made default. |
| 5109 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 5110 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
| 5111 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 5112 | |
Zhongyi Shi | 8de4383 | 2018-08-15 23:40:00 | [diff] [blame] | 5113 | stream.reset(); |
| 5114 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5115 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5116 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5117 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5118 | } |
| 5119 | |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5120 | // Test that connection will be closed with PACKET_WRITE_ERROR if a write error |
| 5121 | // is triggered before handshake is confirmed and connection migration is turned |
| 5122 | // on. |
| 5123 | TEST_P(QuicStreamFactoryTest, MigrationOnWriteErrorBeforeHandshakeConfirmed) { |
| 5124 | InitializeConnectionMigrationV2Test( |
| 5125 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5126 | |
| 5127 | // Use unmocked crypto stream to do crypto connect. |
| 5128 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 5129 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5130 | |
| 5131 | MockQuicData socket_data; |
| 5132 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5133 | // Trigger PACKET_WRITE_ERROR when sending packets in crypto connect. |
| 5134 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
| 5135 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5136 | |
| 5137 | // Create request, should fail after the write of the CHLO fails. |
| 5138 | QuicStreamRequest request(factory_.get()); |
| 5139 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5140 | request.Request( |
| 5141 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5142 | SocketTag(), |
| 5143 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5144 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5145 | EXPECT_EQ(ERR_QUIC_HANDSHAKE_FAILED, callback_.WaitForResult()); |
| 5146 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5147 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5148 | |
| 5149 | // Verify new requests can be sent normally. |
| 5150 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 5151 | MockCryptoClientStream::COLD_START); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5152 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5153 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5154 | MockQuicData socket_data2; |
| 5155 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5156 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 5157 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5158 | |
| 5159 | QuicStreamRequest request2(factory_.get()); |
| 5160 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5161 | request2.Request( |
| 5162 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5163 | SocketTag(), |
| 5164 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5165 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 247d632 | 2018-07-24 07:03:35 | [diff] [blame] | 5166 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5167 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5168 | // Run the message loop to complete host resolution. |
| 5169 | base::RunLoop().RunUntilIdle(); |
| 5170 | |
| 5171 | // Complete handshake. QuicStreamFactory::Job should complete and succeed. |
| 5172 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 5173 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 5174 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5175 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5176 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 5177 | |
| 5178 | // Create QuicHttpStream. |
| 5179 | std::unique_ptr<HttpStream> stream = CreateStream(&request2); |
| 5180 | EXPECT_TRUE(stream.get()); |
| 5181 | stream.reset(); |
| 5182 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5183 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5184 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 5185 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 5186 | } |
| 5187 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5188 | void QuicStreamFactoryTestBase::TestMigrationOnWriteError( |
| 5189 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5190 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5191 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5192 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5193 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5194 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5195 | |
Zhongyi Shi | 3c4c9e9 | 2018-07-02 23:16:23 | [diff] [blame] | 5196 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 5197 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5198 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5199 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5200 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 5201 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5202 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5203 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5204 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5205 | |
| 5206 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5207 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5208 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5209 | request.Request( |
| 5210 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5211 | SocketTag(), |
| 5212 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5213 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5214 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5215 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5216 | EXPECT_TRUE(stream.get()); |
| 5217 | |
| 5218 | // Cause QUIC stream to be created. |
| 5219 | HttpRequestInfo request_info; |
| 5220 | request_info.method = "GET"; |
| 5221 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5222 | request_info.traffic_annotation = |
| 5223 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5224 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5225 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5226 | |
| 5227 | // Ensure that session is alive and active. |
| 5228 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5229 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5230 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5231 | |
| 5232 | // Set up second socket data provider that is used after |
| 5233 | // migration. The request is rewritten to this new socket, and the |
| 5234 | // response to the request is read on this new socket. |
| 5235 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5236 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 5237 | 2, GetNthClientInitiatedStreamId(0), |
| 5238 | true, true, &header_stream_offset)); |
| 5239 | socket_data1.AddRead( |
| 5240 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5241 | false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5242 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5243 | socket_data1.AddWrite(SYNCHRONOUS, |
| 5244 | client_maker_.MakeAckAndRstPacket( |
| 5245 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5246 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5247 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5248 | |
| 5249 | // Send GET request on stream. This should cause a write error, which triggers |
| 5250 | // a connection migration attempt. |
| 5251 | HttpResponseInfo response; |
| 5252 | HttpRequestHeaders request_headers; |
| 5253 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5254 | callback_.callback())); |
| 5255 | |
| 5256 | // Run the message loop so that the migration attempt is executed and |
| 5257 | // data queued in the new socket is read by the packet reader. |
| 5258 | base::RunLoop().RunUntilIdle(); |
| 5259 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5260 | // Verify that session is alive and not marked as going awya. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5261 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5262 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5263 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5264 | |
| 5265 | // Verify that response headers on the migrated socket were delivered to the |
| 5266 | // stream. |
| 5267 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 5268 | EXPECT_EQ(200, response.headers->response_code()); |
| 5269 | |
| 5270 | stream.reset(); |
| 5271 | |
| 5272 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5273 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5274 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5275 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5276 | } |
| 5277 | |
| 5278 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorSynchronous) { |
| 5279 | TestMigrationOnWriteError(SYNCHRONOUS); |
| 5280 | } |
| 5281 | |
| 5282 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorAsync) { |
| 5283 | TestMigrationOnWriteError(ASYNC); |
| 5284 | } |
| 5285 | |
| 5286 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNoNewNetwork( |
| 5287 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5288 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5289 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5290 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5291 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5292 | // Use the test task runner, to force the migration alarm timeout later. |
| 5293 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 5294 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5295 | MockQuicData socket_data; |
| 5296 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5297 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5298 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5299 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5300 | |
| 5301 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5302 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5303 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5304 | request.Request( |
| 5305 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5306 | SocketTag(), |
| 5307 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5308 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5309 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5310 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5311 | EXPECT_TRUE(stream.get()); |
| 5312 | |
| 5313 | // Cause QUIC stream to be created. |
| 5314 | HttpRequestInfo request_info; |
| 5315 | request_info.method = "GET"; |
| 5316 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5317 | request_info.traffic_annotation = |
| 5318 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5319 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5320 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5321 | |
| 5322 | // Ensure that session is alive and active. |
| 5323 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5324 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5325 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5326 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5327 | // Send GET request on stream. This causes a write error, which triggers |
| 5328 | // a connection migration attempt. Since there are no networks |
| 5329 | // to migrate to, this causes the session to wait for a new network. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5330 | HttpResponseInfo response; |
| 5331 | HttpRequestHeaders request_headers; |
| 5332 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5333 | callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5334 | |
| 5335 | // Complete any pending writes. Pending async MockQuicData writes |
| 5336 | // are run on the message loop, not on the test runner. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5337 | base::RunLoop().RunUntilIdle(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5338 | |
| 5339 | // Write error causes migration task to be posted. Spin the loop. |
| 5340 | if (write_error_mode == ASYNC) |
| 5341 | runner_->RunNextTask(); |
| 5342 | |
| 5343 | // Migration has not yet failed. The session should be alive and active. |
| 5344 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5345 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5346 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5347 | EXPECT_TRUE(session->connection()->writer()->IsWriteBlocked()); |
| 5348 | |
| 5349 | // The migration will not fail until the migration alarm timeout. |
| 5350 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5351 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5352 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5353 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 5354 | |
| 5355 | // Force migration alarm timeout to run. |
| 5356 | RunTestLoopUntilIdle(); |
| 5357 | |
| 5358 | // The connection should be closed. A request for response headers |
| 5359 | // should fail. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5360 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5361 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 5362 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
| 5363 | EXPECT_EQ(ERR_NETWORK_CHANGED, |
| 5364 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5365 | |
| 5366 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5367 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5368 | } |
| 5369 | |
| 5370 | TEST_P(QuicStreamFactoryTest, |
| 5371 | MigrateSessionOnWriteErrorNoNewNetworkSynchronous) { |
| 5372 | TestMigrationOnWriteErrorNoNewNetwork(SYNCHRONOUS); |
| 5373 | } |
| 5374 | |
| 5375 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnWriteErrorNoNewNetworkAsync) { |
| 5376 | TestMigrationOnWriteErrorNoNewNetwork(ASYNC); |
| 5377 | } |
| 5378 | |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5379 | TEST_P(QuicStreamFactoryTest, |
| 5380 | MigrateSessionOnWriteErrorWithMultipleRequestsSync) { |
| 5381 | TestMigrationOnWriteErrorWithMultipleRequests(SYNCHRONOUS); |
| 5382 | } |
| 5383 | |
| 5384 | TEST_P(QuicStreamFactoryTest, |
| 5385 | MigrateSessionOnWriteErrorWithMultipleRequestsAsync) { |
| 5386 | TestMigrationOnWriteErrorWithMultipleRequests(ASYNC); |
| 5387 | } |
| 5388 | |
| 5389 | // Sets up a test which verifies that connection migration on write error can |
| 5390 | // eventually succeed and rewrite the packet on the new network with *multiple* |
| 5391 | // migratable streams. |
| 5392 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorWithMultipleRequests( |
| 5393 | IoMode write_error_mode) { |
| 5394 | InitializeConnectionMigrationV2Test( |
| 5395 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5396 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5397 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5398 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5399 | |
| 5400 | MockQuicData socket_data; |
| 5401 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5402 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5403 | socket_data.AddWrite( |
| 5404 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5405 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5406 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5407 | |
| 5408 | // Set up second socket data provider that is used after |
| 5409 | // migration. The request is rewritten to this new socket, and the |
| 5410 | // response to the request is read on this new socket. |
| 5411 | MockQuicData socket_data1; |
| 5412 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 5413 | 2, GetNthClientInitiatedStreamId(0), |
| 5414 | true, true, &header_stream_offset)); |
| 5415 | socket_data1.AddRead( |
| 5416 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5417 | false, false)); |
| 5418 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5419 | socket_data1.AddWrite(SYNCHRONOUS, |
| 5420 | client_maker_.MakeAckAndRstPacket( |
| 5421 | 3, false, GetNthClientInitiatedStreamId(0), |
| 5422 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5423 | socket_data1.AddWrite( |
| 5424 | SYNCHRONOUS, |
| 5425 | client_maker_.MakeRstPacket(4, false, GetNthClientInitiatedStreamId(1), |
| 5426 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 5427 | |
| 5428 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5429 | |
| 5430 | // Create request #1 and QuicHttpStream. |
| 5431 | QuicStreamRequest request1(factory_.get()); |
| 5432 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5433 | request1.Request( |
| 5434 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5435 | SocketTag(), |
| 5436 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5437 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5438 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5439 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5440 | EXPECT_TRUE(stream1.get()); |
| 5441 | |
| 5442 | HttpRequestInfo request_info1; |
| 5443 | request_info1.method = "GET"; |
| 5444 | request_info1.url = GURL("https://www.example.org/"); |
| 5445 | request_info1.traffic_annotation = |
| 5446 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5447 | EXPECT_EQ(OK, |
| 5448 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5449 | net_log_, CompletionOnceCallback())); |
| 5450 | |
| 5451 | // Second request returns synchronously because it pools to existing session. |
| 5452 | TestCompletionCallback callback2; |
| 5453 | QuicStreamRequest request2(factory_.get()); |
| 5454 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5455 | DEFAULT_PRIORITY, SocketTag(), |
| 5456 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5457 | &net_error_details_, |
| 5458 | failed_on_default_network_callback_, |
| 5459 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5460 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5461 | EXPECT_TRUE(stream2.get()); |
| 5462 | HttpRequestInfo request_info2; |
| 5463 | request_info2.method = "GET"; |
| 5464 | request_info2.url = GURL("https://www.example.org/"); |
| 5465 | request_info2.traffic_annotation = |
| 5466 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5467 | EXPECT_EQ(OK, |
| 5468 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5469 | net_log_, CompletionOnceCallback())); |
| 5470 | |
| 5471 | // Ensure that session is alive and active. |
| 5472 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5473 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5474 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5475 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5476 | |
| 5477 | // Send GET request on stream. This should cause a write error, which triggers |
| 5478 | // a connection migration attempt. |
| 5479 | HttpResponseInfo response; |
| 5480 | HttpRequestHeaders request_headers; |
| 5481 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5482 | callback_.callback())); |
| 5483 | |
| 5484 | // Run the message loop so that the migration attempt is executed and |
| 5485 | // data queued in the new socket is read by the packet reader. |
| 5486 | base::RunLoop().RunUntilIdle(); |
| 5487 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5488 | // Verify session is still alive and not marked as going away. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5489 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5490 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5491 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5492 | |
| 5493 | // Verify that response headers on the migrated socket were delivered to the |
| 5494 | // stream. |
| 5495 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5496 | EXPECT_EQ(200, response.headers->response_code()); |
| 5497 | |
| 5498 | stream1.reset(); |
| 5499 | stream2.reset(); |
| 5500 | |
| 5501 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5502 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5503 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5504 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5505 | } |
| 5506 | |
| 5507 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsSync) { |
| 5508 | TestMigrationOnWriteErrorMixedStreams(SYNCHRONOUS); |
| 5509 | } |
| 5510 | |
| 5511 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequestsAsync) { |
| 5512 | TestMigrationOnWriteErrorMixedStreams(ASYNC); |
| 5513 | } |
| 5514 | |
| 5515 | // Sets up a test that verifies connection migration manages to migrate to |
| 5516 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5517 | // |write_error_mode| on the original network. |
| 5518 | // Note there are mixed types of unfinished requests before migration: one |
| 5519 | // migratable and one non-migratable. The *migratable* one triggers write |
| 5520 | // error. |
| 5521 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams( |
| 5522 | IoMode write_error_mode) { |
| 5523 | InitializeConnectionMigrationV2Test( |
| 5524 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5525 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5526 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5527 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5528 | |
| 5529 | int packet_number = 1; |
| 5530 | MockQuicData socket_data; |
| 5531 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5532 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5533 | socket_data.AddWrite( |
| 5534 | SYNCHRONOUS, |
| 5535 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5536 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
| 5537 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5538 | |
| 5539 | // Set up second socket data provider that is used after |
| 5540 | // migration. The request is rewritten to this new socket, and the |
| 5541 | // response to the request is read on this new socket. |
| 5542 | MockQuicData socket_data1; |
| 5543 | socket_data1.AddWrite( |
| 5544 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5545 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 5546 | true, &header_stream_offset)); |
| 5547 | socket_data1.AddWrite( |
| 5548 | SYNCHRONOUS, client_maker_.MakeRstPacket(packet_number++, true, |
| 5549 | GetNthClientInitiatedStreamId(1), |
| 5550 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 5551 | socket_data1.AddRead( |
| 5552 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5553 | false, false)); |
| 5554 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5555 | socket_data1.AddWrite( |
| 5556 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5557 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 5558 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5559 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5560 | |
| 5561 | // Create request #1 and QuicHttpStream. |
| 5562 | QuicStreamRequest request1(factory_.get()); |
| 5563 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5564 | request1.Request( |
| 5565 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5566 | SocketTag(), |
| 5567 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5568 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5569 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5570 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5571 | EXPECT_TRUE(stream1.get()); |
| 5572 | |
| 5573 | HttpRequestInfo request_info1; |
| 5574 | request_info1.method = "GET"; |
| 5575 | request_info1.url = GURL("https://www.example.org/"); |
| 5576 | request_info1.traffic_annotation = |
| 5577 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5578 | EXPECT_EQ(OK, |
| 5579 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5580 | net_log_, CompletionOnceCallback())); |
| 5581 | |
| 5582 | // Second request returns synchronously because it pools to existing session. |
| 5583 | TestCompletionCallback callback2; |
| 5584 | QuicStreamRequest request2(factory_.get()); |
| 5585 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5586 | DEFAULT_PRIORITY, SocketTag(), |
| 5587 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5588 | &net_error_details_, |
| 5589 | failed_on_default_network_callback_, |
| 5590 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5591 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5592 | EXPECT_TRUE(stream2.get()); |
| 5593 | |
| 5594 | HttpRequestInfo request_info2; |
| 5595 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5596 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5597 | request_info2.url = GURL("https://www.example.org/"); |
| 5598 | request_info2.traffic_annotation = |
| 5599 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5600 | EXPECT_EQ(OK, |
| 5601 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5602 | net_log_, CompletionOnceCallback())); |
| 5603 | |
| 5604 | // Ensure that session is alive and active. |
| 5605 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5606 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5607 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5608 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5609 | |
| 5610 | // Send GET request on stream 1. This should cause a write error, which |
| 5611 | // triggers a connection migration attempt. |
| 5612 | HttpResponseInfo response; |
| 5613 | HttpRequestHeaders request_headers; |
| 5614 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5615 | callback_.callback())); |
| 5616 | |
| 5617 | // Run the message loop so that the migration attempt is executed and |
| 5618 | // data queued in the new socket is read by the packet reader. |
| 5619 | base::RunLoop().RunUntilIdle(); |
| 5620 | |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5621 | // Verify that the session is still alive and not marked as going away. |
| 5622 | // Non-migratable stream should be closed due to migration. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5623 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5624 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5625 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5626 | |
| 5627 | // Verify that response headers on the migrated socket were delivered to the |
| 5628 | // stream. |
| 5629 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5630 | EXPECT_EQ(200, response.headers->response_code()); |
| 5631 | |
| 5632 | stream1.reset(); |
| 5633 | |
| 5634 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5635 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5636 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5637 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5638 | } |
| 5639 | |
| 5640 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Sync) { |
| 5641 | TestMigrationOnWriteErrorMixedStreams2(SYNCHRONOUS); |
| 5642 | } |
| 5643 | |
| 5644 | TEST_P(QuicStreamFactoryTest, MigrateOnWriteErrorWithMixedRequests2Async) { |
| 5645 | TestMigrationOnWriteErrorMixedStreams2(ASYNC); |
| 5646 | } |
| 5647 | |
| 5648 | // The one triggers write error is a non-migratable stream. |
| 5649 | // Sets up a test that verifies connection migration manages to migrate to |
| 5650 | // alternate network after encountering a SYNC/ASYNC write error based on |
| 5651 | // |write_error_mode| on the original network. |
| 5652 | // Note there are mixed types of unfinished requests before migration: one |
| 5653 | // migratable and one non-migratable. The *non-migratable* one triggers write |
| 5654 | // error. |
| 5655 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMixedStreams2( |
| 5656 | IoMode write_error_mode) { |
| 5657 | InitializeConnectionMigrationV2Test( |
| 5658 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5659 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5660 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5661 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5662 | |
| 5663 | int packet_number = 1; |
| 5664 | MockQuicData socket_data; |
| 5665 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5666 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5667 | socket_data.AddWrite( |
| 5668 | SYNCHRONOUS, |
| 5669 | ConstructInitialSettingsPacket(packet_number++, &header_stream_offset)); |
| 5670 | socket_data.AddWrite(write_error_mode, |
| 5671 | ERR_ADDRESS_UNREACHABLE); // Write error. |
| 5672 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 5673 | |
| 5674 | // Set up second socket data provider that is used after |
| 5675 | // migration. The request is rewritten to this new socket, and the |
| 5676 | // response to the request is read on this new socket. |
| 5677 | MockQuicData socket_data1; |
| 5678 | // The packet triggered writer error will be sent anyway even if the stream |
| 5679 | // will be cancelled later. |
| 5680 | socket_data1.AddWrite( |
| 5681 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5682 | packet_number++, GetNthClientInitiatedStreamId(1), true, |
| 5683 | true, &header_stream_offset)); |
| 5684 | socket_data1.AddWrite( |
| 5685 | SYNCHRONOUS, client_maker_.MakeRstPacket(packet_number++, true, |
| 5686 | GetNthClientInitiatedStreamId(1), |
| 5687 | quic::QUIC_STREAM_CANCELLED, 0)); |
| 5688 | socket_data1.AddWrite( |
| 5689 | SYNCHRONOUS, ConstructGetRequestPacket( |
| 5690 | packet_number++, GetNthClientInitiatedStreamId(0), true, |
| 5691 | true, &header_stream_offset)); |
| 5692 | socket_data1.AddRead( |
| 5693 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5694 | false, false)); |
| 5695 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5696 | socket_data1.AddWrite( |
| 5697 | SYNCHRONOUS, client_maker_.MakeAckAndRstPacket( |
| 5698 | packet_number++, false, GetNthClientInitiatedStreamId(0), |
| 5699 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5700 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5701 | |
| 5702 | // Create request #1 and QuicHttpStream. |
| 5703 | QuicStreamRequest request1(factory_.get()); |
| 5704 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5705 | request1.Request( |
| 5706 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5707 | SocketTag(), |
| 5708 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5709 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5710 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 5711 | std::unique_ptr<HttpStream> stream1 = CreateStream(&request1); |
| 5712 | EXPECT_TRUE(stream1.get()); |
| 5713 | |
| 5714 | HttpRequestInfo request_info1; |
| 5715 | request_info1.method = "GET"; |
| 5716 | request_info1.url = GURL("https://www.example.org/"); |
| 5717 | request_info1.traffic_annotation = |
| 5718 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5719 | EXPECT_EQ(OK, |
| 5720 | stream1->InitializeStream(&request_info1, true, DEFAULT_PRIORITY, |
| 5721 | net_log_, CompletionOnceCallback())); |
| 5722 | |
| 5723 | // Second request returns synchronously because it pools to existing session. |
| 5724 | TestCompletionCallback callback2; |
| 5725 | QuicStreamRequest request2(factory_.get()); |
| 5726 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 5727 | DEFAULT_PRIORITY, SocketTag(), |
| 5728 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5729 | &net_error_details_, |
| 5730 | failed_on_default_network_callback_, |
| 5731 | callback2.callback())); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5732 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
| 5733 | EXPECT_TRUE(stream2.get()); |
| 5734 | |
| 5735 | HttpRequestInfo request_info2; |
| 5736 | request_info2.method = "GET"; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5737 | request_info2.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5738 | request_info2.url = GURL("https://www.example.org/"); |
| 5739 | request_info2.traffic_annotation = |
| 5740 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5741 | EXPECT_EQ(OK, |
| 5742 | stream2->InitializeStream(&request_info2, true, DEFAULT_PRIORITY, |
| 5743 | net_log_, CompletionOnceCallback())); |
| 5744 | |
| 5745 | // Ensure that session is alive and active. |
| 5746 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5747 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5748 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5749 | EXPECT_EQ(2u, session->GetNumActiveStreams()); |
| 5750 | |
| 5751 | // Send GET request on stream 2 which is non-migratable. This should cause a |
| 5752 | // write error, which triggers a connection migration attempt. |
| 5753 | HttpResponseInfo response2; |
| 5754 | HttpRequestHeaders request_headers2; |
| 5755 | EXPECT_EQ(OK, stream2->SendRequest(request_headers2, &response2, |
| 5756 | callback2.callback())); |
| 5757 | |
| 5758 | // Run the message loop so that the migration attempt is executed and |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5759 | // data queued in the new socket is read by the packet reader. Session is |
| 5760 | // still alive and not marked as going away, non-migratable stream will be |
| 5761 | // closed. |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5762 | base::RunLoop().RunUntilIdle(); |
| 5763 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 5764 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 0439ecc7 | 2018-07-11 04:41:26 | [diff] [blame] | 5765 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 5766 | |
| 5767 | // Send GET request on stream 1. |
| 5768 | HttpResponseInfo response; |
| 5769 | HttpRequestHeaders request_headers; |
| 5770 | EXPECT_EQ(OK, stream1->SendRequest(request_headers, &response, |
| 5771 | callback_.callback())); |
| 5772 | |
| 5773 | base::RunLoop().RunUntilIdle(); |
| 5774 | |
| 5775 | // Verify that response headers on the migrated socket were delivered to the |
| 5776 | // stream. |
| 5777 | EXPECT_EQ(OK, stream1->ReadResponseHeaders(callback_.callback())); |
| 5778 | EXPECT_EQ(200, response.headers->response_code()); |
| 5779 | |
| 5780 | stream1.reset(); |
| 5781 | |
| 5782 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5783 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5784 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 5785 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 5786 | } |
| 5787 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5788 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorNonMigratableStream( |
| 5789 | IoMode write_error_mode) { |
| 5790 | DVLOG(1) << "Mode: " |
| 5791 | << ((write_error_mode == SYNCHRONOUS) ? "SYNCHRONOUS" : "ASYNC"); |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5792 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5793 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5794 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5795 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5796 | |
| 5797 | MockQuicData socket_data; |
| 5798 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5799 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5800 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5801 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5802 | |
| 5803 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5804 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5805 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5806 | request.Request( |
| 5807 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5808 | SocketTag(), |
| 5809 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5810 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5811 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5812 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5813 | EXPECT_TRUE(stream.get()); |
| 5814 | |
| 5815 | // Cause QUIC stream to be created, but marked as non-migratable. |
| 5816 | HttpRequestInfo request_info; |
Zhongyi Shi | bb28b1f | 2018-07-18 02:41:26 | [diff] [blame] | 5817 | request_info.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION_TO_CELLULAR; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5818 | request_info.method = "GET"; |
| 5819 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5820 | request_info.traffic_annotation = |
| 5821 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5822 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5823 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5824 | |
| 5825 | // Ensure that session is alive and active. |
| 5826 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5827 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5828 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5829 | |
| 5830 | // Send GET request on stream. This should cause a write error, which triggers |
| 5831 | // a connection migration attempt. |
| 5832 | HttpResponseInfo response; |
| 5833 | HttpRequestHeaders request_headers; |
| 5834 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5835 | callback_.callback())); |
| 5836 | |
| 5837 | // Run message loop to execute migration attempt. |
| 5838 | base::RunLoop().RunUntilIdle(); |
| 5839 | |
| 5840 | // Migration fails, and session is closed and deleted. |
| 5841 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5842 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5843 | |
| 5844 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5845 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5846 | } |
| 5847 | |
| 5848 | TEST_P(QuicStreamFactoryTest, |
| 5849 | MigrateSessionOnWriteErrorNonMigratableStreamSynchronous) { |
| 5850 | TestMigrationOnWriteErrorNonMigratableStream(SYNCHRONOUS); |
| 5851 | } |
| 5852 | |
| 5853 | TEST_P(QuicStreamFactoryTest, |
| 5854 | MigrateSessionOnWriteErrorNonMigratableStreamAsync) { |
| 5855 | TestMigrationOnWriteErrorNonMigratableStream(ASYNC); |
| 5856 | } |
| 5857 | |
| 5858 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorMigrationDisabled( |
| 5859 | IoMode write_error_mode) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 5860 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5861 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5862 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5863 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5864 | |
| 5865 | MockQuicData socket_data; |
| 5866 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 5867 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5868 | socket_data.AddWrite(write_error_mode, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 5869 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5870 | |
| 5871 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5872 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5873 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5874 | request.Request( |
| 5875 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 5876 | SocketTag(), |
| 5877 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 5878 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5879 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 5880 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5881 | EXPECT_TRUE(stream.get()); |
| 5882 | |
| 5883 | // Cause QUIC stream to be created. |
| 5884 | HttpRequestInfo request_info; |
| 5885 | request_info.method = "GET"; |
| 5886 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 5887 | request_info.traffic_annotation = |
| 5888 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 5889 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 5890 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5891 | |
| 5892 | // Ensure that session is alive and active. |
| 5893 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 5894 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5895 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 5896 | |
| 5897 | // Set session config to have connection migration disabled. |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 5898 | quic::test::QuicConfigPeer::SetReceivedDisableConnectionMigration( |
| 5899 | session->config()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5900 | EXPECT_TRUE(session->config()->DisableConnectionMigration()); |
| 5901 | |
| 5902 | // Send GET request on stream. This should cause a write error, which triggers |
| 5903 | // a connection migration attempt. |
| 5904 | HttpResponseInfo response; |
| 5905 | HttpRequestHeaders request_headers; |
| 5906 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 5907 | callback_.callback())); |
| 5908 | // Run message loop to execute migration attempt. |
| 5909 | base::RunLoop().RunUntilIdle(); |
| 5910 | // Migration fails, and session is closed and deleted. |
| 5911 | EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 5912 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 5913 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 5914 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 5915 | } |
| 5916 | |
| 5917 | TEST_P(QuicStreamFactoryTest, |
| 5918 | MigrateSessionOnWriteErrorMigrationDisabledSynchronous) { |
| 5919 | TestMigrationOnWriteErrorMigrationDisabled(SYNCHRONOUS); |
| 5920 | } |
| 5921 | |
| 5922 | TEST_P(QuicStreamFactoryTest, |
| 5923 | MigrateSessionOnWriteErrorMigrationDisabledAsync) { |
| 5924 | TestMigrationOnWriteErrorMigrationDisabled(ASYNC); |
| 5925 | } |
| 5926 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5927 | // Sets up a test which verifies that connection migration on write error can |
| 5928 | // eventually succeed and rewrite the packet on the new network with singals |
| 5929 | // delivered in the following order (alternate network is always availabe): |
| 5930 | // - original network encounters a SYNC/ASYNC write error based on |
| 5931 | // |write_error_mode_on_old_network|, the packet failed to be written is |
| 5932 | // cached, session migrates immediately to the alternate network. |
| 5933 | // - an immediate SYNC/ASYNC write error based on |
| 5934 | // |write_error_mode_on_new_network| is encountered after migration to the |
| 5935 | // alternate network, session migrates immediately to the original network. |
| 5936 | // - an immediate SYNC/ASYNC write error based on |
| 5937 | // |write_error_mode_on_old_network| is encountered after migration to the |
| 5938 | // original network, session migrates immediately to the alternate network. |
| 5939 | // - finally, session successfully sends the packet and reads the response on |
| 5940 | // the alternate network. |
| 5941 | // TODO(zhongyi): once https://crbug.com/855666 is fixed, this test should be |
| 5942 | // modified to test that session is closed early if hopping between networks |
| 5943 | // with consecutive write errors is detected. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5944 | void QuicStreamFactoryTestBase::TestMigrationOnMultipleWriteErrors( |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5945 | IoMode write_error_mode_on_old_network, |
| 5946 | IoMode write_error_mode_on_new_network) { |
| 5947 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5948 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 5949 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 5950 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5951 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 5952 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 5953 | // Set up the socket data used by the original network, which encounters a |
| 5954 | // write erorr. |
| 5955 | MockQuicData socket_data1; |
| 5956 | quic::QuicStreamOffset header_stream_offset = 0; |
| 5957 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5958 | socket_data1.AddWrite( |
| 5959 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 5960 | socket_data1.AddWrite(write_error_mode_on_old_network, |
| 5961 | ERR_ADDRESS_UNREACHABLE); // Write Error |
| 5962 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5963 | |
| 5964 | // Set up the socket data used by the alternate network, which also |
| 5965 | // encounters a write error. |
| 5966 | MockQuicData failed_quic_data2; |
| 5967 | failed_quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5968 | failed_quic_data2.AddWrite(write_error_mode_on_new_network, ERR_FAILED); |
| 5969 | failed_quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 5970 | |
| 5971 | // Set up the third socket data used by original network, which encounters a |
| 5972 | // write error again. |
| 5973 | MockQuicData failed_quic_data1; |
| 5974 | failed_quic_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5975 | failed_quic_data1.AddWrite(write_error_mode_on_old_network, ERR_FAILED); |
| 5976 | failed_quic_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 5977 | |
| 5978 | // Set up the last socket data used by the alternate network, which will |
| 5979 | // finish migration successfully. The request is rewritten to this new socket, |
| 5980 | // and the response to the request is read on this socket. |
| 5981 | MockQuicData socket_data2; |
| 5982 | socket_data2.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 5983 | 2, GetNthClientInitiatedStreamId(0), |
| 5984 | true, true, &header_stream_offset)); |
| 5985 | socket_data2.AddRead( |
| 5986 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 5987 | false, false)); |
| 5988 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 5989 | socket_data2.AddWrite(SYNCHRONOUS, |
| 5990 | client_maker_.MakeAckAndRstPacket( |
| 5991 | 3, false, GetNthClientInitiatedStreamId(0), |
| 5992 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 5993 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 5994 | |
| 5995 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 5996 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 5997 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 5998 | request.Request( |
| 5999 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6000 | SocketTag(), |
| 6001 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6002 | failed_on_default_network_callback_, callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6003 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6004 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6005 | EXPECT_TRUE(stream.get()); |
| 6006 | |
| 6007 | // Cause QUIC stream to be created. |
| 6008 | HttpRequestInfo request_info; |
| 6009 | request_info.method = "GET"; |
| 6010 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6011 | request_info.traffic_annotation = |
| 6012 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6013 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6014 | net_log_, CompletionOnceCallback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6015 | |
| 6016 | // Ensure that session is alive and active. |
| 6017 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6018 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6019 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6020 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6021 | // Send GET request on stream. |
| 6022 | // This should encounter a write error on network 1, |
| 6023 | // then migrate to network 2, which encounters another write error, |
| 6024 | // and migrate again to network 1, which encoutners one more write error. |
| 6025 | // Finally the session migrates to network 2 successfully. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6026 | HttpResponseInfo response; |
| 6027 | HttpRequestHeaders request_headers; |
| 6028 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6029 | callback_.callback())); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6030 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6031 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6032 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6033 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6034 | |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6035 | // Verify that response headers on the migrated socket were delivered to the |
| 6036 | // stream. |
| 6037 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6038 | EXPECT_EQ(200, response.headers->response_code()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6039 | |
| 6040 | stream.reset(); |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6041 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6042 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6043 | EXPECT_TRUE(failed_quic_data2.AllReadDataConsumed()); |
| 6044 | EXPECT_TRUE(failed_quic_data2.AllWriteDataConsumed()); |
| 6045 | EXPECT_TRUE(failed_quic_data1.AllReadDataConsumed()); |
| 6046 | EXPECT_TRUE(failed_quic_data1.AllWriteDataConsumed()); |
| 6047 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 6048 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6049 | } |
| 6050 | |
| 6051 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6052 | TestMigrationOnMultipleWriteErrors( |
| 6053 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6054 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsSyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6058 | TestMigrationOnMultipleWriteErrors( |
| 6059 | /*write_error_mode_on_old_network*/ SYNCHRONOUS, |
| 6060 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncSync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6064 | TestMigrationOnMultipleWriteErrors( |
| 6065 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6066 | /*write_error_mode_on_new_network*/ SYNCHRONOUS); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6067 | } |
| 6068 | |
| 6069 | TEST_P(QuicStreamFactoryTest, MigrateSessionOnMultipleWriteErrorsAsyncAsync) { |
Zhongyi Shi | 7f1d921 | 2018-06-22 23:24:36 | [diff] [blame] | 6070 | TestMigrationOnMultipleWriteErrors( |
| 6071 | /*write_error_mode_on_old_network*/ ASYNC, |
| 6072 | /*write_error_mode_on_new_network*/ ASYNC); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6073 | } |
| 6074 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6075 | // Verifies that a connection is closed when connection migration is triggered |
| 6076 | // on network being disconnected and the handshake is not confirmed. |
| 6077 | TEST_P(QuicStreamFactoryTest, NoMigrationBeforeHandshakeOnNetworkDisconnected) { |
| 6078 | InitializeConnectionMigrationV2Test( |
| 6079 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6080 | |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6081 | // 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] | 6082 | crypto_client_stream_factory_.set_handshake_mode( |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6083 | MockCryptoClientStream::COLD_START_WITH_CHLO_SENT); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6084 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6085 | MockQuicData socket_data; |
Zhongyi Shi | 87965942 | 2018-08-02 17:58:25 | [diff] [blame] | 6086 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 5068bb0 | 2018-08-03 02:44:09 | [diff] [blame] | 6087 | socket_data.AddWrite(ASYNC, client_maker_.MakeDummyCHLOPacket(1)); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6088 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6089 | |
| 6090 | // Create request and QuicHttpStream. |
| 6091 | QuicStreamRequest request(factory_.get()); |
| 6092 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6093 | request.Request( |
| 6094 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6095 | SocketTag(), |
| 6096 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6097 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6098 | // Deliver the network notification, which should cause the connection to be |
| 6099 | // closed. |
| 6100 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6101 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6102 | EXPECT_EQ(ERR_NETWORK_CHANGED, callback_.WaitForResult()); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6103 | |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6104 | EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 6105 | EXPECT_FALSE(HasActiveJob(host_port_pair_, privacy_mode_)); |
Zhongyi Shi | 4293b14 | 2018-07-25 00:33:57 | [diff] [blame] | 6106 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6107 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
Zhongyi Shi | 6abe3381 | 2018-07-24 19:43:11 | [diff] [blame] | 6108 | } |
| 6109 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6110 | // Sets up the connection migration test where network change notification is |
| 6111 | // queued BEFORE connection migration attempt on write error is posted. |
| 6112 | void QuicStreamFactoryTestBase:: |
| 6113 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6114 | bool disconnected) { |
| 6115 | InitializeConnectionMigrationV2Test( |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6116 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6117 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6118 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6119 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6120 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6121 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6122 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6123 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6124 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6125 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6126 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6127 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6128 | |
| 6129 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6130 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6131 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6132 | request.Request( |
| 6133 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6134 | SocketTag(), |
| 6135 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6136 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6137 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6138 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6139 | EXPECT_TRUE(stream.get()); |
| 6140 | |
| 6141 | // Cause QUIC stream to be created. |
| 6142 | HttpRequestInfo request_info; |
| 6143 | request_info.method = "GET"; |
| 6144 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6145 | request_info.traffic_annotation = |
| 6146 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6147 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6148 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6149 | |
| 6150 | // Ensure that session is alive and active. |
| 6151 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6152 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6153 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6154 | |
| 6155 | // Set up second socket data provider that is used after |
| 6156 | // migration. The request is rewritten to this new socket, and the |
| 6157 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6158 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6159 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6160 | 2, GetNthClientInitiatedStreamId(0), |
| 6161 | true, true, &header_stream_offset)); |
| 6162 | socket_data1.AddRead( |
| 6163 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6164 | false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6165 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6166 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6167 | client_maker_.MakeAckAndRstPacket( |
| 6168 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6169 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6170 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6171 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6172 | // First queue a network change notification in the message loop. |
| 6173 | if (disconnected) { |
| 6174 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6175 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6176 | } else { |
| 6177 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6178 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6179 | } |
| 6180 | // Send GET request on stream. This should cause a write error, |
| 6181 | // which triggers a connection migration attempt. This will queue a |
| 6182 | // migration attempt behind the notification in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6183 | HttpResponseInfo response; |
| 6184 | HttpRequestHeaders request_headers; |
| 6185 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6186 | callback_.callback())); |
| 6187 | |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6188 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6189 | // Verify the session is still alive and not marked as going away post |
| 6190 | // migration. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6191 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6192 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6193 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6194 | |
| 6195 | // Verify that response headers on the migrated socket were delivered to the |
| 6196 | // stream. |
| 6197 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6198 | EXPECT_EQ(200, response.headers->response_code()); |
| 6199 | |
| 6200 | stream.reset(); |
| 6201 | |
| 6202 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6203 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6204 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6205 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6206 | } |
| 6207 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6208 | // This test verifies that session attempts connection migration successfully |
| 6209 | // with signals delivered in the following order (alternate network is always |
| 6210 | // available): |
| 6211 | // - a notification that default network is disconnected is queued. |
| 6212 | // - write error is triggered: session posts a task to attempt connection |
| 6213 | // migration, |migration_pending_| set to true. |
| 6214 | // - default network disconnected is delivered: session immediately migrates to |
| 6215 | // the alternate network, |migration_pending_| set to false. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6216 | // - connection migration on write error attempt aborts: writer encountered |
| 6217 | // error is no longer in active use. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6218 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6219 | MigrateOnNetworkDisconnectedWithWriteErrorQueuedLater) { |
| 6220 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6221 | /*disconnected=*/true); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6222 | } |
| 6223 | |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6224 | // This test verifies that session attempts connection migration successfully |
| 6225 | // with signals delivered in the following order (alternate network is always |
| 6226 | // available): |
| 6227 | // - a notification that alternate network is made default is queued. |
| 6228 | // - write error is triggered: session posts a task to attempt connection |
| 6229 | // migration, block future migrations. |
| 6230 | // - new default notification is delivered: migrate back timer spins and task is |
| 6231 | // posted to migrate to the new default network. |
| 6232 | // - connection migration on write error attempt proceeds successfully: session |
| 6233 | // is |
| 6234 | // marked as going away, future migrations unblocked. |
| 6235 | // - migrate back to default network task executed: session is already on the |
| 6236 | // default network, no-op. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6237 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | b24001c0 | 2018-06-18 20:01:52 | [diff] [blame] | 6238 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedEarlier) { |
| 6239 | TestMigrationOnNetworkNotificationWithWriteErrorQueuedLater( |
| 6240 | /*disconnected=*/false); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6241 | } |
| 6242 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6243 | // Sets up the connection migration test where network change notification is |
| 6244 | // queued AFTER connection migration attempt on write error is posted. |
| 6245 | void QuicStreamFactoryTestBase:: |
| 6246 | TestMigrationOnWriteErrorWithNotificationQueuedLater(bool disconnected) { |
Zhongyi Shi | 1a05461 | 2018-06-14 04:59:08 | [diff] [blame] | 6247 | InitializeConnectionMigrationV2Test( |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6248 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6249 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6250 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6251 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6252 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6253 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6254 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6255 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6256 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6257 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 6258 | socket_data.AddWrite(SYNCHRONOUS, ERR_ADDRESS_UNREACHABLE); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6259 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6260 | |
| 6261 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6262 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6263 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6264 | request.Request( |
| 6265 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6266 | SocketTag(), |
| 6267 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6268 | failed_on_default_network_callback_, callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6269 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6270 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6271 | EXPECT_TRUE(stream.get()); |
| 6272 | |
| 6273 | // Cause QUIC stream to be created. |
| 6274 | HttpRequestInfo request_info; |
| 6275 | request_info.method = "GET"; |
| 6276 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6277 | request_info.traffic_annotation = |
| 6278 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6279 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6280 | net_log_, CompletionOnceCallback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6281 | |
| 6282 | // Ensure that session is alive and active. |
| 6283 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6284 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6285 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6286 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6287 | // Set up second socket data provider that is used after |
| 6288 | // migration. The request is rewritten to this new socket, and the |
| 6289 | // response to the request is read on this new socket. |
| 6290 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6291 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6292 | 2, GetNthClientInitiatedStreamId(0), |
| 6293 | true, true, &header_stream_offset)); |
| 6294 | socket_data1.AddRead( |
| 6295 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6296 | false, false)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6297 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6298 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6299 | client_maker_.MakeAckAndRstPacket( |
| 6300 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6301 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6302 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6303 | |
| 6304 | // Send GET request on stream. This should cause a write error, |
| 6305 | // which triggers a connection migration attempt. This will queue a |
| 6306 | // migration attempt in the message loop. |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6307 | HttpResponseInfo response; |
| 6308 | HttpRequestHeaders request_headers; |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6309 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6310 | callback_.callback())); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6311 | |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6312 | // Now queue a network change notification in the message loop behind |
| 6313 | // the migration attempt. |
| 6314 | if (disconnected) { |
| 6315 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6316 | ->QueueNetworkDisconnected(kDefaultNetworkForTests); |
| 6317 | } else { |
| 6318 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6319 | ->QueueNetworkMadeDefault(kNewNetworkForTests); |
| 6320 | } |
| 6321 | |
| 6322 | base::RunLoop().RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6323 | // Verify session is still alive and not marked as going away. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6324 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6325 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6326 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6327 | |
| 6328 | // Verify that response headers on the migrated socket were delivered to the |
| 6329 | // stream. |
| 6330 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6331 | EXPECT_EQ(200, response.headers->response_code()); |
| 6332 | |
| 6333 | stream.reset(); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6334 | |
| 6335 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6336 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6337 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6338 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6339 | } |
| 6340 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6341 | // This test verifies that session attempts connection migration successfully |
| 6342 | // with signals delivered in the following order (alternate network is always |
| 6343 | // available): |
| 6344 | // - write error is triggered: session posts a task to complete connection |
| 6345 | // migration. |
| 6346 | // - a notification that alternate network is made default is queued. |
| 6347 | // - connection migration attempt proceeds successfully, session is marked as |
| 6348 | // going away. |
| 6349 | // - new default notification is delivered after connection migration has been |
| 6350 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6351 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6352 | MigrateOnWriteErrorWithNetworkMadeDefaultQueuedLater) { |
| 6353 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/false); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6354 | } |
| 6355 | |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6356 | // This test verifies that session attempts connection migration successfully |
| 6357 | // with signals delivered in the following order (alternate network is always |
| 6358 | // available): |
| 6359 | // - write error is triggered: session posts a task to complete connection |
| 6360 | // migration. |
| 6361 | // - a notification that default network is diconnected is queued. |
| 6362 | // - connection migration attempt proceeds successfully, session is marked as |
| 6363 | // going away. |
| 6364 | // - disconnect notification is delivered after connection migration has been |
| 6365 | // completed. |
jri | 9f30371 | 2016-09-13 01:10:22 | [diff] [blame] | 6366 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | 1e2bc74 | 2018-06-16 02:06:07 | [diff] [blame] | 6367 | MigrateOnWriteErrorWithNetworkDisconnectedQueuedLater) { |
| 6368 | TestMigrationOnWriteErrorWithNotificationQueuedLater(/*disconnected=*/true); |
jri | ed79618b | 2016-07-02 03:18:52 | [diff] [blame] | 6369 | } |
| 6370 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6371 | // This tests connection migration on write error with signals delivered in the |
| 6372 | // following order: |
| 6373 | // - a synchronous/asynchronous write error is triggered base on |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6374 | // |write_error_mode|: connection migration attempt is posted. |
| 6375 | // - old default network disconnects, migration waits for a new network. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6376 | // - after a pause, new network is connected: session will migrate to new |
| 6377 | // network immediately. |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6378 | // - migration on writer error is exectued and aborts as writer passed in is no |
| 6379 | // longer active in use. |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6380 | // - new network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6381 | void QuicStreamFactoryTestBase::TestMigrationOnWriteErrorPauseBeforeConnected( |
| 6382 | IoMode write_error_mode) { |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6383 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6384 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6385 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6386 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6387 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6388 | // Use the test task runner. |
| 6389 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 6390 | |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6391 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6392 | quic::QuicStreamOffset header_stream_offset = 0; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6393 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // Hanging read. |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6394 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6395 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6396 | socket_data.AddWrite(write_error_mode, ERR_FAILED); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6397 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6398 | |
| 6399 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 6400 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 6401 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6402 | request.Request( |
| 6403 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6404 | SocketTag(), |
| 6405 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6406 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6407 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 6408 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6409 | EXPECT_TRUE(stream.get()); |
| 6410 | |
| 6411 | // Cause QUIC stream to be created. |
| 6412 | HttpRequestInfo request_info; |
| 6413 | request_info.method = "GET"; |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6414 | request_info.url = url_; |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 6415 | request_info.traffic_annotation = |
| 6416 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 6417 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 6418 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6419 | |
| 6420 | // Ensure that session is alive and active. |
| 6421 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6422 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6423 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6424 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6425 | // Send GET request on stream. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6426 | HttpResponseInfo response; |
| 6427 | HttpRequestHeaders request_headers; |
| 6428 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6429 | callback_.callback())); |
| 6430 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6431 | // The connection should still be alive, not marked as going away. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6432 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6433 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6434 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6435 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6436 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6437 | // Set up second socket data provider that is used after migration. |
| 6438 | // The response to the earlier request is read on this new socket. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6439 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6440 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6441 | 2, GetNthClientInitiatedStreamId(0), |
| 6442 | true, true, &header_stream_offset)); |
| 6443 | socket_data1.AddRead( |
| 6444 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6445 | false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6446 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6447 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6448 | client_maker_.MakeAckAndRstPacket( |
| 6449 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6450 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6451 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6452 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6453 | // On a DISCONNECTED notification, nothing happens. |
| 6454 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6455 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6456 | // Add a new network and notify the stream factory of a new connected network. |
| 6457 | // This causes a PING packet to be sent over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6458 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6459 | ->SetConnectedNetworksList({kNewNetworkForTests}); |
| 6460 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6461 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 6462 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6463 | // Ensure that the session is still alive. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6464 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6465 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6466 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6467 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6468 | // Run the message loop migration for write error can finish. |
| 6469 | runner_->RunUntilIdle(); |
| 6470 | |
| 6471 | // Response headers are received over the new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6472 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 6473 | EXPECT_EQ(200, response.headers->response_code()); |
| 6474 | |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6475 | // Check that the session is still alive. |
| 6476 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6477 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6478 | |
| 6479 | // There should be no posted tasks not executed, no way to migrate back to |
| 6480 | // default network. |
| 6481 | EXPECT_TRUE(runner_->GetPostedTasks().empty()); |
| 6482 | |
| 6483 | // Receive signal to mark new network as default. |
| 6484 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6485 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6486 | |
| 6487 | stream.reset(); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6488 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6489 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6490 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6491 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6492 | } |
| 6493 | |
| 6494 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6495 | MigrateSessionOnSyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6496 | TestMigrationOnWriteErrorPauseBeforeConnected(SYNCHRONOUS); |
| 6497 | } |
| 6498 | |
| 6499 | TEST_P(QuicStreamFactoryTest, |
Zhongyi Shi | a3810c5 | 2018-06-15 23:07:19 | [diff] [blame] | 6500 | MigrateSessionOnAsyncWriteErrorPauseBeforeConnected) { |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6501 | TestMigrationOnWriteErrorPauseBeforeConnected(ASYNC); |
| 6502 | } |
| 6503 | |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6504 | // This test verifies that when session successfully migrate to the alternate |
| 6505 | // network, packet write error on the old writer will be ignored and will not |
| 6506 | // trigger connection migration on write error. |
| 6507 | TEST_P(QuicStreamFactoryTest, IgnoreWriteErrorFromOldWriterAfterMigration) { |
| 6508 | InitializeConnectionMigrationV2Test( |
| 6509 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6510 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6511 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6512 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6513 | |
| 6514 | // Using a testing task runner so that we can verify whether the migrate on |
| 6515 | // write error task is posted. |
| 6516 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6517 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6518 | |
| 6519 | MockQuicData socket_data; |
| 6520 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6521 | socket_data.AddWrite( |
| 6522 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6523 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6524 | socket_data.AddWrite(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6525 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6526 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6527 | |
| 6528 | // Create request and QuicHttpStream. |
| 6529 | QuicStreamRequest request(factory_.get()); |
| 6530 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6531 | request.Request( |
| 6532 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6533 | SocketTag(), |
| 6534 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6535 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6536 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6537 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6538 | EXPECT_TRUE(stream.get()); |
| 6539 | |
| 6540 | // Cause QUIC stream to be created. |
| 6541 | HttpRequestInfo request_info; |
| 6542 | request_info.method = "GET"; |
| 6543 | request_info.url = GURL("https://www.example.org/"); |
| 6544 | request_info.traffic_annotation = |
| 6545 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6546 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6547 | net_log_, CompletionOnceCallback())); |
| 6548 | |
| 6549 | // Ensure that session is alive and active. |
| 6550 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6551 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6552 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6553 | |
| 6554 | // Set up second socket data provider that is used after |
| 6555 | // migration. The response to the request is read on this new socket. |
| 6556 | MockQuicData socket_data1; |
| 6557 | socket_data1.AddWrite( |
| 6558 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 6559 | socket_data1.AddRead( |
| 6560 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6561 | false, false)); |
| 6562 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6563 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6564 | client_maker_.MakeAckAndRstPacket( |
| 6565 | 4, false, GetNthClientInitiatedStreamId(0), |
| 6566 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 6567 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6568 | |
| 6569 | // Send GET request on stream. |
| 6570 | HttpResponseInfo response; |
| 6571 | HttpRequestHeaders request_headers; |
| 6572 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6573 | callback_.callback())); |
| 6574 | |
| 6575 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6576 | // Now notify network is disconnected, cause the migration to complete |
| 6577 | // immediately. |
| 6578 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6579 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6580 | // There will be two pending task, one will complete migration with no delay |
| 6581 | // and the other will attempt to migrate back to the default network with |
| 6582 | // delay. |
| 6583 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6584 | |
| 6585 | // Complete migration. |
| 6586 | task_runner->RunUntilIdle(); |
| 6587 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6588 | |
| 6589 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6590 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6591 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6592 | |
| 6593 | // Verify that response headers on the migrated socket were delivered to the |
| 6594 | // stream. |
| 6595 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6596 | EXPECT_EQ(200, response.headers->response_code()); |
| 6597 | |
| 6598 | // Resume the old socket data, a write error will be delivered to the old |
| 6599 | // packet writer. Verify no additional task is posted. |
| 6600 | socket_data.Resume(); |
| 6601 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6602 | |
| 6603 | stream.reset(); |
| 6604 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6605 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6606 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6607 | } |
| 6608 | |
| 6609 | // This test verifies that when session successfully migrate to the alternate |
| 6610 | // network, packet read error on the old reader will be ignored and will not |
| 6611 | // close the connection. |
| 6612 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorFromOldReaderAfterMigration) { |
| 6613 | InitializeConnectionMigrationV2Test( |
| 6614 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6615 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6616 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6617 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6618 | |
| 6619 | // Using a testing task runner. |
| 6620 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6621 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6622 | |
| 6623 | MockQuicData socket_data; |
| 6624 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6625 | socket_data.AddWrite( |
| 6626 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6627 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6628 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6629 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6630 | |
| 6631 | // Create request and QuicHttpStream. |
| 6632 | QuicStreamRequest request(factory_.get()); |
| 6633 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6634 | request.Request( |
| 6635 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6636 | SocketTag(), |
| 6637 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6638 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6639 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6640 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6641 | EXPECT_TRUE(stream.get()); |
| 6642 | |
| 6643 | // Cause QUIC stream to be created. |
| 6644 | HttpRequestInfo request_info; |
| 6645 | request_info.method = "GET"; |
| 6646 | request_info.url = GURL("https://www.example.org/"); |
| 6647 | request_info.traffic_annotation = |
| 6648 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6649 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6650 | net_log_, CompletionOnceCallback())); |
| 6651 | |
| 6652 | // Ensure that session is alive and active. |
| 6653 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6654 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6655 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6656 | |
| 6657 | // Set up second socket data provider that is used after |
| 6658 | // migration. The request is written to this new socket, and the |
| 6659 | // response to the request is read on this new socket. |
| 6660 | MockQuicData socket_data1; |
| 6661 | socket_data1.AddWrite( |
| 6662 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 6663 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6664 | 3, GetNthClientInitiatedStreamId(0), |
| 6665 | true, true, &header_stream_offset)); |
| 6666 | socket_data1.AddRead( |
| 6667 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6668 | false, false)); |
| 6669 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6670 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6671 | client_maker_.MakeAckAndRstPacket( |
| 6672 | 4, false, GetNthClientInitiatedStreamId(0), |
| 6673 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 6674 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6675 | |
| 6676 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6677 | // Now notify network is disconnected, cause the migration to complete |
| 6678 | // immediately. |
| 6679 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6680 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6681 | // There will be two pending task, one will complete migration with no delay |
| 6682 | // and the other will attempt to migrate back to the default network with |
| 6683 | // delay. |
| 6684 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6685 | |
| 6686 | // Complete migration. |
| 6687 | task_runner->RunUntilIdle(); |
| 6688 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6689 | |
| 6690 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6691 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6692 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6693 | |
| 6694 | // Send GET request on stream. |
| 6695 | HttpResponseInfo response; |
| 6696 | HttpRequestHeaders request_headers; |
| 6697 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6698 | callback_.callback())); |
| 6699 | |
| 6700 | // Verify that response headers on the migrated socket were delivered to the |
| 6701 | // stream. |
| 6702 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6703 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6704 | EXPECT_EQ(200, response.headers->response_code()); |
| 6705 | |
| 6706 | // Resume the old socket data, a read error will be delivered to the old |
| 6707 | // packet reader. Verify that the session is not affected. |
| 6708 | socket_data.Resume(); |
| 6709 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6710 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6711 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6712 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6713 | |
| 6714 | stream.reset(); |
| 6715 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6716 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6717 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6718 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6719 | } |
| 6720 | |
| 6721 | // This test verifies that after migration on network is executed, packet |
| 6722 | // read error on the old reader will be ignored and will not close the |
| 6723 | // connection. |
| 6724 | TEST_P(QuicStreamFactoryTest, IgnoreReadErrorOnOldReaderDuringMigration) { |
| 6725 | InitializeConnectionMigrationV2Test( |
| 6726 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6727 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6728 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6729 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6730 | |
| 6731 | // Using a testing task runner. |
| 6732 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6733 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6734 | |
| 6735 | MockQuicData socket_data; |
| 6736 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6737 | socket_data.AddWrite( |
| 6738 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6739 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 6740 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); |
| 6741 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6742 | |
| 6743 | // Create request and QuicHttpStream. |
| 6744 | QuicStreamRequest request(factory_.get()); |
| 6745 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6746 | request.Request( |
| 6747 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6748 | SocketTag(), |
| 6749 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6750 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6751 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6752 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6753 | EXPECT_TRUE(stream.get()); |
| 6754 | |
| 6755 | // Cause QUIC stream to be created. |
| 6756 | HttpRequestInfo request_info; |
| 6757 | request_info.method = "GET"; |
| 6758 | request_info.url = GURL("https://www.example.org/"); |
| 6759 | request_info.traffic_annotation = |
| 6760 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6761 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6762 | net_log_, CompletionOnceCallback())); |
| 6763 | |
| 6764 | // Ensure that session is alive and active. |
| 6765 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6766 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6767 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6768 | |
| 6769 | // Set up second socket data provider that is used after |
| 6770 | // migration. The request is written to this new socket, and the |
| 6771 | // response to the request is read on this new socket. |
| 6772 | MockQuicData socket_data1; |
| 6773 | socket_data1.AddWrite( |
| 6774 | SYNCHRONOUS, client_maker_.MakePingPacket(2, /*include_version=*/true)); |
| 6775 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6776 | 3, GetNthClientInitiatedStreamId(0), |
| 6777 | true, true, &header_stream_offset)); |
| 6778 | socket_data1.AddRead( |
| 6779 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6780 | false, false)); |
| 6781 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 6782 | socket_data1.AddWrite(SYNCHRONOUS, |
| 6783 | client_maker_.MakeAckAndRstPacket( |
| 6784 | 4, false, GetNthClientInitiatedStreamId(0), |
| 6785 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
| 6786 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6787 | |
| 6788 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6789 | // Now notify network is disconnected, cause the migration to complete |
| 6790 | // immediately. |
| 6791 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 6792 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 6793 | // There will be two pending task, one will complete migration with no delay |
| 6794 | // and the other will attempt to migrate back to the default network with |
| 6795 | // delay. |
| 6796 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6797 | |
| 6798 | // Resume the old socket data, a read error will be delivered to the old |
| 6799 | // packet reader. Verify that the session is not affected. |
| 6800 | socket_data.Resume(); |
| 6801 | EXPECT_EQ(2u, task_runner->GetPendingTaskCount()); |
| 6802 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6803 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6804 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6805 | |
| 6806 | // Complete migration. |
| 6807 | task_runner->RunUntilIdle(); |
| 6808 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6809 | |
| 6810 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6811 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6812 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6813 | |
| 6814 | // Send GET request on stream. |
| 6815 | HttpResponseInfo response; |
| 6816 | HttpRequestHeaders request_headers; |
| 6817 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6818 | callback_.callback())); |
| 6819 | |
| 6820 | // Verify that response headers on the migrated socket were delivered to the |
| 6821 | // stream. |
| 6822 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 6823 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6824 | EXPECT_EQ(200, response.headers->response_code()); |
| 6825 | |
| 6826 | stream.reset(); |
| 6827 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6828 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6829 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6830 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6831 | } |
| 6832 | |
| 6833 | // This test verifies that after migration on write error is posted, packet |
| 6834 | // read error on the old reader will be ignored and will not close the |
| 6835 | // connection. |
| 6836 | TEST_P(QuicStreamFactoryTest, |
| 6837 | IgnoreReadErrorOnOldReaderDuringPendingMigrationOnWriteError) { |
| 6838 | InitializeConnectionMigrationV2Test( |
| 6839 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 6840 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6841 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6842 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6843 | |
| 6844 | // Using a testing task runner. |
| 6845 | auto task_runner = base::MakeRefCounted<base::TestMockTimeTaskRunner>(); |
| 6846 | QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), task_runner.get()); |
| 6847 | |
| 6848 | MockQuicData socket_data; |
| 6849 | quic::QuicStreamOffset header_stream_offset = 0; |
| 6850 | socket_data.AddWrite( |
| 6851 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 6852 | socket_data.AddWrite(ASYNC, ERR_FAILED); // Write error. |
| 6853 | socket_data.AddRead(ASYNC, ERR_ADDRESS_UNREACHABLE); // Read error. |
| 6854 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 6855 | |
| 6856 | // Create request and QuicHttpStream. |
| 6857 | QuicStreamRequest request(factory_.get()); |
| 6858 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 6859 | request.Request( |
| 6860 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 6861 | SocketTag(), |
| 6862 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 6863 | failed_on_default_network_callback_, callback_.callback())); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6864 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 6865 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 6866 | EXPECT_TRUE(stream.get()); |
| 6867 | |
| 6868 | // Cause QUIC stream to be created. |
| 6869 | HttpRequestInfo request_info; |
| 6870 | request_info.method = "GET"; |
| 6871 | request_info.url = GURL("https://www.example.org/"); |
| 6872 | request_info.traffic_annotation = |
| 6873 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6874 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
| 6875 | net_log_, CompletionOnceCallback())); |
| 6876 | |
| 6877 | // Ensure that session is alive and active. |
| 6878 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 6879 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6880 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6881 | |
| 6882 | // Set up second socket data provider that is used after |
| 6883 | // migration. The request is written to this new socket, and the |
| 6884 | // response to the request is read on this new socket. |
| 6885 | MockQuicData socket_data1; |
| 6886 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 6887 | 2, GetNthClientInitiatedStreamId(0), |
| 6888 | true, true, &header_stream_offset)); |
| 6889 | socket_data1.AddRead( |
| 6890 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 6891 | false, false)); |
| 6892 | |
| 6893 | socket_data1.AddRead(ASYNC, ERR_IO_PENDING); // Pause. |
| 6894 | socket_data1.AddRead(ASYNC, ERR_FAILED); // Read error to close connection. |
| 6895 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
| 6896 | |
| 6897 | EXPECT_EQ(0u, task_runner->GetPendingTaskCount()); |
| 6898 | // Send GET request on stream. |
| 6899 | HttpResponseInfo response; |
| 6900 | HttpRequestHeaders request_headers; |
| 6901 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 6902 | callback_.callback())); |
| 6903 | // Run the message loop to complete asynchronous write and read with errors. |
| 6904 | base::RunLoop().RunUntilIdle(); |
| 6905 | // There will be one pending task to complete migration on write error. |
| 6906 | // Verify session is not closed with read error. |
| 6907 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
| 6908 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 6909 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 6910 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6911 | |
| 6912 | // Complete migration. |
| 6913 | task_runner->RunUntilIdle(); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6914 | // There will be one more task posted attempting to migrate back to the |
| 6915 | // default network. |
| 6916 | EXPECT_EQ(1u, task_runner->GetPendingTaskCount()); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6917 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | a7dd46b | 2018-07-12 22:59:29 | [diff] [blame] | 6918 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | f3d6cddb | 2018-07-11 03:30:02 | [diff] [blame] | 6919 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 6920 | |
| 6921 | // Verify that response headers on the migrated socket were delivered to the |
| 6922 | // stream. |
| 6923 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 6924 | EXPECT_EQ(200, response.headers->response_code()); |
| 6925 | |
| 6926 | // Resume to consume the read error on new socket, which will close |
| 6927 | // the connection. |
| 6928 | socket_data1.Resume(); |
| 6929 | |
| 6930 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 6931 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 6932 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 6933 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 6934 | } |
| 6935 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6936 | // Migrate on asynchronous write error, old network disconnects after alternate |
| 6937 | // network connects. |
| 6938 | TEST_P(QuicStreamFactoryTest, |
| 6939 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectAysnc) { |
| 6940 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6941 | ASYNC, /*disconnect_before_connect*/ false); |
| 6942 | } |
| 6943 | |
| 6944 | // Migrate on synchronous write error, old network disconnects after alternate |
| 6945 | // network connects. |
| 6946 | TEST_P(QuicStreamFactoryTest, |
| 6947 | MigrateSessionOnWriteErrorWithDisconnectAfterConnectSync) { |
| 6948 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6949 | SYNCHRONOUS, /*disconnect_before_connect*/ false); |
| 6950 | } |
| 6951 | |
| 6952 | // Migrate on asynchronous write error, old network disconnects before alternate |
| 6953 | // network connects. |
| 6954 | TEST_P(QuicStreamFactoryTest, |
| 6955 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectAysnc) { |
| 6956 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6957 | ASYNC, /*disconnect_before_connect*/ true); |
| 6958 | } |
| 6959 | |
| 6960 | // Migrate on synchronous write error, old network disconnects before alternate |
| 6961 | // network connects. |
| 6962 | TEST_P(QuicStreamFactoryTest, |
| 6963 | MigrateSessionOnWriteErrorWithDisconnectBeforeConnectSync) { |
| 6964 | TestMigrationOnWriteErrorWithMultipleNotifications( |
| 6965 | SYNCHRONOUS, /*disconnect_before_connect*/ true); |
| 6966 | } |
| 6967 | |
| 6968 | // Setps up test which verifies that session successfully migrate to alternate |
| 6969 | // network with signals delivered in the following order: |
| 6970 | // *NOTE* Signal (A) and (B) can reverse order based on |
| 6971 | // |disconnect_before_connect|. |
| 6972 | // - (No alternate network is connected) session connects to |
| 6973 | // kDefaultNetworkForTests. |
| 6974 | // - An async/sync write error is encountered based on |write_error_mode|: |
| 6975 | // session posted task to migrate session on write error. |
| 6976 | // - Posted task is executed, miration moves to pending state due to lack of |
| 6977 | // alternate network. |
| 6978 | // - (A) An alternate network is connected, pending migration completes. |
| 6979 | // - (B) Old default network disconnects, no migration will be attempted as |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 6980 | // session has already migrate to the alternate network. |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6981 | // - The alternate network is made default. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6982 | void QuicStreamFactoryTestBase:: |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6983 | TestMigrationOnWriteErrorWithMultipleNotifications( |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6984 | IoMode write_error_mode, |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6985 | bool disconnect_before_connect) { |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 6986 | InitializeConnectionMigrationV2Test({kDefaultNetworkForTests}); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6987 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 6988 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6989 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 6990 | |
| 6991 | MockQuicData socket_data; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 6992 | quic::QuicStreamOffset header_stream_offset = 0; |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6993 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 6994 | socket_data.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 6995 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 6996 | socket_data.AddWrite(write_error_mode, ERR_FAILED); // Write error. |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 6997 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 6998 | |
| 6999 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7000 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7001 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7002 | request.Request( |
| 7003 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7004 | SocketTag(), |
| 7005 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7006 | failed_on_default_network_callback_, callback_.callback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7007 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7008 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7009 | EXPECT_TRUE(stream.get()); |
| 7010 | |
| 7011 | // Cause QUIC stream to be created. |
| 7012 | HttpRequestInfo request_info; |
| 7013 | request_info.method = "GET"; |
| 7014 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7015 | request_info.traffic_annotation = |
| 7016 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7017 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7018 | net_log_, CompletionOnceCallback())); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7019 | |
| 7020 | // Ensure that session is alive and active. |
| 7021 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7022 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7023 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7024 | |
| 7025 | // Send GET request on stream. This should cause a write error, which triggers |
| 7026 | // a connection migration attempt. |
| 7027 | HttpResponseInfo response; |
| 7028 | HttpRequestHeaders request_headers; |
| 7029 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7030 | callback_.callback())); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7031 | // Run the message loop so that posted task to migrate to socket will be |
| 7032 | // executed. A new task will be posted to wait for a new network. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7033 | base::RunLoop().RunUntilIdle(); |
| 7034 | |
| 7035 | // In this particular code path, the network will not yet be marked |
| 7036 | // as going away and the session will still be alive. |
| 7037 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7038 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7039 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7040 | EXPECT_EQ(ERR_IO_PENDING, stream->ReadResponseHeaders(callback_.callback())); |
| 7041 | |
| 7042 | // Set up second socket data provider that is used after |
| 7043 | // migration. The request is rewritten to this new socket, and the |
| 7044 | // response to the request is read on this new socket. |
| 7045 | MockQuicData socket_data1; |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7046 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 7047 | 2, GetNthClientInitiatedStreamId(0), |
| 7048 | true, true, &header_stream_offset)); |
| 7049 | socket_data1.AddRead( |
| 7050 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 7051 | false, false)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7052 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7053 | socket_data1.AddWrite(SYNCHRONOUS, |
| 7054 | client_maker_.MakeAckAndRstPacket( |
| 7055 | 3, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7056 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7057 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7058 | |
| 7059 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7060 | ->SetConnectedNetworksList( |
| 7061 | {kDefaultNetworkForTests, kNewNetworkForTests}); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7062 | if (disconnect_before_connect) { |
| 7063 | // Now deliver a DISCONNECT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7064 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7065 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7066 | |
| 7067 | // Now deliver a CONNECTED notification and completes migration. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7068 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7069 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7070 | } else { |
| 7071 | // Now deliver a CONNECTED notification and completes migration. |
| 7072 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7073 | ->NotifyNetworkConnected(kNewNetworkForTests); |
| 7074 | |
| 7075 | // Now deliver a DISCONNECT notification. |
| 7076 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 7077 | ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7078 | } |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7079 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7080 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7081 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7082 | |
| 7083 | // This is the callback for the response headers that returned |
| 7084 | // pending previously, because no result was available. Check that |
| 7085 | // the result is now available due to the successful migration. |
| 7086 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 7087 | EXPECT_EQ(200, response.headers->response_code()); |
| 7088 | |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7089 | // Deliver a MADEDEFAULT notification. |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7090 | scoped_mock_network_change_notifier_->mock_network_change_notifier() |
Zhongyi Shi | 4ac9e1f | 2018-06-21 05:21:47 | [diff] [blame] | 7091 | ->NotifyNetworkMadeDefault(kNewNetworkForTests); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7092 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7093 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7094 | EXPECT_EQ(OK, request2.Request(host_port_pair_, version_, privacy_mode_, |
| 7095 | DEFAULT_PRIORITY, SocketTag(), |
| 7096 | /*cert_verify_flags=*/0, url_, net_log_, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7097 | &net_error_details_, |
| 7098 | failed_on_default_network_callback_, |
| 7099 | callback_.callback())); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7100 | std::unique_ptr<HttpStream> stream2 = CreateStream(&request2); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7101 | EXPECT_TRUE(stream2.get()); |
| 7102 | |
| 7103 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
Zhongyi Shi | 329f5cbd | 2018-06-22 23:51:18 | [diff] [blame] | 7104 | EXPECT_EQ(session, GetActiveSession(host_port_pair_)); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7105 | |
| 7106 | stream.reset(); |
| 7107 | stream2.reset(); |
| 7108 | |
| 7109 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7110 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7111 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7112 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
jri | 5b78551 | 2016-09-13 04:29:11 | [diff] [blame] | 7113 | } |
| 7114 | |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7115 | TEST_P(QuicStreamFactoryTest, ServerMigration) { |
| 7116 | allow_server_migration_ = true; |
| 7117 | Initialize(); |
| 7118 | |
| 7119 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7120 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7121 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7122 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7123 | MockQuicData socket_data1; |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7124 | quic::QuicStreamOffset header_stream_offset = 0; |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7125 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 5cb52246 | 2017-04-25 20:18:36 | [diff] [blame] | 7126 | socket_data1.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7127 | SYNCHRONOUS, ConstructInitialSettingsPacket(1, &header_stream_offset)); |
| 7128 | socket_data1.AddWrite(SYNCHRONOUS, ConstructGetRequestPacket( |
| 7129 | 2, GetNthClientInitiatedStreamId(0), |
| 7130 | true, true, &header_stream_offset)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7131 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7132 | |
| 7133 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7134 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7135 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7136 | request.Request( |
| 7137 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7138 | SocketTag(), |
| 7139 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7140 | failed_on_default_network_callback_, callback_.callback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7141 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7142 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7143 | EXPECT_TRUE(stream.get()); |
| 7144 | |
| 7145 | // Cause QUIC stream to be created. |
| 7146 | HttpRequestInfo request_info; |
| 7147 | request_info.method = "GET"; |
| 7148 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7149 | request_info.traffic_annotation = |
| 7150 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7151 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7152 | net_log_, CompletionOnceCallback())); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7153 | |
| 7154 | // Ensure that session is alive and active. |
| 7155 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7156 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7157 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7158 | |
| 7159 | // Send GET request on stream. |
| 7160 | HttpResponseInfo response; |
| 7161 | HttpRequestHeaders request_headers; |
| 7162 | EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 7163 | callback_.callback())); |
| 7164 | |
| 7165 | IPEndPoint ip; |
| 7166 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7167 | DVLOG(1) << "Socket connected to: " << ip.address().ToString() << " " |
| 7168 | << ip.port(); |
| 7169 | |
| 7170 | // Set up second socket data provider that is used after |
| 7171 | // migration. The request is rewritten to this new socket, and the |
| 7172 | // response to the request is read on this new socket. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7173 | MockQuicData socket_data2; |
| 7174 | socket_data2.AddWrite( |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7175 | SYNCHRONOUS, client_maker_.MakePingPacket(3, /*include_version=*/true)); |
| 7176 | socket_data2.AddRead( |
| 7177 | ASYNC, ConstructOkResponsePacket(1, GetNthClientInitiatedStreamId(0), |
| 7178 | false, false)); |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7179 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7180 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7181 | client_maker_.MakeAckAndRstPacket( |
| 7182 | 4, false, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7183 | quic::QUIC_STREAM_CANCELLED, 1, 1, 1, true)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7184 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7185 | |
| 7186 | const uint8_t kTestIpAddress[] = {1, 2, 3, 4}; |
| 7187 | const uint16_t kTestPort = 123; |
Zhongyi Shi | f124a58 | 2017-11-02 00:15:04 | [diff] [blame] | 7188 | session->Migrate(NetworkChangeNotifier::kInvalidNetworkHandle, |
| 7189 | IPEndPoint(IPAddress(kTestIpAddress), kTestPort), true, |
| 7190 | net_log_); |
jri | 217455a1 | 2016-07-13 20:15:09 | [diff] [blame] | 7191 | |
| 7192 | session->GetDefaultSocket()->GetPeerAddress(&ip); |
| 7193 | DVLOG(1) << "Socket migrated to: " << ip.address().ToString() << " " |
| 7194 | << ip.port(); |
| 7195 | |
| 7196 | // The session should be alive and active. |
| 7197 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7198 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7199 | EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 7200 | |
| 7201 | // Run the message loop so that data queued in the new socket is read by the |
| 7202 | // packet reader. |
| 7203 | base::RunLoop().RunUntilIdle(); |
| 7204 | |
| 7205 | // Verify that response headers on the migrated socket were delivered to the |
| 7206 | // stream. |
| 7207 | EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 7208 | EXPECT_EQ(200, response.headers->response_code()); |
| 7209 | |
| 7210 | stream.reset(); |
| 7211 | |
| 7212 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7213 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7214 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7215 | EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 7216 | } |
| 7217 | |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7218 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv4) { |
| 7219 | // Add alternate IPv4 server address to config. |
| 7220 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7221 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7222 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7223 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7224 | VerifyServerMigration(config, alt_address); |
| 7225 | } |
| 7226 | |
| 7227 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv6) { |
| 7228 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7229 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7230 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7231 | // Add alternate IPv6 server address to config. |
| 7232 | IPEndPoint alt_address = IPEndPoint( |
| 7233 | 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] | 7234 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7235 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7236 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7237 | VerifyServerMigration(config, alt_address); |
| 7238 | } |
| 7239 | |
| 7240 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv6ToIPv4) { |
| 7241 | // Add a resolver rule to make initial connection to an IPv6 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7242 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 7243 | "fe80::aebc:32ff:febb:1e33", ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7244 | // Add alternate IPv4 server address to config. |
| 7245 | IPEndPoint alt_address = IPEndPoint(IPAddress(1, 2, 3, 4), 123); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7246 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7247 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7248 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7249 | IPEndPoint expected_address( |
| 7250 | ConvertIPv4ToIPv4MappedIPv6(alt_address.address()), alt_address.port()); |
| 7251 | VerifyServerMigration(config, expected_address); |
| 7252 | } |
| 7253 | |
| 7254 | TEST_P(QuicStreamFactoryTest, ServerMigrationIPv4ToIPv6Fails) { |
| 7255 | allow_server_migration_ = true; |
| 7256 | Initialize(); |
| 7257 | |
| 7258 | // Add a resolver rule to make initial connection to an IPv4 address. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 7259 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), "1.2.3.4", |
| 7260 | ""); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7261 | // Add alternate IPv6 server address to config. |
| 7262 | IPEndPoint alt_address = IPEndPoint( |
| 7263 | 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] | 7264 | quic::QuicConfig config; |
fayang | 91ca201 | 2016-11-22 07:42:46 | [diff] [blame] | 7265 | config.SetAlternateServerAddressToSend( |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7266 | quic::QuicSocketAddress(quic::QuicSocketAddressImpl(alt_address))); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7267 | |
| 7268 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7269 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7270 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7271 | |
| 7272 | crypto_client_stream_factory_.SetConfig(config); |
| 7273 | |
| 7274 | // Set up only socket data provider. |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7275 | MockQuicData socket_data1; |
| 7276 | socket_data1.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7277 | socket_data1.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 7278 | socket_data1.AddWrite( |
| 7279 | SYNCHRONOUS, |
| 7280 | client_maker_.MakeRstPacket(2, true, GetNthClientInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7281 | quic::QUIC_STREAM_CANCELLED)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7282 | socket_data1.AddSocketDataToFactory(socket_factory_.get()); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7283 | |
| 7284 | // Create request and QuicHttpStream. |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7285 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7286 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7287 | request.Request( |
| 7288 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7289 | SocketTag(), |
| 7290 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7291 | failed_on_default_network_callback_, callback_.callback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7292 | EXPECT_EQ(OK, callback_.WaitForResult()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7293 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7294 | EXPECT_TRUE(stream.get()); |
| 7295 | |
| 7296 | // Cause QUIC stream to be created. |
| 7297 | HttpRequestInfo request_info; |
| 7298 | request_info.method = "GET"; |
| 7299 | request_info.url = GURL("https://www.example.org/"); |
Ramin Halavati | 683bcaa9 | 2018-02-14 08:42:39 | [diff] [blame] | 7300 | request_info.traffic_annotation = |
| 7301 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 7302 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, true, DEFAULT_PRIORITY, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 7303 | net_log_, CompletionOnceCallback())); |
jri | 053fdbd | 2016-08-19 02:33:05 | [diff] [blame] | 7304 | |
| 7305 | // Ensure that session is alive and active. |
| 7306 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 7307 | EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 7308 | EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 7309 | |
| 7310 | IPEndPoint actual_address; |
| 7311 | session->GetDefaultSocket()->GetPeerAddress(&actual_address); |
| 7312 | // No migration should have happened. |
| 7313 | IPEndPoint expected_address = |
| 7314 | IPEndPoint(IPAddress(1, 2, 3, 4), kDefaultServerPort); |
| 7315 | EXPECT_EQ(actual_address, expected_address); |
| 7316 | DVLOG(1) << "Socket connected to: " << actual_address.address().ToString() |
| 7317 | << " " << actual_address.port(); |
| 7318 | DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 7319 | << " " << expected_address.port(); |
| 7320 | |
| 7321 | stream.reset(); |
| 7322 | EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 7323 | EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 7324 | } |
| 7325 | |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7326 | TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7327 | Initialize(); |
rch | 6faa4d4 | 2016-01-05 20:48:43 | [diff] [blame] | 7328 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 7329 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7330 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 7331 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7332 | MockQuicData socket_data; |
| 7333 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7334 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 7335 | socket_data.AddWrite( |
| 7336 | SYNCHRONOUS, ConstructClientRstPacket(2, quic::QUIC_RST_ACKNOWLEDGEMENT)); |
Renjie | ba55fae | 2018-09-20 03:05:16 | [diff] [blame] | 7337 | socket_data.AddWrite( |
| 7338 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 7339 | 3, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7340 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7341 | |
rch | a0056973 | 2016-08-27 11:09:36 | [diff] [blame] | 7342 | MockQuicData socket_data2; |
| 7343 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 7344 | socket_data2.AddWrite(SYNCHRONOUS, |
| 7345 | ConstructInitialSettingsPacket(1, nullptr)); |
Zhongyi Shi | 5f587cc | 2017-11-21 23:24:17 | [diff] [blame] | 7346 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7347 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7348 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7349 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7350 | request.Request( |
| 7351 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7352 | SocketTag(), |
| 7353 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7354 | failed_on_default_network_callback_, callback_.callback())); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7355 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7356 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Yixin Wang | 7891a39d | 2017-11-08 20:59:24 | [diff] [blame] | 7357 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7358 | HttpRequestInfo request_info; |
| 7359 | request_info.traffic_annotation = |
| 7360 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7361 | EXPECT_EQ(OK, stream->InitializeStream(&request_info, false, DEFAULT_PRIORITY, |
Bence Béky | d8a21fc3 | 2018-06-27 18:29:58 | [diff] [blame] | 7362 | net_log_, CompletionOnceCallback())); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7363 | |
nharper | 642ae4b | 2016-06-30 00:40:36 | [diff] [blame] | 7364 | ssl_config_service_->NotifySSLConfigChange(); |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7365 | EXPECT_EQ(ERR_CERT_DATABASE_CHANGED, |
| 7366 | stream->ReadResponseHeaders(callback_.callback())); |
jri | 7046038f | 2015-10-22 00:29:26 | [diff] [blame] | 7367 | EXPECT_FALSE(factory_->require_confirmation()); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7368 | |
| 7369 | // Now attempting to request a stream to the same origin should create |
| 7370 | // a new session. |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7371 | |
zhongyi | 98d6a926 | 2017-05-19 02:47:45 | [diff] [blame] | 7372 | QuicStreamRequest request2(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 7373 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 7374 | request2.Request( |
| 7375 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 7376 | SocketTag(), |
| 7377 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 7378 | failed_on_default_network_callback_, callback_.callback())); |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7379 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7380 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
Cherie Shi | e615a084 | 2018-02-28 02:01:13 | [diff] [blame] | 7381 | stream = CreateStream(&request2); |
| 7382 | stream.reset(); // Will reset stream 3. |
rch | 02d8779 | 2015-09-09 09:05:53 | [diff] [blame] | 7383 | |
| 7384 | EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 7385 | EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 7386 | EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 7387 | EXPECT_TRUE(socket_data2.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( |
| 7861 | session, GetNthServerInitiatedStreamId(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( |
| 7886 | SYNCHRONOUS, |
| 7887 | client_maker_.MakeRstPacket(2, true, GetNthServerInitiatedStreamId(0), |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 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( |
| 7914 | session, GetNthServerInitiatedStreamId(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 | |
Bence Béky | ce380cb | 2018-04-26 23:39:55 | [diff] [blame] | 8049 | INSTANTIATE_TEST_CASE_P(VersionIncludeStreamDependencySequence, |
bnc | 359ed2a | 2016-04-29 20:43:45 | [diff] [blame] | 8050 | QuicStreamFactoryWithDestinationTest, |
| 8051 | ::testing::ValuesIn(GetPoolingTestParams())); |
| 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 | |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8434 | // Passes |max_time_before_crypto_handshake_seconds| and |
| 8435 | // |max_idle_time_before_crypto_handshake_seconds| to QuicStreamFactory, then |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8436 | // checks that its internal quic::QuicConfig is correct. |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8437 | TEST_P(QuicStreamFactoryTest, ConfigMaxTimeBeforeCryptoHandshake) { |
| 8438 | max_time_before_crypto_handshake_seconds_ = 11; |
| 8439 | max_idle_time_before_crypto_handshake_seconds_ = 13; |
| 8440 | |
| 8441 | Initialize(); |
| 8442 | |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8443 | const quic::QuicConfig* config = |
| 8444 | QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 8445 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(11), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8446 | config->max_time_before_crypto_handshake()); |
Ryan Hamilton | 8d9ee76e | 2018-05-29 23:52:52 | [diff] [blame] | 8447 | EXPECT_EQ(quic::QuicTime::Delta::FromSeconds(13), |
Yixin Wang | 469da56 | 2017-11-15 21:34:58 | [diff] [blame] | 8448 | config->max_idle_time_before_crypto_handshake()); |
| 8449 | } |
| 8450 | |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8451 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8452 | // succeeds asynchronously, then crypto handshake fails synchronously. |
| 8453 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncSync) { |
| 8454 | Initialize(); |
| 8455 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8456 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8457 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8458 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8459 | |
| 8460 | MockQuicData socket_data; |
| 8461 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8462 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8463 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8464 | |
| 8465 | QuicStreamRequest request(factory_.get()); |
| 8466 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8467 | request.Request( |
| 8468 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8469 | SocketTag(), |
| 8470 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8471 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8472 | |
| 8473 | TestCompletionCallback host_resolution_callback; |
| 8474 | EXPECT_TRUE( |
| 8475 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8476 | |
| 8477 | // |host_resolver_| has not finished host resolution at this point, so |
| 8478 | // |host_resolution_callback| should not have a result. |
| 8479 | base::RunLoop().RunUntilIdle(); |
| 8480 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8481 | |
| 8482 | // Allow |host_resolver_| to finish host resolution. |
| 8483 | // Since the request fails immediately after host resolution (getting |
| 8484 | // ERR_FAILED from socket reads/writes), |host_resolution_callback| should be |
| 8485 | // called with ERR_QUIC_PROTOCOL_ERROR since that's the next result in |
| 8486 | // forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8487 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8488 | base::RunLoop().RunUntilIdle(); |
| 8489 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8490 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, host_resolution_callback.WaitForResult()); |
| 8491 | |
| 8492 | // Calling WaitForHostResolution() a second time should return |
| 8493 | // false since host resolution has finished already. |
| 8494 | EXPECT_FALSE( |
| 8495 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8496 | |
| 8497 | EXPECT_TRUE(callback_.have_result()); |
| 8498 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8499 | } |
| 8500 | |
| 8501 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8502 | // succeeds asynchronously, then crypto handshake fails asynchronously. |
| 8503 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackAsyncAsync) { |
| 8504 | Initialize(); |
| 8505 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8506 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8507 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8508 | host_resolver_->set_ondemand_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8509 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8510 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8511 | factory_->set_require_confirmation(true); |
| 8512 | |
| 8513 | MockQuicData socket_data; |
| 8514 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8515 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8516 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8517 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8518 | |
| 8519 | QuicStreamRequest request(factory_.get()); |
| 8520 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8521 | request.Request( |
| 8522 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8523 | SocketTag(), |
| 8524 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8525 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8526 | |
| 8527 | TestCompletionCallback host_resolution_callback; |
| 8528 | EXPECT_TRUE( |
| 8529 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8530 | |
| 8531 | // |host_resolver_| has not finished host resolution at this point, so |
| 8532 | // |host_resolution_callback| should not have a result. |
| 8533 | base::RunLoop().RunUntilIdle(); |
| 8534 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8535 | |
| 8536 | // Allow |host_resolver_| to finish host resolution. Since crypto handshake |
| 8537 | // will hang after host resolution, |host_resolution_callback| should run with |
| 8538 | // ERR_IO_PENDING since that's the next result in forming the connection. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8539 | host_resolver_->ResolveAllPending(); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8540 | base::RunLoop().RunUntilIdle(); |
| 8541 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8542 | EXPECT_EQ(ERR_IO_PENDING, host_resolution_callback.WaitForResult()); |
| 8543 | |
| 8544 | // Calling WaitForHostResolution() a second time should return |
| 8545 | // false since host resolution has finished already. |
| 8546 | EXPECT_FALSE( |
| 8547 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8548 | |
| 8549 | EXPECT_FALSE(callback_.have_result()); |
| 8550 | socket_data.GetSequencedSocketData()->Resume(); |
| 8551 | base::RunLoop().RunUntilIdle(); |
| 8552 | EXPECT_TRUE(callback_.have_result()); |
| 8553 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8554 | } |
| 8555 | |
| 8556 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8557 | // succeeds synchronously, then crypto handshake fails synchronously. |
| 8558 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncSync) { |
| 8559 | Initialize(); |
| 8560 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8561 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8562 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8563 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8564 | |
| 8565 | MockQuicData socket_data; |
| 8566 | socket_data.AddRead(SYNCHRONOUS, ERR_FAILED); |
| 8567 | socket_data.AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 8568 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8569 | |
| 8570 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8571 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8572 | request.Request( |
| 8573 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8574 | SocketTag(), |
| 8575 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8576 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8577 | |
| 8578 | // WaitForHostResolution() should return false since host |
| 8579 | // resolution has finished already. |
| 8580 | TestCompletionCallback host_resolution_callback; |
| 8581 | EXPECT_FALSE( |
| 8582 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8583 | base::RunLoop().RunUntilIdle(); |
| 8584 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8585 | EXPECT_FALSE(callback_.have_result()); |
| 8586 | } |
| 8587 | |
| 8588 | // Verify ResultAfterHostResolutionCallback behavior when host resolution |
| 8589 | // succeeds synchronously, then crypto handshake fails asynchronously. |
| 8590 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackSyncAsync) { |
| 8591 | Initialize(); |
| 8592 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8593 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8594 | |
| 8595 | // Host resolution will succeed synchronously, but Request() as a whole |
| 8596 | // will fail asynchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8597 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8598 | crypto_client_stream_factory_.set_handshake_mode( |
Ryan Hamilton | 9835e66 | 2018-08-02 05:36:27 | [diff] [blame] | 8599 | MockCryptoClientStream::ZERO_RTT); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8600 | factory_->set_require_confirmation(true); |
| 8601 | |
| 8602 | MockQuicData socket_data; |
| 8603 | socket_data.AddRead(ASYNC, ERR_IO_PENDING); // Pause |
| 8604 | socket_data.AddRead(ASYNC, ERR_FAILED); |
| 8605 | socket_data.AddWrite(ASYNC, ERR_FAILED); |
| 8606 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8607 | |
| 8608 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8609 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8610 | request.Request( |
| 8611 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8612 | SocketTag(), |
| 8613 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8614 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8615 | |
| 8616 | // WaitForHostResolution() should return false since host |
| 8617 | // resolution has finished already. |
| 8618 | TestCompletionCallback host_resolution_callback; |
| 8619 | EXPECT_FALSE( |
| 8620 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8621 | base::RunLoop().RunUntilIdle(); |
| 8622 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8623 | |
| 8624 | EXPECT_FALSE(callback_.have_result()); |
| 8625 | socket_data.GetSequencedSocketData()->Resume(); |
| 8626 | base::RunLoop().RunUntilIdle(); |
| 8627 | EXPECT_TRUE(callback_.have_result()); |
| 8628 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, callback_.WaitForResult()); |
| 8629 | } |
| 8630 | |
| 8631 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8632 | // synchronously. |
| 8633 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailSync) { |
| 8634 | Initialize(); |
| 8635 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8636 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8637 | |
| 8638 | // Host resolution will fail synchronously. |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8639 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 8640 | host_resolver_->set_synchronous_mode(true); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8641 | |
| 8642 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8643 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8644 | request.Request( |
| 8645 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8646 | SocketTag(), |
| 8647 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8648 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8649 | |
| 8650 | // WaitForHostResolution() should return false since host |
| 8651 | // resolution has failed already. |
| 8652 | TestCompletionCallback host_resolution_callback; |
| 8653 | EXPECT_FALSE( |
| 8654 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8655 | base::RunLoop().RunUntilIdle(); |
| 8656 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8657 | } |
| 8658 | |
| 8659 | // Verify ResultAfterHostResolutionCallback behavior when host resolution fails |
| 8660 | // asynchronously. |
| 8661 | TEST_P(QuicStreamFactoryTest, ResultAfterHostResolutionCallbackFailAsync) { |
| 8662 | Initialize(); |
| 8663 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8664 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8665 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8666 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8667 | |
| 8668 | QuicStreamRequest request(factory_.get()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 8669 | EXPECT_EQ(ERR_IO_PENDING, |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 8670 | request.Request( |
| 8671 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8672 | SocketTag(), |
| 8673 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8674 | failed_on_default_network_callback_, callback_.callback())); |
Yixin Wang | 7c5d11a8 | 2017-12-21 02:40:00 | [diff] [blame] | 8675 | |
| 8676 | TestCompletionCallback host_resolution_callback; |
| 8677 | EXPECT_TRUE( |
| 8678 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8679 | |
| 8680 | // Allow |host_resolver_| to fail host resolution. |host_resolution_callback| |
| 8681 | // Should run with ERR_NAME_NOT_RESOLVED since that's the error host |
| 8682 | // resolution failed with. |
| 8683 | base::RunLoop().RunUntilIdle(); |
| 8684 | EXPECT_TRUE(host_resolution_callback.have_result()); |
| 8685 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, host_resolution_callback.WaitForResult()); |
| 8686 | |
| 8687 | EXPECT_TRUE(callback_.have_result()); |
| 8688 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback_.WaitForResult()); |
| 8689 | } |
| 8690 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8691 | // With dns race experiment turned on, and DNS resolve succeeds synchronously, |
| 8692 | // the final connection is established through the resolved DNS. No racing |
| 8693 | // connection. |
| 8694 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionSync) { |
| 8695 | race_stale_dns_on_connection_ = true; |
| 8696 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8697 | Initialize(); |
| 8698 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8699 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8700 | |
| 8701 | // Set an address in resolver for synchronous return. |
| 8702 | host_resolver_->set_synchronous_mode(true); |
| 8703 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8704 | kNonCachedIPAddress, ""); |
| 8705 | |
| 8706 | // Set up a different address in stale resolver cache. |
| 8707 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8708 | HostCache::Entry entry(OK, |
| 8709 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8710 | HostCache::Entry::SOURCE_DNS); |
| 8711 | base::TimeDelta zero; |
| 8712 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8713 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8714 | // Expire the cache |
| 8715 | cache->OnNetworkChange(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 8716 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 8717 | MockQuicData quic_data; |
| 8718 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8719 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8720 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8721 | |
| 8722 | QuicStreamRequest request(factory_.get()); |
| 8723 | EXPECT_THAT(request.Request( |
| 8724 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8725 | SocketTag(), |
| 8726 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8727 | failed_on_default_network_callback_, callback_.callback()), |
| 8728 | IsOk()); |
| 8729 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8730 | EXPECT_TRUE(stream.get()); |
| 8731 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8732 | EXPECT_EQ( |
| 8733 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8734 | kNonCachedIPAddress); |
| 8735 | |
| 8736 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8737 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8738 | } |
| 8739 | |
| 8740 | // With dns race experiment on, DNS resolve returns async, no matching cache in |
| 8741 | // host resolver, connection should be successful and through resolved DNS. No |
| 8742 | // racing connection. |
| 8743 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceAndHostResolutionAsync) { |
| 8744 | race_stale_dns_on_connection_ = true; |
| 8745 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8746 | Initialize(); |
| 8747 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8748 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8749 | |
| 8750 | // Set an address in resolver for asynchronous return. |
| 8751 | host_resolver_->set_ondemand_mode(true); |
| 8752 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8753 | kNonCachedIPAddress, ""); |
| 8754 | |
| 8755 | MockQuicData quic_data; |
| 8756 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8757 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8758 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8759 | |
| 8760 | QuicStreamRequest request(factory_.get()); |
| 8761 | EXPECT_EQ(ERR_IO_PENDING, |
| 8762 | request.Request( |
| 8763 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8764 | SocketTag(), |
| 8765 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8766 | failed_on_default_network_callback_, callback_.callback())); |
| 8767 | TestCompletionCallback host_resolution_callback; |
| 8768 | EXPECT_TRUE( |
| 8769 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 8770 | base::RunLoop().RunUntilIdle(); |
| 8771 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 8772 | |
| 8773 | // Cause the host resolution to return. |
| 8774 | host_resolver_->ResolveAllPending(); |
| 8775 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 8776 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8777 | |
| 8778 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8779 | EXPECT_TRUE(stream.get()); |
| 8780 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8781 | |
| 8782 | EXPECT_EQ( |
| 8783 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8784 | kNonCachedIPAddress); |
| 8785 | |
| 8786 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8787 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8788 | } |
| 8789 | |
| 8790 | // With dns race experiment on, DNS resolve returns async, stale dns used, |
| 8791 | // connects synchrounously, and then the resolved DNS matches. |
| 8792 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncStaleMatch) { |
| 8793 | race_stale_dns_on_connection_ = true; |
| 8794 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8795 | Initialize(); |
| 8796 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8797 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8798 | |
| 8799 | // Set an address in resolver for asynchronous return. |
| 8800 | host_resolver_->set_ondemand_mode(true); |
| 8801 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8802 | kCachedIPAddress.ToString(), ""); |
| 8803 | |
| 8804 | // Set up the same address in the stale resolver cache. |
| 8805 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8806 | HostCache::Entry entry(OK, |
| 8807 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8808 | HostCache::Entry::SOURCE_DNS); |
| 8809 | base::TimeDelta zero; |
| 8810 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8811 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8812 | // Expire the cache |
| 8813 | cache->OnNetworkChange(); |
| 8814 | |
| 8815 | MockQuicData quic_data; |
| 8816 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8817 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8818 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8819 | |
| 8820 | QuicStreamRequest request(factory_.get()); |
| 8821 | EXPECT_EQ(ERR_IO_PENDING, |
| 8822 | request.Request( |
| 8823 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8824 | SocketTag(), |
| 8825 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8826 | failed_on_default_network_callback_, callback_.callback())); |
| 8827 | |
| 8828 | // Check that the racing job is running. |
| 8829 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8830 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8831 | |
| 8832 | // Resolve dns and return. |
| 8833 | host_resolver_->ResolveAllPending(); |
| 8834 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8835 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8836 | EXPECT_TRUE(stream.get()); |
| 8837 | |
| 8838 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8839 | |
| 8840 | EXPECT_EQ( |
| 8841 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8842 | kCachedIPAddress.ToString()); |
| 8843 | |
| 8844 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8845 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8846 | } |
| 8847 | |
| 8848 | // With dns race experiment on, dns resolve async, stale dns used, connect |
| 8849 | // async, and then the result matches. |
| 8850 | TEST_P(QuicStreamFactoryTest, |
| 8851 | ResultAfterDNSRaceHostResolveAsyncConnectAsyncStaleMatch) { |
| 8852 | race_stale_dns_on_connection_ = true; |
| 8853 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8854 | Initialize(); |
| 8855 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8856 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8857 | |
| 8858 | // Set an address in resolver for asynchronous return. |
| 8859 | host_resolver_->set_ondemand_mode(true); |
| 8860 | factory_->set_require_confirmation(true); |
| 8861 | crypto_client_stream_factory_.set_handshake_mode( |
| 8862 | MockCryptoClientStream::ZERO_RTT); |
| 8863 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8864 | kCachedIPAddress.ToString(), ""); |
| 8865 | |
| 8866 | // Set up the same address in the stale resolver cache. |
| 8867 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8868 | HostCache::Entry entry(OK, |
| 8869 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8870 | HostCache::Entry::SOURCE_DNS); |
| 8871 | base::TimeDelta zero; |
| 8872 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8873 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8874 | // Expire the cache |
| 8875 | cache->OnNetworkChange(); |
| 8876 | |
| 8877 | MockQuicData quic_data; |
| 8878 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8879 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8880 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8881 | |
| 8882 | QuicStreamRequest request(factory_.get()); |
| 8883 | EXPECT_EQ(ERR_IO_PENDING, |
| 8884 | request.Request( |
| 8885 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8886 | SocketTag(), |
| 8887 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8888 | failed_on_default_network_callback_, callback_.callback())); |
| 8889 | |
| 8890 | // Send Crypto handshake so connect will call back. |
| 8891 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 8892 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 8893 | base::RunLoop().RunUntilIdle(); |
| 8894 | |
| 8895 | // Check that the racing job is running. |
| 8896 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 8897 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 8898 | |
| 8899 | // Resolve dns and call back, make sure job finishes. |
| 8900 | host_resolver_->ResolveAllPending(); |
| 8901 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8902 | |
| 8903 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8904 | EXPECT_TRUE(stream.get()); |
| 8905 | |
| 8906 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8907 | |
| 8908 | EXPECT_EQ( |
| 8909 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8910 | kCachedIPAddress.ToString()); |
| 8911 | |
| 8912 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8913 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8914 | } |
| 8915 | |
| 8916 | // With dns race experiment on, dns resolve async, stale dns used, dns resolve |
| 8917 | // return, then connection finishes and matches with the result. |
| 8918 | TEST_P(QuicStreamFactoryTest, |
| 8919 | ResultAfterDNSRaceHostResolveAsyncStaleMatchConnectAsync) { |
| 8920 | race_stale_dns_on_connection_ = true; |
| 8921 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8922 | Initialize(); |
| 8923 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8924 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8925 | |
| 8926 | // Set an address in resolver for asynchronous return. |
| 8927 | host_resolver_->set_ondemand_mode(true); |
| 8928 | factory_->set_require_confirmation(true); |
| 8929 | crypto_client_stream_factory_.set_handshake_mode( |
| 8930 | MockCryptoClientStream::ZERO_RTT); |
| 8931 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8932 | kCachedIPAddress.ToString(), ""); |
| 8933 | |
| 8934 | // Set up the same address in the stale resolver cache. |
| 8935 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8936 | HostCache::Entry entry(OK, |
| 8937 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8938 | HostCache::Entry::SOURCE_DNS); |
| 8939 | base::TimeDelta zero; |
| 8940 | HostCache* cache = host_resolver_->GetHostCache(); |
| 8941 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 8942 | // Expire the cache |
| 8943 | cache->OnNetworkChange(); |
| 8944 | |
| 8945 | MockQuicData quic_data; |
| 8946 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 8947 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 8948 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 8949 | |
| 8950 | QuicStreamRequest request(factory_.get()); |
| 8951 | EXPECT_EQ(ERR_IO_PENDING, |
| 8952 | request.Request( |
| 8953 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 8954 | SocketTag(), |
| 8955 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 8956 | failed_on_default_network_callback_, callback_.callback())); |
| 8957 | |
| 8958 | // Finish dns async, check we still need to wait for stale connection async. |
| 8959 | host_resolver_->ResolveAllPending(); |
| 8960 | base::RunLoop().RunUntilIdle(); |
| 8961 | EXPECT_FALSE(callback_.have_result()); |
| 8962 | |
| 8963 | // Finish stale connection async, and the stale connection should pass dns |
| 8964 | // validation. |
| 8965 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 8966 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 8967 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 8968 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 8969 | EXPECT_TRUE(stream.get()); |
| 8970 | |
| 8971 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 8972 | EXPECT_EQ( |
| 8973 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 8974 | kCachedIPAddress.ToString()); |
| 8975 | |
| 8976 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 8977 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 8978 | } |
| 8979 | |
| 8980 | // With dns race experiment on, dns resolve async, stale used and connects |
| 8981 | // sync, but dns no match |
| 8982 | TEST_P(QuicStreamFactoryTest, |
| 8983 | ResultAfterDNSRaceHostResolveAsyncStaleSyncNoMatch) { |
| 8984 | race_stale_dns_on_connection_ = true; |
| 8985 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 8986 | Initialize(); |
| 8987 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 8988 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 8989 | |
| 8990 | // Set an address in resolver for asynchronous return. |
| 8991 | host_resolver_->set_ondemand_mode(true); |
| 8992 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 8993 | kNonCachedIPAddress, ""); |
| 8994 | |
| 8995 | // Set up a different address in the stale resolver cache. |
| 8996 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 8997 | HostCache::Entry entry(OK, |
| 8998 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 8999 | HostCache::Entry::SOURCE_DNS); |
| 9000 | base::TimeDelta zero; |
| 9001 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9002 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9003 | // Expire the cache |
| 9004 | cache->OnNetworkChange(); |
| 9005 | |
| 9006 | // Socket for the stale connection which will invoke connection closure. |
| 9007 | MockQuicData quic_data; |
| 9008 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9009 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9010 | quic_data.AddWrite( |
| 9011 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9012 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9013 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9014 | |
| 9015 | // Socket for the new connection. |
| 9016 | MockQuicData quic_data2; |
| 9017 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9018 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9019 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9020 | |
| 9021 | QuicStreamRequest request(factory_.get()); |
| 9022 | EXPECT_EQ(ERR_IO_PENDING, |
| 9023 | request.Request( |
| 9024 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9025 | SocketTag(), |
| 9026 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9027 | failed_on_default_network_callback_, callback_.callback())); |
| 9028 | |
| 9029 | // Check the stale connection is running. |
| 9030 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9031 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9032 | |
| 9033 | // Finish dns resolution and check the job has finished. |
| 9034 | host_resolver_->ResolveAllPending(); |
| 9035 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9036 | |
| 9037 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9038 | EXPECT_TRUE(stream.get()); |
| 9039 | |
| 9040 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9041 | |
| 9042 | EXPECT_EQ( |
| 9043 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9044 | kNonCachedIPAddress); |
| 9045 | |
| 9046 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9047 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9048 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9049 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9050 | } |
| 9051 | |
| 9052 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9053 | // async, finishes before dns, but no match |
| 9054 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleAsyncResolveAsyncNoMatch) { |
| 9055 | race_stale_dns_on_connection_ = true; |
| 9056 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9057 | Initialize(); |
| 9058 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9059 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9060 | |
| 9061 | // Set an address in resolver for asynchronous return. |
| 9062 | host_resolver_->set_ondemand_mode(true); |
| 9063 | factory_->set_require_confirmation(true); |
| 9064 | crypto_client_stream_factory_.set_handshake_mode( |
| 9065 | MockCryptoClientStream::ZERO_RTT); |
| 9066 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9067 | kNonCachedIPAddress, ""); |
| 9068 | |
| 9069 | // Set up a different address in the stale resolvercache. |
| 9070 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9071 | HostCache::Entry entry(OK, |
| 9072 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9073 | HostCache::Entry::SOURCE_DNS); |
| 9074 | base::TimeDelta zero; |
| 9075 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9076 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9077 | // Expire the cache |
| 9078 | cache->OnNetworkChange(); |
| 9079 | |
| 9080 | MockQuicData quic_data; |
| 9081 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9082 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9083 | quic_data.AddWrite( |
| 9084 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9085 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9086 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9087 | |
| 9088 | MockQuicData quic_data2; |
| 9089 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9090 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9091 | |
| 9092 | QuicStreamRequest request(factory_.get()); |
| 9093 | EXPECT_EQ(ERR_IO_PENDING, |
| 9094 | request.Request( |
| 9095 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9096 | SocketTag(), |
| 9097 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9098 | failed_on_default_network_callback_, callback_.callback())); |
| 9099 | |
| 9100 | // Finish the stale connection. |
| 9101 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9102 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9103 | base::RunLoop().RunUntilIdle(); |
| 9104 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9105 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9106 | |
| 9107 | // Finish host resolution and check the job is done. |
| 9108 | host_resolver_->ResolveAllPending(); |
| 9109 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9110 | |
| 9111 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9112 | EXPECT_TRUE(stream.get()); |
| 9113 | |
| 9114 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9115 | EXPECT_EQ( |
| 9116 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9117 | kNonCachedIPAddress); |
| 9118 | |
| 9119 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9120 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9121 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9122 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9123 | } |
| 9124 | |
| 9125 | // With dns race experiment on, dns resolve async, stale used and connects |
| 9126 | // async, dns finishes first, but no match |
| 9127 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncStaleAsyncNoMatch) { |
| 9128 | race_stale_dns_on_connection_ = true; |
| 9129 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9130 | Initialize(); |
| 9131 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9132 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9133 | |
| 9134 | // Set an address in resolver for asynchronous return. |
| 9135 | host_resolver_->set_ondemand_mode(true); |
| 9136 | factory_->set_require_confirmation(true); |
| 9137 | crypto_client_stream_factory_.set_handshake_mode( |
| 9138 | MockCryptoClientStream::ZERO_RTT); |
| 9139 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9140 | kNonCachedIPAddress, ""); |
| 9141 | |
| 9142 | // Set up a different address in the stale resolver cache. |
| 9143 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9144 | HostCache::Entry entry(OK, |
| 9145 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9146 | HostCache::Entry::SOURCE_DNS); |
| 9147 | base::TimeDelta zero; |
| 9148 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9149 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9150 | // Expire the cache |
| 9151 | cache->OnNetworkChange(); |
| 9152 | |
| 9153 | MockQuicData quic_data; |
| 9154 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9155 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9156 | quic_data.AddWrite( |
| 9157 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9158 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9159 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9160 | |
| 9161 | MockQuicData quic_data2; |
| 9162 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9163 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_FORWARD_SECURE); |
| 9164 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9165 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9166 | |
| 9167 | QuicStreamRequest request(factory_.get()); |
| 9168 | EXPECT_EQ(ERR_IO_PENDING, |
| 9169 | request.Request( |
| 9170 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9171 | SocketTag(), |
| 9172 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9173 | failed_on_default_network_callback_, callback_.callback())); |
| 9174 | // Finish dns resolution, but need to wait for stale connection. |
| 9175 | host_resolver_->ResolveAllPending(); |
Renjie | 8d2d8d91b | 2018-09-29 00:29:03 | [diff] [blame] | 9176 | base::RunLoop().RunUntilIdle(); |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9177 | crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent( |
| 9178 | quic::QuicSession::HANDSHAKE_CONFIRMED); |
| 9179 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9180 | |
| 9181 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9182 | EXPECT_TRUE(stream.get()); |
| 9183 | |
| 9184 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9185 | EXPECT_EQ( |
| 9186 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9187 | kNonCachedIPAddress); |
| 9188 | |
| 9189 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9190 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9191 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9192 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9193 | } |
| 9194 | |
| 9195 | // With dns race experiment on, dns resolve returns error sync, same behavior |
| 9196 | // as experiment is not on |
| 9197 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveError) { |
| 9198 | race_stale_dns_on_connection_ = true; |
| 9199 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9200 | Initialize(); |
| 9201 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9202 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9203 | |
| 9204 | // Set synchronous failure in resolver. |
| 9205 | host_resolver_->set_synchronous_mode(true); |
| 9206 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9207 | |
| 9208 | MockQuicData quic_data; |
| 9209 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9210 | QuicStreamRequest request(factory_.get()); |
| 9211 | |
| 9212 | EXPECT_EQ(ERR_NAME_NOT_RESOLVED, |
| 9213 | request.Request( |
| 9214 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9215 | SocketTag(), |
| 9216 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9217 | failed_on_default_network_callback_, callback_.callback())); |
| 9218 | } |
| 9219 | |
| 9220 | // With dns race experiment on, no cache available, dns resolve returns error |
| 9221 | // async |
| 9222 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsyncError) { |
| 9223 | race_stale_dns_on_connection_ = true; |
| 9224 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9225 | Initialize(); |
| 9226 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9227 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9228 | |
| 9229 | // Set asynchronous failure in resolver. |
| 9230 | host_resolver_->set_ondemand_mode(true); |
| 9231 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9232 | |
| 9233 | MockQuicData quic_data; |
| 9234 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9235 | QuicStreamRequest request(factory_.get()); |
| 9236 | |
| 9237 | EXPECT_EQ(ERR_IO_PENDING, |
| 9238 | request.Request( |
| 9239 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9240 | SocketTag(), |
| 9241 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9242 | failed_on_default_network_callback_, callback_.callback())); |
| 9243 | |
| 9244 | // Resolve and expect result that shows the resolution error. |
| 9245 | host_resolver_->ResolveAllPending(); |
| 9246 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9247 | } |
| 9248 | |
| 9249 | // With dns race experiment on, dns resolve async, staled used and connects |
| 9250 | // sync, dns returns error and no connection is established. |
| 9251 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleSyncHostResolveError) { |
| 9252 | race_stale_dns_on_connection_ = true; |
| 9253 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9254 | Initialize(); |
| 9255 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9256 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9257 | |
| 9258 | // Set asynchronous failure in resolver. |
| 9259 | host_resolver_->set_ondemand_mode(true); |
| 9260 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9261 | |
| 9262 | // Set up an address in the stale cache. |
| 9263 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9264 | HostCache::Entry entry(OK, |
| 9265 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9266 | HostCache::Entry::SOURCE_DNS); |
| 9267 | base::TimeDelta zero; |
| 9268 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9269 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9270 | // Expire the cache |
| 9271 | cache->OnNetworkChange(); |
| 9272 | |
| 9273 | // Socket for the stale connection which is supposed to disconnect. |
| 9274 | MockQuicData quic_data; |
| 9275 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9276 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9277 | quic_data.AddWrite( |
| 9278 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9279 | 2, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9280 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9281 | |
| 9282 | QuicStreamRequest request(factory_.get()); |
| 9283 | EXPECT_EQ(ERR_IO_PENDING, |
| 9284 | request.Request( |
| 9285 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9286 | SocketTag(), |
| 9287 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9288 | failed_on_default_network_callback_, callback_.callback())); |
| 9289 | |
| 9290 | // Check that the stale connection is running. |
| 9291 | EXPECT_TRUE(HasLiveSession(host_port_pair_)); |
| 9292 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9293 | |
| 9294 | // Finish host resolution. |
| 9295 | host_resolver_->ResolveAllPending(); |
| 9296 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9297 | |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9298 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9299 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9300 | } |
| 9301 | |
| 9302 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9303 | // return error, then dns matches |
| 9304 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSMatches) { |
| 9305 | race_stale_dns_on_connection_ = true; |
| 9306 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9307 | Initialize(); |
| 9308 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9309 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9310 | |
| 9311 | // Set an address in host resolver for asynchronous return. |
| 9312 | host_resolver_->set_ondemand_mode(true); |
| 9313 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9314 | kCachedIPAddress.ToString(), ""); |
| 9315 | |
| 9316 | // Set up the same address in the stale resolver cache. |
| 9317 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9318 | HostCache::Entry entry(OK, |
| 9319 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9320 | HostCache::Entry::SOURCE_DNS); |
| 9321 | base::TimeDelta zero; |
| 9322 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9323 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9324 | // Expire the cache |
| 9325 | cache->OnNetworkChange(); |
| 9326 | |
| 9327 | // Simulate synchronous connect failure. |
| 9328 | MockQuicData quic_data; |
| 9329 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9330 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9331 | |
| 9332 | MockQuicData quic_data2; |
| 9333 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9334 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9335 | |
| 9336 | QuicStreamRequest request(factory_.get()); |
| 9337 | EXPECT_EQ(ERR_IO_PENDING, |
| 9338 | request.Request( |
| 9339 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9340 | SocketTag(), |
| 9341 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9342 | failed_on_default_network_callback_, callback_.callback())); |
| 9343 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9344 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9345 | |
| 9346 | host_resolver_->ResolveAllPending(); |
| 9347 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9348 | } |
| 9349 | |
| 9350 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9351 | // returns error, dns no match, new connection is established |
| 9352 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatch) { |
| 9353 | race_stale_dns_on_connection_ = true; |
| 9354 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9355 | Initialize(); |
| 9356 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9357 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9358 | |
| 9359 | // Set an address in host resolver. |
| 9360 | host_resolver_->set_ondemand_mode(true); |
| 9361 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9362 | kNonCachedIPAddress, ""); |
| 9363 | |
| 9364 | // Set up a different address in stale resolver cache. |
| 9365 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9366 | HostCache::Entry entry(OK, |
| 9367 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9368 | HostCache::Entry::SOURCE_DNS); |
| 9369 | base::TimeDelta zero; |
| 9370 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9371 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9372 | // Expire the cache |
| 9373 | cache->OnNetworkChange(); |
| 9374 | |
| 9375 | // Add failure for the stale connection. |
| 9376 | MockQuicData quic_data; |
| 9377 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9378 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9379 | |
| 9380 | MockQuicData quic_data2; |
| 9381 | quic_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9382 | quic_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9383 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9384 | |
| 9385 | QuicStreamRequest request(factory_.get()); |
| 9386 | EXPECT_EQ(ERR_IO_PENDING, |
| 9387 | request.Request( |
| 9388 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9389 | SocketTag(), |
| 9390 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9391 | failed_on_default_network_callback_, callback_.callback())); |
| 9392 | |
| 9393 | // Check that the stale connection fails. |
| 9394 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9395 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9396 | |
| 9397 | // Finish host resolution and check the job finishes ok. |
| 9398 | host_resolver_->ResolveAllPending(); |
| 9399 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 9400 | |
| 9401 | std::unique_ptr<HttpStream> stream = CreateStream(&request); |
| 9402 | EXPECT_TRUE(stream.get()); |
| 9403 | |
| 9404 | QuicChromiumClientSession* session = GetActiveSession(host_port_pair_); |
| 9405 | |
| 9406 | EXPECT_EQ( |
| 9407 | session->peer_address().impl().socket_address().ToStringWithoutPort(), |
| 9408 | kNonCachedIPAddress); |
| 9409 | |
| 9410 | EXPECT_TRUE(quic_data2.AllReadDataConsumed()); |
| 9411 | EXPECT_TRUE(quic_data2.AllWriteDataConsumed()); |
| 9412 | } |
| 9413 | |
| 9414 | // With dns race experiment on, dns resolve async, stale used and connection |
| 9415 | // returns error, dns no match, new connection error |
| 9416 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceStaleErrorDNSNoMatchError) { |
| 9417 | race_stale_dns_on_connection_ = true; |
| 9418 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9419 | Initialize(); |
| 9420 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9421 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9422 | |
| 9423 | // Set an address in host resolver asynchronously. |
| 9424 | host_resolver_->set_ondemand_mode(true); |
| 9425 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9426 | kNonCachedIPAddress, ""); |
| 9427 | |
| 9428 | // Set up a different address in the stale cache. |
| 9429 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9430 | HostCache::Entry entry(OK, |
| 9431 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9432 | HostCache::Entry::SOURCE_DNS); |
| 9433 | base::TimeDelta zero; |
| 9434 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9435 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9436 | // Expire the cache |
| 9437 | cache->OnNetworkChange(); |
| 9438 | |
| 9439 | // Add failure for stale connection. |
| 9440 | MockQuicData quic_data; |
| 9441 | quic_data.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9442 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9443 | |
| 9444 | // Add failure for resolved dns connection. |
| 9445 | MockQuicData quic_data2; |
| 9446 | quic_data2.AddConnect(SYNCHRONOUS, ERR_ADDRESS_IN_USE); |
| 9447 | quic_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9448 | |
| 9449 | QuicStreamRequest request(factory_.get()); |
| 9450 | EXPECT_EQ(ERR_IO_PENDING, |
| 9451 | request.Request( |
| 9452 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9453 | SocketTag(), |
| 9454 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9455 | failed_on_default_network_callback_, callback_.callback())); |
| 9456 | |
| 9457 | // Check the stale connection fails. |
| 9458 | EXPECT_FALSE(HasLiveSession(host_port_pair_)); |
| 9459 | EXPECT_TRUE(HasActiveJob(host_port_pair_, privacy_mode_)); |
| 9460 | |
| 9461 | // Check the resolved dns connection fails. |
| 9462 | host_resolver_->ResolveAllPending(); |
| 9463 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_ADDRESS_IN_USE)); |
| 9464 | } |
| 9465 | |
| 9466 | // With dns race experiment on, dns resolve async and stale connect async, dns |
| 9467 | // resolve returns error and then preconnect finishes |
| 9468 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceResolveAsyncErrorStaleAsync) { |
| 9469 | race_stale_dns_on_connection_ = true; |
| 9470 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9471 | Initialize(); |
| 9472 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9473 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9474 | |
| 9475 | // Add asynchronous failure in host resolver. |
| 9476 | host_resolver_->set_ondemand_mode(true); |
| 9477 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9478 | factory_->set_require_confirmation(true); |
| 9479 | crypto_client_stream_factory_.set_handshake_mode( |
| 9480 | MockCryptoClientStream::ZERO_RTT); |
| 9481 | |
| 9482 | // Set up an address in stale resolver cache. |
| 9483 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9484 | HostCache::Entry entry(OK, |
| 9485 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9486 | HostCache::Entry::SOURCE_DNS); |
| 9487 | base::TimeDelta zero; |
| 9488 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9489 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9490 | // Expire the cache |
| 9491 | cache->OnNetworkChange(); |
| 9492 | |
| 9493 | // Socket data for stale connection which is supposed to disconnect. |
| 9494 | MockQuicData quic_data; |
| 9495 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9496 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9497 | quic_data.AddWrite( |
| 9498 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9499 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9500 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9501 | |
| 9502 | QuicStreamRequest request(factory_.get()); |
| 9503 | EXPECT_EQ(ERR_IO_PENDING, |
| 9504 | request.Request( |
| 9505 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9506 | SocketTag(), |
| 9507 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9508 | failed_on_default_network_callback_, callback_.callback())); |
| 9509 | |
| 9510 | // host resolution returned but stale connection hasn't finished yet. |
| 9511 | host_resolver_->ResolveAllPending(); |
| 9512 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9513 | |
| 9514 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9515 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9516 | } |
| 9517 | |
| 9518 | // With dns race experiment on, dns resolve async and stale connect async, dns |
Renjie | a0cb4a2c | 2018-09-26 23:37:30 | [diff] [blame] | 9519 | // resolve returns error and then preconnect fails. |
| 9520 | TEST_P(QuicStreamFactoryTest, |
| 9521 | ResultAfterDNSRaceResolveAsyncErrorStaleAsyncError) { |
| 9522 | race_stale_dns_on_connection_ = true; |
| 9523 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9524 | Initialize(); |
| 9525 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9526 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9527 | |
| 9528 | // Add asynchronous failure to host resolver. |
| 9529 | host_resolver_->set_ondemand_mode(true); |
| 9530 | factory_->set_require_confirmation(true); |
| 9531 | crypto_client_stream_factory_.set_handshake_mode( |
| 9532 | MockCryptoClientStream::ZERO_RTT); |
| 9533 | host_resolver_->rules()->AddSimulatedFailure(host_port_pair_.host()); |
| 9534 | |
| 9535 | // Set up an address in stale resolver cache. |
| 9536 | HostCache::Key key(host_port_pair_.host(), ADDRESS_FAMILY_UNSPECIFIED, 0); |
| 9537 | HostCache::Entry entry(OK, |
| 9538 | AddressList::CreateFromIPAddress(kCachedIPAddress, 0), |
| 9539 | HostCache::Entry::SOURCE_DNS); |
| 9540 | base::TimeDelta zero; |
| 9541 | HostCache* cache = host_resolver_->GetHostCache(); |
| 9542 | cache->Set(key, entry, base::TimeTicks::Now(), zero); |
| 9543 | // Expire the cache |
| 9544 | cache->OnNetworkChange(); |
| 9545 | |
| 9546 | MockQuicData quic_data; |
| 9547 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9548 | client_maker_.SetEncryptionLevel(quic::ENCRYPTION_INITIAL); |
| 9549 | quic_data.AddWrite( |
| 9550 | SYNCHRONOUS, client_maker_.MakeConnectionClosePacket( |
| 9551 | 1, true, quic::QUIC_CONNECTION_CANCELLED, "net error")); |
| 9552 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9553 | |
| 9554 | QuicStreamRequest request(factory_.get()); |
| 9555 | EXPECT_EQ(ERR_IO_PENDING, |
| 9556 | request.Request( |
| 9557 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9558 | SocketTag(), |
| 9559 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9560 | failed_on_default_network_callback_, callback_.callback())); |
| 9561 | |
| 9562 | // Host Resolution returns failure but stale connection hasn't finished. |
| 9563 | host_resolver_->ResolveAllPending(); |
| 9564 | |
| 9565 | // Check that the final error is on resolution failure. |
| 9566 | EXPECT_THAT(callback_.WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED)); |
| 9567 | |
| 9568 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9569 | } |
| 9570 | |
| 9571 | // With dns race experiment on, test that host resolution callback behaves |
| 9572 | // normal as experiment is not on |
| 9573 | TEST_P(QuicStreamFactoryTest, ResultAfterDNSRaceHostResolveAsync) { |
| 9574 | race_stale_dns_on_connection_ = true; |
| 9575 | host_resolver_ = std::make_unique<MockCachingHostResolver>(); |
| 9576 | Initialize(); |
| 9577 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9578 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9579 | |
| 9580 | host_resolver_->set_ondemand_mode(true); |
| 9581 | host_resolver_->rules()->AddIPLiteralRule(host_port_pair_.host(), |
| 9582 | kNonCachedIPAddress, ""); |
| 9583 | |
| 9584 | MockQuicData quic_data; |
| 9585 | quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 9586 | quic_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
| 9587 | quic_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9588 | |
| 9589 | QuicStreamRequest request(factory_.get()); |
| 9590 | EXPECT_EQ(ERR_IO_PENDING, |
| 9591 | request.Request( |
| 9592 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, |
| 9593 | SocketTag(), |
| 9594 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9595 | failed_on_default_network_callback_, callback_.callback())); |
| 9596 | |
| 9597 | // Check that expect_on_host_resolution_ is properlly set. |
| 9598 | TestCompletionCallback host_resolution_callback; |
| 9599 | EXPECT_TRUE( |
| 9600 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9601 | base::RunLoop().RunUntilIdle(); |
| 9602 | EXPECT_FALSE(host_resolution_callback.have_result()); |
| 9603 | |
| 9604 | host_resolver_->ResolveAllPending(); |
| 9605 | EXPECT_THAT(host_resolution_callback.WaitForResult(), IsOk()); |
| 9606 | |
| 9607 | // Check that expect_on_host_resolution_ is flipped back. |
| 9608 | EXPECT_FALSE( |
| 9609 | request.WaitForHostResolution(host_resolution_callback.callback())); |
| 9610 | |
| 9611 | EXPECT_TRUE(quic_data.AllReadDataConsumed()); |
| 9612 | EXPECT_TRUE(quic_data.AllWriteDataConsumed()); |
| 9613 | } |
| 9614 | |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9615 | // Test that QuicStreamRequests with similar and different tags results in |
| 9616 | // reused and unique QUIC streams using appropriately tagged sockets. |
| 9617 | TEST_P(QuicStreamFactoryTest, Tag) { |
| 9618 | MockTaggingClientSocketFactory* socket_factory = |
| 9619 | new MockTaggingClientSocketFactory(); |
| 9620 | socket_factory_.reset(socket_factory); |
| 9621 | Initialize(); |
| 9622 | ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 9623 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 9624 | |
| 9625 | // Prepare to establish two QUIC sessions. |
| 9626 | MockQuicData socket_data; |
| 9627 | socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9628 | socket_data.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9629 | socket_data.AddSocketDataToFactory(socket_factory_.get()); |
| 9630 | MockQuicData socket_data2; |
| 9631 | socket_data2.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
Zhongyi Shi | 32f2fd0 | 2018-04-16 18:23:43 | [diff] [blame] | 9632 | socket_data2.AddWrite(SYNCHRONOUS, ConstructInitialSettingsPacket()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9633 | socket_data2.AddSocketDataToFactory(socket_factory_.get()); |
| 9634 | |
| 9635 | #if defined(OS_ANDROID) |
| 9636 | SocketTag tag1(SocketTag::UNSET_UID, 0x12345678); |
| 9637 | SocketTag tag2(getuid(), 0x87654321); |
| 9638 | #else |
| 9639 | // On non-Android platforms we can only use the default constructor. |
| 9640 | SocketTag tag1, tag2; |
| 9641 | #endif |
| 9642 | |
| 9643 | // Request a stream with |tag1|. |
| 9644 | QuicStreamRequest request1(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9645 | int rv = request1.Request( |
| 9646 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9647 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9648 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9649 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9650 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag1); |
| 9651 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9652 | ->tagged_before_data_transferred()); |
| 9653 | std::unique_ptr<QuicChromiumClientSession::Handle> stream1 = |
| 9654 | request1.ReleaseSessionHandle(); |
| 9655 | EXPECT_TRUE(stream1); |
| 9656 | EXPECT_TRUE(stream1->IsConnected()); |
| 9657 | |
| 9658 | // Request a stream with |tag1| and verify underlying session is reused. |
| 9659 | QuicStreamRequest request2(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9660 | rv = request2.Request( |
| 9661 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag1, |
| 9662 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9663 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9664 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9665 | std::unique_ptr<QuicChromiumClientSession::Handle> stream2 = |
| 9666 | request2.ReleaseSessionHandle(); |
| 9667 | EXPECT_TRUE(stream2); |
| 9668 | EXPECT_TRUE(stream2->IsConnected()); |
| 9669 | EXPECT_TRUE(stream2->SharesSameSession(*stream1)); |
| 9670 | |
| 9671 | // Request a stream with |tag2| and verify a new session is created. |
| 9672 | QuicStreamRequest request3(factory_.get()); |
Zhongyi Shi | a6b68d11 | 2018-09-24 07:49:03 | [diff] [blame] | 9673 | rv = request3.Request( |
| 9674 | host_port_pair_, version_, privacy_mode_, DEFAULT_PRIORITY, tag2, |
| 9675 | /*cert_verify_flags=*/0, url_, net_log_, &net_error_details_, |
| 9676 | failed_on_default_network_callback_, callback_.callback()); |
Paul Jensen | 8e3c5d3 | 2018-02-19 17:06:33 | [diff] [blame] | 9677 | EXPECT_THAT(callback_.GetResult(rv), IsOk()); |
| 9678 | EXPECT_EQ(socket_factory->GetLastProducedUDPSocket()->tag(), tag2); |
| 9679 | EXPECT_TRUE(socket_factory->GetLastProducedUDPSocket() |
| 9680 | ->tagged_before_data_transferred()); |
| 9681 | std::unique_ptr<QuicChromiumClientSession::Handle> stream3 = |
| 9682 | request3.ReleaseSessionHandle(); |
| 9683 | EXPECT_TRUE(stream3); |
| 9684 | EXPECT_TRUE(stream3->IsConnected()); |
| 9685 | #if defined(OS_ANDROID) |
| 9686 | EXPECT_FALSE(stream3->SharesSameSession(*stream1)); |
| 9687 | #else |
| 9688 | // Same tag should reuse session. |
| 9689 | EXPECT_TRUE(stream3->SharesSameSession(*stream1)); |
| 9690 | #endif |
| 9691 | } |
| 9692 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9693 | } // namespace test |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 9694 | } // namespace net |