Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: net/quic/quic_stream_factory_test.cc

Issue 1327923002: Migrates QUIC sessions to a new network when old network is (about to be) disconnected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@home
Patch Set: Fixed a test that I missed earlier. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 return maker_.MakeRequestHeadersPacket(packet_number, stream_id,
360 should_include_version, fin,
361 priority, headers);
362 }
363
364 scoped_ptr<QuicEncryptedPacket> ConstructOkResponsePacket(
365 QuicPacketNumber packet_number,
366 QuicStreamId stream_id,
367 bool should_include_version,
368 bool fin) {
369 SpdyHeaderBlock headers = maker_.GetResponseHeaders("200 OK");
370 return maker_.MakeResponseHeadersPacket(
371 packet_number, stream_id, should_include_version, fin, headers);
372 }
373
271 MockHostResolver host_resolver_; 374 MockHostResolver host_resolver_;
272 MockClientSocketFactory socket_factory_; 375 MockClientSocketFactory socket_factory_;
273 MockCryptoClientStreamFactory crypto_client_stream_factory_; 376 MockCryptoClientStreamFactory crypto_client_stream_factory_;
377 ProofVerifyDetailsChromium verify_details_;
274 MockRandom random_generator_; 378 MockRandom random_generator_;
275 MockClock* clock_; // Owned by factory_. 379 MockClock* clock_; // Owned by factory_.
276 scoped_refptr<TestTaskRunner> runner_; 380 scoped_refptr<TestTaskRunner> runner_;
277 QuicTestPacketMaker maker_; 381 QuicTestPacketMaker maker_;
278 HttpServerPropertiesImpl http_server_properties_; 382 HttpServerPropertiesImpl http_server_properties_;
279 scoped_ptr<CertVerifier> cert_verifier_; 383 scoped_ptr<CertVerifier> cert_verifier_;
280 scoped_ptr<ChannelIDService> channel_id_service_; 384 scoped_ptr<ChannelIDService> channel_id_service_;
281 TransportSecurityState transport_security_state_; 385 TransportSecurityState transport_security_state_;
282 scoped_ptr<CTVerifier> cert_transparency_verifier_; 386 scoped_ptr<CTVerifier> cert_transparency_verifier_;
387 scoped_ptr<ScopedMockNetworkChangeNotifier>
388 scoped_mock_network_change_notifier_;
283 scoped_ptr<QuicStreamFactory> factory_; 389 scoped_ptr<QuicStreamFactory> factory_;
284 HostPortPair host_port_pair_; 390 HostPortPair host_port_pair_;
285 PrivacyMode privacy_mode_; 391 PrivacyMode privacy_mode_;
286 BoundNetLog net_log_; 392 BoundNetLog net_log_;
287 TestCompletionCallback callback_; 393 TestCompletionCallback callback_;
288 394
289 // Variables to configure QuicStreamFactory. 395 // Variables to configure QuicStreamFactory.
290 bool enable_port_selection_; 396 bool enable_port_selection_;
291 bool always_require_handshake_confirmation_; 397 bool always_require_handshake_confirmation_;
292 bool disable_connection_pooling_; 398 bool disable_connection_pooling_;
293 double load_server_info_timeout_srtt_multiplier_; 399 double load_server_info_timeout_srtt_multiplier_;
294 bool enable_connection_racing_; 400 bool enable_connection_racing_;
295 bool enable_non_blocking_io_; 401 bool enable_non_blocking_io_;
296 bool disable_disk_cache_; 402 bool disable_disk_cache_;
297 bool prefer_aes_; 403 bool prefer_aes_;
298 int max_number_of_lossy_connections_; 404 int max_number_of_lossy_connections_;
299 double packet_loss_threshold_; 405 double packet_loss_threshold_;
300 int max_disabled_reasons_; 406 int max_disabled_reasons_;
301 int threshold_timeouts_with_open_streams_; 407 int threshold_timeouts_with_open_streams_;
302 int threshold_public_resets_post_handshake_; 408 int threshold_public_resets_post_handshake_;
303 int receive_buffer_size_; 409 int receive_buffer_size_;
304 bool delay_tcp_race_; 410 bool delay_tcp_race_;
305 bool store_server_configs_in_properties_; 411 bool store_server_configs_in_properties_;
306 bool close_sessions_on_ip_change_; 412 bool close_sessions_on_ip_change_;
307 int idle_connection_timeout_seconds_; 413 int idle_connection_timeout_seconds_;
414 bool migrate_sessions_on_network_change_;
308 }; 415 };
309 416
310 INSTANTIATE_TEST_CASE_P(Version, 417 INSTANTIATE_TEST_CASE_P(Version,
311 QuicStreamFactoryTest, 418 QuicStreamFactoryTest,
312 ::testing::ValuesIn(GetTestParams())); 419 ::testing::ValuesIn(GetTestParams()));
313 420
314 TEST_P(QuicStreamFactoryTest, Create) { 421 TEST_P(QuicStreamFactoryTest, Create) {
315 Initialize(); 422 Initialize();
316 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 423 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
317 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 424 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 /*cert_verify_flags=*/0, host_port_pair_.host(), 1272 /*cert_verify_flags=*/0, host_port_pair_.host(),
1166 "GET", net_log_, callback_.callback())); 1273 "GET", net_log_, callback_.callback()));
1167 1274
1168 EXPECT_EQ(OK, callback_.WaitForResult()); 1275 EXPECT_EQ(OK, callback_.WaitForResult());
1169 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 1276 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1170 HttpRequestInfo request_info; 1277 HttpRequestInfo request_info;
1171 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY, 1278 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1172 net_log_, CompletionCallback())); 1279 net_log_, CompletionCallback()));
1173 1280
1174 // Close the session and verify that stream saw the error. 1281 // Close the session and verify that stream saw the error.
1175 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED); 1282 factory_->CloseAllSessions(ERR_INTERNET_DISCONNECTED, QUIC_INTERNAL_ERROR);
1176 EXPECT_EQ(ERR_INTERNET_DISCONNECTED, 1283 EXPECT_EQ(ERR_INTERNET_DISCONNECTED,
1177 stream->ReadResponseHeaders(callback_.callback())); 1284 stream->ReadResponseHeaders(callback_.callback()));
1178 1285
1179 // Now attempting to request a stream to the same origin should create 1286 // Now attempting to request a stream to the same origin should create
1180 // a new session. 1287 // a new session.
1181 1288
1182 QuicStreamRequest request2(factory_.get()); 1289 QuicStreamRequest request2(factory_.get());
1183 EXPECT_EQ(ERR_IO_PENDING, 1290 EXPECT_EQ(ERR_IO_PENDING,
1184 request2.Request(host_port_pair_, privacy_mode_, 1291 request2.Request(host_port_pair_, privacy_mode_,
1185 /*cert_verify_flags=*/0, host_port_pair_.host(), 1292 /*cert_verify_flags=*/0, host_port_pair_.host(),
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 EXPECT_EQ(OK, callback_.WaitForResult()); 1352 EXPECT_EQ(OK, callback_.WaitForResult());
1246 stream = request2.ReleaseStream(); 1353 stream = request2.ReleaseStream();
1247 stream.reset(); // Will reset stream 3. 1354 stream.reset(); // Will reset stream 3.
1248 1355
1249 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 1356 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1250 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 1357 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1251 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); 1358 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1252 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); 1359 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1253 } 1360 }
1254 1361
1362 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnect) {
1363 InitializeConnectionMigrationTest(
1364 {kDefaultNetworkForTests, kNewNetworkForTests});
1365 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1366 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1367 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1368
1369 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1370 scoped_ptr<QuicEncryptedPacket> request_packet(
1371 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true));
1372 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(),
1373 request_packet->length(), 1)};
1374 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1375 arraysize(writes));
1376 socket_factory_.AddSocketDataProvider(&socket_data);
1377
1378 // Create request and QuicHttpStream.
1379 QuicStreamRequest request(factory_.get());
1380 EXPECT_EQ(ERR_IO_PENDING,
1381 request.Request(host_port_pair_, privacy_mode_,
1382 /*cert_verify_flags=*/0, host_port_pair_.host(),
1383 "GET", net_log_, callback_.callback()));
1384 EXPECT_EQ(OK, callback_.WaitForResult());
1385 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1386 EXPECT_TRUE(stream.get());
1387
1388 // Cause QUIC stream to be created.
1389 HttpRequestInfo request_info;
1390 request_info.method = "GET";
1391 request_info.url = GURL("https://www.example.org/");
1392 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1393 net_log_, CompletionCallback()));
1394
1395 // Ensure that session is alive and active.
1396 QuicChromiumClientSession* session =
1397 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1398 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1399 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1400
1401 // Send GET request on stream.
1402 HttpResponseInfo response;
1403 HttpRequestHeaders request_headers;
1404 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response,
1405 callback_.callback()));
1406
1407 // Set up second socket data provider that is used after migration.
1408 // The response to the earlier request is read on this new socket.
1409 scoped_ptr<QuicEncryptedPacket> ping(
1410 maker_.MakePingPacket(2, /*include_version=*/true));
1411 MockWrite writes1[] = {
1412 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)};
1413 scoped_ptr<QuicEncryptedPacket> response_headers_packet(
1414 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false));
1415 MockRead reads1[] = {MockRead(ASYNC, response_headers_packet->data(),
1416 response_headers_packet->length(), 1),
1417 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)};
1418 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1,
1419 arraysize(writes1));
1420 socket_factory_.AddSocketDataProvider(&socket_data1);
1421
1422 // Trigger connection migration. This should cause a PING frame
1423 // to be emitted.
1424 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1425 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests);
1426
1427 // The session should now be marked as going away. Ensure that
1428 // while it is still alive, it is no longer active.
1429 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1430 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1431 EXPECT_EQ(1u, session->GetNumActiveStreams());
1432
1433 // Verify that response headers on the migrated socket were delivered to the
1434 // stream.
1435 EXPECT_EQ(OK, stream->ReadResponseHeaders(callback_.callback()));
1436 EXPECT_EQ(200, response.headers->response_code());
1437
1438 // Create a new request for the same destination and verify that a
1439 // new session is created.
1440 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1441 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1442 socket_factory_.AddSocketDataProvider(&socket_data2);
1443
1444 QuicStreamRequest request2(factory_.get());
1445 EXPECT_EQ(ERR_IO_PENDING,
1446 request2.Request(host_port_pair_, privacy_mode_,
1447 /*cert_verify_flags=*/0, host_port_pair_.host(),
1448 "GET", net_log_, callback_.callback()));
1449 EXPECT_EQ(OK, callback_.WaitForResult());
1450 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1451 EXPECT_TRUE(stream2.get());
1452
1453 EXPECT_TRUE(
1454 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_));
1455 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(),
1456 host_port_pair_));
1457
1458 // On a DISCONNECTED notification, nothing happens to the migrated session.
1459 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1460 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1461 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1462 EXPECT_EQ(1u, session->GetNumActiveStreams());
1463
1464 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1465 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1466 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
1467 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
1468 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1469 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1470 }
1471
1472 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnected) {
1473 InitializeConnectionMigrationTest(
1474 {kDefaultNetworkForTests, kNewNetworkForTests});
1475 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1476 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1477 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1478
1479 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1480 scoped_ptr<QuicEncryptedPacket> request_packet(
1481 ConstructGetRequestPacket(1, kClientDataStreamId1, true, true));
1482 MockWrite writes[] = {MockWrite(SYNCHRONOUS, request_packet->data(),
1483 request_packet->length(), 1)};
1484 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1485 arraysize(writes));
1486 socket_factory_.AddSocketDataProvider(&socket_data);
1487
1488 // Create request and QuicHttpStream.
1489 QuicStreamRequest request(factory_.get());
1490 EXPECT_EQ(ERR_IO_PENDING,
1491 request.Request(host_port_pair_, privacy_mode_,
1492 /*cert_verify_flags=*/0, host_port_pair_.host(),
1493 "GET", net_log_, callback_.callback()));
1494 EXPECT_EQ(OK, callback_.WaitForResult());
1495 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1496 EXPECT_TRUE(stream.get());
1497
1498 // Cause QUIC stream to be created.
1499 HttpRequestInfo request_info;
1500 request_info.method = "GET";
1501 request_info.url = GURL("https://www.example.org/");
1502 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1503 net_log_, CompletionCallback()));
1504
1505 // Ensure that session is alive and active.
1506 QuicChromiumClientSession* session =
1507 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1508 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1509 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1510
1511 // Send GET request on stream.
1512 HttpResponseInfo response_info;
1513 HttpRequestHeaders request_headers;
1514 EXPECT_EQ(OK, stream->SendRequest(request_headers, &response_info,
1515 callback_.callback()));
1516
1517 // Set up second socket data provider that is used after migration.
1518 scoped_ptr<QuicEncryptedPacket> ping(
1519 maker_.MakePingPacket(2, /*include_version=*/true));
1520 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket(
1521 3, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED));
1522 MockWrite writes1[] = {
1523 MockWrite(SYNCHRONOUS, ping->data(), ping->length(), 0)};
1524 scoped_ptr<QuicEncryptedPacket> response_packet(
1525 ConstructOkResponsePacket(1, kClientDataStreamId1, false, false));
1526 MockRead reads1[] = {
1527 MockRead(ASYNC, response_packet->data(), response_packet->length(), 1),
1528 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 2)};
1529 SequencedSocketData socket_data1(reads1, arraysize(reads1), writes1,
1530 arraysize(writes1));
1531 socket_factory_.AddSocketDataProvider(&socket_data1);
1532
1533 // Trigger connection migration. This should cause a PING frame
1534 // to be emitted.
1535 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1536 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1537
1538 // The session should now be marked as going away. Ensure that
1539 // while it is still alive, it is no longer active.
1540 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1541 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1542 EXPECT_EQ(1u, session->GetNumActiveStreams());
1543
1544 // Create a new request for the same destination and verify that a
1545 // new session is created.
1546 MockRead reads2[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1547 SequencedSocketData socket_data2(reads2, arraysize(reads2), nullptr, 0);
1548 socket_factory_.AddSocketDataProvider(&socket_data2);
1549
1550 QuicStreamRequest request2(factory_.get());
1551 EXPECT_EQ(ERR_IO_PENDING,
1552 request2.Request(host_port_pair_, privacy_mode_,
1553 /*cert_verify_flags=*/0, host_port_pair_.host(),
1554 "GET", net_log_, callback_.callback()));
1555 EXPECT_EQ(OK, callback_.WaitForResult());
1556 scoped_ptr<QuicHttpStream> stream2 = request2.ReleaseStream();
1557 EXPECT_TRUE(stream2.get());
1558
1559 EXPECT_TRUE(
1560 QuicStreamFactoryPeer::HasActiveSession(factory_.get(), host_port_pair_));
1561 EXPECT_NE(session, QuicStreamFactoryPeer::GetActiveSession(factory_.get(),
1562 host_port_pair_));
1563 EXPECT_EQ(true,
1564 QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1565
1566 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1567 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1568 EXPECT_TRUE(socket_data1.AllReadDataConsumed());
1569 EXPECT_TRUE(socket_data1.AllWriteDataConsumed());
1570 EXPECT_TRUE(socket_data2.AllReadDataConsumed());
1571 EXPECT_TRUE(socket_data2.AllWriteDataConsumed());
1572 }
1573
1574 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNetworks) {
1575 NetworkChangeNotifier::NetworkList no_networks(0);
1576 InitializeConnectionMigrationTest(no_networks);
1577 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1578 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1579
1580 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1581 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket(
1582 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED));
1583 MockWrite writes[] = {
1584 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1),
1585 };
1586 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1587 arraysize(writes));
1588 socket_factory_.AddSocketDataProvider(&socket_data);
1589
1590 // Create request and QuicHttpStream.
1591 QuicStreamRequest request(factory_.get());
1592 EXPECT_EQ(ERR_IO_PENDING,
1593 request.Request(host_port_pair_, privacy_mode_,
1594 /*cert_verify_flags=*/0, host_port_pair_.host(),
1595 "GET", net_log_, callback_.callback()));
1596 EXPECT_EQ(OK, callback_.WaitForResult());
1597 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1598 EXPECT_TRUE(stream.get());
1599
1600 // Cause QUIC stream to be created.
1601 HttpRequestInfo request_info;
1602 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1603 net_log_, CompletionCallback()));
1604
1605 // Ensure that session is alive and active.
1606 QuicChromiumClientSession* session =
1607 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1608 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1609 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1610 EXPECT_EQ(1u, session->GetNumActiveStreams());
1611
1612 // Trigger connection migration. Since there are no networks
1613 // to migrate to, this should cause the session to continue on the same
1614 // socket, but be marked as going away.
1615 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1616 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests);
1617
1618 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1619 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1620 EXPECT_EQ(1u, session->GetNumActiveStreams());
1621
1622 stream.reset();
1623
1624 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1625 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1626 }
1627
1628 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNetworks) {
1629 NetworkChangeNotifier::NetworkList no_networks(0);
1630 InitializeConnectionMigrationTest(no_networks);
1631 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1632 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1633
1634 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1635 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket(
1636 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT));
1637 MockWrite writes[] = {
1638 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1),
1639 };
1640 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1641 arraysize(writes));
1642 socket_factory_.AddSocketDataProvider(&socket_data);
1643
1644 // Create request and QuicHttpStream.
1645 QuicStreamRequest request(factory_.get());
1646 EXPECT_EQ(ERR_IO_PENDING,
1647 request.Request(host_port_pair_, privacy_mode_,
1648 /*cert_verify_flags=*/0, host_port_pair_.host(),
1649 "GET", net_log_, callback_.callback()));
1650 EXPECT_EQ(OK, callback_.WaitForResult());
1651 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1652 EXPECT_TRUE(stream.get());
1653
1654 // Cause QUIC stream to be created.
1655 HttpRequestInfo request_info;
1656 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1657 net_log_, CompletionCallback()));
1658
1659 // Ensure that session is alive and active.
1660 QuicChromiumClientSession* session =
1661 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1662 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1663 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1664
1665 // Trigger connection migration. Since there are no networks
1666 // to migrate to, this should cause a RST_STREAM frame to be emitted
1667 // and the session to be closed.
1668 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1669 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1670
1671 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1672 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1673
1674 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1675 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1676 }
1677
1678 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoNewNetwork) {
1679 InitializeConnectionMigrationTest({kDefaultNetworkForTests});
1680 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1681 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1682
1683 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1684 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket(
1685 1, true, kClientDataStreamId1, QUIC_STREAM_CANCELLED));
1686 MockWrite writes[] = {
1687 MockWrite(SYNCHRONOUS, client_rst->data(), client_rst->length(), 1),
1688 };
1689 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1690 arraysize(writes));
1691 socket_factory_.AddSocketDataProvider(&socket_data);
1692
1693 // Create request and QuicHttpStream.
1694 QuicStreamRequest request(factory_.get());
1695 EXPECT_EQ(ERR_IO_PENDING,
1696 request.Request(host_port_pair_, privacy_mode_,
1697 /*cert_verify_flags=*/0, host_port_pair_.host(),
1698 "GET", net_log_, callback_.callback()));
1699 EXPECT_EQ(OK, callback_.WaitForResult());
1700 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1701 EXPECT_TRUE(stream.get());
1702
1703 // Cause QUIC stream to be created.
1704 HttpRequestInfo request_info;
1705 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1706 net_log_, CompletionCallback()));
1707
1708 // Ensure that session is alive and active.
1709 QuicChromiumClientSession* session =
1710 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1711 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1712 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1713
1714 // Trigger connection migration. Since there are no networks
1715 // to migrate to, this should cause session to be continue but be marked as
1716 // going away.
1717 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1718 ->NotifyNetworkSoonToDisconnect(kDefaultNetworkForTests);
1719
1720 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1721 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1722 EXPECT_EQ(1u, session->GetNumActiveStreams());
1723
1724 stream.reset();
1725
1726 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1727 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1728 }
1729
1730 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoNewNetwork) {
1731 InitializeConnectionMigrationTest({kDefaultNetworkForTests});
1732 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1733 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1734
1735 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1736 scoped_ptr<QuicEncryptedPacket> client_rst(maker_.MakeRstPacket(
1737 1, true, kClientDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT));
1738 MockWrite writes[] = {
1739 MockWrite(ASYNC, client_rst->data(), client_rst->length(), 1),
1740 };
1741 SequencedSocketData socket_data(reads, arraysize(reads), writes,
1742 arraysize(writes));
1743 socket_factory_.AddSocketDataProvider(&socket_data);
1744
1745 // Create request and QuicHttpStream.
1746 QuicStreamRequest request(factory_.get());
1747 EXPECT_EQ(ERR_IO_PENDING,
1748 request.Request(host_port_pair_, privacy_mode_,
1749 /*cert_verify_flags=*/0, host_port_pair_.host(),
1750 "GET", net_log_, callback_.callback()));
1751 EXPECT_EQ(OK, callback_.WaitForResult());
1752 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1753 EXPECT_TRUE(stream.get());
1754
1755 // Cause QUIC stream to be created.
1756 HttpRequestInfo request_info;
1757 EXPECT_EQ(OK, stream->InitializeStream(&request_info, DEFAULT_PRIORITY,
1758 net_log_, CompletionCallback()));
1759
1760 // Ensure that session is alive and active.
1761 QuicChromiumClientSession* session =
1762 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1763 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1764 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1765
1766 // Trigger connection migration. Since there are no networks
1767 // to migrate to, this should cause a RST_STREAM frame to be emitted
1768 // with QUIC_RST_ACKNOWLEDGEMENT error code, and the session will be closed.
1769 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1770 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1771
1772 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1773 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1774
1775 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1776 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1777 }
1778
1779 TEST_P(QuicStreamFactoryTest, OnNetworkChangeSoonToDisconnectNoOpenStreams) {
1780 InitializeConnectionMigrationTest(
1781 {kDefaultNetworkForTests, kNewNetworkForTests});
1782 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1783 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1784
1785 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1786 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u);
1787 socket_factory_.AddSocketDataProvider(&socket_data);
1788
1789 // Create request and QuicHttpStream.
1790 QuicStreamRequest request(factory_.get());
1791 EXPECT_EQ(ERR_IO_PENDING,
1792 request.Request(host_port_pair_, privacy_mode_,
1793 /*cert_verify_flags=*/0, host_port_pair_.host(),
1794 "GET", net_log_, callback_.callback()));
1795 EXPECT_EQ(OK, callback_.WaitForResult());
1796 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1797 EXPECT_TRUE(stream.get());
1798
1799 // Ensure that session is alive and active.
1800 QuicChromiumClientSession* session =
1801 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1802 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1803 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1804
1805 // Trigger connection migration. Since there are no active streams,
1806 // the session will be closed.
1807 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1808 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1809
1810 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1811 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1812
1813 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1814 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1815 }
1816
1817 TEST_P(QuicStreamFactoryTest, OnNetworkChangeDisconnectedNoOpenStreams) {
1818 InitializeConnectionMigrationTest(
1819 {kDefaultNetworkForTests, kNewNetworkForTests});
1820 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1821 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1822
1823 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1824 SequencedSocketData socket_data(reads, arraysize(reads), nullptr, 0u);
1825 socket_factory_.AddSocketDataProvider(&socket_data);
1826
1827 // Create request and QuicHttpStream.
1828 QuicStreamRequest request(factory_.get());
1829 EXPECT_EQ(ERR_IO_PENDING,
1830 request.Request(host_port_pair_, privacy_mode_,
1831 /*cert_verify_flags=*/0, host_port_pair_.host(),
1832 "GET", net_log_, callback_.callback()));
1833 EXPECT_EQ(OK, callback_.WaitForResult());
1834 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
1835 EXPECT_TRUE(stream.get());
1836
1837 // Ensure that session is alive and active.
1838 QuicChromiumClientSession* session =
1839 QuicStreamFactoryPeer::GetActiveSession(factory_.get(), host_port_pair_);
1840 EXPECT_TRUE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1841 EXPECT_TRUE(HasActiveSession(host_port_pair_));
1842
1843 // Trigger connection migration. Since there are no active streams,
1844 // the session will be closed.
1845 scoped_mock_network_change_notifier_->mock_network_change_notifier()
1846 ->NotifyNetworkDisconnected(kDefaultNetworkForTests);
1847
1848 EXPECT_FALSE(QuicStreamFactoryPeer::IsLiveSession(factory_.get(), session));
1849 EXPECT_FALSE(HasActiveSession(host_port_pair_));
1850
1851 EXPECT_TRUE(socket_data.AllReadDataConsumed());
1852 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
1853 }
1854
1255 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) { 1855 TEST_P(QuicStreamFactoryTest, OnSSLConfigChanged) {
1256 Initialize(); 1856 Initialize();
1257 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); 1857 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails();
1258 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 1858 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1259 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); 1859 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details);
1260 1860
1261 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; 1861 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
1262 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket()); 1862 scoped_ptr<QuicEncryptedPacket> rst(ConstructRstPacket());
1263 std::vector<MockWrite> writes; 1863 std::vector<MockWrite> writes;
1264 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1)); 1864 writes.push_back(MockWrite(ASYNC, rst->data(), rst->length(), 1));
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 EXPECT_EQ(1u, observer.executed_count()); 3278 EXPECT_EQ(1u, observer.executed_count());
2679 3279
2680 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream(); 3280 scoped_ptr<QuicHttpStream> stream = request.ReleaseStream();
2681 EXPECT_TRUE(stream.get()); 3281 EXPECT_TRUE(stream.get());
2682 EXPECT_TRUE(socket_data.AllReadDataConsumed()); 3282 EXPECT_TRUE(socket_data.AllReadDataConsumed());
2683 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); 3283 EXPECT_TRUE(socket_data.AllWriteDataConsumed());
2684 } 3284 }
2685 3285
2686 } // namespace test 3286 } // namespace test
2687 } // namespace net 3287 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698