1 // Copyright 2014 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.
5 #include "net/spdy/hpack_encoding_context.h"
9 #include "base/basictypes.h"
10 #include "testing/gtest/include/gtest/gtest.h"
16 // Try to process an indexed header with an invalid index. That should
18 TEST(HpackEncodingContextTest, IndexedHeaderInvalid) {
19 HpackEncodingContext encoding_context;
22 std::vector<uint32> removed_referenced_indices;
24 encoding_context.ProcessIndexedHeader(kuint32max,
26 &removed_referenced_indices));
29 // Try to process an indexed header with an index for a static
30 // header. That should succeed and add a mutable copy into the header
32 TEST(HpackEncodingContextTest, IndexedHeaderStatic) {
33 HpackEncodingContext encoding_context;
35 std::string name = encoding_context.GetNameAt(1).as_string();
36 std::string value = encoding_context.GetValueAt(1).as_string();
37 EXPECT_NE(name, encoding_context.GetNameAt(0));
38 EXPECT_NE(value, encoding_context.GetValueAt(0));
42 std::vector<uint32> removed_referenced_indices;
44 encoding_context.ProcessIndexedHeader(1,
46 &removed_referenced_indices));
47 EXPECT_EQ(0, new_index);
48 EXPECT_TRUE(removed_referenced_indices.empty());
50 EXPECT_EQ(name, encoding_context.GetNameAt(0));
51 EXPECT_EQ(value, encoding_context.GetValueAt(0));
52 EXPECT_TRUE(encoding_context.IsReferencedAt(0));
56 std::vector<uint32> removed_referenced_indices;
58 encoding_context.ProcessIndexedHeader(0,
60 &removed_referenced_indices));
61 EXPECT_EQ(0, new_index);
62 EXPECT_TRUE(removed_referenced_indices.empty());
64 EXPECT_EQ(name, encoding_context.GetNameAt(0));
65 EXPECT_EQ(value, encoding_context.GetValueAt(0));
66 EXPECT_FALSE(encoding_context.IsReferencedAt(0));
69 // Try to process an indexed header with an index for a static header
70 // and an encoding context where a copy of that header wouldn't
71 // fit. That should succeed without making a copy.
72 TEST(HpackEncodingContextTest, IndexedHeaderStaticCopyDoesNotFit) {
73 HpackEncodingContext encoding_context;
74 encoding_context.SetMaxSize(0);
77 std::vector<uint32> removed_referenced_indices;
79 encoding_context.ProcessIndexedHeader(1,
81 &removed_referenced_indices));
82 EXPECT_EQ(-1, new_index);
83 EXPECT_TRUE(removed_referenced_indices.empty());
86 // NOTE: It's too onerous to try to test invalid input to
87 // ProcessLiteralHeaderWithIncrementalIndexing(); that would require
88 // making a really large (>4GB of memory) string.
90 // Try to process a reasonably-sized literal header with incremental
91 // indexing. It should succeed.
92 TEST(HpackEncodingContextTest, LiteralHeaderIncrementalIndexing) {
93 HpackEncodingContext encoding_context;
96 std::vector<uint32> removed_referenced_indices;
98 encoding_context.ProcessLiteralHeaderWithIncrementalIndexing(
99 "name", "value", &index, &removed_referenced_indices));
101 EXPECT_TRUE(removed_referenced_indices.empty());
102 EXPECT_EQ("name", encoding_context.GetNameAt(0).as_string());
103 EXPECT_EQ("value", encoding_context.GetValueAt(0).as_string());
104 EXPECT_TRUE(encoding_context.IsReferencedAt(0));
107 // Try to process a literal header with incremental indexing that is
108 // too large for the header table. It should succeed without indexing
110 TEST(HpackEncodingContextTest, LiteralHeaderIncrementalIndexingDoesNotFit) {
111 HpackEncodingContext encoding_context;
112 encoding_context.SetMaxSize(0);
115 std::vector<uint32> removed_referenced_indices;
117 encoding_context.ProcessLiteralHeaderWithIncrementalIndexing(
118 "name", "value", &index, &removed_referenced_indices));
119 EXPECT_EQ(-1, index);
120 EXPECT_TRUE(removed_referenced_indices.empty());