blob: e1f32bb817da7acda1b2598c876b93af6b2e4461 [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_send_stream.h"
6
bnc3fc60df2019-07-17 11:55:10 -07007#include "net/third_party/quiche/src/quic/core/http/http_constants.h"
bnc8464f312019-06-21 11:43:07 -07008#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
renjietangbb2e22a2019-09-12 15:46:39 -07009#include "net/third_party/quiche/src/quic/test_tools/quic_config_peer.h"
renjietangd21094b2019-06-14 09:39:11 -070010#include "net/third_party/quiche/src/quic/test_tools/quic_spdy_session_peer.h"
11#include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h"
QUICHE team11f55d42019-12-11 10:36:09 -080012#include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h"
13#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
renjietangd21094b2019-06-14 09:39:11 -070014
15namespace quic {
16namespace test {
17
18namespace {
19using ::testing::_;
20using ::testing::Invoke;
21using ::testing::StrictMock;
22
23struct TestParams {
24 TestParams(const ParsedQuicVersion& version, Perspective perspective)
25 : version(version), perspective(perspective) {
26 QUIC_LOG(INFO) << "TestParams: version: "
27 << ParsedQuicVersionToString(version)
28 << ", perspective: " << perspective;
29 }
30
31 TestParams(const TestParams& other)
32 : version(other.version), perspective(other.perspective) {}
33
34 ParsedQuicVersion version;
35 Perspective perspective;
36};
37
dschinazi88bd5b02019-10-10 00:52:20 -070038// Used by ::testing::PrintToStringParamName().
39std::string PrintToString(const TestParams& tp) {
QUICHE team11f55d42019-12-11 10:36:09 -080040 return quiche::QuicheStrCat(
dschinazi88bd5b02019-10-10 00:52:20 -070041 ParsedQuicVersionToString(tp.version), "_",
42 (tp.perspective == Perspective::IS_CLIENT ? "client" : "server"));
43}
44
renjietangd21094b2019-06-14 09:39:11 -070045std::vector<TestParams> GetTestParams() {
46 std::vector<TestParams> params;
47 ParsedQuicVersionVector all_supported_versions = AllSupportedVersions();
48 for (const auto& version : AllSupportedVersions()) {
renjietanga29a96a2019-10-10 12:47:50 -070049 if (!VersionUsesHttp3(version.transport_version)) {
renjietangd21094b2019-06-14 09:39:11 -070050 continue;
51 }
52 for (Perspective p : {Perspective::IS_SERVER, Perspective::IS_CLIENT}) {
53 params.emplace_back(version, p);
54 }
55 }
56 return params;
57}
58
59class QpackSendStreamTest : public QuicTestWithParam<TestParams> {
60 public:
61 QpackSendStreamTest()
62 : connection_(new StrictMock<MockQuicConnection>(
63 &helper_,
64 &alarm_factory_,
65 perspective(),
66 SupportedVersions(GetParam().version))),
67 session_(connection_) {
68 session_.Initialize();
renjietangbb2e22a2019-09-12 15:46:39 -070069 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(
70 session_.config(), kMinimumFlowControlSendWindow);
dschinazi18cdf132019-10-09 16:08:18 -070071 QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesUnidirectional(
72 session_.config(), kMinimumFlowControlSendWindow);
renjietangbb2e22a2019-09-12 15:46:39 -070073 QuicConfigPeer::SetReceivedMaxIncomingUnidirectionalStreams(
74 session_.config(), 3);
75 session_.OnConfigNegotiated();
renjietang77dd8242019-08-09 13:00:42 -070076
renjietang578cf9f2019-08-23 11:57:52 -070077 qpack_send_stream_ =
78 QuicSpdySessionPeer::GetQpackDecoderSendStream(&session_);
renjietang77dd8242019-08-09 13:00:42 -070079
renjietangd21094b2019-06-14 09:39:11 -070080 ON_CALL(session_, WritevData(_, _, _, _, _))
81 .WillByDefault(Invoke(MockQuicSession::ConsumeData));
82 }
83
84 Perspective perspective() const { return GetParam().perspective; }
85
86 MockQuicConnectionHelper helper_;
87 MockAlarmFactory alarm_factory_;
88 StrictMock<MockQuicConnection>* connection_;
89 StrictMock<MockQuicSpdySession> session_;
renjietang77dd8242019-08-09 13:00:42 -070090 QpackSendStream* qpack_send_stream_;
renjietangd21094b2019-06-14 09:39:11 -070091};
92
93INSTANTIATE_TEST_SUITE_P(Tests,
94 QpackSendStreamTest,
dschinazi88bd5b02019-10-10 00:52:20 -070095 ::testing::ValuesIn(GetTestParams()),
96 ::testing::PrintToStringParamName());
renjietangd21094b2019-06-14 09:39:11 -070097
98TEST_P(QpackSendStreamTest, WriteStreamTypeOnlyFirstTime) {
renjietangd21094b2019-06-14 09:39:11 -070099 std::string data = "data";
100 EXPECT_CALL(session_, WritevData(_, _, 1, _, _));
101 EXPECT_CALL(session_, WritevData(_, _, data.length(), _, _));
QUICHE team11f55d42019-12-11 10:36:09 -0800102 qpack_send_stream_->WriteStreamData(quiche::QuicheStringPiece(data));
renjietangd21094b2019-06-14 09:39:11 -0700103
104 EXPECT_CALL(session_, WritevData(_, _, data.length(), _, _));
QUICHE team11f55d42019-12-11 10:36:09 -0800105 qpack_send_stream_->WriteStreamData(quiche::QuicheStringPiece(data));
renjietangd6f5afa2019-08-19 11:27:55 -0700106 EXPECT_CALL(session_, WritevData(_, _, _, _, _)).Times(0);
renjietangc8c02a52019-08-22 10:38:37 -0700107 qpack_send_stream_->MaybeSendStreamType();
renjietangd21094b2019-06-14 09:39:11 -0700108}
109
110TEST_P(QpackSendStreamTest, ResetQpackStream) {
111 QuicRstStreamFrame rst_frame(kInvalidControlFrameId, qpack_send_stream_->id(),
112 QUIC_STREAM_CANCELLED, 1234);
113 EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, _, _));
114 qpack_send_stream_->OnStreamReset(rst_frame);
115}
116
117TEST_P(QpackSendStreamTest, ReceiveDataOnSendStream) {
118 QuicStreamFrame frame(qpack_send_stream_->id(), false, 0, "test");
119 EXPECT_CALL(
120 *connection_,
121 CloseConnection(QUIC_DATA_RECEIVED_ON_WRITE_UNIDIRECTIONAL_STREAM, _, _));
122 qpack_send_stream_->OnStreamFrame(frame);
123}
124
125} // namespace
126} // namespace test
127} // namespace quic