renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_receive_stream.h" |
| 6 | |
| 7 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
bnc | 8464f31 | 2019-06-21 11:43:07 -0700 | [diff] [blame] | 8 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/test_tools/quic_spdy_session_peer.h" |
| 10 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | namespace test { |
| 14 | |
| 15 | namespace { |
| 16 | using ::testing::_; |
| 17 | using ::testing::StrictMock; |
| 18 | |
| 19 | struct TestParams { |
| 20 | TestParams(const ParsedQuicVersion& version, Perspective perspective) |
| 21 | : version(version), perspective(perspective) { |
| 22 | QUIC_LOG(INFO) << "TestParams: version: " |
| 23 | << ParsedQuicVersionToString(version) |
| 24 | << ", perspective: " << perspective; |
| 25 | } |
| 26 | |
| 27 | TestParams(const TestParams& other) |
| 28 | : version(other.version), perspective(other.perspective) {} |
| 29 | |
| 30 | ParsedQuicVersion version; |
| 31 | Perspective perspective; |
| 32 | }; |
| 33 | |
| 34 | std::vector<TestParams> GetTestParams() { |
| 35 | std::vector<TestParams> params; |
| 36 | ParsedQuicVersionVector all_supported_versions = AllSupportedVersions(); |
| 37 | for (const auto& version : AllSupportedVersions()) { |
| 38 | if (!VersionHasStreamType(version.transport_version)) { |
| 39 | continue; |
| 40 | } |
| 41 | for (Perspective p : {Perspective::IS_SERVER, Perspective::IS_CLIENT}) { |
| 42 | params.emplace_back(version, p); |
| 43 | } |
| 44 | } |
| 45 | return params; |
| 46 | } |
| 47 | |
| 48 | class QpackReceiveStreamTest : public QuicTestWithParam<TestParams> { |
| 49 | public: |
| 50 | QpackReceiveStreamTest() |
| 51 | : connection_(new StrictMock<MockQuicConnection>( |
| 52 | &helper_, |
| 53 | &alarm_factory_, |
| 54 | perspective(), |
| 55 | SupportedVersions(GetParam().version))), |
| 56 | session_(connection_) { |
| 57 | session_.Initialize(); |
nharper | 4eba09b | 2019-06-26 20:17:25 -0700 | [diff] [blame] | 58 | PendingStream* pending = |
| 59 | new PendingStream(QuicUtils::GetFirstUnidirectionalStreamId( |
| 60 | GetParam().version.transport_version, |
| 61 | QuicUtils::InvertPerspective(perspective())), |
| 62 | &session_); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 63 | qpack_receive_stream_ = QuicMakeUnique<QpackReceiveStream>(pending); |
| 64 | delete pending; |
| 65 | } |
| 66 | |
| 67 | Perspective perspective() const { return GetParam().perspective; } |
| 68 | |
| 69 | MockQuicConnectionHelper helper_; |
| 70 | MockAlarmFactory alarm_factory_; |
| 71 | StrictMock<MockQuicConnection>* connection_; |
| 72 | StrictMock<MockQuicSpdySession> session_; |
| 73 | std::unique_ptr<QpackReceiveStream> qpack_receive_stream_; |
| 74 | }; |
| 75 | |
| 76 | INSTANTIATE_TEST_SUITE_P(Tests, |
| 77 | QpackReceiveStreamTest, |
| 78 | ::testing::ValuesIn(GetTestParams())); |
| 79 | |
| 80 | TEST_P(QpackReceiveStreamTest, ResetQpackReceiveStream) { |
| 81 | EXPECT_TRUE(qpack_receive_stream_->is_static()); |
| 82 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, |
| 83 | qpack_receive_stream_->id(), |
| 84 | QUIC_STREAM_CANCELLED, 1234); |
| 85 | EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, _, _)); |
| 86 | qpack_receive_stream_->OnStreamReset(rst_frame); |
| 87 | } |
| 88 | |
| 89 | } // namespace |
| 90 | } // namespace test |
| 91 | } // namespace quic |