blob: 121043fc57666e02ba1249e26f148757e5fe78f7 [file] [log] [blame]
renjietangd21094b2019-06-14 09:39:11 -07001// 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"
bnc8464f312019-06-21 11:43:07 -07008#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
renjietangd21094b2019-06-14 09:39:11 -07009#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
12namespace quic {
13namespace test {
14
15namespace {
16using ::testing::_;
17using ::testing::StrictMock;
18
19struct 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
34std::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
48class 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();
nharper4eba09b2019-06-26 20:17:25 -070058 PendingStream* pending =
59 new PendingStream(QuicUtils::GetFirstUnidirectionalStreamId(
60 GetParam().version.transport_version,
61 QuicUtils::InvertPerspective(perspective())),
62 &session_);
renjietangd21094b2019-06-14 09:39:11 -070063 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
76INSTANTIATE_TEST_SUITE_P(Tests,
77 QpackReceiveStreamTest,
78 ::testing::ValuesIn(GetTestParams()));
79
80TEST_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