Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_chromium_client_session.h" | 5 #include "net/quic/quic_chromium_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "net/base/socket_performance_watcher.h" | 13 #include "net/base/socket_performance_watcher.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/base/test_data_directory.h" | 15 #include "net/base/test_data_directory.h" |
| 16 #include "net/cert/cert_verify_result.h" | 16 #include "net/cert/cert_verify_result.h" |
| 17 #include "net/http/transport_security_state.h" | 17 #include "net/http/transport_security_state.h" |
| 18 #include "net/log/test_net_log.h" | 18 #include "net/log/test_net_log.h" |
| 19 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 19 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 20 #include "net/quic/crypto/crypto_protocol.h" | 20 #include "net/quic/crypto/crypto_protocol.h" |
| 21 #include "net/quic/crypto/proof_verifier_chromium.h" | 21 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 22 #include "net/quic/crypto/quic_decrypter.h" | 22 #include "net/quic/crypto/quic_decrypter.h" |
| 23 #include "net/quic/crypto/quic_encrypter.h" | 23 #include "net/quic/crypto/quic_encrypter.h" |
| 24 #include "net/quic/crypto/quic_server_info.h" | 24 #include "net/quic/crypto/quic_server_info.h" |
| 25 #include "net/quic/quic_connection_helper.h" | |
| 25 #include "net/quic/quic_crypto_client_stream_factory.h" | 26 #include "net/quic/quic_crypto_client_stream_factory.h" |
| 27 #include "net/quic/quic_default_packet_writer.h" | |
| 26 #include "net/quic/quic_flags.h" | 28 #include "net/quic/quic_flags.h" |
| 29 #include "net/quic/quic_http_utils.h" | |
| 27 #include "net/quic/quic_packet_reader.h" | 30 #include "net/quic/quic_packet_reader.h" |
| 31 #include "net/quic/quic_packet_writer.h" | |
| 28 #include "net/quic/quic_protocol.h" | 32 #include "net/quic/quic_protocol.h" |
| 29 #include "net/quic/test_tools/crypto_test_utils.h" | 33 #include "net/quic/test_tools/crypto_test_utils.h" |
| 34 #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" | |
| 30 #include "net/quic/test_tools/quic_chromium_client_session_peer.h" | 35 #include "net/quic/test_tools/quic_chromium_client_session_peer.h" |
| 31 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 36 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 37 #include "net/quic/test_tools/quic_test_packet_maker.h" | |
| 32 #include "net/quic/test_tools/quic_test_utils.h" | 38 #include "net/quic/test_tools/quic_test_utils.h" |
| 33 #include "net/quic/test_tools/simple_quic_framer.h" | 39 #include "net/quic/test_tools/simple_quic_framer.h" |
| 34 #include "net/socket/socket_test_util.h" | 40 #include "net/socket/socket_test_util.h" |
| 35 #include "net/spdy/spdy_test_utils.h" | 41 #include "net/spdy/spdy_test_utils.h" |
| 36 #include "net/test/cert_test_util.h" | 42 #include "net/test/cert_test_util.h" |
| 37 #include "net/udp/datagram_client_socket.h" | 43 #include "net/udp/datagram_client_socket.h" |
| 38 | 44 |
| 39 using testing::_; | 45 using testing::_; |
| 40 | 46 |
| 41 namespace net { | 47 namespace net { |
| 42 namespace test { | 48 namespace test { |
| 43 namespace { | 49 namespace { |
| 44 | 50 |
| 51 const IPEndPoint kIpEndPoint(IPAddressNumber(kIPv4AddressSize, 0), 0); | |
| 45 const char kServerHostname[] = "test.example.com"; | 52 const char kServerHostname[] = "test.example.com"; |
| 46 const uint16_t kServerPort = 443; | 53 const uint16_t kServerPort = 443; |
| 54 const size_t kMaxReadersPerQuicSession = 5; | |
| 55 | |
| 56 class DefaultPacketWriterFactory : public QuicConnection::PacketWriterFactory { | |
| 57 public: | |
| 58 explicit DefaultPacketWriterFactory(DatagramClientSocket* socket) | |
| 59 : socket_(socket) {} | |
| 60 ~DefaultPacketWriterFactory() override {} | |
| 61 | |
| 62 QuicPacketWriter* Create(QuicConnection* connection) const override { | |
| 63 scoped_ptr<net::QuicDefaultPacketWriter> writer( | |
| 64 new net::QuicDefaultPacketWriter(socket_)); | |
| 65 writer->SetConnection(connection); | |
| 66 return writer.release(); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 DatagramClientSocket* socket_; | |
| 71 }; | |
| 47 | 72 |
| 48 class QuicChromiumClientSessionTest | 73 class QuicChromiumClientSessionTest |
| 49 : public ::testing::TestWithParam<QuicVersion> { | 74 : public ::testing::TestWithParam<QuicVersion> { |
| 50 protected: | 75 protected: |
| 51 QuicChromiumClientSessionTest() | 76 QuicChromiumClientSessionTest() |
| 52 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), | 77 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
| 53 connection_(new PacketSavingConnection(&helper_, | 78 socket_(GetSocket()), |
| 54 Perspective::IS_CLIENT, | 79 random_(0), |
| 55 SupportedVersions(GetParam()))), | 80 helper_(base::ThreadTaskRunnerHandle::Get().get(), &clock_, &random_), |
| 81 writer_factory_(socket_.get()), | |
| 82 connection_(new QuicConnection(0, | |
| 83 kIpEndPoint, | |
| 84 &helper_, | |
| 85 writer_factory_, | |
| 86 true, | |
| 87 Perspective::IS_CLIENT, | |
| 88 SupportedVersions(GetParam()))), | |
| 56 session_( | 89 session_( |
| 57 connection_, | 90 connection_, |
| 58 GetSocket(), | 91 std::move(socket_), |
| 59 /*stream_factory=*/nullptr, | 92 /*stream_factory=*/nullptr, |
| 60 QuicCryptoClientStreamFactory::GetDefaultFactory(), | 93 &crypto_client_stream_factory_, |
| 61 &clock_, | 94 &clock_, |
| 62 &transport_security_state_, | 95 &transport_security_state_, |
| 63 make_scoped_ptr((QuicServerInfo*)nullptr), | 96 make_scoped_ptr((QuicServerInfo*)nullptr), |
| 64 QuicServerId(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), | 97 QuicServerId(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), |
| 65 kQuicYieldAfterPacketsRead, | 98 kQuicYieldAfterPacketsRead, |
| 66 QuicTime::Delta::FromMilliseconds( | 99 QuicTime::Delta::FromMilliseconds( |
| 67 kQuicYieldAfterDurationMilliseconds), | 100 kQuicYieldAfterDurationMilliseconds), |
| 68 /*cert_verify_flags=*/0, | 101 /*cert_verify_flags=*/0, |
| 69 DefaultQuicConfig(), | 102 DefaultQuicConfig(), |
| 70 &crypto_config_, | 103 &crypto_config_, |
| 71 "CONNECTION_UNKNOWN", | 104 "CONNECTION_UNKNOWN", |
| 72 base::TimeTicks::Now(), | 105 base::TimeTicks::Now(), |
| 73 base::ThreadTaskRunnerHandle::Get().get(), | 106 base::ThreadTaskRunnerHandle::Get().get(), |
| 74 /*socket_performance_watcher=*/nullptr, | 107 /*socket_performance_watcher=*/nullptr, |
| 75 &net_log_) { | 108 &net_log_), |
| 109 maker_(GetParam(), 0, &clock_, kServerHostname) { | |
| 110 scoped_refptr<X509Certificate> cert( | |
| 111 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem")); | |
| 112 verify_details_.cert_verify_result.verified_cert = cert; | |
| 113 verify_details_.cert_verify_result.is_issued_by_known_root = true; | |
| 114 // Advance the time, because timers do not like uninitialized times. | |
| 115 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | |
| 76 session_.Initialize(); | 116 session_.Initialize(); |
| 77 // Advance the time, because timers do not like uninitialized times. | 117 session_.StartReading(); |
| 78 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | |
| 79 } | 118 } |
| 80 | 119 |
| 81 void TearDown() override { | 120 void TearDown() override { |
| 82 session_.CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR); | 121 session_.CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR); |
| 83 } | 122 } |
| 84 | 123 |
| 85 scoped_ptr<DatagramClientSocket> GetSocket() { | 124 scoped_ptr<DatagramClientSocket> GetSocket() { |
| 86 socket_factory_.AddSocketDataProvider(&socket_data_); | 125 reads_[0] = MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0); |
| 87 return socket_factory_.CreateDatagramClientSocket( | 126 socket_data_.reset( |
| 88 DatagramSocket::DEFAULT_BIND, base::Bind(&base::RandInt), &net_log_, | 127 new StaticSocketDataProvider(reads_, arraysize(reads_), nullptr, 0)); |
| 89 NetLog::Source()); | 128 socket_factory_.AddSocketDataProvider(socket_data_.get()); |
| 129 scoped_ptr<DatagramClientSocket> socket = | |
| 130 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, | |
| 131 base::Bind(&base::RandInt), | |
| 132 &net_log_, NetLog::Source()); | |
| 133 socket->Connect(kIpEndPoint); | |
| 134 return socket; | |
| 90 } | 135 } |
| 91 | 136 |
| 92 void CompleteCryptoHandshake() { | 137 void CompleteCryptoHandshake() { |
| 93 ASSERT_EQ(ERR_IO_PENDING, | 138 ASSERT_EQ(OK, session_.CryptoConnect(false, callback_.callback())); |
| 94 session_.CryptoConnect(false, callback_.callback())); | |
| 95 CryptoTestUtils::FakeServerOptions server_options; | |
| 96 CryptoTestUtils::HandshakeWithFakeServer( | |
| 97 &helper_, connection_, session_.GetCryptoStream(), server_options); | |
| 98 ASSERT_EQ(OK, callback_.WaitForResult()); | |
| 99 } | 139 } |
| 100 | 140 |
| 101 MockConnectionHelper helper_; | 141 QuicPacketWriter* CreateQuicPacketWriter(DatagramClientSocket* socket, |
| 142 QuicConnection* connection) const { | |
| 143 scoped_ptr<QuicDefaultPacketWriter> writer( | |
| 144 new QuicDefaultPacketWriter(socket)); | |
| 145 writer->SetConnection(connection); | |
| 146 return writer.release(); | |
| 147 } | |
| 148 | |
| 102 QuicCryptoClientConfig crypto_config_; | 149 QuicCryptoClientConfig crypto_config_; |
| 103 PacketSavingConnection* connection_; | |
| 104 TestNetLog net_log_; | 150 TestNetLog net_log_; |
| 151 BoundTestNetLog bound_net_log_; | |
| 105 MockClientSocketFactory socket_factory_; | 152 MockClientSocketFactory socket_factory_; |
| 106 StaticSocketDataProvider socket_data_; | 153 MockRead reads_[1]; |
| 107 TransportSecurityState transport_security_state_; | 154 scoped_ptr<StaticSocketDataProvider> socket_data_; |
| 108 QuicChromiumClientSession session_; | 155 scoped_ptr<DatagramClientSocket> socket_; |
| 109 MockClock clock_; | 156 MockClock clock_; |
| 110 MockRandom random_; | 157 MockRandom random_; |
| 158 QuicConnectionHelper helper_; | |
| 159 DefaultPacketWriterFactory writer_factory_; | |
| 160 QuicConnection* connection_; | |
| 161 TransportSecurityState transport_security_state_; | |
| 162 MockCryptoClientStreamFactory crypto_client_stream_factory_; | |
| 163 QuicChromiumClientSession session_; | |
| 111 QuicConnectionVisitorInterface* visitor_; | 164 QuicConnectionVisitorInterface* visitor_; |
| 112 TestCompletionCallback callback_; | 165 TestCompletionCallback callback_; |
| 166 QuicTestPacketMaker maker_; | |
| 167 ProofVerifyDetailsChromium verify_details_; | |
| 113 }; | 168 }; |
| 114 | 169 |
| 115 INSTANTIATE_TEST_CASE_P(Tests, | 170 INSTANTIATE_TEST_CASE_P(Tests, |
| 116 QuicChromiumClientSessionTest, | 171 QuicChromiumClientSessionTest, |
| 117 ::testing::ValuesIn(QuicSupportedVersions())); | 172 ::testing::ValuesIn(QuicSupportedVersions())); |
| 118 | 173 |
| 119 TEST_P(QuicChromiumClientSessionTest, CryptoConnect) { | 174 TEST_P(QuicChromiumClientSessionTest, CryptoConnect) { |
| 120 CompleteCryptoHandshake(); | 175 CompleteCryptoHandshake(); |
| 121 } | 176 } |
| 122 | 177 |
| 123 TEST_P(QuicChromiumClientSessionTest, MaxNumStreams) { | 178 TEST_P(QuicChromiumClientSessionTest, MaxNumStreams) { |
| 124 CompleteCryptoHandshake(); | 179 CompleteCryptoHandshake(); |
| 180 const size_t kMaxOpenStreams = session_.get_max_open_streams(); | |
|
Ryan Hamilton
2016/01/08 05:01:06
What's the story with this change?
Jana
2016/01/09 02:06:54
It's being set to kDefaultMaxNumStreams/2 in MockC
| |
| 125 | 181 |
| 126 std::vector<QuicReliableClientStream*> streams; | 182 std::vector<QuicReliableClientStream*> streams; |
| 127 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { | 183 for (size_t i = 0; i < kMaxOpenStreams; i++) { |
| 128 QuicReliableClientStream* stream = | 184 QuicReliableClientStream* stream = |
| 129 session_.CreateOutgoingDynamicStream(kDefaultPriority); | 185 session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 130 EXPECT_TRUE(stream); | 186 EXPECT_TRUE(stream); |
| 131 streams.push_back(stream); | 187 streams.push_back(stream); |
| 132 } | 188 } |
| 133 EXPECT_FALSE(session_.CreateOutgoingDynamicStream(kDefaultPriority)); | 189 EXPECT_FALSE(session_.CreateOutgoingDynamicStream(kDefaultPriority)); |
| 134 | 190 |
| 135 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 191 EXPECT_EQ(kMaxOpenStreams, session_.GetNumOpenOutgoingStreams()); |
| 136 session_.GetNumOpenOutgoingStreams()); | |
| 137 | 192 |
| 138 // Close a stream and ensure I can now open a new one. | 193 // Close a stream and ensure I can now open a new one. |
| 139 QuicStreamId stream_id = streams[0]->id(); | 194 QuicStreamId stream_id = streams[0]->id(); |
| 140 session_.CloseStream(stream_id); | 195 session_.CloseStream(stream_id); |
| 141 | 196 |
| 142 EXPECT_FALSE(session_.CreateOutgoingDynamicStream(kDefaultPriority)); | 197 EXPECT_FALSE(session_.CreateOutgoingDynamicStream(kDefaultPriority)); |
| 143 QuicRstStreamFrame rst1(stream_id, QUIC_STREAM_NO_ERROR, 0); | 198 QuicRstStreamFrame rst1(stream_id, QUIC_STREAM_NO_ERROR, 0); |
| 144 session_.OnRstStream(rst1); | 199 session_.OnRstStream(rst1); |
| 145 EXPECT_EQ(kDefaultMaxStreamsPerConnection - 1, | 200 EXPECT_EQ(kMaxOpenStreams - 1, session_.GetNumOpenOutgoingStreams()); |
| 146 session_.GetNumOpenOutgoingStreams()); | |
| 147 EXPECT_TRUE(session_.CreateOutgoingDynamicStream(kDefaultPriority)); | 201 EXPECT_TRUE(session_.CreateOutgoingDynamicStream(kDefaultPriority)); |
| 148 } | 202 } |
| 149 | 203 |
| 150 TEST_P(QuicChromiumClientSessionTest, MaxNumStreamsViaRequest) { | 204 TEST_P(QuicChromiumClientSessionTest, MaxNumStreamsViaRequest) { |
| 151 CompleteCryptoHandshake(); | 205 CompleteCryptoHandshake(); |
| 206 const size_t kMaxOpenStreams = session_.get_max_open_streams(); | |
| 152 | 207 |
| 153 std::vector<QuicReliableClientStream*> streams; | 208 std::vector<QuicReliableClientStream*> streams; |
| 154 for (size_t i = 0; i < kDefaultMaxStreamsPerConnection; i++) { | 209 for (size_t i = 0; i < kMaxOpenStreams; i++) { |
| 155 QuicReliableClientStream* stream = | 210 QuicReliableClientStream* stream = |
| 156 session_.CreateOutgoingDynamicStream(kDefaultPriority); | 211 session_.CreateOutgoingDynamicStream(kDefaultPriority); |
| 157 EXPECT_TRUE(stream); | 212 EXPECT_TRUE(stream); |
| 158 streams.push_back(stream); | 213 streams.push_back(stream); |
| 159 } | 214 } |
| 160 | 215 |
| 161 QuicReliableClientStream* stream; | 216 QuicReliableClientStream* stream; |
| 162 QuicChromiumClientSession::StreamRequest stream_request; | 217 QuicChromiumClientSession::StreamRequest stream_request; |
| 163 TestCompletionCallback callback; | 218 TestCompletionCallback callback; |
| 164 ASSERT_EQ(ERR_IO_PENDING, | 219 ASSERT_EQ(ERR_IO_PENDING, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 ASSERT_TRUE(details.cert_verify_result.verified_cert.get()); | 323 ASSERT_TRUE(details.cert_verify_result.verified_cert.get()); |
| 269 | 324 |
| 270 CompleteCryptoHandshake(); | 325 CompleteCryptoHandshake(); |
| 271 session_.OnProofVerifyDetailsAvailable(details); | 326 session_.OnProofVerifyDetailsAvailable(details); |
| 272 QuicChromiumClientSessionPeer::SetHostname(&session_, "www.example.org"); | 327 QuicChromiumClientSessionPeer::SetHostname(&session_, "www.example.org"); |
| 273 QuicChromiumClientSessionPeer::SetChannelIDSent(&session_, true); | 328 QuicChromiumClientSessionPeer::SetChannelIDSent(&session_, true); |
| 274 | 329 |
| 275 EXPECT_TRUE(session_.CanPool("mail.example.org", PRIVACY_MODE_DISABLED)); | 330 EXPECT_TRUE(session_.CanPool("mail.example.org", PRIVACY_MODE_DISABLED)); |
| 276 } | 331 } |
| 277 | 332 |
| 333 TEST_P(QuicChromiumClientSessionTest, MigrateToSocket) { | |
| 334 CompleteCryptoHandshake(); | |
| 335 | |
| 336 char data[] = "ABCD"; | |
| 337 scoped_ptr<QuicEncryptedPacket> ping_in( | |
| 338 maker_.MakePingPacket(1, /*include_version=*/false)); | |
| 339 scoped_ptr<QuicEncryptedPacket> ping_out( | |
| 340 maker_.MakePingPacket(1, /*include_version=*/false)); | |
| 341 scoped_ptr<QuicEncryptedPacket> ack_and_data_out(maker_.MakeAckAndDataPacket( | |
| 342 2, false, 5, 1, 1, false, 0, StringPiece(data))); | |
| 343 MockRead reads[] = { | |
| 344 MockRead(SYNCHRONOUS, ping_in->data(), ping_in->length(), 0), | |
| 345 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 1)}; | |
| 346 MockWrite writes[] = { | |
| 347 MockWrite(SYNCHRONOUS, ping_out->data(), ping_out->length(), 2), | |
| 348 MockWrite(SYNCHRONOUS, ack_and_data_out->data(), | |
| 349 ack_and_data_out->length(), 3)}; | |
| 350 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 351 arraysize(writes)); | |
| 352 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 353 | |
| 354 // Create connected socket. | |
| 355 scoped_ptr<DatagramClientSocket> new_socket = | |
| 356 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, | |
| 357 base::Bind(&base::RandInt), | |
| 358 &net_log_, NetLog::Source()); | |
| 359 EXPECT_EQ(OK, new_socket->Connect(kIpEndPoint)); | |
| 360 | |
| 361 // Create reader and writer. | |
| 362 scoped_ptr<QuicPacketReader> new_reader(new QuicPacketReader( | |
| 363 new_socket.get(), &clock_, &session_, kQuicYieldAfterPacketsRead, | |
| 364 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), | |
| 365 bound_net_log_.bound())); | |
| 366 scoped_ptr<QuicPacketWriter> new_writer( | |
| 367 CreateQuicPacketWriter(new_socket.get(), session_.connection())); | |
| 368 | |
| 369 // Migrate session. | |
| 370 EXPECT_TRUE(session_.MigrateToSocket( | |
| 371 std::move(new_socket), std::move(new_reader), std::move(new_writer))); | |
| 372 | |
| 373 // Write data to session. | |
| 374 struct iovec iov[1]; | |
| 375 iov[0].iov_base = data; | |
| 376 iov[0].iov_len = 4; | |
| 377 session_.WritevData(5, QuicIOVector(iov, arraysize(iov), 4), 0, false, | |
| 378 MAY_FEC_PROTECT, nullptr); | |
| 379 | |
| 380 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 381 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 382 } | |
| 383 | |
| 384 TEST_P(QuicChromiumClientSessionTest, MigrateToSocketMaxReaders) { | |
| 385 CompleteCryptoHandshake(); | |
| 386 | |
| 387 for (size_t i = 0; i < kMaxReadersPerQuicSession; ++i) { | |
| 388 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 1)}; | |
| 389 scoped_ptr<QuicEncryptedPacket> ping_out( | |
| 390 maker_.MakePingPacket(i + 1, /*include_version=*/true)); | |
| 391 MockWrite writes[] = { | |
| 392 MockWrite(SYNCHRONOUS, ping_out->data(), ping_out->length(), i + 2)}; | |
| 393 StaticSocketDataProvider socket_data(reads, arraysize(reads), writes, | |
| 394 arraysize(writes)); | |
| 395 socket_factory_.AddSocketDataProvider(&socket_data); | |
| 396 | |
| 397 // Create connected socket. | |
| 398 scoped_ptr<DatagramClientSocket> new_socket = | |
| 399 socket_factory_.CreateDatagramClientSocket(DatagramSocket::DEFAULT_BIND, | |
| 400 base::Bind(&base::RandInt), | |
| 401 &net_log_, NetLog::Source()); | |
| 402 EXPECT_EQ(OK, new_socket->Connect(kIpEndPoint)); | |
| 403 | |
| 404 // Create reader and writer. | |
| 405 scoped_ptr<QuicPacketReader> new_reader(new QuicPacketReader( | |
| 406 new_socket.get(), &clock_, &session_, kQuicYieldAfterPacketsRead, | |
| 407 QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), | |
| 408 bound_net_log_.bound())); | |
| 409 scoped_ptr<QuicPacketWriter> new_writer( | |
| 410 CreateQuicPacketWriter(new_socket.get(), session_.connection())); | |
| 411 | |
| 412 // Migrate session. | |
| 413 if (i < kMaxReadersPerQuicSession - 1) { | |
| 414 EXPECT_TRUE(session_.MigrateToSocket( | |
| 415 std::move(new_socket), std::move(new_reader), std::move(new_writer))); | |
| 416 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | |
| 417 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | |
| 418 } else { | |
| 419 // Max readers exceeded. | |
| 420 EXPECT_FALSE(session_.MigrateToSocket( | |
| 421 std::move(new_socket), std::move(new_reader), std::move(new_writer))); | |
| 422 | |
| 423 EXPECT_FALSE(socket_data.AllReadDataConsumed()); | |
| 424 EXPECT_FALSE(socket_data.AllWriteDataConsumed()); | |
| 425 } | |
| 426 } | |
| 427 } | |
|
Ryan Hamilton
2016/01/08 05:01:06
These tests look good! I think we also need to tes
| |
| 428 | |
| 278 } // namespace | 429 } // namespace |
| 279 } // namespace test | 430 } // namespace test |
| 280 } // namespace net | 431 } // namespace net |
| OLD | NEW |