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

Unified Diff: net/spdy/hpack/hpack_encoder_test.cc

Issue 2237113005: Adds a listener interface to HpackEncoder. Not used in production. Not protected. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Comments Created 4 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/spdy/hpack/hpack_encoder.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/hpack/hpack_encoder_test.cc
diff --git a/net/spdy/hpack/hpack_encoder_test.cc b/net/spdy/hpack/hpack_encoder_test.cc
index 10fd6087da0e92d65ad290ce7f27a7f3992d5d69..c18ad15304c413cab897f117886674d01890cf9a 100644
--- a/net/spdy/hpack/hpack_encoder_test.cc
+++ b/net/spdy/hpack/hpack_encoder_test.cc
@@ -7,6 +7,7 @@
#include <map>
#include <string>
+#include "net/base/arena.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,6 +15,8 @@ namespace net {
using base::StringPiece;
using std::string;
+using std::vector;
+using std::pair;
using testing::ElementsAre;
namespace test {
@@ -76,6 +79,7 @@ namespace {
using std::map;
using testing::ElementsAre;
+using testing::Pair;
class HpackEncoderTest : public ::testing::Test {
protected:
@@ -84,7 +88,8 @@ class HpackEncoderTest : public ::testing::Test {
HpackEncoderTest()
: encoder_(ObtainHpackHuffmanTable()),
peer_(&encoder_),
- static_(peer_.table()->GetByIndex(1)) {}
+ static_(peer_.table()->GetByIndex(1)),
+ headers_storage_(1024 /* block size */) {}
void SetUp() override {
// Populate dynamic entries into the table fixture. For simplicity each
@@ -101,6 +106,14 @@ class HpackEncoderTest : public ::testing::Test {
peer_.set_allow_huffman_compression(false);
}
+ void SaveHeaders(StringPiece name, StringPiece value) {
+ StringPiece n(headers_storage_.Memdup(name.data(), name.size()),
+ name.size());
+ StringPiece v(headers_storage_.Memdup(value.data(), value.size()),
+ value.size());
+ headers_observed_.push_back(make_pair(n, v));
+ }
+
void ExpectIndex(size_t index) {
expected_.AppendPrefix(kIndexedOpcode);
expected_.AppendUint32(index);
@@ -155,15 +168,24 @@ class HpackEncoderTest : public ::testing::Test {
const HpackEntry* cookie_a_;
const HpackEntry* cookie_c_;
+ UnsafeArena headers_storage_;
+ vector<pair<StringPiece, StringPiece>> headers_observed_;
+
HpackOutputStream expected_;
};
TEST_F(HpackEncoderTest, SingleDynamicIndex) {
+ encoder_.SetHeaderListener([this](StringPiece name, StringPiece value) {
+ this->SaveHeaders(name, value);
+ });
+
ExpectIndex(IndexOf(key_2_));
SpdyHeaderBlock headers;
headers[key_2_->name().as_string()] = key_2_->value().as_string();
CompareWithExpectedEncoding(headers);
+ EXPECT_THAT(headers_observed_,
+ ElementsAre(Pair(key_2_->name(), key_2_->value())));
}
TEST_F(HpackEncoderTest, SingleStaticIndex) {
@@ -268,6 +290,10 @@ TEST_F(HpackEncoderTest, StringsDynamicallySelectHuffmanCoding) {
}
TEST_F(HpackEncoderTest, EncodingWithoutCompression) {
+ encoder_.SetHeaderListener([this](StringPiece name, StringPiece value) {
+ this->SaveHeaders(name, value);
+ });
+
// Implementation should internally disable.
peer_.set_allow_huffman_compression(true);
@@ -284,9 +310,18 @@ TEST_F(HpackEncoderTest, EncodingWithoutCompression) {
expected_.TakeString(&expected_out);
encoder_.EncodeHeaderSetWithoutCompression(headers, &actual_out);
EXPECT_EQ(expected_out, actual_out);
+
+ EXPECT_THAT(headers_observed_,
+ ElementsAre(Pair(":path", "/index.html"),
+ Pair("cookie", "foo=bar; baz=bing"),
+ Pair("hello", "goodbye")));
}
TEST_F(HpackEncoderTest, MultipleEncodingPasses) {
+ encoder_.SetHeaderListener([this](StringPiece name, StringPiece value) {
+ this->SaveHeaders(name, value);
+ });
+
// Pass 1.
{
SpdyHeaderBlock headers;
@@ -339,6 +374,19 @@ TEST_F(HpackEncoderTest, MultipleEncodingPasses) {
CompareWithExpectedEncoding(headers);
}
+
+ // clang-format off
+ EXPECT_THAT(headers_observed_,
+ ElementsAre(Pair("key1", "value1"),
+ Pair("cookie", "a=bb"),
+ Pair("key2", "value2"),
+ Pair("cookie", "c=dd"),
+ Pair("cookie", "e=ff"),
+ Pair("key2", "value2"),
+ Pair("cookie", "a=bb"),
+ Pair("cookie", "b=cc"),
+ Pair("cookie", "c=dd")));
+ // clang-format on
}
TEST_F(HpackEncoderTest, PseudoHeadersFirst) {
« no previous file with comments | « net/spdy/hpack/hpack_encoder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698