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 | 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::Invoke; |
| 18 | using ::testing::StrictMock; |
| 19 | |
| 20 | struct TestParams { |
| 21 | TestParams(const ParsedQuicVersion& version, Perspective perspective) |
| 22 | : version(version), perspective(perspective) { |
| 23 | QUIC_LOG(INFO) << "TestParams: version: " |
| 24 | << ParsedQuicVersionToString(version) |
| 25 | << ", perspective: " << perspective; |
| 26 | } |
| 27 | |
| 28 | TestParams(const TestParams& other) |
| 29 | : version(other.version), perspective(other.perspective) {} |
| 30 | |
| 31 | ParsedQuicVersion version; |
| 32 | Perspective perspective; |
| 33 | }; |
| 34 | |
| 35 | std::vector<TestParams> GetTestParams() { |
| 36 | std::vector<TestParams> params; |
| 37 | ParsedQuicVersionVector all_supported_versions = AllSupportedVersions(); |
| 38 | for (const auto& version : AllSupportedVersions()) { |
| 39 | if (!VersionHasStreamType(version.transport_version)) { |
| 40 | continue; |
| 41 | } |
| 42 | for (Perspective p : {Perspective::IS_SERVER, Perspective::IS_CLIENT}) { |
| 43 | params.emplace_back(version, p); |
| 44 | } |
| 45 | } |
| 46 | return params; |
| 47 | } |
| 48 | |
| 49 | class QpackSendStreamTest : public QuicTestWithParam<TestParams> { |
| 50 | public: |
| 51 | QpackSendStreamTest() |
| 52 | : connection_(new StrictMock<MockQuicConnection>( |
| 53 | &helper_, |
| 54 | &alarm_factory_, |
| 55 | perspective(), |
| 56 | SupportedVersions(GetParam().version))), |
| 57 | session_(connection_) { |
| 58 | session_.Initialize(); |
| 59 | qpack_send_stream_ = QuicMakeUnique<QpackSendStream>( |
| 60 | QuicSpdySessionPeer::GetNextOutgoingUnidirectionalStreamId(&session_), |
| 61 | &session_, kQpackEncoderStream); |
| 62 | ON_CALL(session_, WritevData(_, _, _, _, _)) |
| 63 | .WillByDefault(Invoke(MockQuicSession::ConsumeData)); |
| 64 | } |
| 65 | |
| 66 | Perspective perspective() const { return GetParam().perspective; } |
| 67 | |
| 68 | MockQuicConnectionHelper helper_; |
| 69 | MockAlarmFactory alarm_factory_; |
| 70 | StrictMock<MockQuicConnection>* connection_; |
| 71 | StrictMock<MockQuicSpdySession> session_; |
| 72 | std::unique_ptr<QpackSendStream> qpack_send_stream_; |
| 73 | }; |
| 74 | |
| 75 | INSTANTIATE_TEST_SUITE_P(Tests, |
| 76 | QpackSendStreamTest, |
| 77 | ::testing::ValuesIn(GetTestParams())); |
| 78 | |
| 79 | TEST_P(QpackSendStreamTest, WriteStreamTypeOnlyFirstTime) { |
| 80 | if (GetParam().version.handshake_protocol == PROTOCOL_TLS1_3) { |
| 81 | // TODO(nharper, b/112643533): Figure out why this test fails when TLS is |
| 82 | // enabled and fix it. |
| 83 | return; |
| 84 | } |
| 85 | std::string data = "data"; |
| 86 | EXPECT_CALL(session_, WritevData(_, _, 1, _, _)); |
| 87 | EXPECT_CALL(session_, WritevData(_, _, data.length(), _, _)); |
| 88 | qpack_send_stream_->WriteStreamData(QuicStringPiece(data)); |
| 89 | |
| 90 | EXPECT_CALL(session_, WritevData(_, _, data.length(), _, _)); |
| 91 | qpack_send_stream_->WriteStreamData(QuicStringPiece(data)); |
| 92 | } |
| 93 | |
| 94 | TEST_P(QpackSendStreamTest, ResetQpackStream) { |
| 95 | QuicRstStreamFrame rst_frame(kInvalidControlFrameId, qpack_send_stream_->id(), |
| 96 | QUIC_STREAM_CANCELLED, 1234); |
| 97 | EXPECT_CALL(*connection_, CloseConnection(QUIC_INVALID_STREAM_ID, _, _)); |
| 98 | qpack_send_stream_->OnStreamReset(rst_frame); |
| 99 | } |
| 100 | |
| 101 | TEST_P(QpackSendStreamTest, ReceiveDataOnSendStream) { |
| 102 | QuicStreamFrame frame(qpack_send_stream_->id(), false, 0, "test"); |
| 103 | EXPECT_CALL( |
| 104 | *connection_, |
| 105 | CloseConnection(QUIC_DATA_RECEIVED_ON_WRITE_UNIDIRECTIONAL_STREAM, _, _)); |
| 106 | qpack_send_stream_->OnStreamFrame(frame); |
| 107 | } |
| 108 | |
| 109 | } // namespace |
| 110 | } // namespace test |
| 111 | } // namespace quic |