| OLD | NEW |
| (Empty) | |
| 1 #include "net/spdy/hpack_encoding_context.h" |
| 2 |
| 3 #include <vector> |
| 4 |
| 5 #include "base/basictypes.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace net { |
| 9 |
| 10 namespace { |
| 11 |
| 12 // Try to process an indexed header with an invalid index. That should |
| 13 // fail. |
| 14 TEST(HpackEncodingContextTest, IndexedHeaderInvalid) { |
| 15 HpackEncodingContext encoding_context; |
| 16 |
| 17 int32 new_index = -1; |
| 18 std::vector<uint32> removed_referenced_indices; |
| 19 EXPECT_FALSE( |
| 20 encoding_context.ProcessIndexedHeader(kuint32max, |
| 21 &new_index, |
| 22 &removed_referenced_indices)); |
| 23 } |
| 24 |
| 25 // Try to process an indexed header with an index for a static |
| 26 // header. That should succeed and add a mutable copy into the header |
| 27 // table. |
| 28 TEST(HpackEncodingContextTest, IndexedHeaderStatic) { |
| 29 HpackEncodingContext encoding_context; |
| 30 |
| 31 std::string name = encoding_context.GetNameAt(1).as_string(); |
| 32 std::string value = encoding_context.GetValueAt(1).as_string(); |
| 33 EXPECT_NE(name, encoding_context.GetNameAt(0)); |
| 34 EXPECT_NE(value, encoding_context.GetValueAt(0)); |
| 35 |
| 36 { |
| 37 int32 new_index = -1; |
| 38 std::vector<uint32> removed_referenced_indices; |
| 39 EXPECT_TRUE( |
| 40 encoding_context.ProcessIndexedHeader(1, |
| 41 &new_index, |
| 42 &removed_referenced_indices)); |
| 43 EXPECT_EQ(0, new_index); |
| 44 EXPECT_TRUE(removed_referenced_indices.empty()); |
| 45 } |
| 46 EXPECT_EQ(name, encoding_context.GetNameAt(0)); |
| 47 EXPECT_EQ(value, encoding_context.GetValueAt(0)); |
| 48 EXPECT_TRUE(encoding_context.IsReferencedAt(0)); |
| 49 |
| 50 { |
| 51 int32 new_index = -1; |
| 52 std::vector<uint32> removed_referenced_indices; |
| 53 EXPECT_TRUE( |
| 54 encoding_context.ProcessIndexedHeader(0, |
| 55 &new_index, |
| 56 &removed_referenced_indices)); |
| 57 EXPECT_EQ(0, new_index); |
| 58 EXPECT_TRUE(removed_referenced_indices.empty()); |
| 59 } |
| 60 EXPECT_EQ(name, encoding_context.GetNameAt(0)); |
| 61 EXPECT_EQ(value, encoding_context.GetValueAt(0)); |
| 62 EXPECT_FALSE(encoding_context.IsReferencedAt(0)); |
| 63 } |
| 64 |
| 65 // Try to process an indexed header with an index for a static header |
| 66 // and an encoding context where a copy of that header wouldn't |
| 67 // fit. That should succeed without making a copy. |
| 68 TEST(HpackEncodingContextTest, IndexedHeaderStaticCopyDoesNotFit) { |
| 69 HpackEncodingContext encoding_context; |
| 70 encoding_context.SetMaxSize(0); |
| 71 |
| 72 int32 new_index = -1; |
| 73 std::vector<uint32> removed_referenced_indices; |
| 74 EXPECT_TRUE( |
| 75 encoding_context.ProcessIndexedHeader(1, |
| 76 &new_index, |
| 77 &removed_referenced_indices)); |
| 78 EXPECT_EQ(-1, new_index); |
| 79 EXPECT_TRUE(removed_referenced_indices.empty()); |
| 80 } |
| 81 |
| 82 // NOTE: It's too onerous to try to test invalid input to |
| 83 // ProcessLiteralHeaderWithIncrementalIndexing(); that would require |
| 84 // making a really large (>4GB of memory) string. |
| 85 |
| 86 // Try to process a reasonably-sized literal header with incremental |
| 87 // indexing. It should succeed. |
| 88 TEST(HpackEncodingContextTest, LiteralHeaderIncrementalIndexing) { |
| 89 HpackEncodingContext encoding_context; |
| 90 |
| 91 int32 index = -1; |
| 92 std::vector<uint32> removed_referenced_indices; |
| 93 EXPECT_TRUE( |
| 94 encoding_context.ProcessLiteralHeaderWithIncrementalIndexing( |
| 95 "name", "value", &index, &removed_referenced_indices)); |
| 96 EXPECT_EQ(0, index); |
| 97 EXPECT_TRUE(removed_referenced_indices.empty()); |
| 98 EXPECT_EQ("name", encoding_context.GetNameAt(0).as_string()); |
| 99 EXPECT_EQ("value", encoding_context.GetValueAt(0).as_string()); |
| 100 EXPECT_TRUE(encoding_context.IsReferencedAt(0)); |
| 101 } |
| 102 |
| 103 // Try to process a literal header with incremental indexing that is |
| 104 // too large for the header table. It should succeed without indexing |
| 105 // into the table. |
| 106 TEST(HpackEncodingContextTest, LiteralHeaderIncrementalIndexingDoesNotFit) { |
| 107 HpackEncodingContext encoding_context; |
| 108 encoding_context.SetMaxSize(0); |
| 109 |
| 110 int32 index = -1; |
| 111 std::vector<uint32> removed_referenced_indices; |
| 112 EXPECT_TRUE( |
| 113 encoding_context.ProcessLiteralHeaderWithIncrementalIndexing( |
| 114 "name", "value", &index, &removed_referenced_indices)); |
| 115 EXPECT_EQ(-1, index); |
| 116 EXPECT_TRUE(removed_referenced_indices.empty()); |
| 117 } |
| 118 |
| 119 } // namespace |
| 120 |
| 121 } // namespace net |
| OLD | NEW |