| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 SpdyFrameType type = ParseFrameType(serialized_type); | 601 SpdyFrameType type = ParseFrameType(serialized_type); |
| 602 DCHECK_EQ(HEADERS, type); | 602 DCHECK_EQ(HEADERS, type); |
| 603 uint8_t flags; | 603 uint8_t flags; |
| 604 reader.ReadUInt8(&flags); | 604 reader.ReadUInt8(&flags); |
| 605 | 605 |
| 606 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), | 606 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), |
| 607 frame.size() - framer.GetHeadersMinimumSize()); | 607 frame.size() - framer.GetHeadersMinimumSize()); |
| 608 } | 608 } |
| 609 | 609 |
| 610 enum DecoderChoice { DECODER_SELF, DECODER_NESTED, DECODER_HTTP2 }; | 610 enum DecoderChoice { DECODER_SELF, DECODER_NESTED, DECODER_HTTP2 }; |
| 611 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_2 }; | 611 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_2, HPACK_DECODER_3 }; |
| 612 | 612 |
| 613 class SpdyFramerTest | 613 class SpdyFramerTest |
| 614 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> { | 614 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> { |
| 615 protected: | 615 protected: |
| 616 void SetUp() override { | 616 void SetUp() override { |
| 617 auto param = GetParam(); | 617 auto param = GetParam(); |
| 618 switch (std::get<0>(param)) { | 618 switch (std::get<0>(param)) { |
| 619 case DECODER_SELF: | 619 case DECODER_SELF: |
| 620 FLAGS_use_nested_spdy_framer_decoder = false; | 620 FLAGS_use_nested_spdy_framer_decoder = false; |
| 621 FLAGS_use_http2_frame_decoder_adapter = false; | 621 FLAGS_use_http2_frame_decoder_adapter = false; |
| 622 break; | 622 break; |
| 623 case DECODER_NESTED: | 623 case DECODER_NESTED: |
| 624 FLAGS_use_nested_spdy_framer_decoder = true; | 624 FLAGS_use_nested_spdy_framer_decoder = true; |
| 625 FLAGS_use_http2_frame_decoder_adapter = false; | 625 FLAGS_use_http2_frame_decoder_adapter = false; |
| 626 break; | 626 break; |
| 627 case DECODER_HTTP2: | 627 case DECODER_HTTP2: |
| 628 FLAGS_use_nested_spdy_framer_decoder = false; | 628 FLAGS_use_nested_spdy_framer_decoder = false; |
| 629 FLAGS_use_http2_frame_decoder_adapter = true; | 629 FLAGS_use_http2_frame_decoder_adapter = true; |
| 630 break; | 630 break; |
| 631 } | 631 } |
| 632 switch (std::get<1>(param)) { | 632 switch (std::get<1>(param)) { |
| 633 case HPACK_DECODER_1: | 633 case HPACK_DECODER_1: |
| 634 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; | 634 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; |
| 635 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = false; |
| 635 break; | 636 break; |
| 636 case HPACK_DECODER_2: | 637 case HPACK_DECODER_2: |
| 637 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = true; | 638 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = true; |
| 639 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = false; |
| 640 break; |
| 641 case HPACK_DECODER_3: |
| 642 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; |
| 643 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = true; |
| 638 break; | 644 break; |
| 639 } | 645 } |
| 640 } | 646 } |
| 641 | 647 |
| 642 void CompareFrame(const string& description, | 648 void CompareFrame(const string& description, |
| 643 const SpdySerializedFrame& actual_frame, | 649 const SpdySerializedFrame& actual_frame, |
| 644 const unsigned char* expected, | 650 const unsigned char* expected, |
| 645 const int expected_len) { | 651 const int expected_len) { |
| 646 const unsigned char* actual = | 652 const unsigned char* actual = |
| 647 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 653 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 648 CompareCharArraysWithHexError(description, actual, actual_frame.size(), | 654 CompareCharArraysWithHexError(description, actual, actual_frame.size(), |
| 649 expected, expected_len); | 655 expected, expected_len); |
| 650 } | 656 } |
| 651 | 657 |
| 652 void CompareFrames(const string& description, | 658 void CompareFrames(const string& description, |
| 653 const SpdySerializedFrame& expected_frame, | 659 const SpdySerializedFrame& expected_frame, |
| 654 const SpdySerializedFrame& actual_frame) { | 660 const SpdySerializedFrame& actual_frame) { |
| 655 CompareCharArraysWithHexError( | 661 CompareCharArraysWithHexError( |
| 656 description, | 662 description, |
| 657 reinterpret_cast<const unsigned char*>(expected_frame.data()), | 663 reinterpret_cast<const unsigned char*>(expected_frame.data()), |
| 658 expected_frame.size(), | 664 expected_frame.size(), |
| 659 reinterpret_cast<const unsigned char*>(actual_frame.data()), | 665 reinterpret_cast<const unsigned char*>(actual_frame.data()), |
| 660 actual_frame.size()); | 666 actual_frame.size()); |
| 661 } | 667 } |
| 662 }; | 668 }; |
| 663 | 669 |
| 664 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | 670 INSTANTIATE_TEST_CASE_P( |
| 665 SpdyFramerTest, | 671 SpdyFramerTests, |
| 666 ::testing::Combine(::testing::Values(DECODER_SELF, | 672 SpdyFramerTest, |
| 667 DECODER_NESTED, | 673 ::testing::Combine( |
| 668 DECODER_HTTP2), | 674 ::testing::Values(DECODER_SELF, DECODER_NESTED, DECODER_HTTP2), |
| 669 ::testing::Values(HPACK_DECODER_1, | 675 ::testing::Values(HPACK_DECODER_1, HPACK_DECODER_2, HPACK_DECODER_3))); |
| 670 HPACK_DECODER_2))); | |
| 671 | 676 |
| 672 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 677 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
| 673 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { | 678 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
| 674 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); | 679 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 675 | 680 |
| 676 // Encode the header block into a Headers frame. | 681 // Encode the header block into a Headers frame. |
| 677 SpdyHeadersIR headers(1); | 682 SpdyHeadersIR headers(1); |
| 678 headers.SetHeader("alpha", "beta"); | 683 headers.SetHeader("alpha", "beta"); |
| 679 headers.SetHeader("gamma", "charlie"); | 684 headers.SetHeader("gamma", "charlie"); |
| 680 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 685 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| (...skipping 3615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4296 | 4301 |
| 4297 EXPECT_EQ(1, visitor->data_frame_count_); | 4302 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4298 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4303 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4299 EXPECT_EQ(0, visitor->headers_frame_count_); | 4304 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4300 } | 4305 } |
| 4301 } | 4306 } |
| 4302 | 4307 |
| 4303 } // namespace test | 4308 } // namespace test |
| 4304 | 4309 |
| 4305 } // namespace net | 4310 } // namespace net |
| OLD | NEW |