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" |
11 #include "net/cert/cert_verifier.h" | 11 #include "net/cert/cert_verifier.h" |
12 #include "net/cert/multi_log_ct_verifier.h" | 12 #include "net/cert/multi_log_ct_verifier.h" |
13 #include "net/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
15 #include "net/http/http_response_info.h" | 15 #include "net/http/http_response_info.h" |
16 #include "net/http/http_server_properties_impl.h" | 16 #include "net/http/http_server_properties_impl.h" |
17 #include "net/http/http_util.h" | 17 #include "net/http/http_util.h" |
18 #include "net/http/transport_security_state.h" | 18 #include "net/http/transport_security_state.h" |
19 #include "net/quic/crypto/crypto_handshake.h" | 19 #include "net/quic/crypto/crypto_handshake.h" |
20 #include "net/quic/crypto/proof_verifier_chromium.h" | 20 #include "net/quic/crypto/proof_verifier_chromium.h" |
21 #include "net/quic/crypto/properties_based_quic_server_info.h" | 21 #include "net/quic/crypto/properties_based_quic_server_info.h" |
22 #include "net/quic/crypto/quic_crypto_client_config.h" | 22 #include "net/quic/crypto/quic_crypto_client_config.h" |
23 #include "net/quic/crypto/quic_decrypter.h" | 23 #include "net/quic/crypto/quic_decrypter.h" |
24 #include "net/quic/crypto/quic_encrypter.h" | 24 #include "net/quic/crypto/quic_encrypter.h" |
25 #include "net/quic/crypto/quic_server_info.h" | 25 #include "net/quic/crypto/quic_server_info.h" |
26 #include "net/quic/quic_http_stream.h" | 26 #include "net/quic/quic_http_stream.h" |
| 27 #include "net/quic/quic_http_utils.h" |
27 #include "net/quic/quic_server_id.h" | 28 #include "net/quic/quic_server_id.h" |
28 #include "net/quic/test_tools/mock_clock.h" | 29 #include "net/quic/test_tools/mock_clock.h" |
29 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" | 30 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
30 #include "net/quic/test_tools/mock_random.h" | 31 #include "net/quic/test_tools/mock_random.h" |
31 #include "net/quic/test_tools/quic_stream_factory_peer.h" | 32 #include "net/quic/test_tools/quic_stream_factory_peer.h" |
32 #include "net/quic/test_tools/quic_test_packet_maker.h" | 33 #include "net/quic/test_tools/quic_test_packet_maker.h" |
33 #include "net/quic/test_tools/quic_test_utils.h" | 34 #include "net/quic/test_tools/quic_test_utils.h" |
34 #include "net/quic/test_tools/test_task_runner.h" | 35 #include "net/quic/test_tools/test_task_runner.h" |
35 #include "net/socket/socket_test_util.h" | 36 #include "net/socket/socket_test_util.h" |
36 #include "net/spdy/spdy_session_test_util.h" | 37 #include "net/spdy/spdy_session_test_util.h" |
37 #include "net/spdy/spdy_test_utils.h" | 38 #include "net/spdy/spdy_test_utils.h" |
38 #include "net/ssl/channel_id_service.h" | 39 #include "net/ssl/channel_id_service.h" |
39 #include "net/ssl/default_channel_id_store.h" | 40 #include "net/ssl/default_channel_id_store.h" |
40 #include "net/test/cert_test_util.h" | 41 #include "net/test/cert_test_util.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
42 | 43 |
43 using base::StringPiece; | 44 using base::StringPiece; |
44 using std::ostream; | 45 using std::ostream; |
45 using std::string; | 46 using std::string; |
46 using std::vector; | 47 using std::vector; |
47 | 48 |
48 namespace net { | 49 namespace net { |
| 50 |
49 namespace test { | 51 namespace test { |
50 | 52 |
51 namespace { | 53 namespace { |
52 const char kDefaultServerHostName[] = "www.example.org"; | 54 const char kDefaultServerHostName[] = "www.example.org"; |
53 const char kServer2HostName[] = "mail.example.org"; | 55 const char kServer2HostName[] = "mail.example.org"; |
54 const char kServer3HostName[] = "docs.example.org"; | 56 const char kServer3HostName[] = "docs.example.org"; |
55 const char kServer4HostName[] = "images.example.org"; | 57 const char kServer4HostName[] = "images.example.org"; |
56 const int kDefaultServerPort = 443; | 58 const int kDefaultServerPort = 443; |
57 | 59 |
58 // Run all tests with all the combinations of versions and | 60 // Run all tests with all the combinations of versions and |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 class MockQuicServerInfoFactory : public QuicServerInfoFactory { | 114 class MockQuicServerInfoFactory : public QuicServerInfoFactory { |
113 public: | 115 public: |
114 MockQuicServerInfoFactory() {} | 116 MockQuicServerInfoFactory() {} |
115 ~MockQuicServerInfoFactory() override {} | 117 ~MockQuicServerInfoFactory() override {} |
116 | 118 |
117 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { | 119 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { |
118 return new MockQuicServerInfo(server_id); | 120 return new MockQuicServerInfo(server_id); |
119 } | 121 } |
120 }; | 122 }; |
121 | 123 |
| 124 class MockNetworkChangeNotifier : public NetworkChangeNotifier { |
| 125 public: |
| 126 MockNetworkChangeNotifier() : force_network_handles_supported_(false) {} |
| 127 |
| 128 ConnectionType GetCurrentConnectionType() const override { |
| 129 return CONNECTION_UNKNOWN; |
| 130 } |
| 131 |
| 132 void ForceNetworkHandlesSupported() { |
| 133 force_network_handles_supported_ = true; |
| 134 } |
| 135 |
| 136 bool AreNetworkHandlesCurrentlySupported() const override { |
| 137 return force_network_handles_supported_; |
| 138 } |
| 139 |
| 140 void SetConnectedNetworksList(const NetworkList& network_list) { |
| 141 connected_networks_ = network_list; |
| 142 } |
| 143 |
| 144 void GetCurrentConnectedNetworks(NetworkList* network_list) const override { |
| 145 network_list->clear(); |
| 146 *network_list = connected_networks_; |
| 147 } |
| 148 |
| 149 void NotifyNetworkSoonToDisconnect( |
| 150 NetworkChangeNotifier::NetworkHandle network) { |
| 151 NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChange( |
| 152 NetworkChangeNotifier::SOON_TO_DISCONNECT, network); |
| 153 // Spin the message loop so the notification is delivered. |
| 154 base::MessageLoop::current()->RunUntilIdle(); |
| 155 } |
| 156 |
| 157 void NotifyNetworkDisconnected(NetworkChangeNotifier::NetworkHandle network) { |
| 158 NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChange( |
| 159 NetworkChangeNotifier::DISCONNECTED, network); |
| 160 // Spin the message loop so the notification is delivered. |
| 161 base::MessageLoop::current()->RunUntilIdle(); |
| 162 } |
| 163 |
| 164 private: |
| 165 bool force_network_handles_supported_; |
| 166 NetworkChangeNotifier::NetworkList connected_networks_; |
| 167 }; |
| 168 |
| 169 // Class to replace existing NetworkChangeNotifier singleton with a |
| 170 // MockNetworkChangeNotifier for a test. To use, simply create a |
| 171 // ScopedMockNetworkChangeNotifier object in the test. |
| 172 class ScopedMockNetworkChangeNotifier { |
| 173 public: |
| 174 ScopedMockNetworkChangeNotifier() |
| 175 : disable_network_change_notifier_for_tests_( |
| 176 new NetworkChangeNotifier::DisableForTest()), |
| 177 mock_network_change_notifier_(new MockNetworkChangeNotifier()) {} |
| 178 |
| 179 MockNetworkChangeNotifier* mock_network_change_notifier() { |
| 180 return mock_network_change_notifier_.get(); |
| 181 } |
| 182 |
| 183 private: |
| 184 scoped_ptr<NetworkChangeNotifier::DisableForTest> |
| 185 disable_network_change_notifier_for_tests_; |
| 186 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; |
| 187 }; |
| 188 |
122 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> { | 189 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> { |
123 protected: | 190 protected: |
124 QuicStreamFactoryTest() | 191 QuicStreamFactoryTest() |
125 : random_generator_(0), | 192 : random_generator_(0), |
126 clock_(new MockClock()), | 193 clock_(new MockClock()), |
127 runner_(new TestTaskRunner(clock_)), | 194 runner_(new TestTaskRunner(clock_)), |
128 maker_(GetParam().version, 0, clock_, kDefaultServerHostName), | 195 maker_(GetParam().version, 0, clock_, kDefaultServerHostName), |
129 cert_verifier_(CertVerifier::CreateDefault()), | 196 cert_verifier_(CertVerifier::CreateDefault()), |
130 channel_id_service_( | 197 channel_id_service_( |
131 new ChannelIDService(new DefaultChannelIDStore(nullptr), | 198 new ChannelIDService(new DefaultChannelIDStore(nullptr), |
132 base::ThreadTaskRunnerHandle::Get())), | 199 base::ThreadTaskRunnerHandle::Get())), |
133 cert_transparency_verifier_(new MultiLogCTVerifier()), | 200 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 201 scoped_mock_network_change_notifier_(nullptr), |
134 factory_(nullptr), | 202 factory_(nullptr), |
135 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), | 203 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
136 privacy_mode_(PRIVACY_MODE_DISABLED), | 204 privacy_mode_(PRIVACY_MODE_DISABLED), |
137 enable_port_selection_(true), | 205 enable_port_selection_(true), |
138 always_require_handshake_confirmation_(false), | 206 always_require_handshake_confirmation_(false), |
139 disable_connection_pooling_(false), | 207 disable_connection_pooling_(false), |
140 load_server_info_timeout_srtt_multiplier_(0.0f), | 208 load_server_info_timeout_srtt_multiplier_(0.0f), |
141 enable_connection_racing_(true), | 209 enable_connection_racing_(true), |
142 enable_non_blocking_io_(true), | 210 enable_non_blocking_io_(true), |
143 disable_disk_cache_(false), | 211 disable_disk_cache_(false), |
144 prefer_aes_(false), | 212 prefer_aes_(false), |
145 max_number_of_lossy_connections_(0), | 213 max_number_of_lossy_connections_(0), |
146 packet_loss_threshold_(1.0f), | 214 packet_loss_threshold_(1.0f), |
147 max_disabled_reasons_(3), | 215 max_disabled_reasons_(3), |
148 threshold_timeouts_with_open_streams_(2), | 216 threshold_timeouts_with_open_streams_(2), |
149 threshold_public_resets_post_handshake_(2), | 217 threshold_public_resets_post_handshake_(2), |
150 receive_buffer_size_(0), | 218 receive_buffer_size_(0), |
151 delay_tcp_race_(false), | 219 delay_tcp_race_(false), |
152 store_server_configs_in_properties_(false), | 220 store_server_configs_in_properties_(false), |
153 close_sessions_on_ip_change_(false), | 221 close_sessions_on_ip_change_(false), |
154 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds) { | 222 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
| 223 migrate_sessions_on_network_change_(false) { |
155 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 224 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
156 } | 225 } |
157 | 226 |
158 void Initialize() { | 227 void Initialize() { |
159 factory_.reset(new QuicStreamFactory( | 228 factory_.reset(new QuicStreamFactory( |
160 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), | 229 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), |
161 cert_verifier_.get(), nullptr, channel_id_service_.get(), | 230 cert_verifier_.get(), nullptr, channel_id_service_.get(), |
162 &transport_security_state_, cert_transparency_verifier_.get(), | 231 &transport_security_state_, cert_transparency_verifier_.get(), |
163 /*SocketPerformanceWatcherFactory*/ nullptr, | 232 /*SocketPerformanceWatcherFactory*/ nullptr, |
164 &crypto_client_stream_factory_, &random_generator_, clock_, | 233 &crypto_client_stream_factory_, &random_generator_, clock_, |
165 kDefaultMaxPacketSize, std::string(), | 234 kDefaultMaxPacketSize, std::string(), |
166 SupportedVersions(GetParam().version), enable_port_selection_, | 235 SupportedVersions(GetParam().version), enable_port_selection_, |
167 always_require_handshake_confirmation_, disable_connection_pooling_, | 236 always_require_handshake_confirmation_, disable_connection_pooling_, |
168 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, | 237 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, |
169 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, | 238 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, |
170 max_number_of_lossy_connections_, packet_loss_threshold_, | 239 max_number_of_lossy_connections_, packet_loss_threshold_, |
171 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 240 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
172 threshold_public_resets_post_handshake_, receive_buffer_size_, | 241 threshold_public_resets_post_handshake_, receive_buffer_size_, |
173 delay_tcp_race_, store_server_configs_in_properties_, | 242 delay_tcp_race_, store_server_configs_in_properties_, |
174 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, | 243 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, |
175 QuicTagVector())); | 244 migrate_sessions_on_network_change_, QuicTagVector())); |
176 factory_->set_require_confirmation(false); | 245 factory_->set_require_confirmation(false); |
177 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 246 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
178 } | 247 } |
179 | 248 |
| 249 void InitializeConnectionMigrationTest( |
| 250 NetworkChangeNotifier::NetworkList connected_networks) { |
| 251 scoped_mock_network_change_notifier_.reset( |
| 252 new ScopedMockNetworkChangeNotifier()); |
| 253 MockNetworkChangeNotifier* mock_ncn = |
| 254 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 255 mock_ncn->ForceNetworkHandlesSupported(); |
| 256 mock_ncn->SetConnectedNetworksList(connected_networks); |
| 257 migrate_sessions_on_network_change_ = true; |
| 258 Initialize(); |
| 259 } |
| 260 |
180 bool HasActiveSession(const HostPortPair& host_port_pair) { | 261 bool HasActiveSession(const HostPortPair& host_port_pair) { |
181 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), | 262 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), |
182 host_port_pair); | 263 host_port_pair); |
183 } | 264 } |
184 | 265 |
185 scoped_ptr<QuicHttpStream> CreateFromSession( | 266 scoped_ptr<QuicHttpStream> CreateFromSession( |
186 const HostPortPair& host_port_pair) { | 267 const HostPortPair& host_port_pair) { |
187 QuicChromiumClientSession* session = | 268 QuicChromiumClientSession* session = |
188 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair); | 269 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair); |
189 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 270 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); | 337 ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
257 EXPECT_TRUE(test_cert.get()); | 338 EXPECT_TRUE(test_cert.get()); |
258 ProofVerifyDetailsChromium verify_details; | 339 ProofVerifyDetailsChromium verify_details; |
259 verify_details.cert_verify_result.verified_cert = test_cert; | 340 verify_details.cert_verify_result.verified_cert = test_cert; |
260 verify_details.cert_verify_result.is_issued_by_known_root = true; | 341 verify_details.cert_verify_result.is_issued_by_known_root = true; |
261 return verify_details; | 342 return verify_details; |
262 } | 343 } |
263 | 344 |
264 void NotifyIPAddressChanged() { | 345 void NotifyIPAddressChanged() { |
265 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 346 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
266 // For thread safety, the NCN queues tasks to do the actual notifications, | 347 // Spin the message loop so the notification is delivered. |
267 // so we need to spin the message loop so the notification is delivered. | |
268 base::MessageLoop::current()->RunUntilIdle(); | 348 base::MessageLoop::current()->RunUntilIdle(); |
269 } | 349 } |
270 | 350 |
| 351 scoped_ptr<QuicEncryptedPacket> ConstructGetRequestPacket( |
| 352 QuicPacketNumber packet_number, |
| 353 QuicStreamId stream_id, |
| 354 bool should_include_version, |
| 355 bool fin) { |
| 356 SpdyHeaderBlock headers = maker_.GetRequestHeaders("GET", "https", "/"); |
| 357 SpdyPriority priority = |
| 358 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 359 size_t spdy_headers_frame_len; |
| 360 return maker_.MakeRequestHeadersPacket( |
| 361 packet_number, stream_id, should_include_version, fin, priority, |
| 362 headers, &spdy_headers_frame_len); |
| 363 } |
| 364 |
| 365 scoped_ptr<QuicEncryptedPacket> ConstructOkResponsePacket( |
| 366 QuicPacketNumber packet_number, |
| 367 QuicStreamId stream_id, |
| 368 bool should_include_version, |
| 369 bool fin) { |
| 370 SpdyHeaderBlock headers = maker_.GetResponseHeaders("200 OK"); |
| 371 size_t spdy_headers_frame_len; |
| 372 return maker_.MakeResponseHeadersPacket(packet_number, stream_id, |
| 373 should_include_version, fin, |
| 374 headers, &spdy_headers_frame_len); |
| 375 } |
| 376 |
271 MockHostResolver host_resolver_; | 377 MockHostResolver host_resolver_; |
272 MockClientSocketFactory socket_factory_; | 378 MockClientSocketFactory socket_factory_; |
273 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 379 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 380 ProofVerifyDetailsChromium verify_details_; |
274 MockRandom random_generator_; | 381 MockRandom random_generator_; |
275 MockClock* clock_; // Owned by factory_. | 382 MockClock* clock_; // Owned by factory_. |
276 scoped_refptr<TestTaskRunner> runner_; | 383 scoped_refptr<TestTaskRunner> runner_; |
277 QuicTestPacketMaker maker_; | 384 QuicTestPacketMaker maker_; |
278 HttpServerPropertiesImpl http_server_properties_; | 385 HttpServerPropertiesImpl http_server_properties_; |
279 scoped_ptr<CertVerifier> cert_verifier_; | 386 scoped_ptr<CertVerifier> cert_verifier_; |
280 scoped_ptr<ChannelIDService> channel_id_service_; | 387 scoped_ptr<ChannelIDService> channel_id_service_; |
281 TransportSecurityState transport_security_state_; | 388 TransportSecurityState transport_security_state_; |
282 scoped_ptr<CTVerifier> cert_transparency_verifier_; | 389 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
| 390 scoped_ptr<ScopedMockNetworkChangeNotifier> |
| 391 scoped_mock_network_change_notifier_; |
283 scoped_ptr<QuicStreamFactory> factory_; | 392 scoped_ptr<QuicStreamFactory> factory_; |
284 HostPortPair host_port_pair_; | 393 HostPortPair host_port_pair_; |
285 PrivacyMode privacy_mode_; | 394 PrivacyMode privacy_mode_; |
286 BoundNetLog net_log_; | 395 BoundNetLog net_log_; |
287 TestCompletionCallback callback_; | 396 TestCompletionCallback callback_; |
288 | 397 |
289 // Variables to configure QuicStreamFactory. | 398 // Variables to configure QuicStreamFactory. |
290 bool enable_port_selection_; | 399 bool enable_port_selection_; |
291 bool always_require_handshake_confirmation_; | 400 bool always_require_handshake_confirmation_; |
292 bool disable_connection_pooling_; | 401 bool disable_connection_pooling_; |
293 double load_server_info_timeout_srtt_multiplier_; | 402 double load_server_info_timeout_srtt_multiplier_; |
294 bool enable_connection_racing_; | 403 bool enable_connection_racing_; |
295 bool enable_non_blocking_io_; | 404 bool enable_non_blocking_io_; |
296 bool disable_disk_cache_; | 405 bool disable_disk_cache_; |
297 bool prefer_aes_; | 406 bool prefer_aes_; |
298 int max_number_of_lossy_connections_; | 407 int max_number_of_lossy_connections_; |
299 double packet_loss_threshold_; | 408 double packet_loss_threshold_; |
300 int max_disabled_reasons_; | 409 int max_disabled_reasons_; |
301 int threshold_timeouts_with_open_streams_; | 410 int threshold_timeouts_with_open_streams_; |
302 int threshold_public_resets_post_handshake_; | 411 int threshold_public_resets_post_handshake_; |
303 int receive_buffer_size_; | 412 int receive_buffer_size_; |
304 bool delay_tcp_race_; | 413 bool delay_tcp_race_; |
305 bool store_server_configs_in_properties_; | 414 bool store_server_configs_in_properties_; |
306 bool close_sessions_on_ip_change_; | 415 bool close_sessions_on_ip_change_; |
307 int idle_connection_timeout_seconds_; | 416 int idle_connection_timeout_seconds_; |
| 417 bool migrate_sessions_on_network_change_; |
308 }; | 418 }; |
309 | 419 |
310 INSTANTIATE_TEST_CASE_P(Version, | 420 INSTANTIATE_TEST_CASE_P(Version, |
311 QuicStreamFactoryTest, | 421 QuicStreamFactoryTest, |
312 ::testing::ValuesIn(GetTestParams())); | 422 ::testing::ValuesIn(GetTestParams())); |
313 | 423 |
314 TEST_P(QuicStreamFactoryTest, Create) { | 424 TEST_P(QuicStreamFactoryTest, Create) { |
315 Initialize(); | 425 Initialize(); |
316 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 426 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
317 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 427 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 /*cert_verify_flags=*/0, host_port_pair_.host(), | 1275 /*cert_verify_flags=*/0, host_port_pair_.host(), |
1166 "GET", net_log_, callback_.callback())); | 1276 "GET", net_log_, callback_.callback())); |
1167 | 1277 |
1168 EXPECT_EQ(OK, callback_.WaitForResult()); | 1278 EXPECT_EQ(OK, callback_.WaitForResult()); |
1169 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 1279 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
1170 HttpRequestInfo request_info; | 1280 HttpRequestInfo request_info; |
1171 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | 1281 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
1172 net_log_, CompletionCallback())); | 1282 net_log_, CompletionCallback())); |
1173 | 1283 |
1174 // Close the session and verify that stream saw the error. | 1284 // Close the session and verify that stream saw the error. |
1175 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED); | 1285 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, QUIC_INTERNAL_ERROR); |
1176 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, | 1286 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
1177 stream->ReadResponseHeaders(callback_.callback())); | 1287 stream->ReadResponseHeaders(callback_.callback())); |
1178 | 1288 |
1179 // Now attempting to request a stream to the same origin should create | 1289 // Now attempting to request a stream to the same origin should create |
1180 // a new session. | 1290 // a new session. |
1181 | 1291 |
1182 QuicStreamRequest request2(factory_.get()); | 1292 QuicStreamRequest request2(factory_.get()); |
1183 EXPECT_EQ(ERR_IO_PENDING, | 1293 EXPECT_EQ(ERR_IO_PENDING, |
1184 request2.Request(host_port_pair_, privacy_mode_, | 1294 request2.Request(host_port_pair_, privacy_mode_, |
1185 /*cert_verify_flags=*/0, host_port_pair_.host(), | 1295 /*cert_verify_flags=*/0, host_port_pair_.host(), |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 EXPECT_EQ(OK, callback_.WaitForResult()); | 1355 EXPECT_EQ(OK, callback_.WaitForResult()); |
1246 stream = request2.ReleaseStream(); | 1356 stream = request2.ReleaseStream(); |
1247 stream.reset(); // Will reset stream 3. | 1357 stream.reset(); // Will reset stream 3. |
1248 | 1358 |
1249 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 1359 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
1250 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 1360 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
1251 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 1361 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
1252 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 1362 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
1253 } | 1363 } |
1254 | 1364 |
| 1365 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnect) { |
| 1366 InitializeConnectionMigrationTest( |
| 1367 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1368 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1369 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1370 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1371 |
| 1372 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1373 scoped_ptr<QuicEncryptedPacket> request_packet( |
| 1374 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); |
| 1375 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(), |
| 1376 request_packet->length(), 1)}; |
| 1377 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1378 arraysize(writes)); |
| 1379 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1380 |
| 1381 // Create request and QuicHttpStream. |
| 1382 QuicStreamRequest request(factory_.get()); |
| 1383 EXPECT_EQ(ERR_IO_PENDING, |
| 1384 request.Request(host_port_pair_, privacy_mode_, |
| 1385 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1386 "GET", net_log_, callback_.callback())); |
| 1387 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1388 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1389 EXPECT_TRUE(stream.get()); |
| 1390 |
| 1391 // Cause QUIC stream to be created. |
| 1392 HttpRequestInfo request_info; |
| 1393 request_info.method = "GET"; |
| 1394 request_info.url = GURL("https://www.example.org/"); |
| 1395 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1396 net_log_, CompletionCallback())); |
| 1397 |
| 1398 // Ensure that session is alive and active. |
| 1399 QuicChromiumClientSession* session = |
| 1400 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1401 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1402 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1403 |
| 1404 // Send GET request on stream. |
| 1405 HttpResponseInfo response; |
| 1406 HttpRequestHeaders request_headers; |
| 1407 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 1408 callback_.callback())); |
| 1409 |
| 1410 // Set up second socket data provider that is used after migration. |
| 1411 // The response to the earlier request is read on this new socket. |
| 1412 scoped_ptr<QuicEncryptedPacket> ping( |
| 1413 maker_.MakePingPacket(2, /*include_version=*/true)); |
| 1414 MockWrite writes1[] = { |
| 1415 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)}; |
| 1416 scoped_ptr<QuicEncryptedPacket> response_headers_packet( |
| 1417 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); |
| 1418 MockRead reads1[] = {MockRead(ASYNC, response_headers_packet->data(), |
| 1419 response_headers_packet->length(), 1), |
| 1420 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
| 1421 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, |
| 1422 arraysize(writes1)); |
| 1423 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 1424 |
| 1425 // Trigger connection migration. This should cause a PING frame |
| 1426 // to be emitted. |
| 1427 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1428 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests); |
| 1429 |
| 1430 // The session should now be marked as going away. Ensure that |
| 1431 // while it is still alive, it is no longer active. |
| 1432 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1433 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1434 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1435 |
| 1436 // Verify that response headers on the migrated socket were delivered to the |
| 1437 // stream. |
| 1438 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 1439 EXPECT_EQ(200, response.headers->response_code()); |
| 1440 |
| 1441 // Create a new request for the same destination and verify that a |
| 1442 // new session is created. |
| 1443 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1444 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
| 1445 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1446 |
| 1447 QuicStreamRequest request2(factory_.get()); |
| 1448 EXPECT_EQ(ERR_IO_PENDING, |
| 1449 request2.Request(host_port_pair_, privacy_mode_, |
| 1450 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1451 "GET", net_log_, callback_.callback())); |
| 1452 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1453 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 1454 EXPECT_TRUE(stream2.get()); |
| 1455 |
| 1456 EXPECT_TRUE( |
| 1457 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_)); |
| 1458 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(), |
| 1459 host_port_pair_)); |
| 1460 |
| 1461 // On a DISCONNECTED notification, nothing happens to the migrated session. |
| 1462 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1463 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 1464 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1465 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1466 |
| 1467 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1468 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1469 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1470 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1471 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1472 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1473 } |
| 1474 |
| 1475 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnected) { |
| 1476 InitializeConnectionMigrationTest( |
| 1477 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1478 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1479 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1480 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1481 |
| 1482 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1483 scoped_ptr<QuicEncryptedPacket> request_packet( |
| 1484 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); |
| 1485 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(), |
| 1486 request_packet->length(), 1)}; |
| 1487 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1488 arraysize(writes)); |
| 1489 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1490 |
| 1491 // Create request and QuicHttpStream. |
| 1492 QuicStreamRequest request(factory_.get()); |
| 1493 EXPECT_EQ(ERR_IO_PENDING, |
| 1494 request.Request(host_port_pair_, privacy_mode_, |
| 1495 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1496 "GET", net_log_, callback_.callback())); |
| 1497 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1498 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1499 EXPECT_TRUE(stream.get()); |
| 1500 |
| 1501 // Cause QUIC stream to be created. |
| 1502 HttpRequestInfo request_info; |
| 1503 request_info.method = "GET"; |
| 1504 request_info.url = GURL("https://www.example.org/"); |
| 1505 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1506 net_log_, CompletionCallback())); |
| 1507 |
| 1508 // Ensure that session is alive and active. |
| 1509 QuicChromiumClientSession* session = |
| 1510 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1511 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1512 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1513 |
| 1514 // Send GET request on stream. |
| 1515 HttpResponseInfo response_info; |
| 1516 HttpRequestHeaders request_headers; |
| 1517 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response_info, |
| 1518 callback_.callback())); |
| 1519 |
| 1520 // Set up second socket data provider that is used after migration. |
| 1521 scoped_ptr<QuicEncryptedPacket> ping( |
| 1522 maker_.MakePingPacket(2, /*include_version=*/true)); |
| 1523 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1524 3, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1525 MockWrite writes1[] = { |
| 1526 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)}; |
| 1527 scoped_ptr<QuicEncryptedPacket> response_packet( |
| 1528 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); |
| 1529 MockRead reads1[] = { |
| 1530 MockRead(ASYNC, response_packet->data(), response_packet->length(), 1), |
| 1531 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
| 1532 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, |
| 1533 arraysize(writes1)); |
| 1534 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 1535 |
| 1536 // Trigger connection migration. This should cause a PING frame |
| 1537 // to be emitted. |
| 1538 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1539 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 1540 |
| 1541 // The session should now be marked as going away. Ensure that |
| 1542 // while it is still alive, it is no longer active. |
| 1543 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1544 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1545 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1546 |
| 1547 // Create a new request for the same destination and verify that a |
| 1548 // new session is created. |
| 1549 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1550 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
| 1551 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1552 |
| 1553 QuicStreamRequest request2(factory_.get()); |
| 1554 EXPECT_EQ(ERR_IO_PENDING, |
| 1555 request2.Request(host_port_pair_, privacy_mode_, |
| 1556 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1557 "GET", net_log_, callback_.callback())); |
| 1558 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1559 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 1560 EXPECT_TRUE(stream2.get()); |
| 1561 |
| 1562 EXPECT_TRUE( |
| 1563 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_)); |
| 1564 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(), |
| 1565 host_port_pair_)); |
| 1566 EXPECT_EQ(true, |
| 1567 QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1568 |
| 1569 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1570 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1571 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1572 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1573 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1574 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1575 } |
| 1576 |
| 1577 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNetworks) { |
| 1578 NetworkChangeNotifier::NetworkList no_networks(0); |
| 1579 InitializeConnectionMigrationTest(no_networks); |
| 1580 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1581 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1582 |
| 1583 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1584 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1585 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1586 MockWrite writes[] = { |
| 1587 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1), |
| 1588 }; |
| 1589 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1590 arraysize(writes)); |
| 1591 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1592 |
| 1593 // Create request and QuicHttpStream. |
| 1594 QuicStreamRequest request(factory_.get()); |
| 1595 EXPECT_EQ(ERR_IO_PENDING, |
| 1596 request.Request(host_port_pair_, privacy_mode_, |
| 1597 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1598 "GET", net_log_, callback_.callback())); |
| 1599 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1600 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1601 EXPECT_TRUE(stream.get()); |
| 1602 |
| 1603 // Cause QUIC stream to be created. |
| 1604 HttpRequestInfo request_info; |
| 1605 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1606 net_log_, CompletionCallback())); |
| 1607 |
| 1608 // Ensure that session is alive and active. |
| 1609 QuicChromiumClientSession* session = |
| 1610 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1611 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1612 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1613 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1614 |
| 1615 // Trigger connection migration. Since there are no networks |
| 1616 // to migrate to, this should cause the session to continue on the same |
| 1617 // socket, but be marked as going away. |
| 1618 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1619 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests); |
| 1620 |
| 1621 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1622 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1623 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1624 |
| 1625 stream.reset(); |
| 1626 |
| 1627 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1628 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1629 } |
| 1630 |
| 1631 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNetworks) { |
| 1632 NetworkChangeNotifier::NetworkList no_networks(0); |
| 1633 InitializeConnectionMigrationTest(no_networks); |
| 1634 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1635 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1636 |
| 1637 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1638 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1639 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT)); |
| 1640 MockWrite writes[] = { |
| 1641 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1), |
| 1642 }; |
| 1643 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1644 arraysize(writes)); |
| 1645 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1646 |
| 1647 // Create request and QuicHttpStream. |
| 1648 QuicStreamRequest request(factory_.get()); |
| 1649 EXPECT_EQ(ERR_IO_PENDING, |
| 1650 request.Request(host_port_pair_, privacy_mode_, |
| 1651 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1652 "GET", net_log_, callback_.callback())); |
| 1653 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1654 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1655 EXPECT_TRUE(stream.get()); |
| 1656 |
| 1657 // Cause QUIC stream to be created. |
| 1658 HttpRequestInfo request_info; |
| 1659 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1660 net_log_, CompletionCallback())); |
| 1661 |
| 1662 // Ensure that session is alive and active. |
| 1663 QuicChromiumClientSession* session = |
| 1664 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1665 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1666 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1667 |
| 1668 // Trigger connection migration. Since there are no networks |
| 1669 // to migrate to, this should cause a RST_STREAM frame to be emitted |
| 1670 // and the session to be closed. |
| 1671 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1672 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 1673 |
| 1674 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1675 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1676 |
| 1677 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1678 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1679 } |
| 1680 |
| 1681 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNewNetwork) { |
| 1682 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); |
| 1683 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1684 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1685 |
| 1686 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1687 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1688 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1689 MockWrite writes[] = { |
| 1690 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1), |
| 1691 }; |
| 1692 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1693 arraysize(writes)); |
| 1694 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1695 |
| 1696 // Create request and QuicHttpStream. |
| 1697 QuicStreamRequest request(factory_.get()); |
| 1698 EXPECT_EQ(ERR_IO_PENDING, |
| 1699 request.Request(host_port_pair_, privacy_mode_, |
| 1700 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1701 "GET", net_log_, callback_.callback())); |
| 1702 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1703 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1704 EXPECT_TRUE(stream.get()); |
| 1705 |
| 1706 // Cause QUIC stream to be created. |
| 1707 HttpRequestInfo request_info; |
| 1708 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1709 net_log_, CompletionCallback())); |
| 1710 |
| 1711 // Ensure that session is alive and active. |
| 1712 QuicChromiumClientSession* session = |
| 1713 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1714 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1715 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1716 |
| 1717 // Trigger connection migration. Since there are no networks |
| 1718 // to migrate to, this should cause session to be continue but be marked as |
| 1719 // going away. |
| 1720 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1721 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests); |
| 1722 |
| 1723 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1724 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1725 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1726 |
| 1727 stream.reset(); |
| 1728 |
| 1729 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1730 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1731 } |
| 1732 |
| 1733 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNewNetwork) { |
| 1734 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); |
| 1735 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1736 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1737 |
| 1738 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1739 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1740 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT)); |
| 1741 MockWrite writes[] = { |
| 1742 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1), |
| 1743 }; |
| 1744 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1745 arraysize(writes)); |
| 1746 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1747 |
| 1748 // Create request and QuicHttpStream. |
| 1749 QuicStreamRequest request(factory_.get()); |
| 1750 EXPECT_EQ(ERR_IO_PENDING, |
| 1751 request.Request(host_port_pair_, privacy_mode_, |
| 1752 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1753 "GET", net_log_, callback_.callback())); |
| 1754 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1755 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1756 EXPECT_TRUE(stream.get()); |
| 1757 |
| 1758 // Cause QUIC stream to be created. |
| 1759 HttpRequestInfo request_info; |
| 1760 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1761 net_log_, CompletionCallback())); |
| 1762 |
| 1763 // Ensure that session is alive and active. |
| 1764 QuicChromiumClientSession* session = |
| 1765 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1766 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1767 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1768 |
| 1769 // Trigger connection migration. Since there are no networks |
| 1770 // to migrate to, this should cause a RST_STREAM frame to be emitted |
| 1771 // with QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
| 1772 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1773 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 1774 |
| 1775 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1776 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1777 |
| 1778 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1779 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1780 } |
| 1781 |
| 1782 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoOpenStreams) { |
| 1783 InitializeConnectionMigrationTest( |
| 1784 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1785 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1786 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1787 |
| 1788 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1789 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u); |
| 1790 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1791 |
| 1792 // Create request and QuicHttpStream. |
| 1793 QuicStreamRequest request(factory_.get()); |
| 1794 EXPECT_EQ(ERR_IO_PENDING, |
| 1795 request.Request(host_port_pair_, privacy_mode_, |
| 1796 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1797 "GET", net_log_, callback_.callback())); |
| 1798 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1799 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1800 EXPECT_TRUE(stream.get()); |
| 1801 |
| 1802 // Ensure that session is alive and active. |
| 1803 QuicChromiumClientSession* session = |
| 1804 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1805 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1806 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1807 |
| 1808 // Trigger connection migration. Since there are no active streams, |
| 1809 // the session will be closed. |
| 1810 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1811 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 1812 |
| 1813 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1814 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1815 |
| 1816 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1817 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1818 } |
| 1819 |
| 1820 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoOpenStreams) { |
| 1821 InitializeConnectionMigrationTest( |
| 1822 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1823 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 1824 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 1825 |
| 1826 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1827 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u); |
| 1828 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1829 |
| 1830 // Create request and QuicHttpStream. |
| 1831 QuicStreamRequest request(factory_.get()); |
| 1832 EXPECT_EQ(ERR_IO_PENDING, |
| 1833 request.Request(host_port_pair_, privacy_mode_, |
| 1834 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1835 "GET", net_log_, callback_.callback())); |
| 1836 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1837 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1838 EXPECT_TRUE(stream.get()); |
| 1839 |
| 1840 // Ensure that session is alive and active. |
| 1841 QuicChromiumClientSession* session = |
| 1842 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1843 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1844 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1845 |
| 1846 // Trigger connection migration. Since there are no active streams, |
| 1847 // the session will be closed. |
| 1848 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1849 ->NotifyNetworkDisconnected(kDefaultNetworkForTests); |
| 1850 |
| 1851 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1852 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1853 |
| 1854 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1855 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1856 } |
| 1857 |
1255 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { | 1858 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
1256 Initialize(); | 1859 Initialize(); |
1257 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | 1860 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
1258 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 1861 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
1259 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | 1862 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
1260 | 1863 |
1261 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 1864 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
1262 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); | 1865 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
1263 std::vector<MockWrite> writes; | 1866 std::vector<MockWrite> writes; |
1264 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); | 1867 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2678 EXPECT_EQ(1u, observer.executed_count()); | 3281 EXPECT_EQ(1u, observer.executed_count()); |
2679 | 3282 |
2680 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 3283 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
2681 EXPECT_TRUE(stream.get()); | 3284 EXPECT_TRUE(stream.get()); |
2682 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3285 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
2683 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3286 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
2684 } | 3287 } |
2685 | 3288 |
2686 } // namespace test | 3289 } // namespace test |
2687 } // namespace net | 3290 } // namespace net |
OLD | NEW |