| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/hpack_decoder2.h" | 5 #include "net/spdy/hpack/hpack_decoder2.h" |
| 6 | 6 |
| 7 // Tests of HpackDecoder2. | 7 // Tests of HpackDecoder2. |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // | Decoded: | 558 // | Decoded: |
| 559 // | www.example.com | 559 // | www.example.com |
| 560 // | -> :authority: www.example.com | 560 // | -> :authority: www.example.com |
| 561 | 561 |
| 562 string first = a2b_hex("418cf1e3c2e5f23a6ba0ab90f4ff"); | 562 string first = a2b_hex("418cf1e3c2e5f23a6ba0ab90f4ff"); |
| 563 EXPECT_TRUE(DecodeHeaderBlock(first)); | 563 EXPECT_TRUE(DecodeHeaderBlock(first)); |
| 564 first = a2b_hex("418df1e3c2e5f23a6ba0ab90f4ffff"); | 564 first = a2b_hex("418df1e3c2e5f23a6ba0ab90f4ffff"); |
| 565 EXPECT_FALSE(DecodeHeaderBlock(first)); | 565 EXPECT_FALSE(DecodeHeaderBlock(first)); |
| 566 } | 566 } |
| 567 | 567 |
| 568 // Round-tripping the header set from E.2.1 should work. | 568 // Round-tripping the header set from RFC 7541 C.3.1 should work. |
| 569 TEST_P(HpackDecoder2Test, BasicE21) { | 569 // http://httpwg.org/specs/rfc7541.html#rfc.section.C.3.1 |
| 570 TEST_P(HpackDecoder2Test, BasicC31) { |
| 570 HpackEncoder encoder(ObtainHpackHuffmanTable()); | 571 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
| 571 | 572 |
| 572 SpdyHeaderBlock expected_header_set; | 573 SpdyHeaderBlock expected_header_set; |
| 573 expected_header_set[":method"] = "GET"; | 574 expected_header_set[":method"] = "GET"; |
| 574 expected_header_set[":scheme"] = "http"; | 575 expected_header_set[":scheme"] = "http"; |
| 575 expected_header_set[":path"] = "/"; | 576 expected_header_set[":path"] = "/"; |
| 576 expected_header_set[":authority"] = "www.example.com"; | 577 expected_header_set[":authority"] = "www.example.com"; |
| 577 | 578 |
| 578 string encoded_header_set; | 579 string encoded_header_set; |
| 579 EXPECT_TRUE( | 580 EXPECT_TRUE( |
| 580 encoder.EncodeHeaderSet(expected_header_set, &encoded_header_set)); | 581 encoder.EncodeHeaderSet(expected_header_set, &encoded_header_set)); |
| 581 | 582 |
| 582 EXPECT_TRUE(DecodeHeaderBlock(encoded_header_set)); | 583 EXPECT_TRUE(DecodeHeaderBlock(encoded_header_set)); |
| 583 EXPECT_EQ(expected_header_set, decoded_block()); | 584 EXPECT_EQ(expected_header_set, decoded_block()); |
| 584 } | 585 } |
| 585 | 586 |
| 586 TEST_P(HpackDecoder2Test, SectionD4RequestHuffmanExamples) { | 587 // RFC 7541, Section C.4: Request Examples with Huffman Coding |
| 588 // http://httpwg.org/specs/rfc7541.html#rfc.section.C.4 |
| 589 TEST_P(HpackDecoder2Test, SectionC4RequestHuffmanExamples) { |
| 587 // TODO(jamessynge): Use net/http2/hpack/tools/hpack_example.h to parse the | 590 // TODO(jamessynge): Use net/http2/hpack/tools/hpack_example.h to parse the |
| 588 // example directly, instead of having it as a comment. | 591 // example directly, instead of having it as a comment. |
| 589 // 82 | == Indexed - Add == | 592 // 82 | == Indexed - Add == |
| 590 // | idx = 2 | 593 // | idx = 2 |
| 591 // | -> :method: GET | 594 // | -> :method: GET |
| 592 // 86 | == Indexed - Add == | 595 // 86 | == Indexed - Add == |
| 593 // | idx = 6 | 596 // | idx = 6 |
| 594 // | -> :scheme: http | 597 // | -> :scheme: http |
| 595 // 84 | == Indexed - Add == | 598 // 84 | == Indexed - Add == |
| 596 // | idx = 4 | 599 // | idx = 4 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 Pair(":authority", "www.example.com"), | 699 Pair(":authority", "www.example.com"), |
| 697 Pair("custom-key", "custom-value"))); | 700 Pair("custom-key", "custom-value"))); |
| 698 // clang-format on | 701 // clang-format on |
| 699 | 702 |
| 700 expectEntry(62, 54, "custom-key", "custom-value"); | 703 expectEntry(62, 54, "custom-key", "custom-value"); |
| 701 expectEntry(63, 53, "cache-control", "no-cache"); | 704 expectEntry(63, 53, "cache-control", "no-cache"); |
| 702 expectEntry(64, 57, ":authority", "www.example.com"); | 705 expectEntry(64, 57, ":authority", "www.example.com"); |
| 703 EXPECT_EQ(164u, decoder_peer_.header_table()->size()); | 706 EXPECT_EQ(164u, decoder_peer_.header_table()->size()); |
| 704 } | 707 } |
| 705 | 708 |
| 706 TEST_P(HpackDecoder2Test, SectionD6ResponseHuffmanExamples) { | 709 // RFC 7541, Section C.6: Response Examples with Huffman Coding |
| 710 // http://httpwg.org/specs/rfc7541.html#rfc.section.C.6 |
| 711 TEST_P(HpackDecoder2Test, SectionC6ResponseHuffmanExamples) { |
| 707 decoder_.ApplyHeaderTableSizeSetting(256); | 712 decoder_.ApplyHeaderTableSizeSetting(256); |
| 708 | 713 |
| 709 // 48 | == Literal indexed == | 714 // 48 | == Literal indexed == |
| 710 // | Indexed name (idx = 8) | 715 // | Indexed name (idx = 8) |
| 711 // | :status | 716 // | :status |
| 712 // 82 | Literal value (len = 3) | 717 // 82 | Literal value (len = 3) |
| 713 // | Huffman encoded: | 718 // | Huffman encoded: |
| 714 // 6402 | d. | 719 // 6402 | d. |
| 715 // | Decoded: | 720 // | Decoded: |
| 716 // | 302 | 721 // | 302 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 string joined_values = expected_header_set[name].as_string(); | 950 string joined_values = expected_header_set[name].as_string(); |
| 946 EXPECT_EQ(joined_values.size(), | 951 EXPECT_EQ(joined_values.size(), |
| 947 2 * value1.size() + 2 * value2.size() + 2 * value3.size() + 5); | 952 2 * value1.size() + 2 * value2.size() + 2 * value3.size() + 5); |
| 948 | 953 |
| 949 EXPECT_EQ(expected_header_set, decoded_block()); | 954 EXPECT_EQ(expected_header_set, decoded_block()); |
| 950 } | 955 } |
| 951 | 956 |
| 952 } // namespace | 957 } // namespace |
| 953 } // namespace test | 958 } // namespace test |
| 954 } // namespace net | 959 } // namespace net |
| OLD | NEW |