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

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: And removing tabs from net.gyp... 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
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..9a8b6bbbf995d1816155803a5107ec798896251e
--- /dev/null
+++ b/net/spdy/hpack_encoding_context_test.cc
@@ -0,0 +1,121 @@
+#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

Powered by Google App Engine
This is Rietveld 408576698