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

Unified Diff: net/spdy/hpack_encoding_context_test.cc

Issue 138243003: Implement basic classes for HPACK (HTTP/2 compression) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding license to new HPACK sources. Created 6 years, 11 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_encoding_context.cc ('k') | net/spdy/hpack_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/spdy/hpack_encoding_context_test.cc
diff --git a/net/spdy/hpack_encoding_context_test.cc b/net/spdy/hpack_encoding_context_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7face78817d9d414d7faec4144bb0a620365083c
--- /dev/null
+++ b/net/spdy/hpack_encoding_context_test.cc
@@ -0,0 +1,125 @@
+// Copyright (c) 2014 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/spdy/hpack_encoding_context.h"
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace {
+
+// Try to process an indexed header with an invalid index. That should
+// fail.
+TEST(HpackEncodingContextTest, IndexedHeaderInvalid) {
+ HpackEncodingContext encoding_context;
+
+ int32 new_index = -1;
+ std::vector<uint32> removed_referenced_indices;
+ EXPECT_FALSE(
+ encoding_context.ProcessIndexedHeader(kuint32max,
+ &new_index,
+ &removed_referenced_indices));
+}
+
+// Try to process an indexed header with an index for a static
+// header. That should succeed and add a mutable copy into the header
+// table.
+TEST(HpackEncodingContextTest, IndexedHeaderStatic) {
+ HpackEncodingContext encoding_context;
+
+ std::string name = encoding_context.GetNameAt(1).as_string();
+ std::string value = encoding_context.GetValueAt(1).as_string();
+ EXPECT_NE(name, encoding_context.GetNameAt(0));
+ EXPECT_NE(value, encoding_context.GetValueAt(0));
+
+ {
+ int32 new_index = -1;
+ std::vector<uint32> removed_referenced_indices;
+ EXPECT_TRUE(
+ encoding_context.ProcessIndexedHeader(1,
+ &new_index,
+ &removed_referenced_indices));
+ EXPECT_EQ(0, new_index);
+ EXPECT_TRUE(removed_referenced_indices.empty());
+ }
+ EXPECT_EQ(name, encoding_context.GetNameAt(0));
+ EXPECT_EQ(value, encoding_context.GetValueAt(0));
+ EXPECT_TRUE(encoding_context.IsReferencedAt(0));
+
+ {
+ int32 new_index = -1;
+ std::vector<uint32> removed_referenced_indices;
+ EXPECT_TRUE(
+ encoding_context.ProcessIndexedHeader(0,
+ &new_index,
+ &removed_referenced_indices));
+ EXPECT_EQ(0, new_index);
+ EXPECT_TRUE(removed_referenced_indices.empty());
+ }
+ EXPECT_EQ(name, encoding_context.GetNameAt(0));
+ EXPECT_EQ(value, encoding_context.GetValueAt(0));
+ EXPECT_FALSE(encoding_context.IsReferencedAt(0));
+}
+
+// Try to process an indexed header with an index for a static header
+// and an encoding context where a copy of that header wouldn't
+// fit. That should succeed without making a copy.
+TEST(HpackEncodingContextTest, IndexedHeaderStaticCopyDoesNotFit) {
+ HpackEncodingContext encoding_context;
+ encoding_context.SetMaxSize(0);
+
+ int32 new_index = -1;
+ std::vector<uint32> removed_referenced_indices;
+ EXPECT_TRUE(
+ encoding_context.ProcessIndexedHeader(1,
+ &new_index,
+ &removed_referenced_indices));
+ EXPECT_EQ(-1, new_index);
+ EXPECT_TRUE(removed_referenced_indices.empty());
+}
+
+// NOTE: It's too onerous to try to test invalid input to
+// ProcessLiteralHeaderWithIncrementalIndexing(); that would require
+// making a really large (>4GB of memory) string.
+
+// Try to process a reasonably-sized literal header with incremental
+// indexing. It should succeed.
+TEST(HpackEncodingContextTest, LiteralHeaderIncrementalIndexing) {
+ HpackEncodingContext encoding_context;
+
+ int32 index = -1;
+ std::vector<uint32> removed_referenced_indices;
+ EXPECT_TRUE(
+ encoding_context.ProcessLiteralHeaderWithIncrementalIndexing(
+ "name", "value", &index, &removed_referenced_indices));
+ EXPECT_EQ(0, index);
+ EXPECT_TRUE(removed_referenced_indices.empty());
+ EXPECT_EQ("name", encoding_context.GetNameAt(0).as_string());
+ EXPECT_EQ("value", encoding_context.GetValueAt(0).as_string());
+ EXPECT_TRUE(encoding_context.IsReferencedAt(0));
+}
+
+// Try to process a literal header with incremental indexing that is
+// too large for the header table. It should succeed without indexing
+// into the table.
+TEST(HpackEncodingContextTest, LiteralHeaderIncrementalIndexingDoesNotFit) {
+ HpackEncodingContext encoding_context;
+ encoding_context.SetMaxSize(0);
+
+ int32 index = -1;
+ std::vector<uint32> removed_referenced_indices;
+ EXPECT_TRUE(
+ encoding_context.ProcessLiteralHeaderWithIncrementalIndexing(
+ "name", "value", &index, &removed_referenced_indices));
+ EXPECT_EQ(-1, index);
+ EXPECT_TRUE(removed_referenced_indices.empty());
+}
+
+} // namespace
+
+} // namespace net
« no previous file with comments | « net/spdy/hpack_encoding_context.cc ('k') | net/spdy/hpack_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698