blob: c77a6218bcadad6edf7b0838492835c35163eab5 [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);
renjietange6d94672020-01-07 10:30:10 -080073 QuicConfigPeer::SetReceivedMaxUnidirectionalStreams(session_.config(), 3);
renjietangbb2e22a2019-09-12 15:46:39 -070074 session_.OnConfigNegotiated();
renjietang77dd8242019-08-09 13:00:42 -070075
renjietang578cf9f2019-08-23 11:57:52 -070076 qpack_send_stream_ =
77 QuicSpdySessionPeer::GetQpackDecoderSendStream(&session_);
renjietang77dd8242019-08-09 13:00:42 -070078
renjietang41a1b412020-02-27 15:05:14 -080079 ON_CALL(session_, WritevData(_, _, _, _, _, _))
renjietang7c239172020-02-21 13:50:39 -080080 .WillByDefault(Invoke(&session_, &MockQuicSpdySession::ConsumeData));
renjietangd21094b2019-06-14 09:39:11 -070081 }
82
83 Perspective perspective() const { return GetParam().perspective; }
84
85 MockQuicConnectionHelper helper_;
86 MockAlarmFactory alarm_factory_;
87 StrictMock<MockQuicConnection>* connection_;
88 StrictMock<MockQuicSpdySession> session_;
renjietang77dd8242019-08-09 13:00:42 -070089 QpackSendStream* qpack_send_stream_;
renjietangd21094b2019-06-14 09:39:11 -070090};
91
92INSTANTIATE_TEST_SUITE_P(Tests,
93 QpackSendStreamTest,
dschinazi88bd5b02019-10-10 00:52:20 -070094 ::testing::ValuesIn(GetTestParams()),
95 ::testing::PrintToStringParamName());
renjietangd21094b2019-06-14 09:39:11 -070096
97TEST_P(QpackSendStreamTest, WriteStreamTypeOnlyFirstTime) {
renjietangd21094b2019-06-14 09:39:11 -070098 std::string data = "data";
renjietang41a1b412020-02-27 15:05:14 -080099 EXPECT_CALL(session_, WritevData(_, 1, _, _, _, _));
100 EXPECT_CALL(session_, WritevData(_, data.length(), _, _, _, _));
QUICHE team11f55d42019-12-11 10:36:09 -0800101 qpack_send_stream_->WriteStreamData(quiche::QuicheStringPiece(data));
renjietangd21094b2019-06-14 09:39:11 -0700102
renjietang41a1b412020-02-27 15:05:14 -0800103 EXPECT_CALL(session_, WritevData(_, data.length(), _, _, _, _));
QUICHE team11f55d42019-12-11 10:36:09 -0800104 qpack_send_stream_->WriteStreamData(quiche::QuicheStringPiece(data));
renjietang41a1b412020-02-27 15:05:14 -0800105 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(0);
renjietangc8c02a52019-08-22 10:38:37 -0700106 qpack_send_stream_->MaybeSendStreamType();
renjietangd21094b2019-06-14 09:39:11 -0700107}
108
bnc09c1eda2020-03-13 04:52:38 -0700109TEST_P(QpackSendStreamTest, StopSendingQpackStream) {
110 EXPECT_CALL(*connection_,
111 CloseConnection(QUIC_HTTP_CLOSED_CRITICAL_STREAM, _, _));
112 qpack_send_stream_->OnStopSending(QUIC_STREAM_CANCELLED);
renjietangd21094b2019-06-14 09:39:11 -0700113}
114
115TEST_P(QpackSendStreamTest, ReceiveDataOnSendStream) {
116 QuicStreamFrame frame(qpack_send_stream_->id(), false, 0, "test");
117 EXPECT_CALL(
118 *connection_,
119 CloseConnection(QUIC_DATA_RECEIVED_ON_WRITE_UNIDIRECTIONAL_STREAM, _, _));
120 qpack_send_stream_->OnStreamFrame(frame);
121}
122
123} // namespace
124} // namespace test
125} // namespace quic