| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 SpdyFrameType type = ParseFrameType(serialized_type); | 629 SpdyFrameType type = ParseFrameType(serialized_type); |
| 630 DCHECK_EQ(HEADERS, type); | 630 DCHECK_EQ(HEADERS, type); |
| 631 uint8_t flags; | 631 uint8_t flags; |
| 632 reader.ReadUInt8(&flags); | 632 reader.ReadUInt8(&flags); |
| 633 | 633 |
| 634 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), | 634 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), |
| 635 frame.size() - framer.GetHeadersMinimumSize()); | 635 frame.size() - framer.GetHeadersMinimumSize()); |
| 636 } | 636 } |
| 637 | 637 |
| 638 enum DecoderChoice { DECODER_SELF, DECODER_NESTED, DECODER_HTTP2 }; | 638 enum DecoderChoice { DECODER_SELF, DECODER_NESTED, DECODER_HTTP2 }; |
| 639 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_2, HPACK_DECODER_3 }; | 639 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_3 }; |
| 640 | 640 |
| 641 class SpdyFramerTest | 641 class SpdyFramerTest |
| 642 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> { | 642 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> { |
| 643 protected: | 643 protected: |
| 644 void SetUp() override { | 644 void SetUp() override { |
| 645 auto param = GetParam(); | 645 auto param = GetParam(); |
| 646 switch (std::get<0>(param)) { | 646 switch (std::get<0>(param)) { |
| 647 case DECODER_SELF: | 647 case DECODER_SELF: |
| 648 FLAGS_use_nested_spdy_framer_decoder = false; | 648 FLAGS_use_nested_spdy_framer_decoder = false; |
| 649 FLAGS_chromium_http2_flag_spdy_use_http2_frame_decoder_adapter = false; | 649 FLAGS_chromium_http2_flag_spdy_use_http2_frame_decoder_adapter = false; |
| 650 break; | 650 break; |
| 651 case DECODER_NESTED: | 651 case DECODER_NESTED: |
| 652 FLAGS_use_nested_spdy_framer_decoder = true; | 652 FLAGS_use_nested_spdy_framer_decoder = true; |
| 653 FLAGS_chromium_http2_flag_spdy_use_http2_frame_decoder_adapter = false; | 653 FLAGS_chromium_http2_flag_spdy_use_http2_frame_decoder_adapter = false; |
| 654 break; | 654 break; |
| 655 case DECODER_HTTP2: | 655 case DECODER_HTTP2: |
| 656 FLAGS_use_nested_spdy_framer_decoder = false; | 656 FLAGS_use_nested_spdy_framer_decoder = false; |
| 657 FLAGS_chromium_http2_flag_spdy_use_http2_frame_decoder_adapter = true; | 657 FLAGS_chromium_http2_flag_spdy_use_http2_frame_decoder_adapter = true; |
| 658 break; | 658 break; |
| 659 } | 659 } |
| 660 switch (std::get<1>(param)) { | 660 switch (std::get<1>(param)) { |
| 661 case HPACK_DECODER_1: | 661 case HPACK_DECODER_1: |
| 662 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; | |
| 663 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = false; | |
| 664 break; | |
| 665 case HPACK_DECODER_2: | |
| 666 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = true; | |
| 667 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = false; | 662 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = false; |
| 668 break; | 663 break; |
| 669 case HPACK_DECODER_3: | 664 case HPACK_DECODER_3: |
| 670 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; | |
| 671 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = true; | 665 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder3 = true; |
| 672 break; | 666 break; |
| 673 } | 667 } |
| 674 } | 668 } |
| 675 | 669 |
| 676 void CompareFrame(const string& description, | 670 void CompareFrame(const string& description, |
| 677 const SpdySerializedFrame& actual_frame, | 671 const SpdySerializedFrame& actual_frame, |
| 678 const unsigned char* expected, | 672 const unsigned char* expected, |
| 679 const int expected_len) { | 673 const int expected_len) { |
| 680 const unsigned char* actual = | 674 const unsigned char* actual = |
| 681 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 675 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 682 CompareCharArraysWithHexError(description, actual, actual_frame.size(), | 676 CompareCharArraysWithHexError(description, actual, actual_frame.size(), |
| 683 expected, expected_len); | 677 expected, expected_len); |
| 684 } | 678 } |
| 685 | 679 |
| 686 void CompareFrames(const string& description, | 680 void CompareFrames(const string& description, |
| 687 const SpdySerializedFrame& expected_frame, | 681 const SpdySerializedFrame& expected_frame, |
| 688 const SpdySerializedFrame& actual_frame) { | 682 const SpdySerializedFrame& actual_frame) { |
| 689 CompareCharArraysWithHexError( | 683 CompareCharArraysWithHexError( |
| 690 description, | 684 description, |
| 691 reinterpret_cast<const unsigned char*>(expected_frame.data()), | 685 reinterpret_cast<const unsigned char*>(expected_frame.data()), |
| 692 expected_frame.size(), | 686 expected_frame.size(), |
| 693 reinterpret_cast<const unsigned char*>(actual_frame.data()), | 687 reinterpret_cast<const unsigned char*>(actual_frame.data()), |
| 694 actual_frame.size()); | 688 actual_frame.size()); |
| 695 } | 689 } |
| 696 }; | 690 }; |
| 697 | 691 |
| 698 INSTANTIATE_TEST_CASE_P( | 692 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, |
| 699 SpdyFramerTests, | 693 SpdyFramerTest, |
| 700 SpdyFramerTest, | 694 ::testing::Combine(::testing::Values(DECODER_SELF, |
| 701 ::testing::Combine( | 695 DECODER_NESTED, |
| 702 ::testing::Values(DECODER_SELF, DECODER_NESTED, DECODER_HTTP2), | 696 DECODER_HTTP2), |
| 703 ::testing::Values(HPACK_DECODER_1, HPACK_DECODER_2, HPACK_DECODER_3))); | 697 ::testing::Values(HPACK_DECODER_1, |
| 698 HPACK_DECODER_3))); |
| 704 | 699 |
| 705 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 700 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
| 706 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { | 701 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
| 707 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); | 702 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 708 | 703 |
| 709 // Encode the header block into a Headers frame. | 704 // Encode the header block into a Headers frame. |
| 710 SpdyHeadersIR headers(1); | 705 SpdyHeadersIR headers(1); |
| 711 headers.SetHeader("alpha", "beta"); | 706 headers.SetHeader("alpha", "beta"); |
| 712 headers.SetHeader("gamma", "charlie"); | 707 headers.SetHeader("gamma", "charlie"); |
| 713 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 708 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| (...skipping 3766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4480 | 4475 |
| 4481 EXPECT_EQ(1, visitor->data_frame_count_); | 4476 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4482 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4477 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4483 EXPECT_EQ(0, visitor->headers_frame_count_); | 4478 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4484 } | 4479 } |
| 4485 } | 4480 } |
| 4486 | 4481 |
| 4487 } // namespace test | 4482 } // namespace test |
| 4488 | 4483 |
| 4489 } // namespace net | 4484 } // namespace net |
| OLD | NEW |