f3fc90162c88de50fffea77399cb9df46317072c
[platform/framework/web/crosswalk.git] / src / net / spdy / hpack_decoder_test.cc
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.
4
5 #include "net/spdy/hpack_decoder.h"
6
7 #include <map>
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/strings/string_piece.h"
13 #include "net/spdy/hpack_encoder.h"
14 #include "net/spdy/hpack_input_stream.h"
15 #include "net/spdy/hpack_output_stream.h"
16 #include "net/spdy/spdy_test_utils.h"
17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace net {
21
22 namespace test {
23
24 using base::StringPiece;
25 using std::string;
26
27 class HpackDecoderPeer {
28  public:
29   explicit HpackDecoderPeer(HpackDecoder* decoder)
30       : decoder_(decoder) {}
31
32   void HandleHeaderRepresentation(StringPiece name, StringPiece value) {
33     decoder_->HandleHeaderRepresentation(name, value);
34   }
35   bool DecodeNextName(HpackInputStream* in, StringPiece* out) {
36     return decoder_->DecodeNextName(in, out);
37   }
38   HpackHeaderTable* header_table() {
39     return &decoder_->header_table_;
40   }
41   void set_cookie_value(string value) {
42     decoder_->cookie_value_ = value;
43   }
44   string cookie_value() {
45     return decoder_->cookie_value_;
46   }
47   const std::map<string, string>& decoded_block() const {
48     return decoder_->decoded_block_;
49   }
50   const string& headers_block_buffer() const {
51     return decoder_->headers_block_buffer_;
52   }
53
54  private:
55   HpackDecoder* decoder_;
56 };
57
58 }  // namespace test
59
60 namespace {
61
62 using base::StringPiece;
63 using std::string;
64 using test::a2b_hex;
65
66 using testing::ElementsAre;
67 using testing::Pair;
68
69 const size_t kLiteralBound = 1024;
70
71 class HpackDecoderTest : public ::testing::Test {
72  protected:
73   HpackDecoderTest()
74       : decoder_(ObtainHpackHuffmanTable()),
75         decoder_peer_(&decoder_) {}
76
77   bool DecodeHeaderBlock(StringPiece str) {
78     return decoder_.HandleControlFrameHeadersData(0, str.data(), str.size()) &&
79         decoder_.HandleControlFrameHeadersComplete(0);
80   }
81
82   const std::map<string, string>& decoded_block() const {
83     // TODO(jgraettinger): HpackDecoderTest should implement
84     // SpdyHeadersHandlerInterface, and collect headers for examination.
85     return decoder_peer_.decoded_block();
86   }
87
88   const std::map<string, string>& DecodeBlockExpectingSuccess(StringPiece str) {
89     EXPECT_TRUE(DecodeHeaderBlock(str));
90     return decoded_block();
91   }
92
93   void expectEntry(size_t index, size_t size, const string& name,
94                    const string& value) {
95     HpackEntry* entry = decoder_peer_.header_table()->GetByIndex(index);
96     EXPECT_EQ(name, entry->name()) << "index " << index;
97     EXPECT_EQ(value, entry->value());
98     EXPECT_EQ(size, entry->Size());
99     EXPECT_EQ(index, decoder_peer_.header_table()->IndexOf(entry));
100   }
101
102   void expectStaticEntry(size_t index) {
103     HpackEntry* entry = decoder_peer_.header_table()->GetByIndex(index);
104     EXPECT_TRUE(entry->IsStatic()) << "index " << index;
105   }
106
107   HpackDecoder decoder_;
108   test::HpackDecoderPeer decoder_peer_;
109 };
110
111 TEST_F(HpackDecoderTest, HandleControlFrameHeadersData) {
112   // Strings under threshold are concatenated in the buffer.
113   EXPECT_TRUE(decoder_.HandleControlFrameHeadersData(
114       0, "small string one", 16));
115   EXPECT_TRUE(decoder_.HandleControlFrameHeadersData(
116       0, "small string two", 16));
117   // A string which would push the buffer over the threshold is refused.
118   EXPECT_FALSE(decoder_.HandleControlFrameHeadersData(
119       0, "fails", kMaxDecodeBufferSize - 32 + 1));
120
121   EXPECT_EQ(decoder_peer_.headers_block_buffer(),
122             "small string onesmall string two");
123 }
124
125 TEST_F(HpackDecoderTest, HandleControlFrameHeadersComplete) {
126   // Decode a block which toggles two static headers into the reference set.
127   EXPECT_TRUE(DecodeHeaderBlock("\x82\x86"));
128
129   decoder_peer_.set_cookie_value("foobar=baz");
130
131   // Headers in the reference set should be emitted.
132   // Incremental cookie buffer should be emitted and cleared.
133   decoder_.HandleControlFrameHeadersData(0, NULL, 0);
134   decoder_.HandleControlFrameHeadersComplete(0);
135
136   EXPECT_THAT(decoded_block(), ElementsAre(
137       Pair(":method", "GET"),
138       Pair(":path", "/index.html"),
139       Pair("cookie", "foobar=baz")));
140   EXPECT_EQ(decoder_peer_.cookie_value(), "");
141 }
142
143 TEST_F(HpackDecoderTest, HandleHeaderRepresentation) {
144   // All cookie crumbs are joined.
145   decoder_peer_.HandleHeaderRepresentation("cookie", " part 1");
146   decoder_peer_.HandleHeaderRepresentation("cookie", "part 2 ");
147   decoder_peer_.HandleHeaderRepresentation("cookie", "part3");
148
149   // Already-delimited headers are passed through.
150   decoder_peer_.HandleHeaderRepresentation("passed-through",
151                                            string("foo\0baz", 7));
152
153   // Other headers are joined on \0. Case matters.
154   decoder_peer_.HandleHeaderRepresentation("joined", "not joined");
155   decoder_peer_.HandleHeaderRepresentation("joineD", "value 1");
156   decoder_peer_.HandleHeaderRepresentation("joineD", "value 2");
157
158   // Empty headers remain empty.
159   decoder_peer_.HandleHeaderRepresentation("empty", "");
160
161   // Joined empty headers work as expected.
162   decoder_peer_.HandleHeaderRepresentation("empty-joined", "");
163   decoder_peer_.HandleHeaderRepresentation("empty-joined", "foo");
164   decoder_peer_.HandleHeaderRepresentation("empty-joined", "");
165   decoder_peer_.HandleHeaderRepresentation("empty-joined", "");
166
167   // Non-contiguous cookie crumb.
168   decoder_peer_.HandleHeaderRepresentation("cookie", " fin!");
169
170   // Finish and emit all headers.
171   decoder_.HandleControlFrameHeadersComplete(0);
172
173   EXPECT_THAT(decoded_block(), ElementsAre(
174       Pair("cookie", " part 1; part 2 ; part3;  fin!"),
175       Pair("empty", ""),
176       Pair("empty-joined", string("\0foo\0\0", 6)),
177       Pair("joineD", string("value 1\0value 2", 15)),
178       Pair("joined", "not joined"),
179       Pair("passed-through", string("foo\0baz", 7))));
180 }
181
182 // Decoding an encoded name with a valid string literal should work.
183 TEST_F(HpackDecoderTest, DecodeNextNameLiteral) {
184   HpackInputStream input_stream(kLiteralBound, StringPiece("\x00\x04name", 6));
185
186   StringPiece string_piece;
187   EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece));
188   EXPECT_EQ("name", string_piece);
189   EXPECT_FALSE(input_stream.HasMoreData());
190 }
191
192 TEST_F(HpackDecoderTest, DecodeNextNameLiteralWithHuffmanEncoding) {
193   string input = a2b_hex("008825a849e95ba97d7f");
194   HpackInputStream input_stream(kLiteralBound, input);
195
196   StringPiece string_piece;
197   EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece));
198   EXPECT_EQ("custom-key", string_piece);
199   EXPECT_FALSE(input_stream.HasMoreData());
200 }
201
202 // Decoding an encoded name with a valid index should work.
203 TEST_F(HpackDecoderTest, DecodeNextNameIndexed) {
204   HpackInputStream input_stream(kLiteralBound, "\x01");
205
206   StringPiece string_piece;
207   EXPECT_TRUE(decoder_peer_.DecodeNextName(&input_stream, &string_piece));
208   EXPECT_EQ(":authority", string_piece);
209   EXPECT_FALSE(input_stream.HasMoreData());
210 }
211
212 // Decoding an encoded name with an invalid index should fail.
213 TEST_F(HpackDecoderTest, DecodeNextNameInvalidIndex) {
214   // One more than the number of static table entries.
215   HpackInputStream input_stream(kLiteralBound, "\x3e");
216
217   StringPiece string_piece;
218   EXPECT_FALSE(decoder_peer_.DecodeNextName(&input_stream, &string_piece));
219 }
220
221 // Decoding an indexed header should toggle the index's presence in
222 // the reference set, making a copy of static table entries if
223 // necessary. It should also emit the header if toggled on (and only
224 // as many times as it was toggled on).
225 TEST_F(HpackDecoderTest, IndexedHeaderBasic) {
226   // Toggle on static table entry #2 (and make a copy at index #1),
227   // then toggle on static table entry #5 (which is now #6 because of
228   // the copy of #2).
229   std::map<string, string> header_set1 =
230       DecodeBlockExpectingSuccess("\x82\x86");
231   std::map<string, string> expected_header_set1;
232   expected_header_set1[":method"] = "GET";
233   expected_header_set1[":path"] = "/index.html";
234   EXPECT_EQ(expected_header_set1, header_set1);
235
236   std::map<string, string> expected_header_set2;
237   expected_header_set2[":path"] = "/index.html";
238   // Toggle off the copy of static table entry #5.
239   std::map<string, string> header_set2 =
240       DecodeBlockExpectingSuccess("\x82");
241   EXPECT_EQ(expected_header_set2, header_set2);
242 }
243
244 // Test a too-large indexed header.
245 TEST_F(HpackDecoderTest, InvalidIndexedHeader) {
246   // High-bit set, and a prefix of one more than the number of static entries.
247   EXPECT_FALSE(DecodeHeaderBlock(StringPiece("\xbe", 1)));
248 }
249
250 TEST_F(HpackDecoderTest, ContextUpdateMaximumSize) {
251   EXPECT_EQ(kDefaultHeaderTableSizeSetting,
252             decoder_peer_.header_table()->max_size());
253   string input;
254   {
255     // Maximum-size update with size 126. Succeeds.
256     HpackOutputStream output_stream;
257     output_stream.AppendPrefix(kEncodingContextOpcode);
258     output_stream.AppendPrefix(kEncodingContextNewMaximumSize);
259     output_stream.AppendUint32(126);
260
261     output_stream.TakeString(&input);
262     EXPECT_TRUE(DecodeHeaderBlock(StringPiece(input)));
263     EXPECT_EQ(126u, decoder_peer_.header_table()->max_size());
264   }
265   {
266     // Maximum-size update with kDefaultHeaderTableSizeSetting. Succeeds.
267     HpackOutputStream output_stream;
268     output_stream.AppendPrefix(kEncodingContextOpcode);
269     output_stream.AppendPrefix(kEncodingContextNewMaximumSize);
270     output_stream.AppendUint32(kDefaultHeaderTableSizeSetting);
271
272     output_stream.TakeString(&input);
273     EXPECT_TRUE(DecodeHeaderBlock(StringPiece(input)));
274     EXPECT_EQ(kDefaultHeaderTableSizeSetting,
275               decoder_peer_.header_table()->max_size());
276   }
277   {
278     // Maximum-size update with kDefaultHeaderTableSizeSetting + 1. Fails.
279     HpackOutputStream output_stream;
280     output_stream.AppendPrefix(kEncodingContextOpcode);
281     output_stream.AppendPrefix(kEncodingContextNewMaximumSize);
282     output_stream.AppendUint32(kDefaultHeaderTableSizeSetting + 1);
283
284     output_stream.TakeString(&input);
285     EXPECT_FALSE(DecodeHeaderBlock(StringPiece(input)));
286     EXPECT_EQ(kDefaultHeaderTableSizeSetting,
287               decoder_peer_.header_table()->max_size());
288   }
289 }
290
291 TEST_F(HpackDecoderTest, ContextUpdateClearReferenceSet) {
292   // Toggle on a couple of headers.
293   std::map<string, string> header_set1 =
294       DecodeBlockExpectingSuccess("\x82\x86");
295   std::map<string, string> expected_header_set1;
296   expected_header_set1[":method"] = "GET";
297   expected_header_set1[":path"] = "/index.html";
298   EXPECT_EQ(expected_header_set1, header_set1);
299
300   // Send a context update to clear the reference set.
301   std::map<string, string> header_set2 =
302       DecodeBlockExpectingSuccess("\x30");
303   std::map<string, string> expected_header_set2;
304   EXPECT_EQ(expected_header_set2, header_set2);
305 }
306
307 // Decoding two valid encoded literal headers with no indexing should
308 // work.
309 TEST_F(HpackDecoderTest, LiteralHeaderNoIndexing) {
310   // First header with indexed name, second header with string literal
311   // name.
312   const char input[] = "\x04\x0c/sample/path\x00\x06:path2\x0e/sample/path/2";
313   std::map<string, string> header_set =
314       DecodeBlockExpectingSuccess(StringPiece(input, arraysize(input) - 1));
315
316   std::map<string, string> expected_header_set;
317   expected_header_set[":path"] = "/sample/path";
318   expected_header_set[":path2"] = "/sample/path/2";
319   EXPECT_EQ(expected_header_set, header_set);
320 }
321
322 // Decoding two valid encoded literal headers with incremental
323 // indexing and string literal names should work and add the headers
324 // to the reference set.
325 TEST_F(HpackDecoderTest, LiteralHeaderIncrementalIndexing) {
326   const char input[] = "\x44\x0c/sample/path\x40\x06:path2\x0e/sample/path/2";
327   std::map<string, string> header_set =
328       DecodeBlockExpectingSuccess(StringPiece(input, arraysize(input) - 1));
329
330   std::map<string, string> expected_header_set;
331   expected_header_set[":path"] = "/sample/path";
332   expected_header_set[":path2"] = "/sample/path/2";
333   EXPECT_EQ(expected_header_set, header_set);
334
335   // Decoding an empty string should just return the reference set.
336   std::map<string, string> header_set2 = DecodeBlockExpectingSuccess("");
337   EXPECT_EQ(expected_header_set, header_set2);
338 }
339
340 TEST_F(HpackDecoderTest, LiteralHeaderWithIndexingInvalidNameIndex) {
341   decoder_.ApplyHeaderTableSizeSetting(0);
342
343   // Name is the last static index. Works.
344   EXPECT_TRUE(DecodeHeaderBlock(StringPiece("\x7d\x03ooo")));
345   // Name is one beyond the last static index. Fails.
346   EXPECT_FALSE(DecodeHeaderBlock(StringPiece("\x7e\x03ooo")));
347 }
348
349 TEST_F(HpackDecoderTest, LiteralHeaderNoIndexingInvalidNameIndex) {
350   // Name is the last static index. Works.
351   EXPECT_TRUE(DecodeHeaderBlock(StringPiece("\x0f\x2e\x03ooo")));
352   // Name is one beyond the last static index. Fails.
353   EXPECT_FALSE(DecodeHeaderBlock(StringPiece("\x0f\x2f\x03ooo")));
354 }
355
356 TEST_F(HpackDecoderTest, LiteralHeaderNeverIndexedInvalidNameIndex) {
357   // Name is the last static index. Works.
358   EXPECT_TRUE(DecodeHeaderBlock(StringPiece("\x1f\x2e\x03ooo")));
359   // Name is one beyond the last static index. Fails.
360   EXPECT_FALSE(DecodeHeaderBlock(StringPiece("\x1f\x2f\x03ooo")));
361 }
362
363 // Round-tripping the header set from E.2.1 should work.
364 TEST_F(HpackDecoderTest, BasicE21) {
365   HpackEncoder encoder(ObtainHpackHuffmanTable());
366
367   std::map<string, string> expected_header_set;
368   expected_header_set[":method"] = "GET";
369   expected_header_set[":scheme"] = "http";
370   expected_header_set[":path"] = "/";
371   expected_header_set[":authority"] = "www.example.com";
372
373   string encoded_header_set;
374   EXPECT_TRUE(encoder.EncodeHeaderSet(
375       expected_header_set, &encoded_header_set));
376
377   EXPECT_TRUE(DecodeHeaderBlock(encoded_header_set));
378   EXPECT_EQ(expected_header_set, decoded_block());
379 }
380
381 TEST_F(HpackDecoderTest, SectionD3RequestHuffmanExamples) {
382   std::map<string, string> header_set;
383
384   // 82                                      | == Indexed - Add ==
385   //                                         |   idx = 2
386   //                                         | -> :method: GET
387   // 87                                      | == Indexed - Add ==
388   //                                         |   idx = 7
389   //                                         | -> :scheme: http
390   // 86                                      | == Indexed - Add ==
391   //                                         |   idx = 6
392   //                                         | -> :path: /
393   // 44                                      | == Literal indexed ==
394   //                                         |   Indexed name (idx = 4)
395   //                                         |     :authority
396   // 8c                                      |   Literal value (len = 15)
397   //                                         |     Huffman encoded:
398   // f1e3 c2e5 f23a 6ba0 ab90 f4ff           | .....:k.....
399   //                                         |     Decoded:
400   //                                         | www.example.com
401   //                                         | -> :authority: www.example.com
402   string first = a2b_hex("828786448cf1e3c2e5f23a6ba0ab90f4"
403                          "ff");
404   header_set = DecodeBlockExpectingSuccess(first);
405
406   EXPECT_THAT(header_set, ElementsAre(
407       Pair(":authority", "www.example.com"),
408       Pair(":method", "GET"),
409       Pair(":path", "/"),
410       Pair(":scheme", "http")));
411
412   expectEntry(1, 57, ":authority", "www.example.com");
413   expectEntry(2, 38, ":path", "/");
414   expectEntry(3, 43, ":scheme", "http");
415   expectEntry(4, 42, ":method", "GET");
416   expectStaticEntry(5);
417   EXPECT_EQ(180u, decoder_peer_.header_table()->size());
418
419   // 5c                                      | == Literal indexed ==
420   //                                         |   Indexed name (idx = 28)
421   //                                         |     cache-control
422   // 86                                      |   Literal value (len = 8)
423   //                                         |     Huffman encoded:
424   // a8eb 1064 9cbf                          | ...d..
425   //                                         |     Decoded:
426   //                                         | no-cache
427   //                                         | -> cache-control: no-cache
428   string second = a2b_hex("5c86a8eb10649cbf");
429   header_set = DecodeBlockExpectingSuccess(second);
430
431   EXPECT_THAT(header_set, ElementsAre(
432       Pair(":authority", "www.example.com"),
433       Pair(":method", "GET"),
434       Pair(":path", "/"),
435       Pair(":scheme", "http"),
436       Pair("cache-control", "no-cache")));
437
438   expectEntry(1, 53, "cache-control", "no-cache");
439   expectEntry(2, 57, ":authority", "www.example.com");
440   expectEntry(3, 38, ":path", "/");
441   expectEntry(4, 43, ":scheme", "http");
442   expectEntry(5, 42, ":method", "GET");
443   expectStaticEntry(6);
444   EXPECT_EQ(233u, decoder_peer_.header_table()->size());
445
446   // 30                                      | == Empty reference set ==
447   //                                         |   idx = 0
448   //                                         |   flag = 1
449   // 85                                      | == Indexed - Add ==
450   //                                         |   idx = 5
451   //                                         | -> :method: GET
452   // 8c                                      | == Indexed - Add ==
453   //                                         |   idx = 12
454   //                                         | -> :scheme: https
455   // 8b                                      | == Indexed - Add ==
456   //                                         |   idx = 11
457   //                                         | -> :path: /index.html
458   // 84                                      | == Indexed - Add ==
459   //                                         |   idx = 4
460   //                                         | -> :authority: www.example.com
461   // 40                                      | == Literal indexed ==
462   // 88                                      |   Literal name (len = 10)
463   //                                         |     Huffman encoded:
464   // 25a8 49e9 5ba9 7d7f                     | %.I.[.}.
465   //                                         |     Decoded:
466   //                                         | custom-key
467   // 89                                      |   Literal value (len = 12)
468   //                                         |     Huffman encoded:
469   // 25a8 49e9 5bb8 e8b4 bf                  | %.I.[....
470   //                                         |     Decoded:
471   //                                         | custom-value
472   //                                         | -> custom-key: custom-value
473   string third = a2b_hex("30858c8b84408825a849e95ba97d7f89"
474                          "25a849e95bb8e8b4bf");
475   header_set = DecodeBlockExpectingSuccess(third);
476
477   EXPECT_THAT(header_set, ElementsAre(
478       Pair(":authority", "www.example.com"),
479       Pair(":method", "GET"),
480       Pair(":path", "/index.html"),
481       Pair(":scheme", "https"),
482       Pair("custom-key", "custom-value")));
483
484   expectEntry(1, 54, "custom-key", "custom-value");
485   expectEntry(2, 48, ":path", "/index.html");
486   expectEntry(3, 44, ":scheme", "https");
487   expectEntry(4, 53, "cache-control", "no-cache");
488   expectEntry(5, 57, ":authority", "www.example.com");
489   expectEntry(6, 38, ":path", "/");
490   expectEntry(7, 43, ":scheme", "http");
491   expectEntry(8, 42, ":method", "GET");
492   expectStaticEntry(9);
493   EXPECT_EQ(379u, decoder_peer_.header_table()->size());
494 }
495
496 TEST_F(HpackDecoderTest, SectionD5ResponseHuffmanExamples) {
497   std::map<string, string> header_set;
498   decoder_.ApplyHeaderTableSizeSetting(256);
499
500   // 48                                      | == Literal indexed ==
501   //                                         |   Indexed name (idx = 8)
502   //                                         |     :status
503   // 82                                      |   Literal value (len = 3)
504   //                                         |     Huffman encoded:
505   // 6402                                    | d.
506   //                                         |     Decoded:
507   //                                         | 302
508   //                                         | -> :status: 302
509   // 59                                      | == Literal indexed ==
510   //                                         |   Indexed name (idx = 25)
511   //                                         |     cache-control
512   // 85                                      |   Literal value (len = 7)
513   //                                         |     Huffman encoded:
514   // aec3 771a 4b                            | ..w.K
515   //                                         |     Decoded:
516   //                                         | private
517   //                                         | -> cache-control: private
518   // 63                                      | == Literal indexed ==
519   //                                         |   Indexed name (idx = 35)
520   //                                         |     date
521   // 96                                      |   Literal value (len = 29)
522   //                                         |     Huffman encoded:
523   // d07a be94 1054 d444 a820 0595 040b 8166 | .z...T.D. .....f
524   // e082 a62d 1bff                          | ...-..
525   //                                         |     Decoded:
526   //                                         | Mon, 21 Oct 2013 20:13:21
527   //                                         | GMT
528   //                                         | -> date: Mon, 21 Oct 2013
529   //                                         |   20:13:21 GMT
530   // 71                                      | == Literal indexed ==
531   //                                         |   Indexed name (idx = 49)
532   //                                         |     location
533   // 91                                      |   Literal value (len = 23)
534   //                                         |     Huffman encoded:
535   // 9d29 ad17 1863 c78f 0b97 c8e9 ae82 ae43 | .)...c.........C
536   // d3                                      | .
537   //                                         |     Decoded:
538   //                                         | https://www.example.com
539   //                                         | -> location: https://www.e
540   //                                         |    xample.com
541   string first = a2b_hex("488264025985aec3771a4b6396d07abe"
542                          "941054d444a8200595040b8166e082a6"
543                          "2d1bff71919d29ad171863c78f0b97c8"
544                          "e9ae82ae43d3");
545   header_set = DecodeBlockExpectingSuccess(first);
546
547   EXPECT_THAT(header_set, ElementsAre(
548       Pair(":status", "302"),
549       Pair("cache-control", "private"),
550       Pair("date", "Mon, 21 Oct 2013 20:13:21 GMT"),
551       Pair("location", "https://www.example.com")));
552
553   expectEntry(1, 63, "location", "https://www.example.com");
554   expectEntry(2, 65, "date", "Mon, 21 Oct 2013 20:13:21 GMT");
555   expectEntry(3, 52, "cache-control", "private");
556   expectEntry(4, 42, ":status", "302");
557   expectStaticEntry(5);
558   EXPECT_EQ(222u, decoder_peer_.header_table()->size());
559
560   // 8c                                      | == Indexed - Add ==
561   //                                         |   idx = 12
562   //                                         | - evict: :status: 302
563   //                                         | -> :status: 200
564   string second = a2b_hex("8c");
565   header_set = DecodeBlockExpectingSuccess(second);
566
567   EXPECT_THAT(header_set, ElementsAre(
568       Pair(":status", "200"),
569       Pair("cache-control", "private"),
570       Pair("date", "Mon, 21 Oct 2013 20:13:21 GMT"),
571       Pair("location", "https://www.example.com")));
572
573   expectEntry(1, 42, ":status", "200");
574   expectEntry(2, 63, "location", "https://www.example.com");
575   expectEntry(3, 65, "date", "Mon, 21 Oct 2013 20:13:21 GMT");
576   expectEntry(4, 52, "cache-control", "private");
577   expectStaticEntry(5);
578   EXPECT_EQ(222u, decoder_peer_.header_table()->size());
579
580   // 84                                      | == Indexed - Remove ==
581   //                                         |   idx = 4
582   //                                         | -> cache-control: private
583   // 84                                      | == Indexed - Add ==
584   //                                         |   idx = 4
585   //                                         | -> cache-control: private
586   // 43                                      | == Literal indexed ==
587   //                                         |   Indexed name (idx = 3)
588   //                                         |     date
589   // 96                                      |   Literal value (len = 29)
590   //                                         |     Huffman encoded:
591   // d07a be94 1054 d444 a820 0595 040b 8166 | .z...T.D. .....f
592   // e084 a62d 1bff                          | ...-..
593   //                                         |     Decoded:
594   //                                         | Mon, 21 Oct 2013 20:13:22
595   //                                         | GMT
596   //                                         | - evict: cache-control: pr
597   //                                         |   ivate
598   //                                         | -> date: Mon, 21 Oct 2013
599   //                                         |   20:13:22 GMT
600   // 5e                                      | == Literal indexed ==
601   //                                         |   Indexed name (idx = 30)
602   //                                         |     content-encoding
603   // 83                                      |   Literal value (len = 4)
604   //                                         |     Huffman encoded:
605   // 9bd9 ab                                 | ...
606   //                                         |     Decoded:
607   //                                         | gzip
608   //                                         | - evict: date: Mon, 21 Oct
609   //                                         |    2013 20:13:21 GMT
610   //                                         | -> content-encoding: gzip
611   // 84                                      | == Indexed - Remove ==
612   //                                         |   idx = 4
613   //                                         | -> location: https://www.e
614   //                                         |   xample.com
615   // 84                                      | == Indexed - Add ==
616   //                                         |   idx = 4
617   //                                         | -> location: https://www.e
618   //                                         |   xample.com
619   // 83                                      | == Indexed - Remove ==
620   //                                         |   idx = 3
621   //                                         | -> :status: 200
622   // 83                                      | == Indexed - Add ==
623   //                                         |   idx = 3
624   //                                         | -> :status: 200
625   // 7b                                      | == Literal indexed ==
626   //                                         |   Indexed name (idx = 59)
627   //                                         |     set-cookie
628   // ad                                      |   Literal value (len = 56)
629   //                                         |     Huffman encoded:
630   // 94e7 821d d7f2 e6c7 b335 dfdf cd5b 3960 | .........5...[9`
631   // d5af 2708 7f36 72c1 ab27 0fb5 291f 9587 | ..'..6r..'..)...
632   // 3160 65c0 03ed 4ee5 b106 3d50 07        | 1`e...N...=P.
633   //                                         |     Decoded:
634   //                                         | foo=ASDJKHQKBZXOQWEOPIUAXQ
635   //                                         | WEOIU; max-age=3600; versi
636   //                                         | on=1
637   //                                         | - evict: location: https:/
638   //                                         |   /www.example.com
639   //                                         | - evict: :status: 200
640   //                                         | -> set-cookie: foo=ASDJKHQ
641   //                                         |   KBZXOQWEOPIUAXQWEOIU; ma
642   //                                         |   x-age=3600; version=1
643   string third = a2b_hex("84844396d07abe941054d444a8200595"
644                          "040b8166e084a62d1bff5e839bd9ab84"
645                          "8483837bad94e7821dd7f2e6c7b335df"
646                          "dfcd5b3960d5af27087f3672c1ab270f"
647                          "b5291f9587316065c003ed4ee5b1063d"
648                          "5007");
649   header_set = DecodeBlockExpectingSuccess(third);
650
651   EXPECT_THAT(header_set, ElementsAre(
652       Pair(":status", "200"),
653       Pair("cache-control", "private"),
654       Pair("content-encoding", "gzip"),
655       Pair("date", "Mon, 21 Oct 2013 20:13:22 GMT"),
656       Pair("location", "https://www.example.com"),
657       Pair("set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;"
658            " max-age=3600; version=1")));
659
660   expectEntry(1, 98, "set-cookie", "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU;"
661               " max-age=3600; version=1");
662   expectEntry(2, 52, "content-encoding", "gzip");
663   expectEntry(3, 65, "date", "Mon, 21 Oct 2013 20:13:22 GMT");
664   expectStaticEntry(4);
665   EXPECT_EQ(215u, decoder_peer_.header_table()->size());
666 }
667
668 }  // namespace
669
670 }  // namespace net