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_send_stream.h" |
| 6 | |
bnc | 3fc60df | 2019-07-17 11:55:10 -0700 | [diff] [blame] | 7 | #include "net/third_party/quiche/src/quic/core/http/http_constants.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 | bb2e22a | 2019-09-12 15:46:39 -0700 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/test_tools/quic_config_peer.h" |
fayang | 6a25841 | 2020-05-28 08:57:12 -0700 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/test_tools/quic_connection_peer.h" |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/test_tools/quic_spdy_session_peer.h" |
| 12 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
| 14 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 15 | |
| 16 | namespace quic { |
| 17 | namespace test { |
| 18 | |
| 19 | namespace { |
| 20 | using ::testing::_; |
wub | 8eea919 | 2020-08-13 12:05:40 -0700 | [diff] [blame] | 21 | using ::testing::AnyNumber; |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 22 | using ::testing::Invoke; |
| 23 | using ::testing::StrictMock; |
| 24 | |
| 25 | struct TestParams { |
| 26 | TestParams(const ParsedQuicVersion& version, Perspective perspective) |
| 27 | : version(version), perspective(perspective) { |
| 28 | QUIC_LOG(INFO) << "TestParams: version: " |
| 29 | << ParsedQuicVersionToString(version) |
| 30 | << ", perspective: " << perspective; |
| 31 | } |
| 32 | |
| 33 | TestParams(const TestParams& other) |
| 34 | : version(other.version), perspective(other.perspective) {} |
| 35 | |
| 36 | ParsedQuicVersion version; |
| 37 | Perspective perspective; |
| 38 | }; |
| 39 | |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 40 | // Used by ::testing::PrintToStringParamName(). |
| 41 | std::string PrintToString(const TestParams& tp) { |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 42 | return quiche::QuicheStrCat( |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 43 | ParsedQuicVersionToString(tp.version), "_", |
| 44 | (tp.perspective == Perspective::IS_CLIENT ? "client" : "server")); |
| 45 | } |
| 46 | |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 47 | std::vector<TestParams> GetTestParams() { |
| 48 | std::vector<TestParams> params; |
| 49 | ParsedQuicVersionVector all_supported_versions = AllSupportedVersions(); |
| 50 | for (const auto& version : AllSupportedVersions()) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 51 | if (!VersionUsesHttp3(version.transport_version)) { |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 52 | continue; |
| 53 | } |
| 54 | for (Perspective p : {Perspective::IS_SERVER, Perspective::IS_CLIENT}) { |
| 55 | params.emplace_back(version, p); |
| 56 | } |
| 57 | } |
| 58 | return params; |
| 59 | } |
| 60 | |
| 61 | class QpackSendStreamTest : public QuicTestWithParam<TestParams> { |
| 62 | public: |
| 63 | QpackSendStreamTest() |
| 64 | : connection_(new StrictMock<MockQuicConnection>( |
| 65 | &helper_, |
| 66 | &alarm_factory_, |
| 67 | perspective(), |
| 68 | SupportedVersions(GetParam().version))), |
| 69 | session_(connection_) { |
wub | 8eea919 | 2020-08-13 12:05:40 -0700 | [diff] [blame] | 70 | EXPECT_CALL(session_, OnCongestionWindowChange(_)).Times(AnyNumber()); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 71 | session_.Initialize(); |
fayang | 6a25841 | 2020-05-28 08:57:12 -0700 | [diff] [blame] | 72 | if (connection_->version().SupportsAntiAmplificationLimit()) { |
| 73 | QuicConnectionPeer::SetAddressValidated(connection_); |
| 74 | } |
renjietang | bb2e22a | 2019-09-12 15:46:39 -0700 | [diff] [blame] | 75 | QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow( |
| 76 | session_.config(), kMinimumFlowControlSendWindow); |
dschinazi | 18cdf13 | 2019-10-09 16:08:18 -0700 | [diff] [blame] | 77 | QuicConfigPeer::SetReceivedInitialMaxStreamDataBytesUnidirectional( |
| 78 | session_.config(), kMinimumFlowControlSendWindow); |
renjietang | e6d9467 | 2020-01-07 10:30:10 -0800 | [diff] [blame] | 79 | QuicConfigPeer::SetReceivedMaxUnidirectionalStreams(session_.config(), 3); |
renjietang | bb2e22a | 2019-09-12 15:46:39 -0700 | [diff] [blame] | 80 | session_.OnConfigNegotiated(); |
renjietang | 77dd824 | 2019-08-09 13:00:42 -0700 | [diff] [blame] | 81 | |
renjietang | 578cf9f | 2019-08-23 11:57:52 -0700 | [diff] [blame] | 82 | qpack_send_stream_ = |
| 83 | QuicSpdySessionPeer::GetQpackDecoderSendStream(&session_); |
renjietang | 77dd824 | 2019-08-09 13:00:42 -0700 | [diff] [blame] | 84 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame] | 85 | ON_CALL(session_, WritevData(_, _, _, _, _, _)) |
renjietang | 7c23917 | 2020-02-21 13:50:39 -0800 | [diff] [blame] | 86 | .WillByDefault(Invoke(&session_, &MockQuicSpdySession::ConsumeData)); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | Perspective perspective() const { return GetParam().perspective; } |
| 90 | |
| 91 | MockQuicConnectionHelper helper_; |
| 92 | MockAlarmFactory alarm_factory_; |
| 93 | StrictMock<MockQuicConnection>* connection_; |
| 94 | StrictMock<MockQuicSpdySession> session_; |
renjietang | 77dd824 | 2019-08-09 13:00:42 -0700 | [diff] [blame] | 95 | QpackSendStream* qpack_send_stream_; |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | INSTANTIATE_TEST_SUITE_P(Tests, |
| 99 | QpackSendStreamTest, |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 100 | ::testing::ValuesIn(GetTestParams()), |
| 101 | ::testing::PrintToStringParamName()); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 102 | |
| 103 | TEST_P(QpackSendStreamTest, WriteStreamTypeOnlyFirstTime) { |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 104 | std::string data = "data"; |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame] | 105 | EXPECT_CALL(session_, WritevData(_, 1, _, _, _, _)); |
| 106 | EXPECT_CALL(session_, WritevData(_, data.length(), _, _, _, _)); |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 107 | qpack_send_stream_->WriteStreamData(quiche::QuicheStringPiece(data)); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 108 | |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame] | 109 | EXPECT_CALL(session_, WritevData(_, data.length(), _, _, _, _)); |
QUICHE team | 11f55d4 | 2019-12-11 10:36:09 -0800 | [diff] [blame] | 110 | qpack_send_stream_->WriteStreamData(quiche::QuicheStringPiece(data)); |
renjietang | 41a1b41 | 2020-02-27 15:05:14 -0800 | [diff] [blame] | 111 | EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)).Times(0); |
renjietang | c8c02a5 | 2019-08-22 10:38:37 -0700 | [diff] [blame] | 112 | qpack_send_stream_->MaybeSendStreamType(); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 113 | } |
| 114 | |
bnc | 09c1eda | 2020-03-13 04:52:38 -0700 | [diff] [blame] | 115 | TEST_P(QpackSendStreamTest, StopSendingQpackStream) { |
| 116 | EXPECT_CALL(*connection_, |
| 117 | CloseConnection(QUIC_HTTP_CLOSED_CRITICAL_STREAM, _, _)); |
| 118 | qpack_send_stream_->OnStopSending(QUIC_STREAM_CANCELLED); |
renjietang | d21094b | 2019-06-14 09:39:11 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | TEST_P(QpackSendStreamTest, ReceiveDataOnSendStream) { |
| 122 | QuicStreamFrame frame(qpack_send_stream_->id(), false, 0, "test"); |
| 123 | EXPECT_CALL( |
| 124 | *connection_, |
| 125 | CloseConnection(QUIC_DATA_RECEIVED_ON_WRITE_UNIDIRECTIONAL_STREAM, _, _)); |
| 126 | qpack_send_stream_->OnStreamFrame(frame); |
| 127 | } |
| 128 | |
| 129 | } // namespace |
| 130 | } // namespace test |
| 131 | } // namespace quic |