| 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/tools/quic/quic_client_session.h" | 5 #include "net/tools/quic/quic_client_session.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "net/base/ip_endpoint.h" | 10 #include "net/base/ip_endpoint.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 server_id, | 62 server_id, |
| 63 crypto_config, | 63 crypto_config, |
| 64 push_promise_index) {} | 64 push_promise_index) {} |
| 65 | 65 |
| 66 QuicSpdyClientStream* CreateClientStream() override { | 66 QuicSpdyClientStream* CreateClientStream() override { |
| 67 return new MockQuicSpdyClientStream(GetNextOutgoingStreamId(), this); | 67 return new MockQuicSpdyClientStream(GetNextOutgoingStreamId(), this); |
| 68 } | 68 } |
| 69 | 69 |
| 70 MockQuicSpdyClientStream* CreateIncomingDynamicStream( | 70 MockQuicSpdyClientStream* CreateIncomingDynamicStream( |
| 71 QuicStreamId id) override { | 71 QuicStreamId id) override { |
| 72 return new MockQuicSpdyClientStream(id, this); | 72 MockQuicSpdyClientStream* stream = new MockQuicSpdyClientStream(id, this); |
| 73 ActivateStream(stream); |
| 74 return stream; |
| 73 } | 75 } |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { | 78 class QuicClientSessionTest : public ::testing::TestWithParam<QuicVersion> { |
| 77 protected: | 79 protected: |
| 78 QuicClientSessionTest() | 80 QuicClientSessionTest() |
| 79 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), | 81 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
| 80 promised_stream_id_(kServerDataStreamId1), | 82 promised_stream_id_(kServerDataStreamId1), |
| 81 associated_stream_id_(kClientDataStreamId1) { | 83 associated_stream_id_(kClientDataStreamId1) { |
| 82 Initialize(); | 84 Initialize(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 TEST_P(QuicClientSessionTest, GoAwayReceived) { | 226 TEST_P(QuicClientSessionTest, GoAwayReceived) { |
| 225 CompleteCryptoHandshake(); | 227 CompleteCryptoHandshake(); |
| 226 | 228 |
| 227 // After receiving a GoAway, I should no longer be able to create outgoing | 229 // After receiving a GoAway, I should no longer be able to create outgoing |
| 228 // streams. | 230 // streams. |
| 229 session_->connection()->OnGoAwayFrame( | 231 session_->connection()->OnGoAwayFrame( |
| 230 QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); | 232 QuicGoAwayFrame(QUIC_PEER_GOING_AWAY, 1u, "Going away.")); |
| 231 EXPECT_EQ(nullptr, session_->CreateOutgoingDynamicStream(kDefaultPriority)); | 233 EXPECT_EQ(nullptr, session_->CreateOutgoingDynamicStream(kDefaultPriority)); |
| 232 } | 234 } |
| 233 | 235 |
| 234 TEST_P(QuicClientSessionTest, SetFecProtectionFromConfig) { | |
| 235 ValueRestore<bool> old_flag(&FLAGS_enable_quic_fec, true); | |
| 236 | |
| 237 // Set FEC config in client's connection options. | |
| 238 QuicTagVector copt; | |
| 239 copt.push_back(kFHDR); | |
| 240 session_->config()->SetConnectionOptionsToSend(copt); | |
| 241 | |
| 242 // Doing the handshake should set up FEC config correctly. | |
| 243 CompleteCryptoHandshake(); | |
| 244 | |
| 245 // Verify that headers stream is always protected and data streams are | |
| 246 // optionally protected. | |
| 247 EXPECT_EQ( | |
| 248 FEC_PROTECT_ALWAYS, | |
| 249 QuicSpdySessionPeer::GetHeadersStream(session_.get())->fec_policy()); | |
| 250 QuicSpdyClientStream* stream = | |
| 251 session_->CreateOutgoingDynamicStream(kDefaultPriority); | |
| 252 ASSERT_TRUE(stream); | |
| 253 EXPECT_EQ(FEC_PROTECT_OPTIONAL, stream->fec_policy()); | |
| 254 } | |
| 255 | |
| 256 static bool CheckForDecryptionError(QuicFramer* framer) { | 236 static bool CheckForDecryptionError(QuicFramer* framer) { |
| 257 return framer->error() == QUIC_DECRYPTION_FAILURE; | 237 return framer->error() == QUIC_DECRYPTION_FAILURE; |
| 258 } | 238 } |
| 259 | 239 |
| 260 // Regression test for b/17206611. | 240 // Regression test for b/17206611. |
| 261 TEST_P(QuicClientSessionTest, InvalidPacketReceived) { | 241 TEST_P(QuicClientSessionTest, InvalidPacketReceived) { |
| 262 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); | 242 IPEndPoint server_address(TestPeerIPAddress(), kTestPort); |
| 263 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); | 243 IPEndPoint client_address(TestPeerIPAddress(), kTestPort); |
| 264 | 244 |
| 265 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) | 245 EXPECT_CALL(*connection_, ProcessUdpPacket(server_address, client_address, _)) |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 QuicClientPromisedInfo* promised = | 492 QuicClientPromisedInfo* promised = |
| 513 session_->GetPromisedById(promised_stream_id_); | 493 session_->GetPromisedById(promised_stream_id_); |
| 514 EXPECT_NE(promised, nullptr); | 494 EXPECT_NE(promised, nullptr); |
| 515 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); | 495 EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 516 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); | 496 EXPECT_EQ(session_->GetPromisedStream(promised_stream_id_), nullptr); |
| 517 } | 497 } |
| 518 | 498 |
| 519 } // namespace | 499 } // namespace |
| 520 } // namespace test | 500 } // namespace test |
| 521 } // namespace net | 501 } // namespace net |
| OLD | NEW |