summaryrefslogtreecommitdiff
path: root/chromium/net/third_party/quiche/src/quic/core/qpack/qpack_decoder_stream_sender_test.cc
blob: cc957591083482ac8178e2bc7d2c999732741f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/third_party/quiche/src/quic/core/qpack/qpack_decoder_stream_sender.h"

#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_text_utils.h"

using ::testing::Eq;
using ::testing::StrictMock;

namespace quic {
namespace test {
namespace {

class MockSenderDelegate : public QpackDecoderStreamSender::Delegate {
 public:
  ~MockSenderDelegate() override = default;

  MOCK_METHOD1(WriteDecoderStreamData, void(QuicStringPiece data));
};

class QpackDecoderStreamSenderTest : public QuicTest {
 protected:
  QpackDecoderStreamSenderTest() : stream_(&delegate_) {}
  ~QpackDecoderStreamSenderTest() override = default;

  StrictMock<MockSenderDelegate> delegate_;
  QpackDecoderStreamSender stream_;
};

TEST_F(QpackDecoderStreamSenderTest, InsertCountIncrement) {
  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("00"))));
  stream_.SendInsertCountIncrement(0);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("0a"))));
  stream_.SendInsertCountIncrement(10);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("3f00"))));
  stream_.SendInsertCountIncrement(63);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("3f8901"))));
  stream_.SendInsertCountIncrement(200);
}

TEST_F(QpackDecoderStreamSenderTest, HeaderAcknowledgement) {
  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("80"))));
  stream_.SendHeaderAcknowledgement(0);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("a5"))));
  stream_.SendHeaderAcknowledgement(37);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("ff00"))));
  stream_.SendHeaderAcknowledgement(127);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("fff802"))));
  stream_.SendHeaderAcknowledgement(503);
}

TEST_F(QpackDecoderStreamSenderTest, StreamCancellation) {
  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("40"))));
  stream_.SendStreamCancellation(0);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("53"))));
  stream_.SendStreamCancellation(19);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("7f00"))));
  stream_.SendStreamCancellation(63);

  EXPECT_CALL(delegate_,
              WriteDecoderStreamData(Eq(QuicTextUtils::HexDecode("7f2f"))));
  stream_.SendStreamCancellation(110);
}

}  // namespace
}  // namespace test
}  // namespace quic