Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: net/http2/hpack/decoder/hpack_block_collector.cc

Issue 2554683003: Revert of Add new HTTP/2 and HPACK decoder in net/http2/. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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/http2/hpack/decoder/hpack_block_collector.h"
6
7 #include <algorithm>
8 #include <memory>
9
10 #include "base/logging.h"
11 #include "net/http2/tools/failure.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using ::testing::AssertionResult;
15 using ::testing::AssertionSuccess;
16 using std::string;
17
18 using base::StringPiece;
19
20 namespace net {
21 namespace test {
22
23 HpackBlockCollector::HpackBlockCollector() {}
24 HpackBlockCollector::HpackBlockCollector(const HpackBlockCollector& other)
25 : pending_entry_(other.pending_entry_), entries_(other.entries_) {}
26 HpackBlockCollector::~HpackBlockCollector() {}
27
28 void HpackBlockCollector::OnIndexedHeader(size_t index) {
29 pending_entry_.OnIndexedHeader(index);
30 PushPendingEntry();
31 }
32 void HpackBlockCollector::OnDynamicTableSizeUpdate(size_t size) {
33 pending_entry_.OnDynamicTableSizeUpdate(size);
34 PushPendingEntry();
35 }
36 void HpackBlockCollector::OnStartLiteralHeader(HpackEntryType header_type,
37 size_t maybe_name_index) {
38 pending_entry_.OnStartLiteralHeader(header_type, maybe_name_index);
39 }
40 void HpackBlockCollector::OnNameStart(bool huffman_encoded, size_t len) {
41 pending_entry_.OnNameStart(huffman_encoded, len);
42 }
43 void HpackBlockCollector::OnNameData(const char* data, size_t len) {
44 pending_entry_.OnNameData(data, len);
45 }
46 void HpackBlockCollector::OnNameEnd() {
47 pending_entry_.OnNameEnd();
48 }
49 void HpackBlockCollector::OnValueStart(bool huffman_encoded, size_t len) {
50 pending_entry_.OnValueStart(huffman_encoded, len);
51 }
52 void HpackBlockCollector::OnValueData(const char* data, size_t len) {
53 pending_entry_.OnValueData(data, len);
54 }
55 void HpackBlockCollector::OnValueEnd() {
56 pending_entry_.OnValueEnd();
57 PushPendingEntry();
58 }
59
60 void HpackBlockCollector::PushPendingEntry() {
61 EXPECT_TRUE(pending_entry_.IsComplete());
62 DVLOG(2) << "PushPendingEntry: " << pending_entry_;
63 entries_.push_back(pending_entry_);
64 EXPECT_TRUE(entries_.back().IsComplete());
65 pending_entry_.Clear();
66 }
67 void HpackBlockCollector::Clear() {
68 pending_entry_.Clear();
69 entries_.clear();
70 }
71
72 void HpackBlockCollector::ExpectIndexedHeader(size_t index) {
73 entries_.push_back(
74 HpackEntryCollector(HpackEntryType::kIndexedHeader, index));
75 }
76 void HpackBlockCollector::ExpectDynamicTableSizeUpdate(size_t size) {
77 entries_.push_back(
78 HpackEntryCollector(HpackEntryType::kDynamicTableSizeUpdate, size));
79 }
80 void HpackBlockCollector::ExpectNameIndexAndLiteralValue(HpackEntryType type,
81 size_t index,
82 bool value_huffman,
83 const string& value) {
84 entries_.push_back(HpackEntryCollector(type, index, value_huffman, value));
85 }
86 void HpackBlockCollector::ExpectLiteralNameAndValue(HpackEntryType type,
87 bool name_huffman,
88 const string& name,
89 bool value_huffman,
90 const string& value) {
91 entries_.push_back(
92 HpackEntryCollector(type, name_huffman, name, value_huffman, value));
93 }
94
95 void HpackBlockCollector::ShuffleEntries(RandomBase* rng) {
96 std::random_shuffle(entries_.begin(), entries_.end());
97 }
98
99 void HpackBlockCollector::AppendToHpackBlockBuilder(
100 HpackBlockBuilder* hbb) const {
101 CHECK(IsNotPending());
102 for (const auto& entry : entries_) {
103 entry.AppendToHpackBlockBuilder(hbb);
104 }
105 }
106
107 AssertionResult HpackBlockCollector::ValidateSoleIndexedHeader(
108 size_t ndx) const {
109 VERIFY_TRUE(pending_entry_.IsClear());
110 VERIFY_EQ(1u, entries_.size());
111 VERIFY_TRUE(entries_.front().ValidateIndexedHeader(ndx));
112 return AssertionSuccess();
113 }
114 AssertionResult HpackBlockCollector::ValidateSoleLiteralValueHeader(
115 HpackEntryType expected_type,
116 size_t expected_index,
117 bool expected_value_huffman,
118 StringPiece expected_value) const {
119 VERIFY_TRUE(pending_entry_.IsClear());
120 VERIFY_EQ(1u, entries_.size());
121 VERIFY_TRUE(entries_.front().ValidateLiteralValueHeader(
122 expected_type, expected_index, expected_value_huffman, expected_value));
123 return AssertionSuccess();
124 }
125 AssertionResult HpackBlockCollector::ValidateSoleLiteralNameValueHeader(
126 HpackEntryType expected_type,
127 bool expected_name_huffman,
128 StringPiece expected_name,
129 bool expected_value_huffman,
130 StringPiece expected_value) const {
131 VERIFY_TRUE(pending_entry_.IsClear());
132 VERIFY_EQ(1u, entries_.size());
133 VERIFY_TRUE(entries_.front().ValidateLiteralNameValueHeader(
134 expected_type, expected_name_huffman, expected_name,
135 expected_value_huffman, expected_value));
136 return AssertionSuccess();
137 }
138 AssertionResult HpackBlockCollector::ValidateSoleDynamicTableSizeUpdate(
139 size_t size) const {
140 VERIFY_TRUE(pending_entry_.IsClear());
141 VERIFY_EQ(1u, entries_.size());
142 VERIFY_TRUE(entries_.front().ValidateDynamicTableSizeUpdate(size));
143 return AssertionSuccess();
144 }
145
146 AssertionResult HpackBlockCollector::VerifyEq(
147 const HpackBlockCollector& that) const {
148 VERIFY_EQ(pending_entry_, that.pending_entry_);
149 VERIFY_EQ(entries_, that.entries_);
150 return AssertionSuccess();
151 }
152
153 } // namespace test
154 } // namespace net
OLDNEW
« no previous file with comments | « net/http2/hpack/decoder/hpack_block_collector.h ('k') | net/http2/hpack/decoder/hpack_block_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698