Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "net/base/test_data_directory.h" | 10 #include "net/base/test_data_directory.h" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #include "net/ssl/default_channel_id_store.h" | 39 #include "net/ssl/default_channel_id_store.h" |
| 40 #include "net/test/cert_test_util.h" | 40 #include "net/test/cert_test_util.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 | 42 |
| 43 using base::StringPiece; | 43 using base::StringPiece; |
| 44 using std::ostream; | 44 using std::ostream; |
| 45 using std::string; | 45 using std::string; |
| 46 using std::vector; | 46 using std::vector; |
| 47 | 47 |
| 48 namespace net { | 48 namespace net { |
| 49 | |
| 50 extern NetworkChangeNotifier::NetworkHandle kDefaultNetworkForTests; | |
|
Ryan Hamilton
2015/12/29 05:29:36
Is this coming from socket_test_utils.cc? If so, I
Jana
2016/01/06 23:01:17
Done.
| |
| 51 extern NetworkChangeNotifier::NetworkHandle kNewNetworkForTests; | |
| 52 | |
| 49 namespace test { | 53 namespace test { |
| 50 | 54 |
| 51 namespace { | 55 namespace { |
| 52 const char kDefaultServerHostName[] = "www.google.com"; | 56 const char kDefaultServerHostName[] = "www.google.com"; |
| 53 const int kDefaultServerPort = 443; | 57 const int kDefaultServerPort = 443; |
| 54 | 58 |
| 55 // Run all tests with all the combinations of versions and | 59 // Run all tests with all the combinations of versions and |
| 56 // enable_connection_racing. | 60 // enable_connection_racing. |
| 57 struct TestParams { | 61 struct TestParams { |
| 58 TestParams(const QuicVersion version, bool enable_connection_racing) | 62 TestParams(const QuicVersion version, bool enable_connection_racing) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 class MockQuicServerInfoFactory : public QuicServerInfoFactory { | 113 class MockQuicServerInfoFactory : public QuicServerInfoFactory { |
| 110 public: | 114 public: |
| 111 MockQuicServerInfoFactory() {} | 115 MockQuicServerInfoFactory() {} |
| 112 ~MockQuicServerInfoFactory() override {} | 116 ~MockQuicServerInfoFactory() override {} |
| 113 | 117 |
| 114 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { | 118 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { |
| 115 return new MockQuicServerInfo(server_id); | 119 return new MockQuicServerInfo(server_id); |
| 116 } | 120 } |
| 117 }; | 121 }; |
| 118 | 122 |
| 123 class MockNetworkChangeNotifier : public NetworkChangeNotifier { | |
| 124 public: | |
| 125 MockNetworkChangeNotifier() : force_network_handles_supported_(false) {} | |
| 126 | |
| 127 ConnectionType GetCurrentConnectionType() const override { | |
| 128 return CONNECTION_UNKNOWN; | |
| 129 } | |
| 130 | |
| 131 void ForceNetworkHandlesSupported() { | |
| 132 force_network_handles_supported_ = true; | |
| 133 } | |
| 134 | |
| 135 bool AreNetworkHandlesCurrentlySupported() const override { | |
| 136 return force_network_handles_supported_; | |
| 137 } | |
| 138 | |
| 139 void SetConnectedNetworksList(NetworkList network_list) { | |
|
Ryan Hamilton
2015/12/29 21:18:55
nit: const &
Jana
2016/01/06 23:01:17
Done.
| |
| 140 connected_networks_ = network_list; | |
| 141 } | |
| 142 | |
| 143 void GetCurrentConnectedNetworks(NetworkList* network_list) const override { | |
| 144 network_list->clear(); | |
| 145 *network_list = connected_networks_; | |
| 146 } | |
| 147 | |
| 148 private: | |
| 149 bool force_network_handles_supported_; | |
| 150 NetworkChangeNotifier::NetworkList connected_networks_; | |
| 151 }; | |
| 152 | |
| 153 // Class to replace existing NetworkChangeNotifier singleton with a | |
| 154 // MockNetworkChangeNotifier for a test. To use, simply create a | |
| 155 // ScopedMockNetworkChangeNotifier object in the test. | |
| 156 class ScopedMockNetworkChangeNotifier { | |
| 157 public: | |
| 158 ScopedMockNetworkChangeNotifier() | |
| 159 : disable_network_change_notifier_for_tests_( | |
| 160 new NetworkChangeNotifier::DisableForTest()), | |
| 161 mock_network_change_notifier_(new MockNetworkChangeNotifier()) {} | |
| 162 | |
| 163 MockNetworkChangeNotifier* mock_network_change_notifier() { | |
| 164 return mock_network_change_notifier_.get(); | |
| 165 } | |
| 166 | |
| 167 private: | |
| 168 scoped_ptr<NetworkChangeNotifier::DisableForTest> | |
| 169 disable_network_change_notifier_for_tests_; | |
| 170 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; | |
| 171 }; | |
| 172 | |
| 119 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> { | 173 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> { |
| 120 protected: | 174 protected: |
| 121 QuicStreamFactoryTest() | 175 QuicStreamFactoryTest() |
| 122 : random_generator_(0), | 176 : random_generator_(0), |
| 123 clock_(new MockClock()), | 177 clock_(new MockClock()), |
| 124 runner_(new TestTaskRunner(clock_)), | 178 runner_(new TestTaskRunner(clock_)), |
| 125 maker_(GetParam().version, 0, clock_, kDefaultServerHostName), | 179 maker_(GetParam().version, 0, clock_, kDefaultServerHostName), |
| 126 cert_verifier_(CertVerifier::CreateDefault()), | 180 cert_verifier_(CertVerifier::CreateDefault()), |
| 127 channel_id_service_( | 181 channel_id_service_( |
| 128 new ChannelIDService(new DefaultChannelIDStore(nullptr), | 182 new ChannelIDService(new DefaultChannelIDStore(nullptr), |
| 129 base::ThreadTaskRunnerHandle::Get())), | 183 base::ThreadTaskRunnerHandle::Get())), |
| 130 cert_transparency_verifier_(new MultiLogCTVerifier()), | 184 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 185 scoped_mock_network_change_notifier_(nullptr), | |
| 131 factory_(nullptr), | 186 factory_(nullptr), |
| 132 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), | 187 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
| 133 privacy_mode_(PRIVACY_MODE_DISABLED), | 188 privacy_mode_(PRIVACY_MODE_DISABLED), |
| 134 enable_port_selection_(true), | 189 enable_port_selection_(true), |
| 135 always_require_handshake_confirmation_(false), | 190 always_require_handshake_confirmation_(false), |
| 136 disable_connection_pooling_(false), | 191 disable_connection_pooling_(false), |
| 137 load_server_info_timeout_srtt_multiplier_(0.0f), | 192 load_server_info_timeout_srtt_multiplier_(0.0f), |
| 138 enable_connection_racing_(true), | 193 enable_connection_racing_(true), |
| 139 enable_non_blocking_io_(true), | 194 enable_non_blocking_io_(true), |
| 140 disable_disk_cache_(false), | 195 disable_disk_cache_(false), |
| 141 prefer_aes_(false), | 196 prefer_aes_(false), |
| 142 max_number_of_lossy_connections_(0), | 197 max_number_of_lossy_connections_(0), |
| 143 packet_loss_threshold_(1.0f), | 198 packet_loss_threshold_(1.0f), |
| 144 max_disabled_reasons_(3), | 199 max_disabled_reasons_(3), |
| 145 threshold_timeouts_with_open_streams_(2), | 200 threshold_timeouts_with_open_streams_(2), |
| 146 threshold_public_resets_post_handshake_(2), | 201 threshold_public_resets_post_handshake_(2), |
| 147 receive_buffer_size_(0), | 202 receive_buffer_size_(0), |
| 148 delay_tcp_race_(false), | 203 delay_tcp_race_(false), |
| 149 store_server_configs_in_properties_(false), | 204 store_server_configs_in_properties_(false), |
| 150 close_sessions_on_ip_change_(false), | 205 close_sessions_on_ip_change_(false), |
| 151 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds) { | 206 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
| 207 migrate_sessions_on_network_change_(false) { | |
| 152 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 208 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 153 } | 209 } |
| 154 | 210 |
| 155 void Initialize() { | 211 void Initialize() { |
| 156 factory_.reset(new QuicStreamFactory( | 212 factory_.reset(new QuicStreamFactory( |
| 157 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), | 213 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), |
| 158 cert_verifier_.get(), nullptr, channel_id_service_.get(), | 214 cert_verifier_.get(), nullptr, channel_id_service_.get(), |
| 159 &transport_security_state_, cert_transparency_verifier_.get(), | 215 &transport_security_state_, cert_transparency_verifier_.get(), |
| 160 /*SocketPerformanceWatcherFactory*/ nullptr, | 216 /*SocketPerformanceWatcherFactory*/ nullptr, |
| 161 &crypto_client_stream_factory_, &random_generator_, clock_, | 217 &crypto_client_stream_factory_, &random_generator_, clock_, |
| 162 kDefaultMaxPacketSize, std::string(), | 218 kDefaultMaxPacketSize, std::string(), |
| 163 SupportedVersions(GetParam().version), enable_port_selection_, | 219 SupportedVersions(GetParam().version), enable_port_selection_, |
| 164 always_require_handshake_confirmation_, disable_connection_pooling_, | 220 always_require_handshake_confirmation_, disable_connection_pooling_, |
| 165 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, | 221 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, |
| 166 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, | 222 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, |
| 167 max_number_of_lossy_connections_, packet_loss_threshold_, | 223 max_number_of_lossy_connections_, packet_loss_threshold_, |
| 168 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 224 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
| 169 threshold_public_resets_post_handshake_, receive_buffer_size_, | 225 threshold_public_resets_post_handshake_, receive_buffer_size_, |
| 170 delay_tcp_race_, store_server_configs_in_properties_, | 226 delay_tcp_race_, store_server_configs_in_properties_, |
| 171 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, | 227 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, |
| 172 QuicTagVector())); | 228 migrate_sessions_on_network_change_, QuicTagVector())); |
| 173 factory_->set_require_confirmation(false); | 229 factory_->set_require_confirmation(false); |
| 174 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 230 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
| 175 } | 231 } |
| 176 | 232 |
| 233 void InitializeConnectionMigrationTest( | |
| 234 NetworkChangeNotifier::NetworkList connected_networks) { | |
| 235 scoped_mock_network_change_notifier_.reset( | |
| 236 new ScopedMockNetworkChangeNotifier()); | |
| 237 MockNetworkChangeNotifier* mock_ncn = | |
| 238 scoped_mock_network_change_notifier_->mock_network_change_notifier(); | |
| 239 mock_ncn->ForceNetworkHandlesSupported(); | |
| 240 mock_ncn->SetConnectedNetworksList(connected_networks); | |
| 241 migrate_sessions_on_network_change_ = true; | |
| 242 Initialize(); | |
| 243 } | |
| 244 | |
| 177 bool HasActiveSession(const HostPortPair& host_port_pair) { | 245 bool HasActiveSession(const HostPortPair& host_port_pair) { |
| 178 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), | 246 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), |
| 179 host_port_pair); | 247 host_port_pair); |
| 180 } | 248 } |
| 181 | 249 |
| 182 scoped_ptr<QuicHttpStream> CreateFromSession( | 250 scoped_ptr<QuicHttpStream> CreateFromSession( |
| 183 const HostPortPair& host_port_pair) { | 251 const HostPortPair& host_port_pair) { |
| 184 QuicChromiumClientSession* session = | 252 QuicChromiumClientSession* session = |
| 185 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair); | 253 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair); |
| 186 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 254 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); | 322 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
| 255 EXPECT_TRUE(test_cert.get()); | 323 EXPECT_TRUE(test_cert.get()); |
| 256 ProofVerifyDetailsChromium verify_details; | 324 ProofVerifyDetailsChromium verify_details; |
| 257 verify_details.cert_verify_result.verified_cert = test_cert; | 325 verify_details.cert_verify_result.verified_cert = test_cert; |
| 258 verify_details.cert_verify_result.is_issued_by_known_root = true; | 326 verify_details.cert_verify_result.is_issued_by_known_root = true; |
| 259 return verify_details; | 327 return verify_details; |
| 260 } | 328 } |
| 261 | 329 |
| 262 void NotifyIPAddressChanged() { | 330 void NotifyIPAddressChanged() { |
| 263 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 331 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 264 // For thread safety, the NCN queues tasks to do the actual notifications, | 332 // Spin the message loop so the notification is delivered. |
| 265 // so we need to spin the message loop so the notification is delivered. | |
| 266 base::MessageLoop::current()->RunUntilIdle(); | 333 base::MessageLoop::current()->RunUntilIdle(); |
| 267 } | 334 } |
| 268 | 335 |
| 336 void NotifySpecificNetworkChange( | |
| 337 NetworkChangeNotifier::NetworkChangeType type, | |
| 338 NetworkChangeNotifier::NetworkHandle network) { | |
| 339 NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChangeForTests( | |
| 340 type, network); | |
| 341 // Spin the message loop so the notification is delivered. | |
| 342 base::MessageLoop::current()->RunUntilIdle(); | |
| 343 } | |
| 344 | |
| 269 MockHostResolver host_resolver_; | 345 MockHostResolver host_resolver_; |
| 270 MockClientSocketFactory socket_factory_; | 346 MockClientSocketFactory socket_factory_; |
| 271 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 347 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 272 MockRandom random_generator_; | 348 MockRandom random_generator_; |
| 273 MockClock* clock_; // Owned by factory_. | 349 MockClock* clock_; // Owned by factory_. |
| 274 scoped_refptr<TestTaskRunner> runner_; | 350 scoped_refptr<TestTaskRunner> runner_; |
| 275 QuicTestPacketMaker maker_; | 351 QuicTestPacketMaker maker_; |
| 276 HttpServerPropertiesImpl http_server_properties_; | 352 HttpServerPropertiesImpl http_server_properties_; |
| 277 scoped_ptr<CertVerifier> cert_verifier_; | 353 scoped_ptr<CertVerifier> cert_verifier_; |
| 278 scoped_ptr<ChannelIDService> channel_id_service_; | 354 scoped_ptr<ChannelIDService> channel_id_service_; |
| 279 TransportSecurityState transport_security_state_; | 355 TransportSecurityState transport_security_state_; |
| 280 scoped_ptr<CTVerifier> cert_transparency_verifier_; | 356 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
| 357 scoped_ptr<ScopedMockNetworkChangeNotifier> | |
| 358 scoped_mock_network_change_notifier_; | |
| 281 scoped_ptr<QuicStreamFactory> factory_; | 359 scoped_ptr<QuicStreamFactory> factory_; |
| 282 HostPortPair host_port_pair_; | 360 HostPortPair host_port_pair_; |
| 283 PrivacyMode privacy_mode_; | 361 PrivacyMode privacy_mode_; |
| 284 BoundNetLog net_log_; | 362 BoundNetLog net_log_; |
| 285 TestCompletionCallback callback_; | 363 TestCompletionCallback callback_; |
| 286 | 364 |
| 287 // Variables to configure QuicStreamFactory. | 365 // Variables to configure QuicStreamFactory. |
| 288 bool enable_port_selection_; | 366 bool enable_port_selection_; |
| 289 bool always_require_handshake_confirmation_; | 367 bool always_require_handshake_confirmation_; |
| 290 bool disable_connection_pooling_; | 368 bool disable_connection_pooling_; |
| 291 double load_server_info_timeout_srtt_multiplier_; | 369 double load_server_info_timeout_srtt_multiplier_; |
| 292 bool enable_connection_racing_; | 370 bool enable_connection_racing_; |
| 293 bool enable_non_blocking_io_; | 371 bool enable_non_blocking_io_; |
| 294 bool disable_disk_cache_; | 372 bool disable_disk_cache_; |
| 295 bool prefer_aes_; | 373 bool prefer_aes_; |
| 296 int max_number_of_lossy_connections_; | 374 int max_number_of_lossy_connections_; |
| 297 double packet_loss_threshold_; | 375 double packet_loss_threshold_; |
| 298 int max_disabled_reasons_; | 376 int max_disabled_reasons_; |
| 299 int threshold_timeouts_with_open_streams_; | 377 int threshold_timeouts_with_open_streams_; |
| 300 int threshold_public_resets_post_handshake_; | 378 int threshold_public_resets_post_handshake_; |
| 301 int receive_buffer_size_; | 379 int receive_buffer_size_; |
| 302 bool delay_tcp_race_; | 380 bool delay_tcp_race_; |
| 303 bool store_server_configs_in_properties_; | 381 bool store_server_configs_in_properties_; |
| 304 bool close_sessions_on_ip_change_; | 382 bool close_sessions_on_ip_change_; |
| 305 int idle_connection_timeout_seconds_; | 383 int idle_connection_timeout_seconds_; |
| 384 bool migrate_sessions_on_network_change_; | |
| 306 }; | 385 }; |
| 307 | 386 |
| 308 INSTANTIATE_TEST_CASE_P(Version, | 387 INSTANTIATE_TEST_CASE_P(Version, |
| 309 QuicStreamFactoryTest, | 388 QuicStreamFactoryTest, |
| 310 ::testing::ValuesIn(GetTestParams())); | 389 ::testing::ValuesIn(GetTestParams())); |
| 311 | 390 |
| 312 TEST_P(QuicStreamFactoryTest, Create) { | 391 TEST_P(QuicStreamFactoryTest, Create) { |
| 313 Initialize(); | 392 Initialize(); |
| 314 | 393 |
| 315 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 394 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1126 /*cert_verify_flags=*/0, host_port_pair_.host(), | 1205 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1127 "GET", net_log_, callback_.callback())); | 1206 "GET", net_log_, callback_.callback())); |
| 1128 | 1207 |
| 1129 EXPECT_EQ(OK, callback_.WaitForResult()); | 1208 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1130 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 1209 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1131 HttpRequestInfo request_info; | 1210 HttpRequestInfo request_info; |
| 1132 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | 1211 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1133 net_log_, CompletionCallback())); | 1212 net_log_, CompletionCallback())); |
| 1134 | 1213 |
| 1135 // Close the session and verify that stream saw the error. | 1214 // Close the session and verify that stream saw the error. |
| 1136 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED); | 1215 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, QUIC_INTERNAL_ERROR); |
| 1137 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, | 1216 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
| 1138 stream->ReadResponseHeaders(callback_.callback())); | 1217 stream->ReadResponseHeaders(callback_.callback())); |
| 1139 | 1218 |
| 1140 // Now attempting to request a stream to the same origin should create | 1219 // Now attempting to request a stream to the same origin should create |
| 1141 // a new session. | 1220 // a new session. |
| 1142 | 1221 |
| 1143 QuicStreamRequest request2(factory_.get()); | 1222 QuicStreamRequest request2(factory_.get()); |
| 1144 EXPECT_EQ(ERR_IO_PENDING, | 1223 EXPECT_EQ(ERR_IO_PENDING, |
| 1145 request2.Request(host_port_pair_, privacy_mode_, | 1224 request2.Request(host_port_pair_, privacy_mode_, |
| 1146 /*cert_verify_flags=*/0, host_port_pair_.host(), | 1225 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 EXPECT_EQ(OK, callback_.WaitForResult()); | 1282 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1204 stream = request2.ReleaseStream(); | 1283 stream = request2.ReleaseStream(); |
| 1205 stream.reset(); // Will reset stream 3. | 1284 stream.reset(); // Will reset stream 3. |
| 1206 | 1285 |
| 1207 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 1286 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1208 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 1287 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1209 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 1288 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1210 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 1289 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1211 } | 1290 } |
| 1212 | 1291 |
| 1292 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnect) { | |
| 1293 InitializeConnectionMigrationTest( | |
| 1294 {kDefaultNetworkForTests, kNewNetworkForTests}); | |
| 1295 | |
| 1296 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1297 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | |
| 1298 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1299 | |
| 1300 // Create request and QuicHttpStream. | |
| 1301 QuicStreamRequest request(factory_.get()); | |
| 1302 EXPECT_EQ(ERR_IO_PENDING, | |
| 1303 request.Request(host_port_pair_, privacy_mode_, | |
| 1304 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1305 "GET", net_log_, callback_.callback())); | |
| 1306 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1307 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1308 EXPECT_TRUE(stream.get()); | |
| 1309 | |
| 1310 // Cause QUIC stream to be created. | |
| 1311 HttpRequestInfo request_info; | |
| 1312 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 1313 net_log_, CompletionCallback())); | |
| 1314 | |
| 1315 // Ensure that session is alive and active. | |
| 1316 QuicChromiumClientSession* session = | |
| 1317 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1318 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1319 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1320 | |
| 1321 // Set up second socket data provider that is used after migration. | |
| 1322 MockRead reads1[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1323 scoped_ptr<QuicEncryptedPacket> ping( | |
| 1324 maker_.MakePingPacket(1, /*include_version=*/true)); | |
| 1325 MockWrite writes1[] = { | |
| 1326 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 1)}; | |
| 1327 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, | |
| 1328 arraysize(writes1)); | |
| 1329 socket_factory_.AddSocketDataProvider(&socket_data1); | |
| 1330 | |
| 1331 // Cause connection migration to happen. This should cause a PING frame | |
| 1332 // to be emitted. | |
| 1333 NotifySpecificNetworkChange(NetworkChangeNotifier::SOON_TO_DISCONNECT, | |
| 1334 kDefaultNetworkForTests); | |
| 1335 | |
| 1336 // The session should now be marked as going away. Ensure that | |
| 1337 // while it is still alive, it is no longer active. | |
| 1338 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1339 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1340 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
| 1341 | |
| 1342 // Create a new request for the same destination and verify that a | |
| 1343 // new session is created. | |
| 1344 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1345 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); | |
| 1346 socket_factory_.AddSocketDataProvider(&socket_data2); | |
| 1347 | |
| 1348 QuicStreamRequest request2(factory_.get()); | |
| 1349 EXPECT_EQ(ERR_IO_PENDING, | |
| 1350 request2.Request(host_port_pair_, privacy_mode_, | |
| 1351 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1352 "GET", net_log_, callback_.callback())); | |
| 1353 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1354 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | |
| 1355 EXPECT_TRUE(stream2.get()); | |
| 1356 | |
| 1357 EXPECT_TRUE( | |
| 1358 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_)); | |
| 1359 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(), | |
| 1360 host_port_pair_)); | |
| 1361 | |
| 1362 // On a DISCONNECTED notification, nothing happens to the migrated session. | |
| 1363 NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, | |
| 1364 kDefaultNetworkForTests); | |
| 1365 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1366 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
| 1367 | |
| 1368 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1369 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1370 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | |
| 1371 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); | |
| 1372 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | |
| 1373 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | |
| 1374 } | |
| 1375 | |
| 1376 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnected) { | |
| 1377 InitializeConnectionMigrationTest( | |
| 1378 {kDefaultNetworkForTests, kNewNetworkForTests}); | |
| 1379 | |
| 1380 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1381 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0); | |
| 1382 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1383 | |
| 1384 // Create request and QuicHttpStream. | |
| 1385 QuicStreamRequest request(factory_.get()); | |
| 1386 EXPECT_EQ(ERR_IO_PENDING, | |
| 1387 request.Request(host_port_pair_, privacy_mode_, | |
| 1388 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1389 "GET", net_log_, callback_.callback())); | |
| 1390 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1391 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1392 EXPECT_TRUE(stream.get()); | |
| 1393 | |
| 1394 // Cause QUIC stream to be created. | |
| 1395 HttpRequestInfo request_info; | |
| 1396 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 1397 net_log_, CompletionCallback())); | |
| 1398 | |
| 1399 // Ensure that session is alive and active. | |
| 1400 QuicChromiumClientSession* session = | |
| 1401 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1402 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1403 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1404 | |
| 1405 // Set up second socket data provider that is used after migration. | |
| 1406 MockRead reads1[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1407 scoped_ptr<QuicEncryptedPacket> ping( | |
| 1408 maker_.MakePingPacket(1, /*include_version=*/true)); | |
| 1409 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( | |
| 1410 2, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); | |
| 1411 MockWrite writes1[] = { | |
| 1412 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 1), | |
| 1413 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 2)}; | |
| 1414 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, | |
| 1415 arraysize(writes1)); | |
| 1416 socket_factory_.AddSocketDataProvider(&socket_data1); | |
| 1417 | |
| 1418 // Cause connection migration to happen. This should cause a PING frame | |
| 1419 // to be emitted. | |
| 1420 NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, | |
| 1421 kDefaultNetworkForTests); | |
| 1422 | |
| 1423 // The session should now be marked as going away. Ensure that | |
| 1424 // while it is still alive, it is no longer active. | |
| 1425 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1426 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1427 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
| 1428 | |
| 1429 // Create a new request for the same destination and verify that a | |
| 1430 // new session is created. | |
| 1431 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1432 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); | |
| 1433 socket_factory_.AddSocketDataProvider(&socket_data2); | |
| 1434 | |
| 1435 QuicStreamRequest request2(factory_.get()); | |
| 1436 EXPECT_EQ(ERR_IO_PENDING, | |
| 1437 request2.Request(host_port_pair_, privacy_mode_, | |
| 1438 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1439 "GET", net_log_, callback_.callback())); | |
| 1440 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1441 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); | |
| 1442 EXPECT_TRUE(stream2.get()); | |
| 1443 | |
| 1444 EXPECT_TRUE( | |
| 1445 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_)); | |
| 1446 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(), | |
| 1447 host_port_pair_)); | |
| 1448 EXPECT_EQ(true, | |
| 1449 QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1450 | |
| 1451 stream.reset(); | |
| 1452 stream2.reset(); | |
| 1453 | |
| 1454 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1455 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1456 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | |
| 1457 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); | |
| 1458 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | |
| 1459 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | |
| 1460 } | |
| 1461 | |
| 1462 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNetworks) { | |
| 1463 NetworkChangeNotifier::NetworkList no_networks(0); | |
| 1464 InitializeConnectionMigrationTest(no_networks); | |
| 1465 | |
| 1466 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1467 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( | |
| 1468 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); | |
| 1469 MockWrite writes[] = { | |
| 1470 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1), | |
| 1471 }; | |
| 1472 SequencedSocketData socket_data(reads, arraysize(reads), writes, | |
| 1473 arraysize(writes)); | |
| 1474 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1475 | |
| 1476 // Create request and QuicHttpStream. | |
| 1477 QuicStreamRequest request(factory_.get()); | |
| 1478 EXPECT_EQ(ERR_IO_PENDING, | |
| 1479 request.Request(host_port_pair_, privacy_mode_, | |
| 1480 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1481 "GET", net_log_, callback_.callback())); | |
| 1482 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1483 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1484 EXPECT_TRUE(stream.get()); | |
| 1485 | |
| 1486 // Cause QUIC stream to be created. | |
| 1487 HttpRequestInfo request_info; | |
| 1488 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 1489 net_log_, CompletionCallback())); | |
| 1490 | |
| 1491 // Ensure that session is alive and active. | |
| 1492 QuicChromiumClientSession* session = | |
| 1493 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1494 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1495 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1496 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
| 1497 | |
| 1498 // Cause connection migration to happen. Since there are no networks | |
| 1499 // to migrate to, this should cause the session to continue on the same | |
| 1500 // socket, but be marked as going away. | |
| 1501 NotifySpecificNetworkChange(NetworkChangeNotifier::SOON_TO_DISCONNECT, | |
| 1502 kDefaultNetworkForTests); | |
| 1503 | |
| 1504 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1505 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1506 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
| 1507 | |
| 1508 stream.reset(); | |
| 1509 | |
| 1510 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1511 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1512 } | |
| 1513 | |
| 1514 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNetworks) { | |
| 1515 NetworkChangeNotifier::NetworkList no_networks(0); | |
| 1516 InitializeConnectionMigrationTest(no_networks); | |
| 1517 | |
| 1518 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1519 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( | |
| 1520 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT)); | |
| 1521 MockWrite writes[] = { | |
| 1522 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1), | |
| 1523 }; | |
| 1524 SequencedSocketData socket_data(reads, arraysize(reads), writes, | |
| 1525 arraysize(writes)); | |
| 1526 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1527 | |
| 1528 // Create request and QuicHttpStream. | |
| 1529 QuicStreamRequest request(factory_.get()); | |
| 1530 EXPECT_EQ(ERR_IO_PENDING, | |
| 1531 request.Request(host_port_pair_, privacy_mode_, | |
| 1532 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1533 "GET", net_log_, callback_.callback())); | |
| 1534 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1535 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1536 EXPECT_TRUE(stream.get()); | |
| 1537 | |
| 1538 // Cause QUIC stream to be created. | |
| 1539 HttpRequestInfo request_info; | |
| 1540 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 1541 net_log_, CompletionCallback())); | |
| 1542 | |
| 1543 // Ensure that session is alive and active. | |
| 1544 QuicChromiumClientSession* session = | |
| 1545 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1546 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1547 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1548 | |
| 1549 // Cause connection migration to happen. Since there are no networks | |
| 1550 // to migrate to, this should cause a RST_STREAM frame to be emitted | |
| 1551 // and the session to be closed. | |
| 1552 NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, | |
| 1553 kDefaultNetworkForTests); | |
| 1554 | |
| 1555 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1556 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1557 | |
| 1558 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1559 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1560 } | |
| 1561 | |
| 1562 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNewNetwork) { | |
| 1563 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); | |
| 1564 | |
| 1565 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1566 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( | |
| 1567 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); | |
| 1568 MockWrite writes[] = { | |
| 1569 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1), | |
| 1570 }; | |
| 1571 SequencedSocketData socket_data(reads, arraysize(reads), writes, | |
| 1572 arraysize(writes)); | |
| 1573 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1574 | |
| 1575 // Create request and QuicHttpStream. | |
| 1576 QuicStreamRequest request(factory_.get()); | |
| 1577 EXPECT_EQ(ERR_IO_PENDING, | |
| 1578 request.Request(host_port_pair_, privacy_mode_, | |
| 1579 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1580 "GET", net_log_, callback_.callback())); | |
| 1581 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1582 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1583 EXPECT_TRUE(stream.get()); | |
| 1584 | |
| 1585 // Cause QUIC stream to be created. | |
| 1586 HttpRequestInfo request_info; | |
| 1587 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 1588 net_log_, CompletionCallback())); | |
| 1589 | |
| 1590 // Ensure that session is alive and active. | |
| 1591 QuicChromiumClientSession* session = | |
| 1592 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1593 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1594 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1595 | |
| 1596 // Cause connection migration to happen. Since there are no networks | |
| 1597 // to migrate to, this should cause session to be continue but be marked as | |
| 1598 // going away. | |
| 1599 NotifySpecificNetworkChange(NetworkChangeNotifier::SOON_TO_DISCONNECT, | |
| 1600 kDefaultNetworkForTests); | |
| 1601 | |
| 1602 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1603 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1604 EXPECT_EQ(1u, session->GetNumActiveStreams()); | |
| 1605 | |
| 1606 stream.reset(); | |
| 1607 | |
| 1608 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1609 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1610 } | |
| 1611 | |
| 1612 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNewNetwork) { | |
| 1613 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); | |
| 1614 | |
| 1615 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1616 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( | |
| 1617 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT)); | |
| 1618 MockWrite writes[] = { | |
| 1619 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1), | |
| 1620 }; | |
| 1621 SequencedSocketData socket_data(reads, arraysize(reads), writes, | |
| 1622 arraysize(writes)); | |
| 1623 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1624 | |
| 1625 // Create request and QuicHttpStream. | |
| 1626 QuicStreamRequest request(factory_.get()); | |
| 1627 EXPECT_EQ(ERR_IO_PENDING, | |
| 1628 request.Request(host_port_pair_, privacy_mode_, | |
| 1629 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1630 "GET", net_log_, callback_.callback())); | |
| 1631 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1632 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1633 EXPECT_TRUE(stream.get()); | |
| 1634 | |
| 1635 // Cause QUIC stream to be created. | |
| 1636 HttpRequestInfo request_info; | |
| 1637 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | |
| 1638 net_log_, CompletionCallback())); | |
| 1639 | |
| 1640 // Ensure that session is alive and active. | |
| 1641 QuicChromiumClientSession* session = | |
| 1642 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1643 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1644 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1645 | |
| 1646 // Cause connection migration to happen. Since there are no networks | |
| 1647 // to migrate to, this should cause a RST_STREAM frame to be emitted | |
| 1648 // with QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. | |
| 1649 NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, | |
| 1650 kDefaultNetworkForTests); | |
| 1651 | |
| 1652 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1653 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1654 | |
| 1655 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1656 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1657 } | |
| 1658 | |
| 1659 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoOpenStreams) { | |
| 1660 InitializeConnectionMigrationTest( | |
| 1661 {kDefaultNetworkForTests, kNewNetworkForTests}); | |
| 1662 | |
| 1663 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1664 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u); | |
| 1665 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1666 | |
| 1667 // Create request and QuicHttpStream. | |
| 1668 QuicStreamRequest request(factory_.get()); | |
| 1669 EXPECT_EQ(ERR_IO_PENDING, | |
| 1670 request.Request(host_port_pair_, privacy_mode_, | |
| 1671 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1672 "GET", net_log_, callback_.callback())); | |
| 1673 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1674 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1675 EXPECT_TRUE(stream.get()); | |
| 1676 | |
| 1677 // Ensure that session is alive and active. | |
| 1678 QuicChromiumClientSession* session = | |
| 1679 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1680 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1681 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1682 | |
| 1683 // Cause connection migration to happen. Since there are no active streams, | |
| 1684 // the session will be closed. | |
| 1685 NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, | |
| 1686 kDefaultNetworkForTests); | |
| 1687 | |
| 1688 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1689 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1690 | |
| 1691 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1692 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1693 } | |
| 1694 | |
| 1695 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoOpenStreams) { | |
| 1696 InitializeConnectionMigrationTest( | |
| 1697 {kDefaultNetworkForTests, kNewNetworkForTests}); | |
| 1698 | |
| 1699 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | |
| 1700 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u); | |
| 1701 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 1702 | |
| 1703 // Create request and QuicHttpStream. | |
| 1704 QuicStreamRequest request(factory_.get()); | |
| 1705 EXPECT_EQ(ERR_IO_PENDING, | |
| 1706 request.Request(host_port_pair_, privacy_mode_, | |
| 1707 /*cert_verify_flags=*/0, host_port_pair_.host(), | |
| 1708 "GET", net_log_, callback_.callback())); | |
| 1709 EXPECT_EQ(OK, callback_.WaitForResult()); | |
| 1710 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | |
| 1711 EXPECT_TRUE(stream.get()); | |
| 1712 | |
| 1713 // Ensure that session is alive and active. | |
| 1714 QuicChromiumClientSession* session = | |
| 1715 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); | |
| 1716 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1717 EXPECT_TRUE(HasActiveSession(host_port_pair_)); | |
| 1718 | |
| 1719 // Cause connection migration to happen. Since there are no active streams, | |
| 1720 // the session will be closed. | |
| 1721 NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, | |
| 1722 kDefaultNetworkForTests); | |
| 1723 | |
| 1724 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); | |
| 1725 EXPECT_FALSE(HasActiveSession(host_port_pair_)); | |
| 1726 | |
| 1727 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 1728 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 1729 } | |
| 1730 | |
| 1213 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { | 1731 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
| 1214 Initialize(); | 1732 Initialize(); |
| 1215 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 1733 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1216 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); | 1734 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
| 1217 std::vector<MockWrite> writes; | 1735 std::vector<MockWrite> writes; |
| 1218 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); | 1736 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
| 1219 SequencedSocketData socket_data(reads, arraysize(reads), | 1737 SequencedSocketData socket_data(reads, arraysize(reads), |
| 1220 writes.empty() ? nullptr : &writes[0], | 1738 writes.empty() ? nullptr : &writes[0], |
| 1221 writes.size()); | 1739 writes.size()); |
| 1222 socket_factory_.AddSocketDataProvider(&socket_data); | 1740 socket_factory_.AddSocketDataProvider(&socket_data); |
| (...skipping 1356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2579 EXPECT_EQ(1u, observer.executed_count()); | 3097 EXPECT_EQ(1u, observer.executed_count()); |
| 2580 | 3098 |
| 2581 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 3099 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 2582 EXPECT_TRUE(stream.get()); | 3100 EXPECT_TRUE(stream.get()); |
| 2583 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3101 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 2584 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3102 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 2585 } | 3103 } |
| 2586 | 3104 |
| 2587 } // namespace test | 3105 } // namespace test |
| 2588 } // namespace net | 3106 } // namespace net |
| OLD | NEW |