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.google.com"; | 54 const char kDefaultServerHostName[] = "www.google.com"; |
53 const int kDefaultServerPort = 443; | 55 const int kDefaultServerPort = 443; |
54 | 56 |
55 // Run all tests with all the combinations of versions and | 57 // Run all tests with all the combinations of versions and |
56 // enable_connection_racing. | 58 // enable_connection_racing. |
57 struct TestParams { | 59 struct TestParams { |
58 TestParams(const QuicVersion version, bool enable_connection_racing) | 60 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 { | 111 class MockQuicServerInfoFactory : public QuicServerInfoFactory { |
110 public: | 112 public: |
111 MockQuicServerInfoFactory() {} | 113 MockQuicServerInfoFactory() {} |
112 ~MockQuicServerInfoFactory() override {} | 114 ~MockQuicServerInfoFactory() override {} |
113 | 115 |
114 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { | 116 QuicServerInfo* GetForServer(const QuicServerId& server_id) override { |
115 return new MockQuicServerInfo(server_id); | 117 return new MockQuicServerInfo(server_id); |
116 } | 118 } |
117 }; | 119 }; |
118 | 120 |
| 121 class MockNetworkChangeNotifier : public NetworkChangeNotifier { |
| 122 public: |
| 123 MockNetworkChangeNotifier() : force_network_handles_supported_(false) {} |
| 124 |
| 125 ConnectionType GetCurrentConnectionType() const override { |
| 126 return CONNECTION_UNKNOWN; |
| 127 } |
| 128 |
| 129 void ForceNetworkHandlesSupported() { |
| 130 force_network_handles_supported_ = true; |
| 131 } |
| 132 |
| 133 bool AreNetworkHandlesCurrentlySupported() const override { |
| 134 return force_network_handles_supported_; |
| 135 } |
| 136 |
| 137 void SetConnectedNetworksList(const NetworkList& network_list) { |
| 138 connected_networks_ = network_list; |
| 139 } |
| 140 |
| 141 void GetCurrentConnectedNetworks(NetworkList* network_list) const override { |
| 142 network_list->clear(); |
| 143 *network_list = connected_networks_; |
| 144 } |
| 145 |
| 146 void NotifySpecificNetworkChange( |
| 147 NetworkChangeNotifier::NetworkChangeType type, |
| 148 NetworkChangeNotifier::NetworkHandle network) { |
| 149 NetworkChangeNotifier::NotifyObserversOfSpecificNetworkChange(type, |
| 150 network); |
| 151 // Spin the message loop so the notification is delivered. |
| 152 base::MessageLoop::current()->RunUntilIdle(); |
| 153 } |
| 154 |
| 155 private: |
| 156 bool force_network_handles_supported_; |
| 157 NetworkChangeNotifier::NetworkList connected_networks_; |
| 158 }; |
| 159 |
| 160 // Class to replace existing NetworkChangeNotifier singleton with a |
| 161 // MockNetworkChangeNotifier for a test. To use, simply create a |
| 162 // ScopedMockNetworkChangeNotifier object in the test. |
| 163 class ScopedMockNetworkChangeNotifier { |
| 164 public: |
| 165 ScopedMockNetworkChangeNotifier() |
| 166 : disable_network_change_notifier_for_tests_( |
| 167 new NetworkChangeNotifier::DisableForTest()), |
| 168 mock_network_change_notifier_(new MockNetworkChangeNotifier()) {} |
| 169 |
| 170 MockNetworkChangeNotifier* mock_network_change_notifier() { |
| 171 return mock_network_change_notifier_.get(); |
| 172 } |
| 173 |
| 174 private: |
| 175 scoped_ptr<NetworkChangeNotifier::DisableForTest> |
| 176 disable_network_change_notifier_for_tests_; |
| 177 scoped_ptr<MockNetworkChangeNotifier> mock_network_change_notifier_; |
| 178 }; |
| 179 |
119 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> { | 180 class QuicStreamFactoryTest : public ::testing::TestWithParam<TestParams> { |
120 protected: | 181 protected: |
121 QuicStreamFactoryTest() | 182 QuicStreamFactoryTest() |
122 : random_generator_(0), | 183 : random_generator_(0), |
123 clock_(new MockClock()), | 184 clock_(new MockClock()), |
124 runner_(new TestTaskRunner(clock_)), | 185 runner_(new TestTaskRunner(clock_)), |
125 maker_(GetParam().version, 0, clock_, kDefaultServerHostName), | 186 maker_(GetParam().version, 0, clock_, kDefaultServerHostName), |
126 cert_verifier_(CertVerifier::CreateDefault()), | 187 cert_verifier_(CertVerifier::CreateDefault()), |
127 channel_id_service_( | 188 channel_id_service_( |
128 new ChannelIDService(new DefaultChannelIDStore(nullptr), | 189 new ChannelIDService(new DefaultChannelIDStore(nullptr), |
129 base::ThreadTaskRunnerHandle::Get())), | 190 base::ThreadTaskRunnerHandle::Get())), |
130 cert_transparency_verifier_(new MultiLogCTVerifier()), | 191 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 192 scoped_mock_network_change_notifier_(nullptr), |
131 factory_(nullptr), | 193 factory_(nullptr), |
132 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), | 194 host_port_pair_(kDefaultServerHostName, kDefaultServerPort), |
133 privacy_mode_(PRIVACY_MODE_DISABLED), | 195 privacy_mode_(PRIVACY_MODE_DISABLED), |
134 enable_port_selection_(true), | 196 enable_port_selection_(true), |
135 always_require_handshake_confirmation_(false), | 197 always_require_handshake_confirmation_(false), |
136 disable_connection_pooling_(false), | 198 disable_connection_pooling_(false), |
137 load_server_info_timeout_srtt_multiplier_(0.0f), | 199 load_server_info_timeout_srtt_multiplier_(0.0f), |
138 enable_connection_racing_(true), | 200 enable_connection_racing_(true), |
139 enable_non_blocking_io_(true), | 201 enable_non_blocking_io_(true), |
140 disable_disk_cache_(false), | 202 disable_disk_cache_(false), |
141 prefer_aes_(false), | 203 prefer_aes_(false), |
142 max_number_of_lossy_connections_(0), | 204 max_number_of_lossy_connections_(0), |
143 packet_loss_threshold_(1.0f), | 205 packet_loss_threshold_(1.0f), |
144 max_disabled_reasons_(3), | 206 max_disabled_reasons_(3), |
145 threshold_timeouts_with_open_streams_(2), | 207 threshold_timeouts_with_open_streams_(2), |
146 threshold_public_resets_post_handshake_(2), | 208 threshold_public_resets_post_handshake_(2), |
147 receive_buffer_size_(0), | 209 receive_buffer_size_(0), |
148 delay_tcp_race_(false), | 210 delay_tcp_race_(false), |
149 store_server_configs_in_properties_(false), | 211 store_server_configs_in_properties_(false), |
150 close_sessions_on_ip_change_(false), | 212 close_sessions_on_ip_change_(false), |
151 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds) { | 213 idle_connection_timeout_seconds_(kIdleConnectionTimeoutSeconds), |
| 214 migrate_sessions_on_network_change_(false) { |
152 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 215 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
153 } | 216 } |
154 | 217 |
155 void Initialize() { | 218 void Initialize() { |
156 factory_.reset(new QuicStreamFactory( | 219 factory_.reset(new QuicStreamFactory( |
157 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), | 220 &host_resolver_, &socket_factory_, http_server_properties_.GetWeakPtr(), |
158 cert_verifier_.get(), nullptr, channel_id_service_.get(), | 221 cert_verifier_.get(), nullptr, channel_id_service_.get(), |
159 &transport_security_state_, cert_transparency_verifier_.get(), | 222 &transport_security_state_, cert_transparency_verifier_.get(), |
160 /*SocketPerformanceWatcherFactory*/ nullptr, | 223 /*SocketPerformanceWatcherFactory*/ nullptr, |
161 &crypto_client_stream_factory_, &random_generator_, clock_, | 224 &crypto_client_stream_factory_, &random_generator_, clock_, |
162 kDefaultMaxPacketSize, std::string(), | 225 kDefaultMaxPacketSize, std::string(), |
163 SupportedVersions(GetParam().version), enable_port_selection_, | 226 SupportedVersions(GetParam().version), enable_port_selection_, |
164 always_require_handshake_confirmation_, disable_connection_pooling_, | 227 always_require_handshake_confirmation_, disable_connection_pooling_, |
165 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, | 228 load_server_info_timeout_srtt_multiplier_, enable_connection_racing_, |
166 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, | 229 enable_non_blocking_io_, disable_disk_cache_, prefer_aes_, |
167 max_number_of_lossy_connections_, packet_loss_threshold_, | 230 max_number_of_lossy_connections_, packet_loss_threshold_, |
168 max_disabled_reasons_, threshold_timeouts_with_open_streams_, | 231 max_disabled_reasons_, threshold_timeouts_with_open_streams_, |
169 threshold_public_resets_post_handshake_, receive_buffer_size_, | 232 threshold_public_resets_post_handshake_, receive_buffer_size_, |
170 delay_tcp_race_, store_server_configs_in_properties_, | 233 delay_tcp_race_, store_server_configs_in_properties_, |
171 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, | 234 close_sessions_on_ip_change_, idle_connection_timeout_seconds_, |
172 QuicTagVector())); | 235 migrate_sessions_on_network_change_, QuicTagVector())); |
173 factory_->set_require_confirmation(false); | 236 factory_->set_require_confirmation(false); |
174 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); | 237 factory_->set_quic_server_info_factory(new MockQuicServerInfoFactory()); |
175 } | 238 } |
176 | 239 |
| 240 void InitializeConnectionMigrationTest( |
| 241 NetworkChangeNotifier::NetworkList connected_networks) { |
| 242 scoped_mock_network_change_notifier_.reset( |
| 243 new ScopedMockNetworkChangeNotifier()); |
| 244 MockNetworkChangeNotifier* mock_ncn = |
| 245 scoped_mock_network_change_notifier_->mock_network_change_notifier(); |
| 246 mock_ncn->ForceNetworkHandlesSupported(); |
| 247 mock_ncn->SetConnectedNetworksList(connected_networks); |
| 248 migrate_sessions_on_network_change_ = true; |
| 249 Initialize(); |
| 250 } |
| 251 |
177 bool HasActiveSession(const HostPortPair& host_port_pair) { | 252 bool HasActiveSession(const HostPortPair& host_port_pair) { |
178 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), | 253 return QuicStreamFactoryPeer::HasActiveSession(factory_.get(), |
179 host_port_pair); | 254 host_port_pair); |
180 } | 255 } |
181 | 256 |
182 scoped_ptr<QuicHttpStream> CreateFromSession( | 257 scoped_ptr<QuicHttpStream> CreateFromSession( |
183 const HostPortPair& host_port_pair) { | 258 const HostPortPair& host_port_pair) { |
184 QuicChromiumClientSession* session = | 259 QuicChromiumClientSession* session = |
185 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair); | 260 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair); |
186 return QuicStreamFactoryPeer::CreateFromSession(factory_.get(), session); | 261 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")); | 329 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); |
255 EXPECT_TRUE(test_cert.get()); | 330 EXPECT_TRUE(test_cert.get()); |
256 ProofVerifyDetailsChromium verify_details; | 331 ProofVerifyDetailsChromium verify_details; |
257 verify_details.cert_verify_result.verified_cert = test_cert; | 332 verify_details.cert_verify_result.verified_cert = test_cert; |
258 verify_details.cert_verify_result.is_issued_by_known_root = true; | 333 verify_details.cert_verify_result.is_issued_by_known_root = true; |
259 return verify_details; | 334 return verify_details; |
260 } | 335 } |
261 | 336 |
262 void NotifyIPAddressChanged() { | 337 void NotifyIPAddressChanged() { |
263 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 338 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
264 // For thread safety, the NCN queues tasks to do the actual notifications, | 339 // 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(); | 340 base::MessageLoop::current()->RunUntilIdle(); |
267 } | 341 } |
268 | 342 |
| 343 scoped_ptr<QuicEncryptedPacket> ConstructGetRequestPacket( |
| 344 QuicPacketNumber packet_number, |
| 345 QuicStreamId stream_id, |
| 346 bool should_include_version, |
| 347 bool fin) { |
| 348 SpdyHeaderBlock headers = maker_.GetRequestHeaders("GET", "https", "/"); |
| 349 SpdyPriority priority = |
| 350 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 351 return maker_.MakeRequestHeadersPacket(packet_number, stream_id, |
| 352 should_include_version, fin, |
| 353 priority, headers); |
| 354 } |
| 355 |
| 356 scoped_ptr<QuicEncryptedPacket> ConstructOkResponsePacket( |
| 357 QuicPacketNumber packet_number, |
| 358 QuicStreamId stream_id, |
| 359 bool should_include_version, |
| 360 bool fin) { |
| 361 SpdyHeaderBlock headers = maker_.GetResponseHeaders("200 OK"); |
| 362 return maker_.MakeResponseHeadersPacket( |
| 363 packet_number, stream_id, should_include_version, fin, headers); |
| 364 } |
| 365 |
269 MockHostResolver host_resolver_; | 366 MockHostResolver host_resolver_; |
270 MockClientSocketFactory socket_factory_; | 367 MockClientSocketFactory socket_factory_; |
271 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 368 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
272 MockRandom random_generator_; | 369 MockRandom random_generator_; |
273 MockClock* clock_; // Owned by factory_. | 370 MockClock* clock_; // Owned by factory_. |
274 scoped_refptr<TestTaskRunner> runner_; | 371 scoped_refptr<TestTaskRunner> runner_; |
275 QuicTestPacketMaker maker_; | 372 QuicTestPacketMaker maker_; |
276 HttpServerPropertiesImpl http_server_properties_; | 373 HttpServerPropertiesImpl http_server_properties_; |
277 scoped_ptr<CertVerifier> cert_verifier_; | 374 scoped_ptr<CertVerifier> cert_verifier_; |
278 scoped_ptr<ChannelIDService> channel_id_service_; | 375 scoped_ptr<ChannelIDService> channel_id_service_; |
279 TransportSecurityState transport_security_state_; | 376 TransportSecurityState transport_security_state_; |
280 scoped_ptr<CTVerifier> cert_transparency_verifier_; | 377 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
| 378 scoped_ptr<ScopedMockNetworkChangeNotifier> |
| 379 scoped_mock_network_change_notifier_; |
281 scoped_ptr<QuicStreamFactory> factory_; | 380 scoped_ptr<QuicStreamFactory> factory_; |
282 HostPortPair host_port_pair_; | 381 HostPortPair host_port_pair_; |
283 PrivacyMode privacy_mode_; | 382 PrivacyMode privacy_mode_; |
284 BoundNetLog net_log_; | 383 BoundNetLog net_log_; |
285 TestCompletionCallback callback_; | 384 TestCompletionCallback callback_; |
286 | 385 |
287 // Variables to configure QuicStreamFactory. | 386 // Variables to configure QuicStreamFactory. |
288 bool enable_port_selection_; | 387 bool enable_port_selection_; |
289 bool always_require_handshake_confirmation_; | 388 bool always_require_handshake_confirmation_; |
290 bool disable_connection_pooling_; | 389 bool disable_connection_pooling_; |
291 double load_server_info_timeout_srtt_multiplier_; | 390 double load_server_info_timeout_srtt_multiplier_; |
292 bool enable_connection_racing_; | 391 bool enable_connection_racing_; |
293 bool enable_non_blocking_io_; | 392 bool enable_non_blocking_io_; |
294 bool disable_disk_cache_; | 393 bool disable_disk_cache_; |
295 bool prefer_aes_; | 394 bool prefer_aes_; |
296 int max_number_of_lossy_connections_; | 395 int max_number_of_lossy_connections_; |
297 double packet_loss_threshold_; | 396 double packet_loss_threshold_; |
298 int max_disabled_reasons_; | 397 int max_disabled_reasons_; |
299 int threshold_timeouts_with_open_streams_; | 398 int threshold_timeouts_with_open_streams_; |
300 int threshold_public_resets_post_handshake_; | 399 int threshold_public_resets_post_handshake_; |
301 int receive_buffer_size_; | 400 int receive_buffer_size_; |
302 bool delay_tcp_race_; | 401 bool delay_tcp_race_; |
303 bool store_server_configs_in_properties_; | 402 bool store_server_configs_in_properties_; |
304 bool close_sessions_on_ip_change_; | 403 bool close_sessions_on_ip_change_; |
305 int idle_connection_timeout_seconds_; | 404 int idle_connection_timeout_seconds_; |
| 405 bool migrate_sessions_on_network_change_; |
306 }; | 406 }; |
307 | 407 |
308 INSTANTIATE_TEST_CASE_P(Version, | 408 INSTANTIATE_TEST_CASE_P(Version, |
309 QuicStreamFactoryTest, | 409 QuicStreamFactoryTest, |
310 ::testing::ValuesIn(GetTestParams())); | 410 ::testing::ValuesIn(GetTestParams())); |
311 | 411 |
312 TEST_P(QuicStreamFactoryTest, Create) { | 412 TEST_P(QuicStreamFactoryTest, Create) { |
313 Initialize(); | 413 Initialize(); |
314 | 414 |
315 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 415 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(), | 1226 /*cert_verify_flags=*/0, host_port_pair_.host(), |
1127 "GET", net_log_, callback_.callback())); | 1227 "GET", net_log_, callback_.callback())); |
1128 | 1228 |
1129 EXPECT_EQ(OK, callback_.WaitForResult()); | 1229 EXPECT_EQ(OK, callback_.WaitForResult()); |
1130 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 1230 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
1131 HttpRequestInfo request_info; | 1231 HttpRequestInfo request_info; |
1132 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, | 1232 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
1133 net_log_, CompletionCallback())); | 1233 net_log_, CompletionCallback())); |
1134 | 1234 |
1135 // Close the session and verify that stream saw the error. | 1235 // Close the session and verify that stream saw the error. |
1136 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED); | 1236 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, QUIC_INTERNAL_ERROR); |
1137 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, | 1237 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, |
1138 stream->ReadResponseHeaders(callback_.callback())); | 1238 stream->ReadResponseHeaders(callback_.callback())); |
1139 | 1239 |
1140 // Now attempting to request a stream to the same origin should create | 1240 // Now attempting to request a stream to the same origin should create |
1141 // a new session. | 1241 // a new session. |
1142 | 1242 |
1143 QuicStreamRequest request2(factory_.get()); | 1243 QuicStreamRequest request2(factory_.get()); |
1144 EXPECT_EQ(ERR_IO_PENDING, | 1244 EXPECT_EQ(ERR_IO_PENDING, |
1145 request2.Request(host_port_pair_, privacy_mode_, | 1245 request2.Request(host_port_pair_, privacy_mode_, |
1146 /*cert_verify_flags=*/0, host_port_pair_.host(), | 1246 /*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()); | 1303 EXPECT_EQ(OK, callback_.WaitForResult()); |
1204 stream = request2.ReleaseStream(); | 1304 stream = request2.ReleaseStream(); |
1205 stream.reset(); // Will reset stream 3. | 1305 stream.reset(); // Will reset stream 3. |
1206 | 1306 |
1207 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 1307 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
1208 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 1308 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
1209 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 1309 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
1210 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 1310 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
1211 } | 1311 } |
1212 | 1312 |
| 1313 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnect) { |
| 1314 InitializeConnectionMigrationTest( |
| 1315 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1316 |
| 1317 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1318 scoped_ptr<QuicEncryptedPacket> request_packet( |
| 1319 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); |
| 1320 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(), |
| 1321 request_packet->length(), 1)}; |
| 1322 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1323 arraysize(writes)); |
| 1324 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1325 |
| 1326 // Create request and QuicHttpStream. |
| 1327 QuicStreamRequest request(factory_.get()); |
| 1328 EXPECT_EQ(ERR_IO_PENDING, |
| 1329 request.Request(host_port_pair_, privacy_mode_, |
| 1330 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1331 "GET", net_log_, callback_.callback())); |
| 1332 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1333 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1334 EXPECT_TRUE(stream.get()); |
| 1335 |
| 1336 // Cause QUIC stream to be created. |
| 1337 HttpRequestInfo request_info; |
| 1338 request_info.method = "GET"; |
| 1339 request_info.url = GURL("https://www.google.com/"); |
| 1340 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1341 net_log_, CompletionCallback())); |
| 1342 |
| 1343 // Ensure that session is alive and active. |
| 1344 QuicChromiumClientSession* session = |
| 1345 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1346 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1347 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1348 |
| 1349 // Send GET request on stream. |
| 1350 HttpResponseInfo response; |
| 1351 HttpRequestHeaders request_headers; |
| 1352 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response, |
| 1353 callback_.callback())); |
| 1354 |
| 1355 // Set up second socket data provider that is used after migration. |
| 1356 // The response to the earlier request is read on this new socket. |
| 1357 scoped_ptr<QuicEncryptedPacket> ping( |
| 1358 maker_.MakePingPacket(2, /*include_version=*/true)); |
| 1359 MockWrite writes1[] = { |
| 1360 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)}; |
| 1361 scoped_ptr<QuicEncryptedPacket> response_headers_packet( |
| 1362 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); |
| 1363 MockRead reads1[] = {MockRead(ASYNC, response_headers_packet->data(), |
| 1364 response_headers_packet->length(), 1), |
| 1365 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
| 1366 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, |
| 1367 arraysize(writes1)); |
| 1368 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 1369 |
| 1370 // Trigger connection migration. This should cause a PING frame |
| 1371 // to be emitted. |
| 1372 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1373 ->NotifySpecificNetworkChange(NetworkChangeNotifier::SOON_TO_DISCONNECT, |
| 1374 kDefaultNetworkForTests); |
| 1375 |
| 1376 // The session should now be marked as going away. Ensure that |
| 1377 // while it is still alive, it is no longer active. |
| 1378 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1379 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1380 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1381 |
| 1382 // Verify that response headers on the migrated socket were delivered to the |
| 1383 // stream. |
| 1384 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback())); |
| 1385 EXPECT_EQ(200, response.headers->response_code()); |
| 1386 |
| 1387 // Create a new request for the same destination and verify that a |
| 1388 // new session is created. |
| 1389 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1390 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
| 1391 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1392 |
| 1393 QuicStreamRequest request2(factory_.get()); |
| 1394 EXPECT_EQ(ERR_IO_PENDING, |
| 1395 request2.Request(host_port_pair_, privacy_mode_, |
| 1396 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1397 "GET", net_log_, callback_.callback())); |
| 1398 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1399 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 1400 EXPECT_TRUE(stream2.get()); |
| 1401 |
| 1402 EXPECT_TRUE( |
| 1403 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_)); |
| 1404 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(), |
| 1405 host_port_pair_)); |
| 1406 |
| 1407 // On a DISCONNECTED notification, nothing happens to the migrated session. |
| 1408 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1409 ->NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, |
| 1410 kDefaultNetworkForTests); |
| 1411 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1412 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1413 |
| 1414 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1415 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1416 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1417 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1418 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1419 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1420 } |
| 1421 |
| 1422 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnected) { |
| 1423 InitializeConnectionMigrationTest( |
| 1424 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1425 |
| 1426 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1427 scoped_ptr<QuicEncryptedPacket> request_packet( |
| 1428 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true)); |
| 1429 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(), |
| 1430 request_packet->length(), 1)}; |
| 1431 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1432 arraysize(writes)); |
| 1433 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1434 |
| 1435 // Create request and QuicHttpStream. |
| 1436 QuicStreamRequest request(factory_.get()); |
| 1437 EXPECT_EQ(ERR_IO_PENDING, |
| 1438 request.Request(host_port_pair_, privacy_mode_, |
| 1439 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1440 "GET", net_log_, callback_.callback())); |
| 1441 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1442 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1443 EXPECT_TRUE(stream.get()); |
| 1444 |
| 1445 // Cause QUIC stream to be created. |
| 1446 HttpRequestInfo request_info; |
| 1447 request_info.method = "GET"; |
| 1448 request_info.url = GURL("https://www.google.com/"); |
| 1449 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1450 net_log_, CompletionCallback())); |
| 1451 |
| 1452 // Ensure that session is alive and active. |
| 1453 QuicChromiumClientSession* session = |
| 1454 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1455 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1456 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1457 |
| 1458 // Send GET request on stream. |
| 1459 HttpResponseInfo response_info; |
| 1460 HttpRequestHeaders request_headers; |
| 1461 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response_info, |
| 1462 callback_.callback())); |
| 1463 |
| 1464 // Set up second socket data provider that is used after migration. |
| 1465 scoped_ptr<QuicEncryptedPacket> ping( |
| 1466 maker_.MakePingPacket(2, /*include_version=*/true)); |
| 1467 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1468 3, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1469 MockWrite writes1[] = { |
| 1470 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)}; |
| 1471 scoped_ptr<QuicEncryptedPacket> response_packet( |
| 1472 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false)); |
| 1473 MockRead reads1[] = { |
| 1474 MockRead(ASYNC, response_packet->data(), response_packet->length(), 1), |
| 1475 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)}; |
| 1476 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1, |
| 1477 arraysize(writes1)); |
| 1478 socket_factory_.AddSocketDataProvider(&socket_data1); |
| 1479 |
| 1480 // Trigger connection migration. This should cause a PING frame |
| 1481 // to be emitted. |
| 1482 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1483 ->NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, |
| 1484 kDefaultNetworkForTests); |
| 1485 |
| 1486 // The session should now be marked as going away. Ensure that |
| 1487 // while it is still alive, it is no longer active. |
| 1488 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1489 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1490 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1491 |
| 1492 // Create a new request for the same destination and verify that a |
| 1493 // new session is created. |
| 1494 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1495 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0); |
| 1496 socket_factory_.AddSocketDataProvider(&socket_data2); |
| 1497 |
| 1498 QuicStreamRequest request2(factory_.get()); |
| 1499 EXPECT_EQ(ERR_IO_PENDING, |
| 1500 request2.Request(host_port_pair_, privacy_mode_, |
| 1501 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1502 "GET", net_log_, callback_.callback())); |
| 1503 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1504 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream(); |
| 1505 EXPECT_TRUE(stream2.get()); |
| 1506 |
| 1507 EXPECT_TRUE( |
| 1508 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_)); |
| 1509 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(), |
| 1510 host_port_pair_)); |
| 1511 EXPECT_EQ(true, |
| 1512 QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1513 |
| 1514 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1515 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1516 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 1517 EXPECT_TRUE(socket_data1.AllWriteDataConsumed()); |
| 1518 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 1519 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 1520 } |
| 1521 |
| 1522 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNetworks) { |
| 1523 NetworkChangeNotifier::NetworkList no_networks(0); |
| 1524 InitializeConnectionMigrationTest(no_networks); |
| 1525 |
| 1526 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1527 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1528 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1529 MockWrite writes[] = { |
| 1530 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1), |
| 1531 }; |
| 1532 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1533 arraysize(writes)); |
| 1534 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1535 |
| 1536 // Create request and QuicHttpStream. |
| 1537 QuicStreamRequest request(factory_.get()); |
| 1538 EXPECT_EQ(ERR_IO_PENDING, |
| 1539 request.Request(host_port_pair_, privacy_mode_, |
| 1540 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1541 "GET", net_log_, callback_.callback())); |
| 1542 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1543 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1544 EXPECT_TRUE(stream.get()); |
| 1545 |
| 1546 // Cause QUIC stream to be created. |
| 1547 HttpRequestInfo request_info; |
| 1548 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1549 net_log_, CompletionCallback())); |
| 1550 |
| 1551 // Ensure that session is alive and active. |
| 1552 QuicChromiumClientSession* session = |
| 1553 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1554 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1555 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1556 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1557 |
| 1558 // Trigger connection migration. Since there are no networks |
| 1559 // to migrate to, this should cause the session to continue on the same |
| 1560 // socket, but be marked as going away. |
| 1561 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1562 ->NotifySpecificNetworkChange(NetworkChangeNotifier::SOON_TO_DISCONNECT, |
| 1563 kDefaultNetworkForTests); |
| 1564 |
| 1565 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1566 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1567 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1568 |
| 1569 stream.reset(); |
| 1570 |
| 1571 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1572 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1573 } |
| 1574 |
| 1575 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNetworks) { |
| 1576 NetworkChangeNotifier::NetworkList no_networks(0); |
| 1577 InitializeConnectionMigrationTest(no_networks); |
| 1578 |
| 1579 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1580 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1581 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT)); |
| 1582 MockWrite writes[] = { |
| 1583 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1), |
| 1584 }; |
| 1585 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1586 arraysize(writes)); |
| 1587 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1588 |
| 1589 // Create request and QuicHttpStream. |
| 1590 QuicStreamRequest request(factory_.get()); |
| 1591 EXPECT_EQ(ERR_IO_PENDING, |
| 1592 request.Request(host_port_pair_, privacy_mode_, |
| 1593 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1594 "GET", net_log_, callback_.callback())); |
| 1595 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1596 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1597 EXPECT_TRUE(stream.get()); |
| 1598 |
| 1599 // Cause QUIC stream to be created. |
| 1600 HttpRequestInfo request_info; |
| 1601 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1602 net_log_, CompletionCallback())); |
| 1603 |
| 1604 // Ensure that session is alive and active. |
| 1605 QuicChromiumClientSession* session = |
| 1606 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1607 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1608 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1609 |
| 1610 // Trigger connection migration. Since there are no networks |
| 1611 // to migrate to, this should cause a RST_STREAM frame to be emitted |
| 1612 // and the session to be closed. |
| 1613 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1614 ->NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, |
| 1615 kDefaultNetworkForTests); |
| 1616 |
| 1617 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1618 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1619 |
| 1620 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1621 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1622 } |
| 1623 |
| 1624 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNewNetwork) { |
| 1625 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); |
| 1626 |
| 1627 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1628 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1629 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED)); |
| 1630 MockWrite writes[] = { |
| 1631 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1), |
| 1632 }; |
| 1633 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1634 arraysize(writes)); |
| 1635 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1636 |
| 1637 // Create request and QuicHttpStream. |
| 1638 QuicStreamRequest request(factory_.get()); |
| 1639 EXPECT_EQ(ERR_IO_PENDING, |
| 1640 request.Request(host_port_pair_, privacy_mode_, |
| 1641 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1642 "GET", net_log_, callback_.callback())); |
| 1643 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1644 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1645 EXPECT_TRUE(stream.get()); |
| 1646 |
| 1647 // Cause QUIC stream to be created. |
| 1648 HttpRequestInfo request_info; |
| 1649 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1650 net_log_, CompletionCallback())); |
| 1651 |
| 1652 // Ensure that session is alive and active. |
| 1653 QuicChromiumClientSession* session = |
| 1654 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1655 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1656 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1657 |
| 1658 // Trigger connection migration. Since there are no networks |
| 1659 // to migrate to, this should cause session to be continue but be marked as |
| 1660 // going away. |
| 1661 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1662 ->NotifySpecificNetworkChange(NetworkChangeNotifier::SOON_TO_DISCONNECT, |
| 1663 kDefaultNetworkForTests); |
| 1664 |
| 1665 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1666 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1667 EXPECT_EQ(1u, session->GetNumActiveStreams()); |
| 1668 |
| 1669 stream.reset(); |
| 1670 |
| 1671 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1672 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1673 } |
| 1674 |
| 1675 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNewNetwork) { |
| 1676 InitializeConnectionMigrationTest({kDefaultNetworkForTests}); |
| 1677 |
| 1678 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1679 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket( |
| 1680 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT)); |
| 1681 MockWrite writes[] = { |
| 1682 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1), |
| 1683 }; |
| 1684 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
| 1685 arraysize(writes)); |
| 1686 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1687 |
| 1688 // Create request and QuicHttpStream. |
| 1689 QuicStreamRequest request(factory_.get()); |
| 1690 EXPECT_EQ(ERR_IO_PENDING, |
| 1691 request.Request(host_port_pair_, privacy_mode_, |
| 1692 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1693 "GET", net_log_, callback_.callback())); |
| 1694 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1695 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1696 EXPECT_TRUE(stream.get()); |
| 1697 |
| 1698 // Cause QUIC stream to be created. |
| 1699 HttpRequestInfo request_info; |
| 1700 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, |
| 1701 net_log_, CompletionCallback())); |
| 1702 |
| 1703 // Ensure that session is alive and active. |
| 1704 QuicChromiumClientSession* session = |
| 1705 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1706 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1707 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1708 |
| 1709 // Trigger connection migration. Since there are no networks |
| 1710 // to migrate to, this should cause a RST_STREAM frame to be emitted |
| 1711 // with QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed. |
| 1712 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1713 ->NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, |
| 1714 kDefaultNetworkForTests); |
| 1715 |
| 1716 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1717 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1718 |
| 1719 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1720 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1721 } |
| 1722 |
| 1723 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoOpenStreams) { |
| 1724 InitializeConnectionMigrationTest( |
| 1725 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1726 |
| 1727 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1728 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u); |
| 1729 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1730 |
| 1731 // Create request and QuicHttpStream. |
| 1732 QuicStreamRequest request(factory_.get()); |
| 1733 EXPECT_EQ(ERR_IO_PENDING, |
| 1734 request.Request(host_port_pair_, privacy_mode_, |
| 1735 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1736 "GET", net_log_, callback_.callback())); |
| 1737 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1738 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1739 EXPECT_TRUE(stream.get()); |
| 1740 |
| 1741 // Ensure that session is alive and active. |
| 1742 QuicChromiumClientSession* session = |
| 1743 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1744 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1745 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1746 |
| 1747 // Trigger connection migration. Since there are no active streams, |
| 1748 // the session will be closed. |
| 1749 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1750 ->NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, |
| 1751 kDefaultNetworkForTests); |
| 1752 |
| 1753 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1754 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1755 |
| 1756 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1757 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1758 } |
| 1759 |
| 1760 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoOpenStreams) { |
| 1761 InitializeConnectionMigrationTest( |
| 1762 {kDefaultNetworkForTests, kNewNetworkForTests}); |
| 1763 |
| 1764 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
| 1765 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u); |
| 1766 socket_factory_.AddSocketDataProvider(&socket_data); |
| 1767 |
| 1768 // Create request and QuicHttpStream. |
| 1769 QuicStreamRequest request(factory_.get()); |
| 1770 EXPECT_EQ(ERR_IO_PENDING, |
| 1771 request.Request(host_port_pair_, privacy_mode_, |
| 1772 /*cert_verify_flags=*/0, host_port_pair_.host(), |
| 1773 "GET", net_log_, callback_.callback())); |
| 1774 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 1775 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
| 1776 EXPECT_TRUE(stream.get()); |
| 1777 |
| 1778 // Ensure that session is alive and active. |
| 1779 QuicChromiumClientSession* session = |
| 1780 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_); |
| 1781 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1782 EXPECT_TRUE(HasActiveSession(host_port_pair_)); |
| 1783 |
| 1784 // Trigger connection migration. Since there are no active streams, |
| 1785 // the session will be closed. |
| 1786 scoped_mock_network_change_notifier_->mock_network_change_notifier() |
| 1787 ->NotifySpecificNetworkChange(NetworkChangeNotifier::DISCONNECTED, |
| 1788 kDefaultNetworkForTests); |
| 1789 |
| 1790 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session)); |
| 1791 EXPECT_FALSE(HasActiveSession(host_port_pair_)); |
| 1792 |
| 1793 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 1794 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 1795 } |
| 1796 |
1213 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { | 1797 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { |
1214 Initialize(); | 1798 Initialize(); |
1215 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 1799 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
1216 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); | 1800 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); |
1217 std::vector<MockWrite> writes; | 1801 std::vector<MockWrite> writes; |
1218 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); | 1802 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); |
1219 SequencedSocketData socket_data(reads, arraysize(reads), | 1803 SequencedSocketData socket_data(reads, arraysize(reads), |
1220 writes.empty() ? nullptr : &writes[0], | 1804 writes.empty() ? nullptr : &writes[0], |
1221 writes.size()); | 1805 writes.size()); |
1222 socket_factory_.AddSocketDataProvider(&socket_data); | 1806 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()); | 3163 EXPECT_EQ(1u, observer.executed_count()); |
2580 | 3164 |
2581 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); | 3165 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); |
2582 EXPECT_TRUE(stream.get()); | 3166 EXPECT_TRUE(stream.get()); |
2583 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 3167 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
2584 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 3168 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
2585 } | 3169 } |
2586 | 3170 |
2587 } // namespace test | 3171 } // namespace test |
2588 } // namespace net | 3172 } // namespace net |
OLD | NEW |