OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/hpack_encoder.h" | 5 #include "net/spdy/hpack_encoder.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 using base::StringPiece; | 15 using base::StringPiece; |
16 using std::string; | 16 using std::string; |
17 using testing::ElementsAre; | 17 using testing::ElementsAre; |
18 | 18 |
19 namespace test { | 19 namespace test { |
20 | 20 |
21 class HpackEncoderPeer { | 21 class HpackEncoderPeer { |
22 public: | 22 public: |
23 explicit HpackEncoderPeer(HpackEncoder* encoder) | 23 explicit HpackEncoderPeer(HpackEncoder* encoder) |
24 : encoder_(encoder) {} | 24 : encoder_(encoder) {} |
25 | 25 |
| 26 void UpdateCharacterCounts(StringPiece str) { |
| 27 encoder_->UpdateCharacterCounts(str); |
| 28 } |
26 void set_max_string_literal_size(uint32 size) { | 29 void set_max_string_literal_size(uint32 size) { |
27 encoder_->max_string_literal_size_ = size; | 30 encoder_->max_string_literal_size_ = size; |
28 } | 31 } |
29 static void CookieToCrumbs(StringPiece cookie, | 32 static void CookieToCrumbs(StringPiece cookie, |
30 std::vector<StringPiece>* out) { | 33 std::vector<StringPiece>* out) { |
31 HpackEncoder::CookieToCrumbs(cookie, out); | 34 HpackEncoder::CookieToCrumbs(cookie, out); |
32 } | 35 } |
33 private: | 36 private: |
34 HpackEncoder* encoder_; | 37 HpackEncoder* encoder_; |
35 }; | 38 }; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 std::map<string, string> header_set; | 108 std::map<string, string> header_set; |
106 header_set["name1"] = "too-long value"; | 109 header_set["name1"] = "too-long value"; |
107 header_set["name2"] = "value2"; | 110 header_set["name2"] = "value2"; |
108 | 111 |
109 // TODO(akalin): Verify that the encoder did not attempt to encode | 112 // TODO(akalin): Verify that the encoder did not attempt to encode |
110 // the second header field. | 113 // the second header field. |
111 string encoded_header_set; | 114 string encoded_header_set; |
112 EXPECT_FALSE(encoder.EncodeHeaderSet(header_set, &encoded_header_set)); | 115 EXPECT_FALSE(encoder.EncodeHeaderSet(header_set, &encoded_header_set)); |
113 } | 116 } |
114 | 117 |
| 118 TEST(HpackEncoderTest, UpdateCharacterCounts) { |
| 119 HpackEncoder encoder; |
| 120 test::HpackEncoderPeer peer(&encoder); |
| 121 |
| 122 std::vector<size_t> counts(256, 0); |
| 123 size_t total_counts = 0; |
| 124 encoder.SetCharCountsStorage(&counts, &total_counts); |
| 125 |
| 126 char kTestString[] = "foo\0\1\xff""boo"; |
| 127 peer.UpdateCharacterCounts( |
| 128 StringPiece(kTestString, arraysize(kTestString) - 1)); |
| 129 |
| 130 std::vector<size_t> expect(256, 0); |
| 131 expect[static_cast<uint8>('f')] = 1; |
| 132 expect[static_cast<uint8>('o')] = 4; |
| 133 expect[static_cast<uint8>('\0')] = 1; |
| 134 expect[static_cast<uint8>('\1')] = 1; |
| 135 expect[static_cast<uint8>('\xff')] = 1; |
| 136 expect[static_cast<uint8>('b')] = 1; |
| 137 |
| 138 EXPECT_EQ(expect, counts); |
| 139 EXPECT_EQ(9u, total_counts); |
| 140 } |
| 141 |
115 } // namespace | 142 } // namespace |
116 | 143 |
117 } // namespace net | 144 } // namespace net |
OLD | NEW |