| 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> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <tuple> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/macros.h" | 19 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "net/quic/core/quic_flags.h" | 22 #include "net/quic/core/quic_flags.h" |
| 22 #include "net/spdy/hpack/hpack_constants.h" | 23 #include "net/spdy/hpack/hpack_constants.h" |
| 23 #include "net/spdy/mock_spdy_framer_visitor.h" | 24 #include "net/spdy/mock_spdy_framer_visitor.h" |
| 24 #include "net/spdy/spdy_flags.h" | 25 #include "net/spdy/spdy_flags.h" |
| 25 #include "net/spdy/spdy_frame_builder.h" | 26 #include "net/spdy/spdy_frame_builder.h" |
| 26 #include "net/spdy/spdy_frame_reader.h" | 27 #include "net/spdy/spdy_frame_reader.h" |
| 27 #include "net/spdy/spdy_protocol.h" | 28 #include "net/spdy/spdy_protocol.h" |
| 28 #include "net/spdy/spdy_test_utils.h" | 29 #include "net/spdy/spdy_test_utils.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "testing/platform_test.h" | 32 #include "testing/platform_test.h" |
| 31 | 33 |
| 32 using base::StringPiece; | 34 using base::StringPiece; |
| 33 using std::string; | 35 using std::string; |
| 34 using testing::_; | 36 using testing::_; |
| 35 | 37 |
| 36 namespace net { | 38 namespace net { |
| 37 | 39 |
| 38 namespace test { | 40 namespace test { |
| 39 | 41 |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 reader.ReadUInt8(&serialized_type); | 606 reader.ReadUInt8(&serialized_type); |
| 605 SpdyFrameType type = SpdyConstants::ParseFrameType(serialized_type); | 607 SpdyFrameType type = SpdyConstants::ParseFrameType(serialized_type); |
| 606 DCHECK_EQ(HEADERS, type); | 608 DCHECK_EQ(HEADERS, type); |
| 607 uint8_t flags; | 609 uint8_t flags; |
| 608 reader.ReadUInt8(&flags); | 610 reader.ReadUInt8(&flags); |
| 609 | 611 |
| 610 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), | 612 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), |
| 611 frame.size() - framer.GetHeadersMinimumSize()); | 613 frame.size() - framer.GetHeadersMinimumSize()); |
| 612 } | 614 } |
| 613 | 615 |
| 614 class SpdyFramerTest : public ::testing::Test { | 616 enum DecoderChoice { DECODER_SELF, DECODER_NESTED }; |
| 617 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_2 }; |
| 618 |
| 619 class SpdyFramerTest |
| 620 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> { |
| 615 protected: | 621 protected: |
| 622 void SetUp() override { |
| 623 auto param = GetParam(); |
| 624 switch (std::get<0>(param)) { |
| 625 case DECODER_SELF: |
| 626 FLAGS_use_nested_spdy_framer_decoder = false; |
| 627 break; |
| 628 case DECODER_NESTED: |
| 629 FLAGS_use_nested_spdy_framer_decoder = true; |
| 630 break; |
| 631 } |
| 632 switch (std::get<1>(param)) { |
| 633 case HPACK_DECODER_1: |
| 634 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; |
| 635 break; |
| 636 case HPACK_DECODER_2: |
| 637 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = true; |
| 638 break; |
| 639 } |
| 640 } |
| 641 |
| 616 void CompareFrame(const string& description, | 642 void CompareFrame(const string& description, |
| 617 const SpdySerializedFrame& actual_frame, | 643 const SpdySerializedFrame& actual_frame, |
| 618 const unsigned char* expected, | 644 const unsigned char* expected, |
| 619 const int expected_len) { | 645 const int expected_len) { |
| 620 const unsigned char* actual = | 646 const unsigned char* actual = |
| 621 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 647 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 622 CompareCharArraysWithHexError(description, actual, actual_frame.size(), | 648 CompareCharArraysWithHexError(description, actual, actual_frame.size(), |
| 623 expected, expected_len); | 649 expected, expected_len); |
| 624 } | 650 } |
| 625 | 651 |
| 626 void CompareFrames(const string& description, | 652 void CompareFrames(const string& description, |
| 627 const SpdySerializedFrame& expected_frame, | 653 const SpdySerializedFrame& expected_frame, |
| 628 const SpdySerializedFrame& actual_frame) { | 654 const SpdySerializedFrame& actual_frame) { |
| 629 CompareCharArraysWithHexError( | 655 CompareCharArraysWithHexError( |
| 630 description, | 656 description, |
| 631 reinterpret_cast<const unsigned char*>(expected_frame.data()), | 657 reinterpret_cast<const unsigned char*>(expected_frame.data()), |
| 632 expected_frame.size(), | 658 expected_frame.size(), |
| 633 reinterpret_cast<const unsigned char*>(actual_frame.data()), | 659 reinterpret_cast<const unsigned char*>(actual_frame.data()), |
| 634 actual_frame.size()); | 660 actual_frame.size()); |
| 635 } | 661 } |
| 636 }; | 662 }; |
| 637 | 663 |
| 664 INSTANTIATE_TEST_CASE_P( |
| 665 SpdyFramerTests, |
| 666 SpdyFramerTest, |
| 667 ::testing::Combine(::testing::Values(DECODER_SELF, DECODER_NESTED), |
| 668 ::testing::Values(HPACK_DECODER_1, HPACK_DECODER_2))); |
| 669 |
| 638 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 670 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
| 639 TEST_F(SpdyFramerTest, HeaderBlockInBuffer) { | 671 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
| 640 SpdyFramer framer; | 672 SpdyFramer framer; |
| 641 framer.set_enable_compression(false); | 673 framer.set_enable_compression(false); |
| 642 | 674 |
| 643 // Encode the header block into a Headers frame. | 675 // Encode the header block into a Headers frame. |
| 644 SpdyHeadersIR headers(1); | 676 SpdyHeadersIR headers(1); |
| 645 headers.SetHeader("alpha", "beta"); | 677 headers.SetHeader("alpha", "beta"); |
| 646 headers.SetHeader("gamma", "charlie"); | 678 headers.SetHeader("gamma", "charlie"); |
| 647 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 679 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| 648 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 680 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 649 | 681 |
| 650 TestSpdyVisitor visitor; | 682 TestSpdyVisitor visitor; |
| 651 visitor.use_compression_ = false; | 683 visitor.use_compression_ = false; |
| 652 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 684 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 653 frame.size()); | 685 frame.size()); |
| 654 | 686 |
| 655 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 687 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 656 EXPECT_EQ(headers.header_block(), visitor.headers_); | 688 EXPECT_EQ(headers.header_block(), visitor.headers_); |
| 657 } | 689 } |
| 658 | 690 |
| 659 // Test that if there's not a full frame, we fail to parse it. | 691 // Test that if there's not a full frame, we fail to parse it. |
| 660 TEST_F(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { | 692 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { |
| 661 SpdyFramer framer; | 693 SpdyFramer framer; |
| 662 framer.set_enable_compression(false); | 694 framer.set_enable_compression(false); |
| 663 | 695 |
| 664 // Encode the header block into a Headers frame. | 696 // Encode the header block into a Headers frame. |
| 665 SpdyHeadersIR headers(1); | 697 SpdyHeadersIR headers(1); |
| 666 headers.SetHeader("alpha", "beta"); | 698 headers.SetHeader("alpha", "beta"); |
| 667 headers.SetHeader("gamma", "charlie"); | 699 headers.SetHeader("gamma", "charlie"); |
| 668 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 700 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 669 | 701 |
| 670 TestSpdyVisitor visitor; | 702 TestSpdyVisitor visitor; |
| 671 visitor.use_compression_ = false; | 703 visitor.use_compression_ = false; |
| 672 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 704 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 673 frame.size() - 2); | 705 frame.size() - 2); |
| 674 | 706 |
| 675 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 707 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 676 EXPECT_EQ(0u, visitor.headers_.size()); | 708 EXPECT_EQ(0u, visitor.headers_.size()); |
| 677 } | 709 } |
| 678 | 710 |
| 679 // Test that we treat incoming upper-case or mixed-case header values as | 711 // Test that we treat incoming upper-case or mixed-case header values as |
| 680 // malformed. | 712 // malformed. |
| 681 TEST_F(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { | 713 TEST_P(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { |
| 682 SpdyFramer framer; | 714 SpdyFramer framer; |
| 683 framer.set_enable_compression(false); | 715 framer.set_enable_compression(false); |
| 684 | 716 |
| 685 SpdyFrameBuilder frame(1024); | 717 SpdyFrameBuilder frame(1024); |
| 686 frame.BeginNewFrame(framer, HEADERS, 0, 1); | 718 frame.BeginNewFrame(framer, HEADERS, 0, 1); |
| 687 frame.WriteUInt32(1); | 719 frame.WriteUInt32(1); |
| 688 frame.WriteStringPiece32("Name1"); | 720 frame.WriteStringPiece32("Name1"); |
| 689 frame.WriteStringPiece32("value1"); | 721 frame.WriteStringPiece32("value1"); |
| 690 frame.RewriteLength(framer); | 722 frame.RewriteLength(framer); |
| 691 | 723 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 706 | 738 |
| 707 SpdyHeaderBlock new_headers; | 739 SpdyHeaderBlock new_headers; |
| 708 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 740 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 709 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 741 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 710 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 742 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 711 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); | 743 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); |
| 712 } | 744 } |
| 713 | 745 |
| 714 // Test that we can encode and decode stream dependency values in a header | 746 // Test that we can encode and decode stream dependency values in a header |
| 715 // frame. | 747 // frame. |
| 716 TEST_F(SpdyFramerTest, HeaderStreamDependencyValues) { | 748 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { |
| 717 SpdyFramer framer; | 749 SpdyFramer framer; |
| 718 framer.set_enable_compression(false); | 750 framer.set_enable_compression(false); |
| 719 | 751 |
| 720 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; | 752 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; |
| 721 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { | 753 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { |
| 722 const bool exclusive_test_array[] = {true, false}; | 754 const bool exclusive_test_array[] = {true, false}; |
| 723 for (bool exclusive : exclusive_test_array) { | 755 for (bool exclusive : exclusive_test_array) { |
| 724 SpdyHeadersIR headers(1); | 756 SpdyHeadersIR headers(1); |
| 725 headers.set_has_priority(true); | 757 headers.set_has_priority(true); |
| 726 headers.set_parent_stream_id(parent_stream_id); | 758 headers.set_parent_stream_id(parent_stream_id); |
| 727 headers.set_exclusive(exclusive); | 759 headers.set_exclusive(exclusive); |
| 728 SpdySerializedFrame frame( | 760 SpdySerializedFrame frame( |
| 729 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 761 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 730 | 762 |
| 731 TestSpdyVisitor visitor; | 763 TestSpdyVisitor visitor; |
| 732 visitor.use_compression_ = false; | 764 visitor.use_compression_ = false; |
| 733 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 765 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 734 frame.size()); | 766 frame.size()); |
| 735 | 767 |
| 736 EXPECT_TRUE(visitor.header_has_priority_); | 768 EXPECT_TRUE(visitor.header_has_priority_); |
| 737 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); | 769 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); |
| 738 EXPECT_EQ(exclusive, visitor.header_exclusive_); | 770 EXPECT_EQ(exclusive, visitor.header_exclusive_); |
| 739 } | 771 } |
| 740 } | 772 } |
| 741 } | 773 } |
| 742 | 774 |
| 743 // Test that if we receive a frame with payload length field at the | 775 // Test that if we receive a frame with payload length field at the |
| 744 // advertised max size, we do not set an error in ProcessInput. | 776 // advertised max size, we do not set an error in ProcessInput. |
| 745 TEST_F(SpdyFramerTest, AcceptMaxFrameSizeSetting) { | 777 TEST_P(SpdyFramerTest, AcceptMaxFrameSizeSetting) { |
| 746 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 778 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 747 SpdyFramer framer; | 779 SpdyFramer framer; |
| 748 framer.set_visitor(&visitor); | 780 framer.set_visitor(&visitor); |
| 749 | 781 |
| 750 // DATA frame with maximum allowed payload length. | 782 // DATA frame with maximum allowed payload length. |
| 751 unsigned char kH2FrameData[] = { | 783 unsigned char kH2FrameData[] = { |
| 752 0x00, 0x40, 0x00, // Length: 2^14 | 784 0x00, 0x40, 0x00, // Length: 2^14 |
| 753 0x00, // Type: HEADERS | 785 0x00, // Type: HEADERS |
| 754 0x00, // Flags: None | 786 0x00, // Flags: None |
| 755 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 787 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 756 0x00, 0x00, 0x00, 0x00, // Junk payload | 788 0x00, 0x00, 0x00, 0x00, // Junk payload |
| 757 }; | 789 }; |
| 758 | 790 |
| 759 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 791 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
| 760 sizeof(kH2FrameData), false); | 792 sizeof(kH2FrameData), false); |
| 761 | 793 |
| 762 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); | 794 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); |
| 763 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); | 795 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); |
| 764 framer.ProcessInput(frame.data(), frame.size()); | 796 framer.ProcessInput(frame.data(), frame.size()); |
| 765 EXPECT_FALSE(framer.HasError()); | 797 EXPECT_FALSE(framer.HasError()); |
| 766 } | 798 } |
| 767 | 799 |
| 768 // Test that if we receive a frame with payload length larger than the | 800 // Test that if we receive a frame with payload length larger than the |
| 769 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. | 801 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. |
| 770 TEST_F(SpdyFramerTest, ExceedMaxFrameSizeSetting) { | 802 TEST_P(SpdyFramerTest, ExceedMaxFrameSizeSetting) { |
| 771 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 803 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 772 SpdyFramer framer; | 804 SpdyFramer framer; |
| 773 framer.set_visitor(&visitor); | 805 framer.set_visitor(&visitor); |
| 774 | 806 |
| 775 // DATA frame with too large payload length. | 807 // DATA frame with too large payload length. |
| 776 unsigned char kH2FrameData[] = { | 808 unsigned char kH2FrameData[] = { |
| 777 0x00, 0x40, 0x01, // Length: 2^14 + 1 | 809 0x00, 0x40, 0x01, // Length: 2^14 + 1 |
| 778 0x00, // Type: HEADERS | 810 0x00, // Type: HEADERS |
| 779 0x00, // Flags: None | 811 0x00, // Flags: None |
| 780 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 812 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 781 0x00, 0x00, 0x00, 0x00, // Junk payload | 813 0x00, 0x00, 0x00, 0x00, // Junk payload |
| 782 }; | 814 }; |
| 783 | 815 |
| 784 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 816 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
| 785 sizeof(kH2FrameData), false); | 817 sizeof(kH2FrameData), false); |
| 786 | 818 |
| 787 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 819 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 788 framer.ProcessInput(frame.data(), frame.size()); | 820 framer.ProcessInput(frame.data(), frame.size()); |
| 789 EXPECT_TRUE(framer.HasError()); | 821 EXPECT_TRUE(framer.HasError()); |
| 790 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) | 822 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) |
| 791 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 823 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 792 } | 824 } |
| 793 | 825 |
| 794 // Test that if we receive a DATA frame with padding length larger than the | 826 // Test that if we receive a DATA frame with padding length larger than the |
| 795 // payload length, we set an error of SPDY_INVALID_PADDING | 827 // payload length, we set an error of SPDY_INVALID_PADDING |
| 796 TEST_F(SpdyFramerTest, OversizedDataPaddingError) { | 828 TEST_P(SpdyFramerTest, OversizedDataPaddingError) { |
| 797 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 829 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 798 SpdyFramer framer; | 830 SpdyFramer framer; |
| 799 framer.set_visitor(&visitor); | 831 framer.set_visitor(&visitor); |
| 800 | 832 |
| 801 // DATA frame with invalid padding length. | 833 // DATA frame with invalid padding length. |
| 802 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 834 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
| 803 // MSVC, where |char| is signed by default, which would not compile because of | 835 // MSVC, where |char| is signed by default, which would not compile because of |
| 804 // the element exceeding 127. | 836 // the element exceeding 127. |
| 805 unsigned char kH2FrameData[] = { | 837 unsigned char kH2FrameData[] = { |
| 806 0x00, 0x00, 0x05, // Length: 5 | 838 0x00, 0x00, 0x05, // Length: 5 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 821 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 853 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 822 } | 854 } |
| 823 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 855 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 824 EXPECT_TRUE(framer.HasError()); | 856 EXPECT_TRUE(framer.HasError()); |
| 825 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 857 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 826 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 858 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 827 } | 859 } |
| 828 | 860 |
| 829 // Test that if we receive a DATA frame with padding length not larger than the | 861 // Test that if we receive a DATA frame with padding length not larger than the |
| 830 // payload length, we do not set an error of SPDY_INVALID_PADDING | 862 // payload length, we do not set an error of SPDY_INVALID_PADDING |
| 831 TEST_F(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { | 863 TEST_P(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { |
| 832 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 864 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 833 SpdyFramer framer; | 865 SpdyFramer framer; |
| 834 framer.set_visitor(&visitor); | 866 framer.set_visitor(&visitor); |
| 835 | 867 |
| 836 // DATA frame with valid Padding length | 868 // DATA frame with valid Padding length |
| 837 char kH2FrameData[] = { | 869 char kH2FrameData[] = { |
| 838 0x00, 0x00, 0x05, // Length: 5 | 870 0x00, 0x00, 0x05, // Length: 5 |
| 839 0x00, // Type: DATA | 871 0x00, // Type: DATA |
| 840 0x08, // Flags: PADDED | 872 0x08, // Flags: PADDED |
| 841 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 873 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 856 } | 888 } |
| 857 | 889 |
| 858 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 890 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 859 EXPECT_FALSE(framer.HasError()); | 891 EXPECT_FALSE(framer.HasError()); |
| 860 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 892 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 861 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 893 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 862 } | 894 } |
| 863 | 895 |
| 864 // Test that if we receive a HEADERS frame with padding length larger than the | 896 // Test that if we receive a HEADERS frame with padding length larger than the |
| 865 // payload length, we set an error of SPDY_INVALID_PADDING | 897 // payload length, we set an error of SPDY_INVALID_PADDING |
| 866 TEST_F(SpdyFramerTest, OversizedHeadersPaddingError) { | 898 TEST_P(SpdyFramerTest, OversizedHeadersPaddingError) { |
| 867 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 899 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 868 SpdyFramer framer; | 900 SpdyFramer framer; |
| 869 framer.set_visitor(&visitor); | 901 framer.set_visitor(&visitor); |
| 870 | 902 |
| 871 // HEADERS frame with invalid padding length. | 903 // HEADERS frame with invalid padding length. |
| 872 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 904 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
| 873 // MSVC, where |char| is signed by default, which would not compile because of | 905 // MSVC, where |char| is signed by default, which would not compile because of |
| 874 // the element exceeding 127. | 906 // the element exceeding 127. |
| 875 unsigned char kH2FrameData[] = { | 907 unsigned char kH2FrameData[] = { |
| 876 0x00, 0x00, 0x05, // Length: 5 | 908 0x00, 0x00, 0x05, // Length: 5 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 888 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | 920 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); |
| 889 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 921 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 890 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 922 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 891 EXPECT_TRUE(framer.HasError()); | 923 EXPECT_TRUE(framer.HasError()); |
| 892 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 924 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 893 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 925 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 894 } | 926 } |
| 895 | 927 |
| 896 // Test that if we receive a HEADERS frame with padding length not larger | 928 // Test that if we receive a HEADERS frame with padding length not larger |
| 897 // than the payload length, we do not set an error of SPDY_INVALID_PADDING | 929 // than the payload length, we do not set an error of SPDY_INVALID_PADDING |
| 898 TEST_F(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { | 930 TEST_P(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { |
| 899 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 931 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 900 SpdyFramer framer; | 932 SpdyFramer framer; |
| 901 framer.set_visitor(&visitor); | 933 framer.set_visitor(&visitor); |
| 902 | 934 |
| 903 // HEADERS frame with invalid Padding length | 935 // HEADERS frame with invalid Padding length |
| 904 char kH2FrameData[] = { | 936 char kH2FrameData[] = { |
| 905 0x00, 0x00, 0x05, // Length: 5 | 937 0x00, 0x00, 0x05, // Length: 5 |
| 906 0x01, // Type: HEADERS | 938 0x01, // Type: HEADERS |
| 907 0x08, // Flags: PADDED | 939 0x08, // Flags: PADDED |
| 908 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 940 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 909 0x04, // PadLen: 4 trailing bytes | 941 0x04, // PadLen: 4 trailing bytes |
| 910 0x00, 0x00, 0x00, 0x00, // Padding | 942 0x00, 0x00, 0x00, 0x00, // Padding |
| 911 }; | 943 }; |
| 912 | 944 |
| 913 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 945 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 914 | 946 |
| 915 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); | 947 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); |
| 916 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | 948 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); |
| 917 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 949 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 918 EXPECT_FALSE(framer.HasError()); | 950 EXPECT_FALSE(framer.HasError()); |
| 919 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 951 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 920 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 952 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 921 } | 953 } |
| 922 | 954 |
| 923 // Test that if we receive a DATA with stream ID zero, we signal an error | 955 // Test that if we receive a DATA with stream ID zero, we signal an error |
| 924 // (but don't crash). | 956 // (but don't crash). |
| 925 TEST_F(SpdyFramerTest, DataWithStreamIdZero) { | 957 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { |
| 926 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 958 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 927 SpdyFramer framer; | 959 SpdyFramer framer; |
| 928 framer.set_visitor(&visitor); | 960 framer.set_visitor(&visitor); |
| 929 | 961 |
| 930 const char bytes[] = "hello"; | 962 const char bytes[] = "hello"; |
| 931 SpdyDataIR data_ir(0, bytes); | 963 SpdyDataIR data_ir(0, bytes); |
| 932 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 964 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 933 | 965 |
| 934 // We shouldn't have to read the whole frame before we signal an error. | 966 // We shouldn't have to read the whole frame before we signal an error. |
| 935 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 967 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 936 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 968 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 937 EXPECT_TRUE(framer.HasError()); | 969 EXPECT_TRUE(framer.HasError()); |
| 938 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 970 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 939 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 971 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 940 } | 972 } |
| 941 | 973 |
| 942 // Test that if we receive a HEADERS with stream ID zero, we signal an error | 974 // Test that if we receive a HEADERS with stream ID zero, we signal an error |
| 943 // (but don't crash). | 975 // (but don't crash). |
| 944 TEST_F(SpdyFramerTest, HeadersWithStreamIdZero) { | 976 TEST_P(SpdyFramerTest, HeadersWithStreamIdZero) { |
| 945 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 977 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 946 SpdyFramer framer; | 978 SpdyFramer framer; |
| 947 framer.set_visitor(&visitor); | 979 framer.set_visitor(&visitor); |
| 948 | 980 |
| 949 SpdyHeadersIR headers(0); | 981 SpdyHeadersIR headers(0); |
| 950 headers.SetHeader("alpha", "beta"); | 982 headers.SetHeader("alpha", "beta"); |
| 951 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 983 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 952 | 984 |
| 953 // We shouldn't have to read the whole frame before we signal an error. | 985 // We shouldn't have to read the whole frame before we signal an error. |
| 954 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 986 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 955 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 987 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 956 EXPECT_TRUE(framer.HasError()); | 988 EXPECT_TRUE(framer.HasError()); |
| 957 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 989 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 958 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 990 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 959 } | 991 } |
| 960 | 992 |
| 961 // Test that if we receive a PRIORITY with stream ID zero, we signal an error | 993 // Test that if we receive a PRIORITY with stream ID zero, we signal an error |
| 962 // (but don't crash). | 994 // (but don't crash). |
| 963 TEST_F(SpdyFramerTest, PriorityWithStreamIdZero) { | 995 TEST_P(SpdyFramerTest, PriorityWithStreamIdZero) { |
| 964 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 996 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 965 SpdyFramer framer; | 997 SpdyFramer framer; |
| 966 framer.set_visitor(&visitor); | 998 framer.set_visitor(&visitor); |
| 967 | 999 |
| 968 SpdyPriorityIR priority_ir(0, 1, 16, true); | 1000 SpdyPriorityIR priority_ir(0, 1, 16, true); |
| 969 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 1001 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
| 970 | 1002 |
| 971 // We shouldn't have to read the whole frame before we signal an error. | 1003 // We shouldn't have to read the whole frame before we signal an error. |
| 972 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1004 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 973 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1005 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 974 EXPECT_TRUE(framer.HasError()); | 1006 EXPECT_TRUE(framer.HasError()); |
| 975 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1007 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 976 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1008 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 977 } | 1009 } |
| 978 | 1010 |
| 979 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error | 1011 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error |
| 980 // (but don't crash). | 1012 // (but don't crash). |
| 981 TEST_F(SpdyFramerTest, RstStreamWithStreamIdZero) { | 1013 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { |
| 982 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1014 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 983 SpdyFramer framer; | 1015 SpdyFramer framer; |
| 984 framer.set_visitor(&visitor); | 1016 framer.set_visitor(&visitor); |
| 985 | 1017 |
| 986 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); | 1018 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); |
| 987 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); | 1019 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); |
| 988 | 1020 |
| 989 // We shouldn't have to read the whole frame before we signal an error. | 1021 // We shouldn't have to read the whole frame before we signal an error. |
| 990 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1022 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 991 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1023 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 992 EXPECT_TRUE(framer.HasError()); | 1024 EXPECT_TRUE(framer.HasError()); |
| 993 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1025 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 994 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1026 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 995 } | 1027 } |
| 996 | 1028 |
| 997 // Test that if we receive a SETTINGS with stream ID other than zero, | 1029 // Test that if we receive a SETTINGS with stream ID other than zero, |
| 998 // we signal an error (but don't crash). | 1030 // we signal an error (but don't crash). |
| 999 TEST_F(SpdyFramerTest, SettingsWithStreamIdNotZero) { | 1031 TEST_P(SpdyFramerTest, SettingsWithStreamIdNotZero) { |
| 1000 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1032 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1001 SpdyFramer framer; | 1033 SpdyFramer framer; |
| 1002 framer.set_visitor(&visitor); | 1034 framer.set_visitor(&visitor); |
| 1003 | 1035 |
| 1004 // Settings frame with invalid StreamID of 0x01 | 1036 // Settings frame with invalid StreamID of 0x01 |
| 1005 char kH2FrameData[] = { | 1037 char kH2FrameData[] = { |
| 1006 0x00, 0x00, 0x06, // Length: 6 | 1038 0x00, 0x00, 0x06, // Length: 6 |
| 1007 0x04, // Type: SETTINGS | 1039 0x04, // Type: SETTINGS |
| 1008 0x00, // Flags: none | 1040 0x00, // Flags: none |
| 1009 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1041 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1010 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1042 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| 1011 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 | 1043 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 |
| 1012 }; | 1044 }; |
| 1013 | 1045 |
| 1014 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1046 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1015 | 1047 |
| 1016 // We shouldn't have to read the whole frame before we signal an error. | 1048 // We shouldn't have to read the whole frame before we signal an error. |
| 1017 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1049 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1018 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1050 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1019 EXPECT_TRUE(framer.HasError()); | 1051 EXPECT_TRUE(framer.HasError()); |
| 1020 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1052 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1021 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1053 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1022 } | 1054 } |
| 1023 | 1055 |
| 1024 // Test that if we receive a GOAWAY with stream ID other than zero, | 1056 // Test that if we receive a GOAWAY with stream ID other than zero, |
| 1025 // we signal an error (but don't crash). | 1057 // we signal an error (but don't crash). |
| 1026 TEST_F(SpdyFramerTest, GoawayWithStreamIdNotZero) { | 1058 TEST_P(SpdyFramerTest, GoawayWithStreamIdNotZero) { |
| 1027 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1059 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1028 SpdyFramer framer; | 1060 SpdyFramer framer; |
| 1029 framer.set_visitor(&visitor); | 1061 framer.set_visitor(&visitor); |
| 1030 | 1062 |
| 1031 // GOAWAY frame with invalid StreamID of 0x01 | 1063 // GOAWAY frame with invalid StreamID of 0x01 |
| 1032 char kH2FrameData[] = { | 1064 char kH2FrameData[] = { |
| 1033 0x00, 0x00, 0x0a, // Length: 10 | 1065 0x00, 0x00, 0x0a, // Length: 10 |
| 1034 0x07, // Type: GOAWAY | 1066 0x07, // Type: GOAWAY |
| 1035 0x00, // Flags: none | 1067 0x00, // Flags: none |
| 1036 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1068 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1037 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1069 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 1038 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1070 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 1039 0x47, 0x41, // Description | 1071 0x47, 0x41, // Description |
| 1040 }; | 1072 }; |
| 1041 | 1073 |
| 1042 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1074 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1043 | 1075 |
| 1044 // We shouldn't have to read the whole frame before we signal an error. | 1076 // We shouldn't have to read the whole frame before we signal an error. |
| 1045 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1077 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1046 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1078 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1047 EXPECT_TRUE(framer.HasError()); | 1079 EXPECT_TRUE(framer.HasError()); |
| 1048 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1080 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1049 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1081 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1050 } | 1082 } |
| 1051 | 1083 |
| 1052 // Test that if we receive a CONTINUATION with stream ID zero, we signal an | 1084 // Test that if we receive a CONTINUATION with stream ID zero, we signal an |
| 1053 // SPDY_INVALID_STREAM_ID. | 1085 // SPDY_INVALID_STREAM_ID. |
| 1054 TEST_F(SpdyFramerTest, ContinuationWithStreamIdZero) { | 1086 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { |
| 1055 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1087 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1056 SpdyFramer framer; | 1088 SpdyFramer framer; |
| 1057 framer.set_visitor(&visitor); | 1089 framer.set_visitor(&visitor); |
| 1058 | 1090 |
| 1059 SpdyContinuationIR continuation(0); | 1091 SpdyContinuationIR continuation(0); |
| 1060 auto some_nonsense_encoding = | 1092 auto some_nonsense_encoding = |
| 1061 base::MakeUnique<string>("some nonsense encoding"); | 1093 base::MakeUnique<string>("some nonsense encoding"); |
| 1062 continuation.take_encoding(std::move(some_nonsense_encoding)); | 1094 continuation.take_encoding(std::move(some_nonsense_encoding)); |
| 1063 continuation.set_end_headers(true); | 1095 continuation.set_end_headers(true); |
| 1064 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 1096 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 1065 | 1097 |
| 1066 // We shouldn't have to read the whole frame before we signal an error. | 1098 // We shouldn't have to read the whole frame before we signal an error. |
| 1067 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1099 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1068 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1100 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1069 EXPECT_TRUE(framer.HasError()); | 1101 EXPECT_TRUE(framer.HasError()); |
| 1070 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1102 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1071 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1103 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1072 } | 1104 } |
| 1073 | 1105 |
| 1074 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 1106 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an |
| 1075 // SPDY_INVALID_STREAM_ID. | 1107 // SPDY_INVALID_STREAM_ID. |
| 1076 TEST_F(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 1108 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
| 1077 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1109 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1078 SpdyFramer framer; | 1110 SpdyFramer framer; |
| 1079 framer.set_visitor(&visitor); | 1111 framer.set_visitor(&visitor); |
| 1080 | 1112 |
| 1081 SpdyPushPromiseIR push_promise(0, 4); | 1113 SpdyPushPromiseIR push_promise(0, 4); |
| 1082 push_promise.SetHeader("alpha", "beta"); | 1114 push_promise.SetHeader("alpha", "beta"); |
| 1083 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1115 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 1084 | 1116 |
| 1085 // We shouldn't have to read the whole frame before we signal an error. | 1117 // We shouldn't have to read the whole frame before we signal an error. |
| 1086 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1118 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1087 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1119 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1088 EXPECT_TRUE(framer.HasError()); | 1120 EXPECT_TRUE(framer.HasError()); |
| 1089 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1121 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1090 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1122 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1091 } | 1123 } |
| 1092 | 1124 |
| 1093 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 1125 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
| 1094 // signal SPDY_INVALID_STREAM_ID. | 1126 // signal SPDY_INVALID_STREAM_ID. |
| 1095 TEST_F(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 1127 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
| 1096 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1128 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1097 SpdyFramer framer; | 1129 SpdyFramer framer; |
| 1098 framer.set_visitor(&visitor); | 1130 framer.set_visitor(&visitor); |
| 1099 | 1131 |
| 1100 SpdyPushPromiseIR push_promise(3, 0); | 1132 SpdyPushPromiseIR push_promise(3, 0); |
| 1101 push_promise.SetHeader("alpha", "beta"); | 1133 push_promise.SetHeader("alpha", "beta"); |
| 1102 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1134 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 1103 | 1135 |
| 1104 // We shouldn't have to read the whole frame before we signal an error. | 1136 // We shouldn't have to read the whole frame before we signal an error. |
| 1105 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1137 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1106 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1138 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1107 EXPECT_TRUE(framer.HasError()); | 1139 EXPECT_TRUE(framer.HasError()); |
| 1108 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 1140 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 1109 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1141 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1110 } | 1142 } |
| 1111 | 1143 |
| 1112 TEST_F(SpdyFramerTest, DuplicateHeader) { | 1144 TEST_P(SpdyFramerTest, DuplicateHeader) { |
| 1113 SpdyFramer framer; | 1145 SpdyFramer framer; |
| 1114 // Frame builder with plentiful buffer size. | 1146 // Frame builder with plentiful buffer size. |
| 1115 SpdyFrameBuilder frame(1024); | 1147 SpdyFrameBuilder frame(1024); |
| 1116 frame.BeginNewFrame(framer, HEADERS, 0, 3); | 1148 frame.BeginNewFrame(framer, HEADERS, 0, 3); |
| 1117 | 1149 |
| 1118 frame.WriteUInt32(2); // Number of headers. | 1150 frame.WriteUInt32(2); // Number of headers. |
| 1119 frame.WriteStringPiece32("name"); | 1151 frame.WriteStringPiece32("name"); |
| 1120 frame.WriteStringPiece32("value1"); | 1152 frame.WriteStringPiece32("value1"); |
| 1121 frame.WriteStringPiece32("name"); | 1153 frame.WriteStringPiece32("name"); |
| 1122 frame.WriteStringPiece32("value2"); | 1154 frame.WriteStringPiece32("value2"); |
| 1123 // write the length | 1155 // write the length |
| 1124 frame.RewriteLength(framer); | 1156 frame.RewriteLength(framer); |
| 1125 | 1157 |
| 1126 SpdyHeaderBlock new_headers; | 1158 SpdyHeaderBlock new_headers; |
| 1127 framer.set_enable_compression(false); | 1159 framer.set_enable_compression(false); |
| 1128 SpdySerializedFrame control_frame(frame.take()); | 1160 SpdySerializedFrame control_frame(frame.take()); |
| 1129 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); | 1161 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); |
| 1130 // This should fail because duplicate headers are verboten by the spec. | 1162 // This should fail because duplicate headers are verboten by the spec. |
| 1131 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 1163 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 1132 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 1164 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 1133 } | 1165 } |
| 1134 | 1166 |
| 1135 TEST_F(SpdyFramerTest, MultiValueHeader) { | 1167 TEST_P(SpdyFramerTest, MultiValueHeader) { |
| 1136 SpdyFramer framer; | 1168 SpdyFramer framer; |
| 1137 // Frame builder with plentiful buffer size. | 1169 // Frame builder with plentiful buffer size. |
| 1138 SpdyFrameBuilder frame(1024); | 1170 SpdyFrameBuilder frame(1024); |
| 1139 frame.BeginNewFrame(framer, HEADERS, | 1171 frame.BeginNewFrame(framer, HEADERS, |
| 1140 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); | 1172 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); |
| 1141 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. | 1173 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. |
| 1142 frame.WriteUInt8(255); // Priority weight. | 1174 frame.WriteUInt8(255); // Priority weight. |
| 1143 | 1175 |
| 1144 string value("value1\0value2", 13); | 1176 string value("value1\0value2", 13); |
| 1145 // TODO(jgraettinger): If this pattern appears again, move to test class. | 1177 // TODO(jgraettinger): If this pattern appears again, move to test class. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1158 TestSpdyVisitor visitor; | 1190 TestSpdyVisitor visitor; |
| 1159 visitor.use_compression_ = false; | 1191 visitor.use_compression_ = false; |
| 1160 visitor.SimulateInFramer( | 1192 visitor.SimulateInFramer( |
| 1161 reinterpret_cast<unsigned char*>(control_frame.data()), | 1193 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 1162 control_frame.size()); | 1194 control_frame.size()); |
| 1163 | 1195 |
| 1164 EXPECT_THAT(visitor.headers_, | 1196 EXPECT_THAT(visitor.headers_, |
| 1165 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); | 1197 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); |
| 1166 } | 1198 } |
| 1167 | 1199 |
| 1168 TEST_F(SpdyFramerTest, CompressEmptyHeaders) { | 1200 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { |
| 1169 // See crbug.com/172383 | 1201 // See crbug.com/172383 |
| 1170 SpdyHeadersIR headers(1); | 1202 SpdyHeadersIR headers(1); |
| 1171 headers.SetHeader("server", "SpdyServer 1.0"); | 1203 headers.SetHeader("server", "SpdyServer 1.0"); |
| 1172 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 1204 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| 1173 headers.SetHeader("status", "200"); | 1205 headers.SetHeader("status", "200"); |
| 1174 headers.SetHeader("version", "HTTP/1.1"); | 1206 headers.SetHeader("version", "HTTP/1.1"); |
| 1175 headers.SetHeader("content-type", "text/html"); | 1207 headers.SetHeader("content-type", "text/html"); |
| 1176 headers.SetHeader("content-length", "12"); | 1208 headers.SetHeader("content-length", "12"); |
| 1177 headers.SetHeader("x-empty-header", ""); | 1209 headers.SetHeader("x-empty-header", ""); |
| 1178 | 1210 |
| 1179 SpdyFramer framer; | 1211 SpdyFramer framer; |
| 1180 framer.set_enable_compression(true); | 1212 framer.set_enable_compression(true); |
| 1181 SpdySerializedFrame frame1( | 1213 SpdySerializedFrame frame1( |
| 1182 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1214 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 1183 } | 1215 } |
| 1184 | 1216 |
| 1185 TEST_F(SpdyFramerTest, Basic) { | 1217 TEST_P(SpdyFramerTest, Basic) { |
| 1186 // Send HEADERS frames with PRIORITY and END_HEADERS set. | 1218 // Send HEADERS frames with PRIORITY and END_HEADERS set. |
| 1187 // frame-format off | 1219 // frame-format off |
| 1188 const unsigned char kH2Input[] = { | 1220 const unsigned char kH2Input[] = { |
| 1189 0x00, 0x00, 0x05, // Length: 5 | 1221 0x00, 0x00, 0x05, // Length: 5 |
| 1190 0x01, // Type: HEADERS | 1222 0x01, // Type: HEADERS |
| 1191 0x24, // Flags: END_HEADERS|PRIORITY | 1223 0x24, // Flags: END_HEADERS|PRIORITY |
| 1192 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1224 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1193 0x00, 0x00, 0x00, 0x00, // Parent: 0 | 1225 0x00, 0x00, 0x00, 0x00, // Parent: 0 |
| 1194 0x82, // Weight: 131 | 1226 0x82, // Weight: 131 |
| 1195 | 1227 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 EXPECT_EQ(3, visitor.headers_frame_count_); | 1288 EXPECT_EQ(3, visitor.headers_frame_count_); |
| 1257 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); | 1289 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); |
| 1258 | 1290 |
| 1259 EXPECT_EQ(0, visitor.fin_flag_count_); | 1291 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1260 EXPECT_EQ(0, visitor.end_of_stream_count_); | 1292 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 1261 EXPECT_EQ(4, visitor.data_frame_count_); | 1293 EXPECT_EQ(4, visitor.data_frame_count_); |
| 1262 visitor.fin_opaque_data_.clear(); | 1294 visitor.fin_opaque_data_.clear(); |
| 1263 } | 1295 } |
| 1264 | 1296 |
| 1265 // Test that the FIN flag on a data frame signifies EOF. | 1297 // Test that the FIN flag on a data frame signifies EOF. |
| 1266 TEST_F(SpdyFramerTest, FinOnDataFrame) { | 1298 TEST_P(SpdyFramerTest, FinOnDataFrame) { |
| 1267 // Send HEADERS frames with END_HEADERS set. | 1299 // Send HEADERS frames with END_HEADERS set. |
| 1268 // frame-format off | 1300 // frame-format off |
| 1269 const unsigned char kH2Input[] = { | 1301 const unsigned char kH2Input[] = { |
| 1270 0x00, 0x00, 0x05, // Length: 5 | 1302 0x00, 0x00, 0x05, // Length: 5 |
| 1271 0x01, // Type: HEADERS | 1303 0x01, // Type: HEADERS |
| 1272 0x24, // Flags: END_HEADERS|PRIORITY | 1304 0x24, // Flags: END_HEADERS|PRIORITY |
| 1273 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1305 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1274 0x00, 0x00, 0x00, 0x00, // Parent: 0 | 1306 0x00, 0x00, 0x00, 0x00, // Parent: 0 |
| 1275 0x82, // Weight: 131 | 1307 0x82, // Weight: 131 |
| 1276 | 1308 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1301 | 1333 |
| 1302 EXPECT_EQ(0, visitor.error_count_); | 1334 EXPECT_EQ(0, visitor.error_count_); |
| 1303 EXPECT_EQ(2, visitor.headers_frame_count_); | 1335 EXPECT_EQ(2, visitor.headers_frame_count_); |
| 1304 EXPECT_EQ(16, visitor.data_bytes_); | 1336 EXPECT_EQ(16, visitor.data_bytes_); |
| 1305 EXPECT_EQ(0, visitor.fin_frame_count_); | 1337 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1306 EXPECT_EQ(0, visitor.fin_flag_count_); | 1338 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1307 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1339 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1308 EXPECT_EQ(2, visitor.data_frame_count_); | 1340 EXPECT_EQ(2, visitor.data_frame_count_); |
| 1309 } | 1341 } |
| 1310 | 1342 |
| 1311 TEST_F(SpdyFramerTest, FinOnHeadersFrame) { | 1343 TEST_P(SpdyFramerTest, FinOnHeadersFrame) { |
| 1312 // Send HEADERS frames with END_HEADERS set. | 1344 // Send HEADERS frames with END_HEADERS set. |
| 1313 // frame-format off | 1345 // frame-format off |
| 1314 const unsigned char kH2Input[] = { | 1346 const unsigned char kH2Input[] = { |
| 1315 0x00, 0x00, 0x05, // Length: 5 | 1347 0x00, 0x00, 0x05, // Length: 5 |
| 1316 0x01, // Type: HEADERS | 1348 0x01, // Type: HEADERS |
| 1317 0x24, // Flags: END_HEADERS|PRIORITY | 1349 0x24, // Flags: END_HEADERS|PRIORITY |
| 1318 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1350 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1319 0x00, 0x00, 0x00, 0x00, // Parent: 0 | 1351 0x00, 0x00, 0x00, 0x00, // Parent: 0 |
| 1320 0x82, // Weight: 131 | 1352 0x82, // Weight: 131 |
| 1321 | 1353 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1334 EXPECT_EQ(2, visitor.headers_frame_count_); | 1366 EXPECT_EQ(2, visitor.headers_frame_count_); |
| 1335 EXPECT_EQ(0, visitor.data_bytes_); | 1367 EXPECT_EQ(0, visitor.data_bytes_); |
| 1336 EXPECT_EQ(0, visitor.fin_frame_count_); | 1368 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1337 EXPECT_EQ(1, visitor.fin_flag_count_); | 1369 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 1338 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1370 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1339 EXPECT_EQ(0, visitor.data_frame_count_); | 1371 EXPECT_EQ(0, visitor.data_frame_count_); |
| 1340 } | 1372 } |
| 1341 | 1373 |
| 1342 // Verify we can decompress the stream even if handed over to the | 1374 // Verify we can decompress the stream even if handed over to the |
| 1343 // framer 1 byte at a time. | 1375 // framer 1 byte at a time. |
| 1344 TEST_F(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { | 1376 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { |
| 1345 SpdyFramer framer; | 1377 SpdyFramer framer; |
| 1346 | 1378 |
| 1347 framer.set_enable_compression(true); | 1379 framer.set_enable_compression(true); |
| 1348 | 1380 |
| 1349 const char kHeader1[] = "header1"; | 1381 const char kHeader1[] = "header1"; |
| 1350 const char kHeader2[] = "header2"; | 1382 const char kHeader2[] = "header2"; |
| 1351 const char kValue1[] = "value1"; | 1383 const char kValue1[] = "value1"; |
| 1352 const char kValue2[] = "value2"; | 1384 const char kValue2[] = "value2"; |
| 1353 | 1385 |
| 1354 SpdyHeadersIR headers(1); | 1386 SpdyHeadersIR headers(1); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1379 | 1411 |
| 1380 EXPECT_EQ(0, visitor.error_count_); | 1412 EXPECT_EQ(0, visitor.error_count_); |
| 1381 EXPECT_EQ(1, visitor.headers_frame_count_); | 1413 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 1382 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); | 1414 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); |
| 1383 EXPECT_EQ(0, visitor.fin_frame_count_); | 1415 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1384 EXPECT_EQ(0, visitor.fin_flag_count_); | 1416 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1385 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1417 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1386 EXPECT_EQ(1, visitor.data_frame_count_); | 1418 EXPECT_EQ(1, visitor.data_frame_count_); |
| 1387 } | 1419 } |
| 1388 | 1420 |
| 1389 TEST_F(SpdyFramerTest, WindowUpdateFrame) { | 1421 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
| 1390 SpdyFramer framer; | 1422 SpdyFramer framer; |
| 1391 SpdySerializedFrame frame( | 1423 SpdySerializedFrame frame( |
| 1392 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); | 1424 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); |
| 1393 | 1425 |
| 1394 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; | 1426 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; |
| 1395 const unsigned char kH2FrameData[] = { | 1427 const unsigned char kH2FrameData[] = { |
| 1396 0x00, 0x00, 0x04, // Length: 4 | 1428 0x00, 0x00, 0x04, // Length: 4 |
| 1397 0x08, // Type: WINDOW_UPDATE | 1429 0x08, // Type: WINDOW_UPDATE |
| 1398 0x00, // Flags: none | 1430 0x00, // Flags: none |
| 1399 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1431 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1400 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 | 1432 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 |
| 1401 }; | 1433 }; |
| 1402 | 1434 |
| 1403 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1435 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1404 } | 1436 } |
| 1405 | 1437 |
| 1406 TEST_F(SpdyFramerTest, CreateDataFrame) { | 1438 TEST_P(SpdyFramerTest, CreateDataFrame) { |
| 1407 SpdyFramer framer; | 1439 SpdyFramer framer; |
| 1408 | 1440 |
| 1409 { | 1441 { |
| 1410 const char kDescription[] = "'hello' data frame, no FIN"; | 1442 const char kDescription[] = "'hello' data frame, no FIN"; |
| 1411 // frame-format off | 1443 // frame-format off |
| 1412 const unsigned char kH2FrameData[] = { | 1444 const unsigned char kH2FrameData[] = { |
| 1413 0x00, 0x00, 0x05, // Length: 5 | 1445 0x00, 0x00, 0x05, // Length: 5 |
| 1414 0x00, // Type: DATA | 1446 0x00, // Type: DATA |
| 1415 0x00, // Flags: none | 1447 0x00, // Flags: none |
| 1416 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1448 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1598 0x68, 0x65, 0x6c, 0x6c, // Payload | 1630 0x68, 0x65, 0x6c, 0x6c, // Payload |
| 1599 0x6f, // | 1631 0x6f, // |
| 1600 }; | 1632 }; |
| 1601 SpdyDataIR data_ir(0x7fffffff, "hello"); | 1633 SpdyDataIR data_ir(0x7fffffff, "hello"); |
| 1602 data_ir.set_fin(true); | 1634 data_ir.set_fin(true); |
| 1603 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1635 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 1604 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1636 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1605 } | 1637 } |
| 1606 } | 1638 } |
| 1607 | 1639 |
| 1608 TEST_F(SpdyFramerTest, CreateRstStream) { | 1640 TEST_P(SpdyFramerTest, CreateRstStream) { |
| 1609 SpdyFramer framer; | 1641 SpdyFramer framer; |
| 1610 | 1642 |
| 1611 { | 1643 { |
| 1612 const char kDescription[] = "RST_STREAM frame"; | 1644 const char kDescription[] = "RST_STREAM frame"; |
| 1613 const unsigned char kH2FrameData[] = { | 1645 const unsigned char kH2FrameData[] = { |
| 1614 0x00, 0x00, 0x04, // Length: 4 | 1646 0x00, 0x00, 0x04, // Length: 4 |
| 1615 0x03, // Type: RST_STREAM | 1647 0x03, // Type: RST_STREAM |
| 1616 0x00, // Flags: none | 1648 0x00, // Flags: none |
| 1617 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1649 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1618 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR | 1650 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1644 0x00, // Flags: none | 1676 0x00, // Flags: none |
| 1645 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1677 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
| 1646 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1678 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
| 1647 }; | 1679 }; |
| 1648 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); | 1680 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); |
| 1649 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1681 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 1650 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1682 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1651 } | 1683 } |
| 1652 } | 1684 } |
| 1653 | 1685 |
| 1654 TEST_F(SpdyFramerTest, CreateSettings) { | 1686 TEST_P(SpdyFramerTest, CreateSettings) { |
| 1655 SpdyFramer framer; | 1687 SpdyFramer framer; |
| 1656 | 1688 |
| 1657 { | 1689 { |
| 1658 const char kDescription[] = "Network byte order SETTINGS frame"; | 1690 const char kDescription[] = "Network byte order SETTINGS frame"; |
| 1659 | 1691 |
| 1660 const unsigned char kH2FrameData[] = { | 1692 const unsigned char kH2FrameData[] = { |
| 1661 0x00, 0x00, 0x06, // Length: 6 | 1693 0x00, 0x00, 0x06, // Length: 6 |
| 1662 0x04, // Type: SETTINGS | 1694 0x04, // Type: SETTINGS |
| 1663 0x00, // Flags: none | 1695 0x00, // Flags: none |
| 1664 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1696 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 0x04, // Type: SETTINGS | 1760 0x04, // Type: SETTINGS |
| 1729 0x00, // Flags: none | 1761 0x00, // Flags: none |
| 1730 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1762 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1731 }; | 1763 }; |
| 1732 SpdySettingsIR settings_ir; | 1764 SpdySettingsIR settings_ir; |
| 1733 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1765 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 1734 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1766 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1735 } | 1767 } |
| 1736 } | 1768 } |
| 1737 | 1769 |
| 1738 TEST_F(SpdyFramerTest, CreatePingFrame) { | 1770 TEST_P(SpdyFramerTest, CreatePingFrame) { |
| 1739 SpdyFramer framer; | 1771 SpdyFramer framer; |
| 1740 | 1772 |
| 1741 { | 1773 { |
| 1742 const char kDescription[] = "PING frame"; | 1774 const char kDescription[] = "PING frame"; |
| 1743 const unsigned char kH2FrameData[] = { | 1775 const unsigned char kH2FrameData[] = { |
| 1744 0x00, 0x00, 0x08, // Length: 8 | 1776 0x00, 0x00, 0x08, // Length: 8 |
| 1745 0x06, // Type: PING | 1777 0x06, // Type: PING |
| 1746 0x00, // Flags: none | 1778 0x00, // Flags: none |
| 1747 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1779 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1748 0x12, 0x34, 0x56, 0x78, // Opaque | 1780 0x12, 0x34, 0x56, 0x78, // Opaque |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1765 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1797 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1766 | 1798 |
| 1767 // Tests SpdyPingIR when the ping is an ack. | 1799 // Tests SpdyPingIR when the ping is an ack. |
| 1768 ping_ir.set_is_ack(true); | 1800 ping_ir.set_is_ack(true); |
| 1769 frame = framer.SerializePing(ping_ir); | 1801 frame = framer.SerializePing(ping_ir); |
| 1770 CompareFrame(kDescription, frame, kH2FrameDataWithAck, | 1802 CompareFrame(kDescription, frame, kH2FrameDataWithAck, |
| 1771 arraysize(kH2FrameDataWithAck)); | 1803 arraysize(kH2FrameDataWithAck)); |
| 1772 } | 1804 } |
| 1773 } | 1805 } |
| 1774 | 1806 |
| 1775 TEST_F(SpdyFramerTest, CreateGoAway) { | 1807 TEST_P(SpdyFramerTest, CreateGoAway) { |
| 1776 SpdyFramer framer; | 1808 SpdyFramer framer; |
| 1777 | 1809 |
| 1778 { | 1810 { |
| 1779 const char kDescription[] = "GOAWAY frame"; | 1811 const char kDescription[] = "GOAWAY frame"; |
| 1780 const unsigned char kH2FrameData[] = { | 1812 const unsigned char kH2FrameData[] = { |
| 1781 0x00, 0x00, 0x0a, // Length: 10 | 1813 0x00, 0x00, 0x0a, // Length: 10 |
| 1782 0x07, // Type: GOAWAY | 1814 0x07, // Type: GOAWAY |
| 1783 0x00, // Flags: none | 1815 0x00, // Flags: none |
| 1784 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1816 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1785 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1817 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1801 0x7f, 0xff, 0xff, 0xff, // Last: 0x7fffffff | 1833 0x7f, 0xff, 0xff, 0xff, // Last: 0x7fffffff |
| 1802 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1834 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
| 1803 0x47, 0x41, // Description | 1835 0x47, 0x41, // Description |
| 1804 }; | 1836 }; |
| 1805 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); | 1837 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); |
| 1806 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 1838 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
| 1807 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1839 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1808 } | 1840 } |
| 1809 } | 1841 } |
| 1810 | 1842 |
| 1811 TEST_F(SpdyFramerTest, CreateHeadersUncompressed) { | 1843 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { |
| 1812 SpdyFramer framer; | 1844 SpdyFramer framer; |
| 1813 framer.set_enable_compression(false); | 1845 framer.set_enable_compression(false); |
| 1814 | 1846 |
| 1815 { | 1847 { |
| 1816 const char kDescription[] = "HEADERS frame, no FIN"; | 1848 const char kDescription[] = "HEADERS frame, no FIN"; |
| 1817 // frame-format off | 1849 // frame-format off |
| 1818 const unsigned char kH2FrameData[] = { | 1850 const unsigned char kH2FrameData[] = { |
| 1819 0x00, 0x00, 0x12, // Length: 18 | 1851 0x00, 0x00, 0x12, // Length: 18 |
| 1820 0x01, // Type: HEADERS | 1852 0x01, // Type: HEADERS |
| 1821 0x04, // Flags: END_HEADERS | 1853 0x04, // Flags: END_HEADERS |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 headers_ir.set_padding_len(6); | 2085 headers_ir.set_padding_len(6); |
| 2054 SpdySerializedFrame frame( | 2086 SpdySerializedFrame frame( |
| 2055 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2087 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2056 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 2088 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 2057 } | 2089 } |
| 2058 } | 2090 } |
| 2059 | 2091 |
| 2060 // TODO(phajdan.jr): Clean up after we no longer need | 2092 // TODO(phajdan.jr): Clean up after we no longer need |
| 2061 // to workaround http://crbug.com/139744. | 2093 // to workaround http://crbug.com/139744. |
| 2062 #if !defined(USE_SYSTEM_ZLIB) | 2094 #if !defined(USE_SYSTEM_ZLIB) |
| 2063 TEST_F(SpdyFramerTest, CreateHeadersCompressed) { | 2095 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
| 2064 SpdyFramer framer; | 2096 SpdyFramer framer; |
| 2065 framer.set_enable_compression(true); | 2097 framer.set_enable_compression(true); |
| 2066 | 2098 |
| 2067 { | 2099 { |
| 2068 SpdyHeadersIR headers_ir(1); | 2100 SpdyHeadersIR headers_ir(1); |
| 2069 headers_ir.SetHeader("bar", "foo"); | 2101 headers_ir.SetHeader("bar", "foo"); |
| 2070 headers_ir.SetHeader("foo", "bar"); | 2102 headers_ir.SetHeader("foo", "bar"); |
| 2071 SpdySerializedFrame frame( | 2103 SpdySerializedFrame frame( |
| 2072 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2104 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2073 // Deflate compression doesn't apply to HPACK. | 2105 // Deflate compression doesn't apply to HPACK. |
| 2074 } | 2106 } |
| 2075 } | 2107 } |
| 2076 #endif // !defined(USE_SYSTEM_ZLIB) | 2108 #endif // !defined(USE_SYSTEM_ZLIB) |
| 2077 | 2109 |
| 2078 TEST_F(SpdyFramerTest, CreateWindowUpdate) { | 2110 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
| 2079 SpdyFramer framer; | 2111 SpdyFramer framer; |
| 2080 | 2112 |
| 2081 { | 2113 { |
| 2082 const char kDescription[] = "WINDOW_UPDATE frame"; | 2114 const char kDescription[] = "WINDOW_UPDATE frame"; |
| 2083 const unsigned char kH2FrameData[] = { | 2115 const unsigned char kH2FrameData[] = { |
| 2084 0x00, 0x00, 0x04, // Length: 4 | 2116 0x00, 0x00, 0x04, // Length: 4 |
| 2085 0x08, // Type: WINDOW_UPDATE | 2117 0x08, // Type: WINDOW_UPDATE |
| 2086 0x00, // Flags: none | 2118 0x00, // Flags: none |
| 2087 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2119 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 2088 0x00, 0x00, 0x00, 0x01, // Increment: 1 | 2120 0x00, 0x00, 0x00, 0x01, // Increment: 1 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2114 0x00, // Flags: none | 2146 0x00, // Flags: none |
| 2115 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2147 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 2116 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff | 2148 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff |
| 2117 }; | 2149 }; |
| 2118 SpdySerializedFrame frame( | 2150 SpdySerializedFrame frame( |
| 2119 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2151 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
| 2120 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 2152 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 2121 } | 2153 } |
| 2122 } | 2154 } |
| 2123 | 2155 |
| 2124 TEST_F(SpdyFramerTest, SerializeBlocked) { | 2156 TEST_P(SpdyFramerTest, SerializeBlocked) { |
| 2125 SpdyFramer framer; | 2157 SpdyFramer framer; |
| 2126 | 2158 |
| 2127 const char kDescription[] = "BLOCKED frame"; | 2159 const char kDescription[] = "BLOCKED frame"; |
| 2128 const unsigned char kType = | 2160 const unsigned char kType = |
| 2129 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(BLOCKED)); | 2161 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(BLOCKED)); |
| 2130 const unsigned char kFrameData[] = { | 2162 const unsigned char kFrameData[] = { |
| 2131 0x00, 0x00, 0x00, // Length: 0 | 2163 0x00, 0x00, 0x00, // Length: 0 |
| 2132 kType, // Type: BLOCKED | 2164 kType, // Type: BLOCKED |
| 2133 0x00, // Flags: none | 2165 0x00, // Flags: none |
| 2134 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2166 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2135 }; | 2167 }; |
| 2136 SpdyBlockedIR blocked_ir(0); | 2168 SpdyBlockedIR blocked_ir(0); |
| 2137 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 2169 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
| 2138 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2170 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2139 } | 2171 } |
| 2140 | 2172 |
| 2141 TEST_F(SpdyFramerTest, CreateBlocked) { | 2173 TEST_P(SpdyFramerTest, CreateBlocked) { |
| 2142 SpdyFramer framer; | 2174 SpdyFramer framer; |
| 2143 | 2175 |
| 2144 const char kDescription[] = "BLOCKED frame"; | 2176 const char kDescription[] = "BLOCKED frame"; |
| 2145 const SpdyStreamId kStreamId = 3; | 2177 const SpdyStreamId kStreamId = 3; |
| 2146 | 2178 |
| 2147 SpdySerializedFrame frame_serialized( | 2179 SpdySerializedFrame frame_serialized( |
| 2148 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2180 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
| 2149 SpdyBlockedIR blocked_ir(kStreamId); | 2181 SpdyBlockedIR blocked_ir(kStreamId); |
| 2150 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); | 2182 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); |
| 2151 | 2183 |
| 2152 CompareFrames(kDescription, frame_serialized, frame_created); | 2184 CompareFrames(kDescription, frame_serialized, frame_created); |
| 2153 } | 2185 } |
| 2154 | 2186 |
| 2155 TEST_F(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2187 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
| 2156 { | 2188 { |
| 2157 // Test framing PUSH_PROMISE without padding. | 2189 // Test framing PUSH_PROMISE without padding. |
| 2158 SpdyFramer framer; | 2190 SpdyFramer framer; |
| 2159 framer.set_enable_compression(false); | 2191 framer.set_enable_compression(false); |
| 2160 const char kDescription[] = "PUSH_PROMISE frame without padding"; | 2192 const char kDescription[] = "PUSH_PROMISE frame without padding"; |
| 2161 | 2193 |
| 2162 // frame-format off | 2194 // frame-format off |
| 2163 const unsigned char kFrameData[] = { | 2195 const unsigned char kFrameData[] = { |
| 2164 0x00, 0x00, 0x16, // Length: 22 | 2196 0x00, 0x00, 0x16, // Length: 22 |
| 2165 0x05, // Type: PUSH_PROMISE | 2197 0x05, // Type: PUSH_PROMISE |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2277 SpdyPushPromiseIR push_promise(42, 57); | 2309 SpdyPushPromiseIR push_promise(42, 57); |
| 2278 push_promise.set_padding_len(177); | 2310 push_promise.set_padding_len(177); |
| 2279 push_promise.SetHeader("bar", "foo"); | 2311 push_promise.SetHeader("bar", "foo"); |
| 2280 push_promise.SetHeader("foo", "bar"); | 2312 push_promise.SetHeader("foo", "bar"); |
| 2281 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2313 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2282 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2314 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2283 } | 2315 } |
| 2284 } | 2316 } |
| 2285 | 2317 |
| 2286 // Regression test for https://crbug.com/464748. | 2318 // Regression test for https://crbug.com/464748. |
| 2287 TEST_F(SpdyFramerTest, GetNumberRequiredContinuationFrames) { | 2319 TEST_P(SpdyFramerTest, GetNumberRequiredContinuationFrames) { |
| 2288 SpdyFramer framer; | 2320 SpdyFramer framer; |
| 2289 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2321 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2290 &framer, 16383 + 16374)); | 2322 &framer, 16383 + 16374)); |
| 2291 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2323 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2292 &framer, 16383 + 16374 + 1)); | 2324 &framer, 16383 + 16374 + 1)); |
| 2293 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2325 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2294 &framer, 16383 + 2 * 16374)); | 2326 &framer, 16383 + 2 * 16374)); |
| 2295 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2327 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2296 &framer, 16383 + 2 * 16374 + 1)); | 2328 &framer, 16383 + 2 * 16374 + 1)); |
| 2297 } | 2329 } |
| 2298 | 2330 |
| 2299 TEST_F(SpdyFramerTest, CreateContinuationUncompressed) { | 2331 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
| 2300 SpdyFramer framer; | 2332 SpdyFramer framer; |
| 2301 framer.set_enable_compression(false); | 2333 framer.set_enable_compression(false); |
| 2302 const char kDescription[] = "CONTINUATION frame"; | 2334 const char kDescription[] = "CONTINUATION frame"; |
| 2303 | 2335 |
| 2304 // frame-format off | 2336 // frame-format off |
| 2305 const unsigned char kFrameData[] = { | 2337 const unsigned char kFrameData[] = { |
| 2306 0x00, 0x00, 0x12, // Length: 18 | 2338 0x00, 0x00, 0x12, // Length: 18 |
| 2307 0x09, // Type: CONTINUATION | 2339 0x09, // Type: CONTINUATION |
| 2308 0x04, // Flags: END_HEADERS | 2340 0x04, // Flags: END_HEADERS |
| 2309 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2341 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2332 SpdyContinuationIR continuation(42); | 2364 SpdyContinuationIR continuation(42); |
| 2333 continuation.take_encoding(std::move(buffer)); | 2365 continuation.take_encoding(std::move(buffer)); |
| 2334 continuation.set_end_headers(true); | 2366 continuation.set_end_headers(true); |
| 2335 | 2367 |
| 2336 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 2368 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 2337 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2369 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2338 } | 2370 } |
| 2339 | 2371 |
| 2340 // Test that if we send an unexpected CONTINUATION | 2372 // Test that if we send an unexpected CONTINUATION |
| 2341 // we signal an error (but don't crash). | 2373 // we signal an error (but don't crash). |
| 2342 TEST_F(SpdyFramerTest, SendUnexpectedContinuation) { | 2374 TEST_P(SpdyFramerTest, SendUnexpectedContinuation) { |
| 2343 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2375 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 2344 SpdyFramer framer; | 2376 SpdyFramer framer; |
| 2345 framer.set_visitor(&visitor); | 2377 framer.set_visitor(&visitor); |
| 2346 | 2378 |
| 2347 // frame-format off | 2379 // frame-format off |
| 2348 char kH2FrameData[] = { | 2380 char kH2FrameData[] = { |
| 2349 0x00, 0x00, 0x12, // Length: 18 | 2381 0x00, 0x00, 0x12, // Length: 18 |
| 2350 0x09, // Type: CONTINUATION | 2382 0x09, // Type: CONTINUATION |
| 2351 0x04, // Flags: END_HEADERS | 2383 0x04, // Flags: END_HEADERS |
| 2352 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2384 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2368 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 2400 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 2369 | 2401 |
| 2370 // We shouldn't have to read the whole frame before we signal an error. | 2402 // We shouldn't have to read the whole frame before we signal an error. |
| 2371 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 2403 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 2372 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 2404 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 2373 EXPECT_TRUE(framer.HasError()); | 2405 EXPECT_TRUE(framer.HasError()); |
| 2374 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) | 2406 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) |
| 2375 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2407 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 2376 } | 2408 } |
| 2377 | 2409 |
| 2378 TEST_F(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { | 2410 TEST_P(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { |
| 2379 { | 2411 { |
| 2380 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of | 2412 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of |
| 2381 // padding, cannot hold all the data payload, which is overflowed to the | 2413 // padding, cannot hold all the data payload, which is overflowed to the |
| 2382 // consecutive CONTINUATION frame. | 2414 // consecutive CONTINUATION frame. |
| 2383 SpdyFramer framer; | 2415 SpdyFramer framer; |
| 2384 framer.set_enable_compression(false); | 2416 framer.set_enable_compression(false); |
| 2385 const char kDescription[] = | 2417 const char kDescription[] = |
| 2386 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; | 2418 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; |
| 2387 | 2419 |
| 2388 // frame-format off | 2420 // frame-format off |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2469 kPartialPushPromiseFrameData, arraysize(kPartialPushPromiseFrameData)); | 2501 kPartialPushPromiseFrameData, arraysize(kPartialPushPromiseFrameData)); |
| 2470 | 2502 |
| 2471 // Compare the CONTINUATION frame against the template. | 2503 // Compare the CONTINUATION frame against the template. |
| 2472 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); | 2504 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); |
| 2473 CompareCharArraysWithHexError( | 2505 CompareCharArraysWithHexError( |
| 2474 kDescription, frame_data, arraysize(kContinuationFrameData), | 2506 kDescription, frame_data, arraysize(kContinuationFrameData), |
| 2475 kContinuationFrameData, arraysize(kContinuationFrameData)); | 2507 kContinuationFrameData, arraysize(kContinuationFrameData)); |
| 2476 } | 2508 } |
| 2477 } | 2509 } |
| 2478 | 2510 |
| 2479 TEST_F(SpdyFramerTest, CreateAltSvc) { | 2511 TEST_P(SpdyFramerTest, CreateAltSvc) { |
| 2480 SpdyFramer framer; | 2512 SpdyFramer framer; |
| 2481 | 2513 |
| 2482 const char kDescription[] = "ALTSVC frame"; | 2514 const char kDescription[] = "ALTSVC frame"; |
| 2483 const char kType = | 2515 const char kType = |
| 2484 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(ALTSVC)); | 2516 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(ALTSVC)); |
| 2485 const unsigned char kFrameData[] = { | 2517 const unsigned char kFrameData[] = { |
| 2486 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', | 2518 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', |
| 2487 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', | 2519 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', |
| 2488 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', | 2520 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', |
| 2489 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', | 2521 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', |
| 2490 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', | 2522 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', |
| 2491 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', | 2523 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', |
| 2492 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; | 2524 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; |
| 2493 SpdyAltSvcIR altsvc_ir(3); | 2525 SpdyAltSvcIR altsvc_ir(3); |
| 2494 altsvc_ir.set_origin("origin"); | 2526 altsvc_ir.set_origin("origin"); |
| 2495 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2527 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2496 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 2528 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 2497 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2529 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2498 "p\"=i:d", "h_\\o\"st", 123, 42, | 2530 "p\"=i:d", "h_\\o\"st", 123, 42, |
| 2499 SpdyAltSvcWireFormat::VersionVector{24})); | 2531 SpdyAltSvcWireFormat::VersionVector{24})); |
| 2500 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 2532 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 2501 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2533 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2502 } | 2534 } |
| 2503 | 2535 |
| 2504 TEST_F(SpdyFramerTest, CreatePriority) { | 2536 TEST_P(SpdyFramerTest, CreatePriority) { |
| 2505 SpdyFramer framer; | 2537 SpdyFramer framer; |
| 2506 | 2538 |
| 2507 const char kDescription[] = "PRIORITY frame"; | 2539 const char kDescription[] = "PRIORITY frame"; |
| 2508 const unsigned char kFrameData[] = { | 2540 const unsigned char kFrameData[] = { |
| 2509 0x00, 0x00, 0x05, // Length: 5 | 2541 0x00, 0x00, 0x05, // Length: 5 |
| 2510 0x02, // Type: PRIORITY | 2542 0x02, // Type: PRIORITY |
| 2511 0x00, // Flags: none | 2543 0x00, // Flags: none |
| 2512 0x00, 0x00, 0x00, 0x02, // Stream: 2 | 2544 0x00, 0x00, 0x00, 0x02, // Stream: 2 |
| 2513 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) | 2545 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) |
| 2514 0x10, // Weight: 17 | 2546 0x10, // Weight: 17 |
| 2515 }; | 2547 }; |
| 2516 SpdyPriorityIR priority_ir(2, 1, 17, true); | 2548 SpdyPriorityIR priority_ir(2, 1, 17, true); |
| 2517 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 2549 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
| 2518 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2550 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2519 SpdyPriorityIR priority2(2); | 2551 SpdyPriorityIR priority2(2); |
| 2520 priority2.set_parent_stream_id(1); | 2552 priority2.set_parent_stream_id(1); |
| 2521 priority2.set_weight(17); | 2553 priority2.set_weight(17); |
| 2522 priority2.set_exclusive(true); | 2554 priority2.set_exclusive(true); |
| 2523 frame = framer.SerializeFrame(priority2); | 2555 frame = framer.SerializeFrame(priority2); |
| 2524 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2556 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2525 } | 2557 } |
| 2526 | 2558 |
| 2527 TEST_F(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { | 2559 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { |
| 2528 SpdyFramer framer; | 2560 SpdyFramer framer; |
| 2529 SpdyHeadersIR headers_ir(1); | 2561 SpdyHeadersIR headers_ir(1); |
| 2530 headers_ir.SetHeader("alpha", "beta"); | 2562 headers_ir.SetHeader("alpha", "beta"); |
| 2531 headers_ir.SetHeader("gamma", "delta"); | 2563 headers_ir.SetHeader("gamma", "delta"); |
| 2532 SpdySerializedFrame control_frame( | 2564 SpdySerializedFrame control_frame( |
| 2533 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2565 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2534 TestSpdyVisitor visitor; | 2566 TestSpdyVisitor visitor; |
| 2535 visitor.use_compression_ = true; | 2567 visitor.use_compression_ = true; |
| 2536 visitor.SimulateInFramer( | 2568 visitor.SimulateInFramer( |
| 2537 reinterpret_cast<unsigned char*>(control_frame.data()), | 2569 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2538 control_frame.size()); | 2570 control_frame.size()); |
| 2539 EXPECT_EQ(1, visitor.headers_frame_count_); | 2571 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2540 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2572 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
| 2541 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2573 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2542 EXPECT_EQ(0, visitor.end_of_stream_count_); | 2574 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 2543 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2575 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
| 2544 } | 2576 } |
| 2545 | 2577 |
| 2546 TEST_F(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { | 2578 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { |
| 2547 SpdyFramer framer; | 2579 SpdyFramer framer; |
| 2548 SpdyHeadersIR headers_ir(1); | 2580 SpdyHeadersIR headers_ir(1); |
| 2549 headers_ir.set_fin(true); | 2581 headers_ir.set_fin(true); |
| 2550 headers_ir.SetHeader("alpha", "beta"); | 2582 headers_ir.SetHeader("alpha", "beta"); |
| 2551 headers_ir.SetHeader("gamma", "delta"); | 2583 headers_ir.SetHeader("gamma", "delta"); |
| 2552 SpdySerializedFrame control_frame( | 2584 SpdySerializedFrame control_frame( |
| 2553 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2585 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2554 TestSpdyVisitor visitor; | 2586 TestSpdyVisitor visitor; |
| 2555 visitor.use_compression_ = true; | 2587 visitor.use_compression_ = true; |
| 2556 visitor.SimulateInFramer( | 2588 visitor.SimulateInFramer( |
| 2557 reinterpret_cast<unsigned char*>(control_frame.data()), | 2589 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2558 control_frame.size()); | 2590 control_frame.size()); |
| 2559 EXPECT_EQ(1, visitor.headers_frame_count_); | 2591 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2560 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2592 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
| 2561 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2593 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2562 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2594 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 2563 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2595 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
| 2564 } | 2596 } |
| 2565 | 2597 |
| 2566 TEST_F(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { | 2598 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
| 2567 SpdyFramer framer; | 2599 SpdyFramer framer; |
| 2568 framer.set_enable_compression(false); | 2600 framer.set_enable_compression(false); |
| 2569 SpdyHeadersIR headers(1); | 2601 SpdyHeadersIR headers(1); |
| 2570 headers.set_padding_len(256); | 2602 headers.set_padding_len(256); |
| 2571 | 2603 |
| 2572 // Exact payload length will change with HPACK, but this should be long | 2604 // Exact payload length will change with HPACK, but this should be long |
| 2573 // enough to cause an overflow. | 2605 // enough to cause an overflow. |
| 2574 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2606 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2575 string big_value(kBigValueSize, 'x'); | 2607 string big_value(kBigValueSize, 'x'); |
| 2576 headers.SetHeader("aa", big_value); | 2608 headers.SetHeader("aa", big_value); |
| 2577 SpdySerializedFrame control_frame( | 2609 SpdySerializedFrame control_frame( |
| 2578 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2610 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 2579 EXPECT_GT(control_frame.size(), | 2611 EXPECT_GT(control_frame.size(), |
| 2580 TestSpdyVisitor::sent_control_frame_max_size()); | 2612 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2581 | 2613 |
| 2582 TestSpdyVisitor visitor; | 2614 TestSpdyVisitor visitor; |
| 2583 visitor.SimulateInFramer( | 2615 visitor.SimulateInFramer( |
| 2584 reinterpret_cast<unsigned char*>(control_frame.data()), | 2616 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2585 control_frame.size()); | 2617 control_frame.size()); |
| 2586 EXPECT_TRUE(visitor.header_buffer_valid_); | 2618 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2587 EXPECT_EQ(0, visitor.error_count_); | 2619 EXPECT_EQ(0, visitor.error_count_); |
| 2588 EXPECT_EQ(1, visitor.headers_frame_count_); | 2620 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2589 EXPECT_EQ(1, visitor.continuation_count_); | 2621 EXPECT_EQ(1, visitor.continuation_count_); |
| 2590 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2622 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2591 } | 2623 } |
| 2592 | 2624 |
| 2593 TEST_F(SpdyFramerTest, MultipleContinuationFramesWithIterator) { | 2625 TEST_P(SpdyFramerTest, MultipleContinuationFramesWithIterator) { |
| 2594 SpdyFramer framer; | 2626 SpdyFramer framer; |
| 2595 framer.set_enable_compression(false); | 2627 framer.set_enable_compression(false); |
| 2596 auto headers = base::MakeUnique<SpdyHeadersIR>(1); | 2628 auto headers = base::MakeUnique<SpdyHeadersIR>(1); |
| 2597 headers->set_padding_len(256); | 2629 headers->set_padding_len(256); |
| 2598 | 2630 |
| 2599 // Exact payload length will change with HPACK, but this should be long | 2631 // Exact payload length will change with HPACK, but this should be long |
| 2600 // enough to cause an overflow. | 2632 // enough to cause an overflow. |
| 2601 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2633 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2602 string big_valuex(kBigValueSize, 'x'); | 2634 string big_valuex(kBigValueSize, 'x'); |
| 2603 headers->SetHeader("aa", big_valuex); | 2635 headers->SetHeader("aa", big_valuex); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2645 second_cont_frame.size()); | 2677 second_cont_frame.size()); |
| 2646 EXPECT_TRUE(visitor.header_buffer_valid_); | 2678 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2647 EXPECT_EQ(0, visitor.error_count_); | 2679 EXPECT_EQ(0, visitor.error_count_); |
| 2648 EXPECT_EQ(1, visitor.headers_frame_count_); | 2680 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2649 EXPECT_EQ(2, visitor.continuation_count_); | 2681 EXPECT_EQ(2, visitor.continuation_count_); |
| 2650 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2682 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2651 | 2683 |
| 2652 EXPECT_FALSE(frame_it.HasNextFrame()); | 2684 EXPECT_FALSE(frame_it.HasNextFrame()); |
| 2653 } | 2685 } |
| 2654 | 2686 |
| 2655 TEST_F(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 2687 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
| 2656 SpdyFramer framer; | 2688 SpdyFramer framer; |
| 2657 framer.set_enable_compression(false); | 2689 framer.set_enable_compression(false); |
| 2658 SpdyPushPromiseIR push_promise(1, 2); | 2690 SpdyPushPromiseIR push_promise(1, 2); |
| 2659 push_promise.set_padding_len(256); | 2691 push_promise.set_padding_len(256); |
| 2660 | 2692 |
| 2661 // Exact payload length will change with HPACK, but this should be long | 2693 // Exact payload length will change with HPACK, but this should be long |
| 2662 // enough to cause an overflow. | 2694 // enough to cause an overflow. |
| 2663 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2695 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2664 string big_value(kBigValueSize, 'x'); | 2696 string big_value(kBigValueSize, 'x'); |
| 2665 push_promise.SetHeader("aa", big_value); | 2697 push_promise.SetHeader("aa", big_value); |
| 2666 SpdySerializedFrame control_frame(framer.SerializePushPromise(push_promise)); | 2698 SpdySerializedFrame control_frame(framer.SerializePushPromise(push_promise)); |
| 2667 EXPECT_GT(control_frame.size(), | 2699 EXPECT_GT(control_frame.size(), |
| 2668 TestSpdyVisitor::sent_control_frame_max_size()); | 2700 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2669 | 2701 |
| 2670 TestSpdyVisitor visitor; | 2702 TestSpdyVisitor visitor; |
| 2671 visitor.SimulateInFramer( | 2703 visitor.SimulateInFramer( |
| 2672 reinterpret_cast<unsigned char*>(control_frame.data()), | 2704 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2673 control_frame.size()); | 2705 control_frame.size()); |
| 2674 EXPECT_TRUE(visitor.header_buffer_valid_); | 2706 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2675 EXPECT_EQ(0, visitor.error_count_); | 2707 EXPECT_EQ(0, visitor.error_count_); |
| 2676 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 2708 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
| 2677 EXPECT_EQ(1, visitor.continuation_count_); | 2709 EXPECT_EQ(1, visitor.continuation_count_); |
| 2678 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2710 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2679 } | 2711 } |
| 2680 | 2712 |
| 2681 // Check that the framer stops delivering header data chunks once the visitor | 2713 // Check that the framer stops delivering header data chunks once the visitor |
| 2682 // declares it doesn't want any more. This is important to guard against | 2714 // declares it doesn't want any more. This is important to guard against |
| 2683 // "zip bomb" types of attacks. | 2715 // "zip bomb" types of attacks. |
| 2684 TEST_F(SpdyFramerTest, ControlFrameMuchTooLarge) { | 2716 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { |
| 2685 const size_t kHeaderBufferChunks = 4; | 2717 const size_t kHeaderBufferChunks = 4; |
| 2686 const size_t kHeaderBufferSize = | 2718 const size_t kHeaderBufferSize = |
| 2687 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 2719 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
| 2688 const size_t kBigValueSize = kHeaderBufferSize * 2; | 2720 const size_t kBigValueSize = kHeaderBufferSize * 2; |
| 2689 string big_value(kBigValueSize, 'x'); | 2721 string big_value(kBigValueSize, 'x'); |
| 2690 SpdyFramer framer; | 2722 SpdyFramer framer; |
| 2691 SpdyHeadersIR headers(1); | 2723 SpdyHeadersIR headers(1); |
| 2692 headers.set_fin(true); | 2724 headers.set_fin(true); |
| 2693 headers.SetHeader("aa", big_value); | 2725 headers.SetHeader("aa", big_value); |
| 2694 SpdySerializedFrame control_frame( | 2726 SpdySerializedFrame control_frame( |
| 2695 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2727 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 2696 TestSpdyVisitor visitor; | 2728 TestSpdyVisitor visitor; |
| 2697 visitor.set_header_buffer_size(kHeaderBufferSize); | 2729 visitor.set_header_buffer_size(kHeaderBufferSize); |
| 2698 visitor.use_compression_ = true; | 2730 visitor.use_compression_ = true; |
| 2699 visitor.SimulateInFramer( | 2731 visitor.SimulateInFramer( |
| 2700 reinterpret_cast<unsigned char*>(control_frame.data()), | 2732 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2701 control_frame.size()); | 2733 control_frame.size()); |
| 2702 // It's up to the visitor to ignore extraneous header data; the framer | 2734 // It's up to the visitor to ignore extraneous header data; the framer |
| 2703 // won't throw an error. | 2735 // won't throw an error. |
| 2704 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); | 2736 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); |
| 2705 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2737 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 2706 } | 2738 } |
| 2707 | 2739 |
| 2708 TEST_F(SpdyFramerTest, ControlFrameSizesAreValidated) { | 2740 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 2709 SpdyFramer framer; | 2741 SpdyFramer framer; |
| 2710 // Create a GoAway frame that has a few extra bytes at the end. | 2742 // Create a GoAway frame that has a few extra bytes at the end. |
| 2711 // We create enough overhead to overflow the framer's control frame buffer. | 2743 // We create enough overhead to overflow the framer's control frame buffer. |
| 2712 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); | 2744 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); |
| 2713 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; | 2745 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; |
| 2714 | 2746 |
| 2715 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may | 2747 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may |
| 2716 // carry opaque data. Verify that minimal length is tested. | 2748 // carry opaque data. Verify that minimal length is tested. |
| 2717 ASSERT_GT(framer.GetGoAwayMinimumSize(), SpdyConstants::kFrameHeaderSize); | 2749 ASSERT_GT(framer.GetGoAwayMinimumSize(), SpdyConstants::kFrameHeaderSize); |
| 2718 const size_t less_than_min_length = | 2750 const size_t less_than_min_length = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2736 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), | 2768 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 2737 pad.length()); | 2769 pad.length()); |
| 2738 | 2770 |
| 2739 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2771 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
| 2740 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 2772 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 2741 visitor.framer_.error_code()) | 2773 visitor.framer_.error_code()) |
| 2742 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2774 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2743 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. | 2775 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. |
| 2744 } | 2776 } |
| 2745 | 2777 |
| 2746 TEST_F(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 2778 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 2747 SpdyFramer framer; | 2779 SpdyFramer framer; |
| 2748 SpdySettingsIR settings_ir; | 2780 SpdySettingsIR settings_ir; |
| 2749 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2781 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2750 SetFrameLength(&control_frame, 0); | 2782 SetFrameLength(&control_frame, 0); |
| 2751 TestSpdyVisitor visitor; | 2783 TestSpdyVisitor visitor; |
| 2752 visitor.use_compression_ = false; | 2784 visitor.use_compression_ = false; |
| 2753 visitor.SimulateInFramer( | 2785 visitor.SimulateInFramer( |
| 2754 reinterpret_cast<unsigned char*>(control_frame.data()), | 2786 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2755 framer.GetFrameHeaderSize()); | 2787 framer.GetFrameHeaderSize()); |
| 2756 // Zero-len settings frames are permitted as of HTTP/2. | 2788 // Zero-len settings frames are permitted as of HTTP/2. |
| 2757 EXPECT_EQ(0, visitor.error_count_); | 2789 EXPECT_EQ(0, visitor.error_count_); |
| 2758 } | 2790 } |
| 2759 | 2791 |
| 2760 // Tests handling of SETTINGS frames with invalid length. | 2792 // Tests handling of SETTINGS frames with invalid length. |
| 2761 TEST_F(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 2793 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| 2762 SpdyFramer framer; | 2794 SpdyFramer framer; |
| 2763 SpdySettingsIR settings_ir; | 2795 SpdySettingsIR settings_ir; |
| 2764 | 2796 |
| 2765 // Add a setting to pad the frame so that we don't get a buffer overflow when | 2797 // Add a setting to pad the frame so that we don't get a buffer overflow when |
| 2766 // calling SimulateInFramer() below. | 2798 // calling SimulateInFramer() below. |
| 2767 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, | 2799 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, |
| 2768 0x00000002); | 2800 0x00000002); |
| 2769 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2801 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2770 const size_t kNewLength = 14; | 2802 const size_t kNewLength = 14; |
| 2771 SetFrameLength(&control_frame, kNewLength); | 2803 SetFrameLength(&control_frame, kNewLength); |
| 2772 TestSpdyVisitor visitor; | 2804 TestSpdyVisitor visitor; |
| 2773 visitor.use_compression_ = false; | 2805 visitor.use_compression_ = false; |
| 2774 visitor.SimulateInFramer( | 2806 visitor.SimulateInFramer( |
| 2775 reinterpret_cast<unsigned char*>(control_frame.data()), | 2807 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2776 framer.GetFrameHeaderSize() + kNewLength); | 2808 framer.GetFrameHeaderSize() + kNewLength); |
| 2777 // Should generate an error, since its not possible to have a | 2809 // Should generate an error, since its not possible to have a |
| 2778 // settings frame of length kNewLength. | 2810 // settings frame of length kNewLength. |
| 2779 EXPECT_EQ(1, visitor.error_count_); | 2811 EXPECT_EQ(1, visitor.error_count_); |
| 2780 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 2812 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 2781 visitor.framer_.error_code()) | 2813 visitor.framer_.error_code()) |
| 2782 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2814 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2783 } | 2815 } |
| 2784 | 2816 |
| 2785 // Tests handling of SETTINGS frames larger than the frame buffer size. | 2817 // Tests handling of SETTINGS frames larger than the frame buffer size. |
| 2786 TEST_F(SpdyFramerTest, ReadLargeSettingsFrame) { | 2818 TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { |
| 2787 SpdyFramer framer; | 2819 SpdyFramer framer; |
| 2788 SpdySettingsIR settings_ir; | 2820 SpdySettingsIR settings_ir; |
| 2789 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, | 2821 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, |
| 2790 false, // persist | 2822 false, // persist |
| 2791 false, // persisted | 2823 false, // persisted |
| 2792 5); | 2824 5); |
| 2793 settings_ir.AddSetting(SETTINGS_ENABLE_PUSH, | 2825 settings_ir.AddSetting(SETTINGS_ENABLE_PUSH, |
| 2794 false, // persist | 2826 false, // persist |
| 2795 false, // persisted | 2827 false, // persisted |
| 2796 6); | 2828 6); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2823 to_read); | 2855 to_read); |
| 2824 unframed_data -= to_read; | 2856 unframed_data -= to_read; |
| 2825 framed_data += to_read; | 2857 framed_data += to_read; |
| 2826 } | 2858 } |
| 2827 EXPECT_EQ(0, visitor.error_count_); | 2859 EXPECT_EQ(0, visitor.error_count_); |
| 2828 EXPECT_EQ(3 * 2, visitor.setting_count_); | 2860 EXPECT_EQ(3 * 2, visitor.setting_count_); |
| 2829 EXPECT_EQ(2, visitor.settings_ack_sent_); | 2861 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| 2830 } | 2862 } |
| 2831 | 2863 |
| 2832 // Tests handling of SETTINGS frame with duplicate entries. | 2864 // Tests handling of SETTINGS frame with duplicate entries. |
| 2833 TEST_F(SpdyFramerTest, ReadDuplicateSettings) { | 2865 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 2834 SpdyFramer framer; | 2866 SpdyFramer framer; |
| 2835 | 2867 |
| 2836 const unsigned char kH2FrameData[] = { | 2868 const unsigned char kH2FrameData[] = { |
| 2837 0x00, 0x00, 0x12, // Length: 18 | 2869 0x00, 0x00, 0x12, // Length: 18 |
| 2838 0x04, // Type: SETTINGS | 2870 0x04, // Type: SETTINGS |
| 2839 0x00, // Flags: none | 2871 0x00, // Flags: none |
| 2840 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2872 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2841 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2873 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2842 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2874 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2843 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2875 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2844 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2876 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2845 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2877 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 2846 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2878 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2847 }; | 2879 }; |
| 2848 | 2880 |
| 2849 TestSpdyVisitor visitor; | 2881 TestSpdyVisitor visitor; |
| 2850 visitor.use_compression_ = false; | 2882 visitor.use_compression_ = false; |
| 2851 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2883 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2852 | 2884 |
| 2853 // In HTTP/2, duplicate settings are allowed; | 2885 // In HTTP/2, duplicate settings are allowed; |
| 2854 // each setting replaces the previous value for that setting. | 2886 // each setting replaces the previous value for that setting. |
| 2855 EXPECT_EQ(3, visitor.setting_count_); | 2887 EXPECT_EQ(3, visitor.setting_count_); |
| 2856 EXPECT_EQ(0, visitor.error_count_); | 2888 EXPECT_EQ(0, visitor.error_count_); |
| 2857 EXPECT_EQ(1, visitor.settings_ack_sent_); | 2889 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 2858 } | 2890 } |
| 2859 | 2891 |
| 2860 // Tests handling of SETTINGS frame with a setting we don't recognize. | 2892 // Tests handling of SETTINGS frame with a setting we don't recognize. |
| 2861 TEST_F(SpdyFramerTest, ReadUnknownSettingsId) { | 2893 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { |
| 2862 SpdyFramer framer; | 2894 SpdyFramer framer; |
| 2863 const unsigned char kH2FrameData[] = { | 2895 const unsigned char kH2FrameData[] = { |
| 2864 0x00, 0x00, 0x06, // Length: 6 | 2896 0x00, 0x00, 0x06, // Length: 6 |
| 2865 0x04, // Type: SETTINGS | 2897 0x04, // Type: SETTINGS |
| 2866 0x00, // Flags: none | 2898 0x00, // Flags: none |
| 2867 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2899 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2868 0x00, 0x10, // Param: 16 | 2900 0x00, 0x10, // Param: 16 |
| 2869 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2901 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2870 }; | 2902 }; |
| 2871 | 2903 |
| 2872 TestSpdyVisitor visitor; | 2904 TestSpdyVisitor visitor; |
| 2873 visitor.use_compression_ = false; | 2905 visitor.use_compression_ = false; |
| 2874 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2906 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2875 | 2907 |
| 2876 // In HTTP/2, we ignore unknown settings because of extensions. | 2908 // In HTTP/2, we ignore unknown settings because of extensions. |
| 2877 EXPECT_EQ(0, visitor.setting_count_); | 2909 EXPECT_EQ(0, visitor.setting_count_); |
| 2878 EXPECT_EQ(0, visitor.error_count_); | 2910 EXPECT_EQ(0, visitor.error_count_); |
| 2879 } | 2911 } |
| 2880 | 2912 |
| 2881 // Tests handling of SETTINGS frame with entries out of order. | 2913 // Tests handling of SETTINGS frame with entries out of order. |
| 2882 TEST_F(SpdyFramerTest, ReadOutOfOrderSettings) { | 2914 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 2883 SpdyFramer framer; | 2915 SpdyFramer framer; |
| 2884 const unsigned char kH2FrameData[] = { | 2916 const unsigned char kH2FrameData[] = { |
| 2885 0x00, 0x00, 0x12, // Length: 18 | 2917 0x00, 0x00, 0x12, // Length: 18 |
| 2886 0x04, // Type: SETTINGS | 2918 0x04, // Type: SETTINGS |
| 2887 0x00, // Flags: none | 2919 0x00, // Flags: none |
| 2888 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2920 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2889 0x00, 0x02, // Param: ENABLE_PUSH | 2921 0x00, 0x02, // Param: ENABLE_PUSH |
| 2890 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2922 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2891 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2923 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2892 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2924 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2893 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2925 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 2894 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2926 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2895 }; | 2927 }; |
| 2896 | 2928 |
| 2897 TestSpdyVisitor visitor; | 2929 TestSpdyVisitor visitor; |
| 2898 visitor.use_compression_ = false; | 2930 visitor.use_compression_ = false; |
| 2899 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2931 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2900 | 2932 |
| 2901 // In HTTP/2, settings are allowed in any order. | 2933 // In HTTP/2, settings are allowed in any order. |
| 2902 EXPECT_EQ(3, visitor.setting_count_); | 2934 EXPECT_EQ(3, visitor.setting_count_); |
| 2903 EXPECT_EQ(0, visitor.error_count_); | 2935 EXPECT_EQ(0, visitor.error_count_); |
| 2904 } | 2936 } |
| 2905 | 2937 |
| 2906 TEST_F(SpdyFramerTest, ProcessSettingsAckFrame) { | 2938 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 2907 SpdyFramer framer; | 2939 SpdyFramer framer; |
| 2908 | 2940 |
| 2909 const unsigned char kFrameData[] = { | 2941 const unsigned char kFrameData[] = { |
| 2910 0x00, 0x00, 0x00, // Length: 0 | 2942 0x00, 0x00, 0x00, // Length: 0 |
| 2911 0x04, // Type: SETTINGS | 2943 0x04, // Type: SETTINGS |
| 2912 0x01, // Flags: ACK | 2944 0x01, // Flags: ACK |
| 2913 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2945 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2914 }; | 2946 }; |
| 2915 | 2947 |
| 2916 TestSpdyVisitor visitor; | 2948 TestSpdyVisitor visitor; |
| 2917 visitor.use_compression_ = false; | 2949 visitor.use_compression_ = false; |
| 2918 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 2950 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 2919 | 2951 |
| 2920 EXPECT_EQ(0, visitor.error_count_); | 2952 EXPECT_EQ(0, visitor.error_count_); |
| 2921 EXPECT_EQ(0, visitor.setting_count_); | 2953 EXPECT_EQ(0, visitor.setting_count_); |
| 2922 EXPECT_EQ(1, visitor.settings_ack_received_); | 2954 EXPECT_EQ(1, visitor.settings_ack_received_); |
| 2923 } | 2955 } |
| 2924 | 2956 |
| 2925 TEST_F(SpdyFramerTest, ProcessDataFrameWithPadding) { | 2957 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
| 2926 const int kPaddingLen = 119; | 2958 const int kPaddingLen = 119; |
| 2927 const char data_payload[] = "hello"; | 2959 const char data_payload[] = "hello"; |
| 2928 | 2960 |
| 2929 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2961 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 2930 SpdyFramer framer; | 2962 SpdyFramer framer; |
| 2931 framer.set_visitor(&visitor); | 2963 framer.set_visitor(&visitor); |
| 2932 | 2964 |
| 2933 SpdyDataIR data_ir(1, data_payload); | 2965 SpdyDataIR data_ir(1, data_payload); |
| 2934 data_ir.set_padding_len(kPaddingLen); | 2966 data_ir.set_padding_len(kPaddingLen); |
| 2935 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 2967 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2973 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3005 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 2974 bytes_consumed += 100; | 3006 bytes_consumed += 100; |
| 2975 | 3007 |
| 2976 // Send rest of the padding payload. | 3008 // Send rest of the padding payload. |
| 2977 EXPECT_CALL(visitor, OnStreamPadding(1, 18)); | 3009 EXPECT_CALL(visitor, OnStreamPadding(1, 18)); |
| 2978 CHECK_EQ(18u, framer.ProcessInput(frame.data() + bytes_consumed, 18)); | 3010 CHECK_EQ(18u, framer.ProcessInput(frame.data() + bytes_consumed, 18)); |
| 2979 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READY_FOR_FRAME); | 3011 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READY_FOR_FRAME); |
| 2980 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3012 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 2981 } | 3013 } |
| 2982 | 3014 |
| 2983 TEST_F(SpdyFramerTest, ReadWindowUpdate) { | 3015 TEST_P(SpdyFramerTest, ReadWindowUpdate) { |
| 2984 SpdyFramer framer; | 3016 SpdyFramer framer; |
| 2985 SpdySerializedFrame control_frame( | 3017 SpdySerializedFrame control_frame( |
| 2986 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 3018 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 2987 TestSpdyVisitor visitor; | 3019 TestSpdyVisitor visitor; |
| 2988 visitor.SimulateInFramer( | 3020 visitor.SimulateInFramer( |
| 2989 reinterpret_cast<unsigned char*>(control_frame.data()), | 3021 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2990 control_frame.size()); | 3022 control_frame.size()); |
| 2991 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3023 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 2992 EXPECT_EQ(2, visitor.last_window_update_delta_); | 3024 EXPECT_EQ(2, visitor.last_window_update_delta_); |
| 2993 } | 3025 } |
| 2994 | 3026 |
| 2995 TEST_F(SpdyFramerTest, ReadCompressedPushPromise) { | 3027 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
| 2996 SpdyFramer framer; | 3028 SpdyFramer framer; |
| 2997 SpdyPushPromiseIR push_promise(42, 57); | 3029 SpdyPushPromiseIR push_promise(42, 57); |
| 2998 push_promise.SetHeader("foo", "bar"); | 3030 push_promise.SetHeader("foo", "bar"); |
| 2999 push_promise.SetHeader("bar", "foofoo"); | 3031 push_promise.SetHeader("bar", "foofoo"); |
| 3000 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 3032 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 3001 TestSpdyVisitor visitor; | 3033 TestSpdyVisitor visitor; |
| 3002 visitor.use_compression_ = true; | 3034 visitor.use_compression_ = true; |
| 3003 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 3035 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 3004 frame.size()); | 3036 frame.size()); |
| 3005 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3037 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3006 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3038 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3007 EXPECT_EQ(push_promise.header_block(), visitor.headers_); | 3039 EXPECT_EQ(push_promise.header_block(), visitor.headers_); |
| 3008 } | 3040 } |
| 3009 | 3041 |
| 3010 TEST_F(SpdyFramerTest, ReadHeadersWithContinuation) { | 3042 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3011 // frame-format off | 3043 // frame-format off |
| 3012 const unsigned char kInput[] = { | 3044 const unsigned char kInput[] = { |
| 3013 0x00, 0x00, 0x14, // Length: 20 | 3045 0x00, 0x00, 0x14, // Length: 20 |
| 3014 0x01, // Type: HEADERS | 3046 0x01, // Type: HEADERS |
| 3015 0x08, // Flags: PADDED | 3047 0x08, // Flags: PADDED |
| 3016 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3048 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3017 0x03, // PadLen: 3 trailing bytes | 3049 0x03, // PadLen: 3 trailing bytes |
| 3018 0x00, // Unindexed Entry | 3050 0x00, // Unindexed Entry |
| 3019 0x06, // Name Len: 6 | 3051 0x06, // Name Len: 6 |
| 3020 'c', 'o', 'o', 'k', 'i', 'e', // Name | 3052 'c', 'o', 'o', 'k', 'i', 'e', // Name |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3058 EXPECT_EQ(2, visitor.continuation_count_); | 3090 EXPECT_EQ(2, visitor.continuation_count_); |
| 3059 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3091 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3060 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3092 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 3061 | 3093 |
| 3062 EXPECT_THAT( | 3094 EXPECT_THAT( |
| 3063 visitor.headers_, | 3095 visitor.headers_, |
| 3064 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3096 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 3065 testing::Pair("name", "value"))); | 3097 testing::Pair("name", "value"))); |
| 3066 } | 3098 } |
| 3067 | 3099 |
| 3068 TEST_F(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { | 3100 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { |
| 3069 // frame-format off | 3101 // frame-format off |
| 3070 const unsigned char kInput[] = { | 3102 const unsigned char kInput[] = { |
| 3071 0x00, 0x00, 0x10, // Length: 20 | 3103 0x00, 0x00, 0x10, // Length: 20 |
| 3072 0x01, // Type: HEADERS | 3104 0x01, // Type: HEADERS |
| 3073 0x01, // Flags: END_STREAM | 3105 0x01, // Flags: END_STREAM |
| 3074 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3106 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3075 0x00, // Unindexed Entry | 3107 0x00, // Unindexed Entry |
| 3076 0x06, // Name Len: 6 | 3108 0x06, // Name Len: 6 |
| 3077 'c', 'o', 'o', 'k', 'i', 'e', // Name | 3109 'c', 'o', 'o', 'k', 'i', 'e', // Name |
| 3078 0x07, // Value Len: 7 | 3110 0x07, // Value Len: 7 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3115 EXPECT_EQ(1, visitor.fin_flag_count_); | 3147 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3116 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3148 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3117 EXPECT_EQ(1, visitor.end_of_stream_count_); | 3149 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 3118 | 3150 |
| 3119 EXPECT_THAT( | 3151 EXPECT_THAT( |
| 3120 visitor.headers_, | 3152 visitor.headers_, |
| 3121 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3153 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 3122 testing::Pair("name", "value"))); | 3154 testing::Pair("name", "value"))); |
| 3123 } | 3155 } |
| 3124 | 3156 |
| 3125 TEST_F(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3157 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 3126 // frame-format off | 3158 // frame-format off |
| 3127 const unsigned char kInput[] = { | 3159 const unsigned char kInput[] = { |
| 3128 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE | 3160 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE |
| 3129 0x08, 0x00, 0x00, 0x00, // PADDED | 3161 0x08, 0x00, 0x00, 0x00, // PADDED |
| 3130 0x01, 0x02, 0x00, 0x00, // Stream 1, Pad length field | 3162 0x01, 0x02, 0x00, 0x00, // Stream 1, Pad length field |
| 3131 0x00, 0x2A, 0x00, 0x06, // Promised stream 42 | 3163 0x00, 0x2A, 0x00, 0x06, // Promised stream 42 |
| 3132 'c', 'o', 'o', 'k', | 3164 'c', 'o', 'o', 'k', |
| 3133 'i', 'e', 0x07, 'f', | 3165 'i', 'e', 0x07, 'f', |
| 3134 'o', 'o', '=', 'b', | 3166 'o', 'o', '=', 'b', |
| 3135 'a', 'r', 0x00, 0x00, | 3167 'a', 'r', 0x00, 0x00, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3165 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3197 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 3166 | 3198 |
| 3167 EXPECT_THAT( | 3199 EXPECT_THAT( |
| 3168 visitor.headers_, | 3200 visitor.headers_, |
| 3169 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3201 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 3170 testing::Pair("name", "value"))); | 3202 testing::Pair("name", "value"))); |
| 3171 } | 3203 } |
| 3172 | 3204 |
| 3173 // Receiving an unknown frame when a continuation is expected should | 3205 // Receiving an unknown frame when a continuation is expected should |
| 3174 // result in a SPDY_UNEXPECTED_FRAME error | 3206 // result in a SPDY_UNEXPECTED_FRAME error |
| 3175 TEST_F(SpdyFramerTest, ReceiveUnknownMidContinuation) { | 3207 TEST_P(SpdyFramerTest, ReceiveUnknownMidContinuation) { |
| 3176 const unsigned char kInput[] = { | 3208 const unsigned char kInput[] = { |
| 3177 0x00, 0x00, 0x10, // Length: 16 | 3209 0x00, 0x00, 0x10, // Length: 16 |
| 3178 0x01, // Type: HEADERS | 3210 0x01, // Type: HEADERS |
| 3179 0x00, // Flags: none | 3211 0x00, // Flags: none |
| 3180 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3212 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3181 0x00, 0x06, 0x63, 0x6f, // HPACK | 3213 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3182 0x6f, 0x6b, 0x69, 0x65, // | 3214 0x6f, 0x6b, 0x69, 0x65, // |
| 3183 0x07, 0x66, 0x6f, 0x6f, // | 3215 0x07, 0x66, 0x6f, 0x6f, // |
| 3184 0x3d, 0x62, 0x61, 0x72, // | 3216 0x3d, 0x62, 0x61, 0x72, // |
| 3185 | 3217 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3202 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3234 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3203 | 3235 |
| 3204 EXPECT_EQ(1, visitor.error_count_); | 3236 EXPECT_EQ(1, visitor.error_count_); |
| 3205 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3237 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3206 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3238 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3207 EXPECT_EQ(1, visitor.headers_frame_count_); | 3239 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3208 EXPECT_EQ(0, visitor.continuation_count_); | 3240 EXPECT_EQ(0, visitor.continuation_count_); |
| 3209 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3241 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3210 } | 3242 } |
| 3211 | 3243 |
| 3212 TEST_F(SpdyFramerTest, ReceiveContinuationOnWrongStream) { | 3244 TEST_P(SpdyFramerTest, ReceiveContinuationOnWrongStream) { |
| 3213 const unsigned char kInput[] = { | 3245 const unsigned char kInput[] = { |
| 3214 0x00, 0x00, 0x10, // Length: 16 | 3246 0x00, 0x00, 0x10, // Length: 16 |
| 3215 0x01, // Type: HEADERS | 3247 0x01, // Type: HEADERS |
| 3216 0x00, // Flags: none | 3248 0x00, // Flags: none |
| 3217 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3249 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3218 0x00, 0x06, 0x63, 0x6f, // HPACK | 3250 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3219 0x6f, 0x6b, 0x69, 0x65, // | 3251 0x6f, 0x6b, 0x69, 0x65, // |
| 3220 0x07, 0x66, 0x6f, 0x6f, // | 3252 0x07, 0x66, 0x6f, 0x6f, // |
| 3221 0x3d, 0x62, 0x61, 0x72, // | 3253 0x3d, 0x62, 0x61, 0x72, // |
| 3222 | 3254 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3237 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3269 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3238 | 3270 |
| 3239 EXPECT_EQ(1, visitor.error_count_); | 3271 EXPECT_EQ(1, visitor.error_count_); |
| 3240 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3272 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3241 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3273 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3242 EXPECT_EQ(1, visitor.headers_frame_count_); | 3274 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3243 EXPECT_EQ(0, visitor.continuation_count_); | 3275 EXPECT_EQ(0, visitor.continuation_count_); |
| 3244 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3276 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3245 } | 3277 } |
| 3246 | 3278 |
| 3247 TEST_F(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3279 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { |
| 3248 const unsigned char kInput[] = { | 3280 const unsigned char kInput[] = { |
| 3249 0x00, 0x00, 0x18, // Length: 24 | 3281 0x00, 0x00, 0x18, // Length: 24 |
| 3250 0x09, // Type: CONTINUATION | 3282 0x09, // Type: CONTINUATION |
| 3251 0x00, // Flags: none | 3283 0x00, // Flags: none |
| 3252 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3284 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3253 0x00, 0x06, 0x63, 0x6f, // HPACK | 3285 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3254 0x6f, 0x6b, 0x69, 0x65, // | 3286 0x6f, 0x6b, 0x69, 0x65, // |
| 3255 0x07, 0x66, 0x6f, 0x6f, // | 3287 0x07, 0x66, 0x6f, 0x6f, // |
| 3256 0x3d, 0x62, 0x61, 0x72, // | 3288 0x3d, 0x62, 0x61, 0x72, // |
| 3257 }; | 3289 }; |
| 3258 | 3290 |
| 3259 SpdyFramer framer; | 3291 SpdyFramer framer; |
| 3260 TestSpdyVisitor visitor; | 3292 TestSpdyVisitor visitor; |
| 3261 framer.set_visitor(&visitor); | 3293 framer.set_visitor(&visitor); |
| 3262 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3294 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3263 | 3295 |
| 3264 EXPECT_EQ(1, visitor.error_count_); | 3296 EXPECT_EQ(1, visitor.error_count_); |
| 3265 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3297 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3266 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3298 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3267 EXPECT_EQ(0, visitor.continuation_count_); | 3299 EXPECT_EQ(0, visitor.continuation_count_); |
| 3268 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3300 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3269 } | 3301 } |
| 3270 | 3302 |
| 3271 TEST_F(SpdyFramerTest, ExpectContinuationReceiveData) { | 3303 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { |
| 3272 const unsigned char kInput[] = { | 3304 const unsigned char kInput[] = { |
| 3273 0x00, 0x00, 0x10, // Length: 16 | 3305 0x00, 0x00, 0x10, // Length: 16 |
| 3274 0x01, // Type: HEADERS | 3306 0x01, // Type: HEADERS |
| 3275 0x00, // Flags: none | 3307 0x00, // Flags: none |
| 3276 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3308 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3277 0x00, 0x06, 0x63, 0x6f, // HPACK | 3309 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3278 0x6f, 0x6b, 0x69, 0x65, // | 3310 0x6f, 0x6b, 0x69, 0x65, // |
| 3279 0x07, 0x66, 0x6f, 0x6f, // | 3311 0x07, 0x66, 0x6f, 0x6f, // |
| 3280 0x3d, 0x62, 0x61, 0x72, // | 3312 0x3d, 0x62, 0x61, 0x72, // |
| 3281 | 3313 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3294 | 3326 |
| 3295 EXPECT_EQ(1, visitor.error_count_); | 3327 EXPECT_EQ(1, visitor.error_count_); |
| 3296 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3328 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3297 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3329 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3298 EXPECT_EQ(1, visitor.headers_frame_count_); | 3330 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3299 EXPECT_EQ(0, visitor.continuation_count_); | 3331 EXPECT_EQ(0, visitor.continuation_count_); |
| 3300 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3332 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3301 EXPECT_EQ(0, visitor.data_frame_count_); | 3333 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3302 } | 3334 } |
| 3303 | 3335 |
| 3304 TEST_F(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { | 3336 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { |
| 3305 const unsigned char kInput[] = { | 3337 const unsigned char kInput[] = { |
| 3306 0x00, 0x00, 0x10, // Length: 16 | 3338 0x00, 0x00, 0x10, // Length: 16 |
| 3307 0x01, // Type: HEADERS | 3339 0x01, // Type: HEADERS |
| 3308 0x00, // Flags: none | 3340 0x00, // Flags: none |
| 3309 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3341 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3310 0x00, 0x06, 0x63, 0x6f, // HPACK | 3342 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3311 0x6f, 0x6b, 0x69, 0x65, // | 3343 0x6f, 0x6b, 0x69, 0x65, // |
| 3312 0x07, 0x66, 0x6f, 0x6f, // | 3344 0x07, 0x66, 0x6f, 0x6f, // |
| 3313 0x3d, 0x62, 0x61, 0x72, // | 3345 0x3d, 0x62, 0x61, 0x72, // |
| 3314 | 3346 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3329 | 3361 |
| 3330 EXPECT_EQ(1, visitor.error_count_); | 3362 EXPECT_EQ(1, visitor.error_count_); |
| 3331 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3363 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3332 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3364 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3333 EXPECT_EQ(1, visitor.headers_frame_count_); | 3365 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3334 EXPECT_EQ(0, visitor.continuation_count_); | 3366 EXPECT_EQ(0, visitor.continuation_count_); |
| 3335 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3367 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3336 EXPECT_EQ(0, visitor.data_frame_count_); | 3368 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3337 } | 3369 } |
| 3338 | 3370 |
| 3339 TEST_F(SpdyFramerTest, ReadGarbage) { | 3371 TEST_P(SpdyFramerTest, ReadGarbage) { |
| 3340 SpdyFramer framer; | 3372 SpdyFramer framer; |
| 3341 unsigned char garbage_frame[256]; | 3373 unsigned char garbage_frame[256]; |
| 3342 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 3374 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 3343 TestSpdyVisitor visitor; | 3375 TestSpdyVisitor visitor; |
| 3344 visitor.use_compression_ = false; | 3376 visitor.use_compression_ = false; |
| 3345 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 3377 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 3346 EXPECT_EQ(1, visitor.error_count_); | 3378 EXPECT_EQ(1, visitor.error_count_); |
| 3347 } | 3379 } |
| 3348 | 3380 |
| 3349 TEST_F(SpdyFramerTest, ReadUnknownExtensionFrame) { | 3381 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) { |
| 3350 SpdyFramer framer; | 3382 SpdyFramer framer; |
| 3351 | 3383 |
| 3352 // The unrecognized frame type should still have a valid length. | 3384 // The unrecognized frame type should still have a valid length. |
| 3353 const unsigned char unknown_frame[] = { | 3385 const unsigned char unknown_frame[] = { |
| 3354 0x00, 0x00, 0x08, // Length: 8 | 3386 0x00, 0x00, 0x08, // Length: 8 |
| 3355 0xff, // Type: UnknownFrameType(255) | 3387 0xff, // Type: UnknownFrameType(255) |
| 3356 0xff, // Flags: 0xff | 3388 0xff, // Flags: 0xff |
| 3357 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3389 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3358 0xff, 0xff, 0xff, 0xff, // Payload | 3390 0xff, 0xff, 0xff, 0xff, // Payload |
| 3359 0xff, 0xff, 0xff, 0xff, // | 3391 0xff, 0xff, 0xff, 0xff, // |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3375 10); | 3407 10); |
| 3376 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3408 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3377 visitor.SimulateInFramer( | 3409 visitor.SimulateInFramer( |
| 3378 reinterpret_cast<unsigned char*>(control_frame.data()), | 3410 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3379 control_frame.size()); | 3411 control_frame.size()); |
| 3380 EXPECT_EQ(0, visitor.error_count_); | 3412 EXPECT_EQ(0, visitor.error_count_); |
| 3381 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3413 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); |
| 3382 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3414 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); |
| 3383 } | 3415 } |
| 3384 | 3416 |
| 3385 TEST_F(SpdyFramerTest, ReadGarbageWithValidLength) { | 3417 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { |
| 3386 SpdyFramer framer; | 3418 SpdyFramer framer; |
| 3387 const unsigned char kFrameData[] = { | 3419 const unsigned char kFrameData[] = { |
| 3388 0x00, 0x00, 0x08, // Length: 8 | 3420 0x00, 0x00, 0x08, // Length: 8 |
| 3389 0xff, // Type: UnknownFrameType(255) | 3421 0xff, // Type: UnknownFrameType(255) |
| 3390 0xff, // Flags: 0xff | 3422 0xff, // Flags: 0xff |
| 3391 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3423 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3392 0xff, 0xff, 0xff, 0xff, // Payload | 3424 0xff, 0xff, 0xff, 0xff, // Payload |
| 3393 0xff, 0xff, 0xff, 0xff, // | 3425 0xff, 0xff, 0xff, 0xff, // |
| 3394 }; | 3426 }; |
| 3395 TestSpdyVisitor visitor; | 3427 TestSpdyVisitor visitor; |
| 3396 visitor.use_compression_ = false; | 3428 visitor.use_compression_ = false; |
| 3397 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 3429 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
| 3398 EXPECT_EQ(1, visitor.error_count_); | 3430 EXPECT_EQ(1, visitor.error_count_); |
| 3399 } | 3431 } |
| 3400 | 3432 |
| 3401 TEST_F(SpdyFramerTest, ReadGarbageHPACKEncoding) { | 3433 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { |
| 3402 const unsigned char kInput[] = { | 3434 const unsigned char kInput[] = { |
| 3403 0x00, 0x12, 0x01, // Length: 4609 | 3435 0x00, 0x12, 0x01, // Length: 4609 |
| 3404 0x04, // Type: SETTINGS | 3436 0x04, // Type: SETTINGS |
| 3405 0x00, // Flags: none | 3437 0x00, // Flags: none |
| 3406 0x00, 0x00, 0x01, 0xef, // Stream: 495 | 3438 0x00, 0x00, 0x01, 0xef, // Stream: 495 |
| 3407 0xef, 0xff, // Param: 61439 | 3439 0xef, 0xff, // Param: 61439 |
| 3408 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3440 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
| 3409 0xff, 0xff, // Param: 0xffff | 3441 0xff, 0xff, // Param: 0xffff |
| 3410 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3442 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
| 3411 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) | 3443 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) |
| 3412 0xff, // | 3444 0xff, // |
| 3413 }; | 3445 }; |
| 3414 | 3446 |
| 3415 TestSpdyVisitor visitor; | 3447 TestSpdyVisitor visitor; |
| 3416 visitor.SimulateInFramer(kInput, arraysize(kInput)); | 3448 visitor.SimulateInFramer(kInput, arraysize(kInput)); |
| 3417 EXPECT_EQ(1, visitor.error_count_); | 3449 EXPECT_EQ(1, visitor.error_count_); |
| 3418 } | 3450 } |
| 3419 | 3451 |
| 3420 TEST_F(SpdyFramerTest, SizesTest) { | 3452 TEST_P(SpdyFramerTest, SizesTest) { |
| 3421 SpdyFramer framer; | 3453 SpdyFramer framer; |
| 3422 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); | 3454 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); |
| 3423 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); | 3455 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); |
| 3424 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); | 3456 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); |
| 3425 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); | 3457 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); |
| 3426 EXPECT_EQ(17u, framer.GetPingSize()); | 3458 EXPECT_EQ(17u, framer.GetPingSize()); |
| 3427 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); | 3459 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); |
| 3428 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); | 3460 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); |
| 3429 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); | 3461 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); |
| 3430 EXPECT_EQ(9u, framer.GetBlockedSize()); | 3462 EXPECT_EQ(9u, framer.GetBlockedSize()); |
| 3431 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); | 3463 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); |
| 3432 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize()); | 3464 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize()); |
| 3433 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); | 3465 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); |
| 3434 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); | 3466 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); |
| 3435 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); | 3467 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); |
| 3436 } | 3468 } |
| 3437 | 3469 |
| 3438 TEST_F(SpdyFramerTest, StateToStringTest) { | 3470 TEST_P(SpdyFramerTest, StateToStringTest) { |
| 3439 EXPECT_STREQ("ERROR", SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); | 3471 EXPECT_STREQ("ERROR", SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); |
| 3440 EXPECT_STREQ("FRAME_COMPLETE", | 3472 EXPECT_STREQ("FRAME_COMPLETE", |
| 3441 SpdyFramer::StateToString(SpdyFramer::SPDY_FRAME_COMPLETE)); | 3473 SpdyFramer::StateToString(SpdyFramer::SPDY_FRAME_COMPLETE)); |
| 3442 EXPECT_STREQ("READY_FOR_FRAME", | 3474 EXPECT_STREQ("READY_FOR_FRAME", |
| 3443 SpdyFramer::StateToString(SpdyFramer::SPDY_READY_FOR_FRAME)); | 3475 SpdyFramer::StateToString(SpdyFramer::SPDY_READY_FOR_FRAME)); |
| 3444 EXPECT_STREQ( | 3476 EXPECT_STREQ( |
| 3445 "READING_COMMON_HEADER", | 3477 "READING_COMMON_HEADER", |
| 3446 SpdyFramer::StateToString(SpdyFramer::SPDY_READING_COMMON_HEADER)); | 3478 SpdyFramer::StateToString(SpdyFramer::SPDY_READING_COMMON_HEADER)); |
| 3447 EXPECT_STREQ( | 3479 EXPECT_STREQ( |
| 3448 "CONTROL_FRAME_PAYLOAD", | 3480 "CONTROL_FRAME_PAYLOAD", |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3462 EXPECT_STREQ( | 3494 EXPECT_STREQ( |
| 3463 "SPDY_SETTINGS_FRAME_PAYLOAD", | 3495 "SPDY_SETTINGS_FRAME_PAYLOAD", |
| 3464 SpdyFramer::StateToString(SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); | 3496 SpdyFramer::StateToString(SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); |
| 3465 EXPECT_STREQ( | 3497 EXPECT_STREQ( |
| 3466 "SPDY_ALTSVC_FRAME_PAYLOAD", | 3498 "SPDY_ALTSVC_FRAME_PAYLOAD", |
| 3467 SpdyFramer::StateToString(SpdyFramer::SPDY_ALTSVC_FRAME_PAYLOAD)); | 3499 SpdyFramer::StateToString(SpdyFramer::SPDY_ALTSVC_FRAME_PAYLOAD)); |
| 3468 EXPECT_STREQ("UNKNOWN_STATE", SpdyFramer::StateToString( | 3500 EXPECT_STREQ("UNKNOWN_STATE", SpdyFramer::StateToString( |
| 3469 SpdyFramer::SPDY_ALTSVC_FRAME_PAYLOAD + 1)); | 3501 SpdyFramer::SPDY_ALTSVC_FRAME_PAYLOAD + 1)); |
| 3470 } | 3502 } |
| 3471 | 3503 |
| 3472 TEST_F(SpdyFramerTest, ErrorCodeToStringTest) { | 3504 TEST_P(SpdyFramerTest, ErrorCodeToStringTest) { |
| 3473 EXPECT_STREQ("NO_ERROR", | 3505 EXPECT_STREQ("NO_ERROR", |
| 3474 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); | 3506 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); |
| 3475 EXPECT_STREQ("INVALID_STREAM_ID", SpdyFramer::ErrorCodeToString( | 3507 EXPECT_STREQ("INVALID_STREAM_ID", SpdyFramer::ErrorCodeToString( |
| 3476 SpdyFramer::SPDY_INVALID_STREAM_ID)); | 3508 SpdyFramer::SPDY_INVALID_STREAM_ID)); |
| 3477 EXPECT_STREQ( | 3509 EXPECT_STREQ( |
| 3478 "INVALID_CONTROL_FRAME", | 3510 "INVALID_CONTROL_FRAME", |
| 3479 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); | 3511 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); |
| 3480 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", | 3512 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", |
| 3481 SpdyFramer::ErrorCodeToString( | 3513 SpdyFramer::ErrorCodeToString( |
| 3482 SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE)); | 3514 SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3497 EXPECT_STREQ( | 3529 EXPECT_STREQ( |
| 3498 "SPDY_INVALID_DATA_FRAME_FLAGS", | 3530 "SPDY_INVALID_DATA_FRAME_FLAGS", |
| 3499 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS)); | 3531 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS)); |
| 3500 EXPECT_STREQ("SPDY_INVALID_CONTROL_FRAME_FLAGS", | 3532 EXPECT_STREQ("SPDY_INVALID_CONTROL_FRAME_FLAGS", |
| 3501 SpdyFramer::ErrorCodeToString( | 3533 SpdyFramer::ErrorCodeToString( |
| 3502 SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS)); | 3534 SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS)); |
| 3503 EXPECT_STREQ("UNKNOWN_ERROR", | 3535 EXPECT_STREQ("UNKNOWN_ERROR", |
| 3504 SpdyFramer::ErrorCodeToString(SpdyFramer::LAST_ERROR)); | 3536 SpdyFramer::ErrorCodeToString(SpdyFramer::LAST_ERROR)); |
| 3505 } | 3537 } |
| 3506 | 3538 |
| 3507 TEST_F(SpdyFramerTest, StatusCodeToStringTest) { | 3539 TEST_P(SpdyFramerTest, StatusCodeToStringTest) { |
| 3508 EXPECT_STREQ("NO_ERROR", SpdyFramer::StatusCodeToString(RST_STREAM_NO_ERROR)); | 3540 EXPECT_STREQ("NO_ERROR", SpdyFramer::StatusCodeToString(RST_STREAM_NO_ERROR)); |
| 3509 EXPECT_STREQ("PROTOCOL_ERROR", | 3541 EXPECT_STREQ("PROTOCOL_ERROR", |
| 3510 SpdyFramer::StatusCodeToString(RST_STREAM_PROTOCOL_ERROR)); | 3542 SpdyFramer::StatusCodeToString(RST_STREAM_PROTOCOL_ERROR)); |
| 3511 EXPECT_STREQ("INVALID_STREAM", | 3543 EXPECT_STREQ("INVALID_STREAM", |
| 3512 SpdyFramer::StatusCodeToString(RST_STREAM_INVALID_STREAM)); | 3544 SpdyFramer::StatusCodeToString(RST_STREAM_INVALID_STREAM)); |
| 3513 EXPECT_STREQ("REFUSED_STREAM", | 3545 EXPECT_STREQ("REFUSED_STREAM", |
| 3514 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); | 3546 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); |
| 3515 EXPECT_STREQ("UNSUPPORTED_VERSION", | 3547 EXPECT_STREQ("UNSUPPORTED_VERSION", |
| 3516 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); | 3548 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); |
| 3517 EXPECT_STREQ("CANCEL", SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); | 3549 EXPECT_STREQ("CANCEL", SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); |
| 3518 EXPECT_STREQ("INTERNAL_ERROR", | 3550 EXPECT_STREQ("INTERNAL_ERROR", |
| 3519 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); | 3551 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); |
| 3520 EXPECT_STREQ("FLOW_CONTROL_ERROR", | 3552 EXPECT_STREQ("FLOW_CONTROL_ERROR", |
| 3521 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); | 3553 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); |
| 3522 EXPECT_STREQ("UNKNOWN_STATUS", SpdyFramer::StatusCodeToString(-1)); | 3554 EXPECT_STREQ("UNKNOWN_STATUS", SpdyFramer::StatusCodeToString(-1)); |
| 3523 } | 3555 } |
| 3524 | 3556 |
| 3525 TEST_F(SpdyFramerTest, FrameTypeToStringTest) { | 3557 TEST_P(SpdyFramerTest, FrameTypeToStringTest) { |
| 3526 EXPECT_STREQ("DATA", SpdyFramer::FrameTypeToString(DATA)); | 3558 EXPECT_STREQ("DATA", SpdyFramer::FrameTypeToString(DATA)); |
| 3527 EXPECT_STREQ("RST_STREAM", SpdyFramer::FrameTypeToString(RST_STREAM)); | 3559 EXPECT_STREQ("RST_STREAM", SpdyFramer::FrameTypeToString(RST_STREAM)); |
| 3528 EXPECT_STREQ("SETTINGS", SpdyFramer::FrameTypeToString(SETTINGS)); | 3560 EXPECT_STREQ("SETTINGS", SpdyFramer::FrameTypeToString(SETTINGS)); |
| 3529 EXPECT_STREQ("PING", SpdyFramer::FrameTypeToString(PING)); | 3561 EXPECT_STREQ("PING", SpdyFramer::FrameTypeToString(PING)); |
| 3530 EXPECT_STREQ("GOAWAY", SpdyFramer::FrameTypeToString(GOAWAY)); | 3562 EXPECT_STREQ("GOAWAY", SpdyFramer::FrameTypeToString(GOAWAY)); |
| 3531 EXPECT_STREQ("HEADERS", SpdyFramer::FrameTypeToString(HEADERS)); | 3563 EXPECT_STREQ("HEADERS", SpdyFramer::FrameTypeToString(HEADERS)); |
| 3532 EXPECT_STREQ("WINDOW_UPDATE", SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); | 3564 EXPECT_STREQ("WINDOW_UPDATE", SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); |
| 3533 EXPECT_STREQ("PUSH_PROMISE", SpdyFramer::FrameTypeToString(PUSH_PROMISE)); | 3565 EXPECT_STREQ("PUSH_PROMISE", SpdyFramer::FrameTypeToString(PUSH_PROMISE)); |
| 3534 EXPECT_STREQ("CONTINUATION", SpdyFramer::FrameTypeToString(CONTINUATION)); | 3566 EXPECT_STREQ("CONTINUATION", SpdyFramer::FrameTypeToString(CONTINUATION)); |
| 3535 } | 3567 } |
| 3536 | 3568 |
| 3537 TEST_F(SpdyFramerTest, DataFrameFlagsV4) { | 3569 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
| 3538 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; | 3570 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; |
| 3539 | 3571 |
| 3540 uint8_t flags = 0; | 3572 uint8_t flags = 0; |
| 3541 do { | 3573 do { |
| 3542 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3574 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3543 << static_cast<int>(flags)); | 3575 << static_cast<int>(flags)); |
| 3544 | 3576 |
| 3545 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3577 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3546 SpdyFramer framer; | 3578 SpdyFramer framer; |
| 3547 framer.set_visitor(&visitor); | 3579 framer.set_visitor(&visitor); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3578 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 3610 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 3579 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3611 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3580 } else { | 3612 } else { |
| 3581 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3613 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3582 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3614 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3583 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3615 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3584 } | 3616 } |
| 3585 } while (++flags != 0); | 3617 } while (++flags != 0); |
| 3586 } | 3618 } |
| 3587 | 3619 |
| 3588 TEST_F(SpdyFramerTest, RstStreamFrameFlags) { | 3620 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { |
| 3589 uint8_t flags = 0; | 3621 uint8_t flags = 0; |
| 3590 do { | 3622 do { |
| 3591 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3623 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3592 << static_cast<int>(flags)); | 3624 << static_cast<int>(flags)); |
| 3593 | 3625 |
| 3594 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3626 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3595 SpdyFramer framer; | 3627 SpdyFramer framer; |
| 3596 framer.set_visitor(&visitor); | 3628 framer.set_visitor(&visitor); |
| 3597 | 3629 |
| 3598 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); | 3630 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); |
| 3599 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 3631 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 3600 SetFrameFlags(&frame, flags); | 3632 SetFrameFlags(&frame, flags); |
| 3601 | 3633 |
| 3602 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); | 3634 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); |
| 3603 | 3635 |
| 3604 framer.ProcessInput(frame.data(), frame.size()); | 3636 framer.ProcessInput(frame.data(), frame.size()); |
| 3605 | 3637 |
| 3606 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3638 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3607 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3639 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3608 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3640 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3609 } while (++flags != 0); | 3641 } while (++flags != 0); |
| 3610 } | 3642 } |
| 3611 | 3643 |
| 3612 TEST_F(SpdyFramerTest, SettingsFrameFlags) { | 3644 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
| 3613 uint8_t flags = 0; | 3645 uint8_t flags = 0; |
| 3614 do { | 3646 do { |
| 3615 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3647 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3616 << static_cast<int>(flags)); | 3648 << static_cast<int>(flags)); |
| 3617 | 3649 |
| 3618 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3650 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3619 SpdyFramer framer; | 3651 SpdyFramer framer; |
| 3620 framer.set_visitor(&visitor); | 3652 framer.set_visitor(&visitor); |
| 3621 | 3653 |
| 3622 SpdySettingsIR settings_ir; | 3654 SpdySettingsIR settings_ir; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3640 framer.error_code()) | 3672 framer.error_code()) |
| 3641 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3673 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3642 } else { | 3674 } else { |
| 3643 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3675 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3644 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3676 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3645 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3677 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3646 } | 3678 } |
| 3647 } while (++flags != 0); | 3679 } while (++flags != 0); |
| 3648 } | 3680 } |
| 3649 | 3681 |
| 3650 TEST_F(SpdyFramerTest, GoawayFrameFlags) { | 3682 TEST_P(SpdyFramerTest, GoawayFrameFlags) { |
| 3651 uint8_t flags = 0; | 3683 uint8_t flags = 0; |
| 3652 do { | 3684 do { |
| 3653 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3685 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3654 << static_cast<int>(flags)); | 3686 << static_cast<int>(flags)); |
| 3655 | 3687 |
| 3656 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3688 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3657 SpdyFramer framer; | 3689 SpdyFramer framer; |
| 3658 framer.set_visitor(&visitor); | 3690 framer.set_visitor(&visitor); |
| 3659 | 3691 |
| 3660 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); | 3692 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); |
| 3661 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 3693 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
| 3662 SetFrameFlags(&frame, flags); | 3694 SetFrameFlags(&frame, flags); |
| 3663 | 3695 |
| 3664 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); | 3696 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); |
| 3665 | 3697 |
| 3666 framer.ProcessInput(frame.data(), frame.size()); | 3698 framer.ProcessInput(frame.data(), frame.size()); |
| 3667 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3699 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3668 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3700 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3669 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3701 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3670 } while (++flags != 0); | 3702 } while (++flags != 0); |
| 3671 } | 3703 } |
| 3672 | 3704 |
| 3673 TEST_F(SpdyFramerTest, HeadersFrameFlags) { | 3705 TEST_P(SpdyFramerTest, HeadersFrameFlags) { |
| 3674 uint8_t flags = 0; | 3706 uint8_t flags = 0; |
| 3675 do { | 3707 do { |
| 3676 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3708 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3677 << static_cast<int>(flags)); | 3709 << static_cast<int>(flags)); |
| 3678 | 3710 |
| 3679 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3711 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3680 SpdyFramer framer; | 3712 SpdyFramer framer; |
| 3681 framer.set_visitor(&visitor); | 3713 framer.set_visitor(&visitor); |
| 3682 | 3714 |
| 3683 SpdyHeadersIR headers_ir(57); | 3715 SpdyHeadersIR headers_ir(57); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3720 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); | 3752 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); |
| 3721 } | 3753 } |
| 3722 | 3754 |
| 3723 framer.ProcessInput(frame.data(), frame.size()); | 3755 framer.ProcessInput(frame.data(), frame.size()); |
| 3724 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3756 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3725 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3757 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3726 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3758 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3727 } while (++flags != 0); | 3759 } while (++flags != 0); |
| 3728 } | 3760 } |
| 3729 | 3761 |
| 3730 TEST_F(SpdyFramerTest, PingFrameFlags) { | 3762 TEST_P(SpdyFramerTest, PingFrameFlags) { |
| 3731 uint8_t flags = 0; | 3763 uint8_t flags = 0; |
| 3732 do { | 3764 do { |
| 3733 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3765 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3734 << static_cast<int>(flags)); | 3766 << static_cast<int>(flags)); |
| 3735 | 3767 |
| 3736 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3768 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3737 SpdyFramer framer; | 3769 SpdyFramer framer; |
| 3738 framer.set_visitor(&visitor); | 3770 framer.set_visitor(&visitor); |
| 3739 | 3771 |
| 3740 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); | 3772 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); |
| 3741 SetFrameFlags(&frame, flags); | 3773 SetFrameFlags(&frame, flags); |
| 3742 | 3774 |
| 3743 if (flags & PING_FLAG_ACK) { | 3775 if (flags & PING_FLAG_ACK) { |
| 3744 EXPECT_CALL(visitor, OnPing(42, true)); | 3776 EXPECT_CALL(visitor, OnPing(42, true)); |
| 3745 } else { | 3777 } else { |
| 3746 EXPECT_CALL(visitor, OnPing(42, false)); | 3778 EXPECT_CALL(visitor, OnPing(42, false)); |
| 3747 } | 3779 } |
| 3748 | 3780 |
| 3749 framer.ProcessInput(frame.data(), frame.size()); | 3781 framer.ProcessInput(frame.data(), frame.size()); |
| 3750 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3782 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3751 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3783 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3752 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3784 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3753 } while (++flags != 0); | 3785 } while (++flags != 0); |
| 3754 } | 3786 } |
| 3755 | 3787 |
| 3756 TEST_F(SpdyFramerTest, WindowUpdateFrameFlags) { | 3788 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { |
| 3757 uint8_t flags = 0; | 3789 uint8_t flags = 0; |
| 3758 do { | 3790 do { |
| 3759 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3791 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3760 << static_cast<int>(flags)); | 3792 << static_cast<int>(flags)); |
| 3761 | 3793 |
| 3762 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3794 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3763 SpdyFramer framer; | 3795 SpdyFramer framer; |
| 3764 framer.set_visitor(&visitor); | 3796 framer.set_visitor(&visitor); |
| 3765 | 3797 |
| 3766 SpdySerializedFrame frame( | 3798 SpdySerializedFrame frame( |
| 3767 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); | 3799 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); |
| 3768 SetFrameFlags(&frame, flags); | 3800 SetFrameFlags(&frame, flags); |
| 3769 | 3801 |
| 3770 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 3802 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
| 3771 | 3803 |
| 3772 framer.ProcessInput(frame.data(), frame.size()); | 3804 framer.ProcessInput(frame.data(), frame.size()); |
| 3773 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3805 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3774 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3806 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3775 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3807 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3776 } while (++flags != 0); | 3808 } while (++flags != 0); |
| 3777 } | 3809 } |
| 3778 | 3810 |
| 3779 TEST_F(SpdyFramerTest, PushPromiseFrameFlags) { | 3811 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { |
| 3780 const SpdyStreamId client_id = 123; // Must be odd. | 3812 const SpdyStreamId client_id = 123; // Must be odd. |
| 3781 const SpdyStreamId promised_id = 22; // Must be even. | 3813 const SpdyStreamId promised_id = 22; // Must be even. |
| 3782 uint8_t flags = 0; | 3814 uint8_t flags = 0; |
| 3783 do { | 3815 do { |
| 3784 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3816 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3785 << static_cast<int>(flags)); | 3817 << static_cast<int>(flags)); |
| 3786 | 3818 |
| 3787 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3819 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3788 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3820 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 3789 SpdyFramer framer; | 3821 SpdyFramer framer; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3809 EXPECT_CALL(visitor, OnHeaderFrameEnd(client_id, _)).Times(1); | 3841 EXPECT_CALL(visitor, OnHeaderFrameEnd(client_id, _)).Times(1); |
| 3810 } | 3842 } |
| 3811 | 3843 |
| 3812 framer.ProcessInput(frame.data(), frame.size()); | 3844 framer.ProcessInput(frame.data(), frame.size()); |
| 3813 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3845 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3814 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3846 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3815 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3847 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3816 } while (++flags != 0); | 3848 } while (++flags != 0); |
| 3817 } | 3849 } |
| 3818 | 3850 |
| 3819 TEST_F(SpdyFramerTest, ContinuationFrameFlags) { | 3851 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { |
| 3820 uint8_t flags = 0; | 3852 uint8_t flags = 0; |
| 3821 do { | 3853 do { |
| 3822 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3854 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3823 << static_cast<int>(flags)); | 3855 << static_cast<int>(flags)); |
| 3824 | 3856 |
| 3825 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3857 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3826 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3858 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 3827 SpdyFramer framer; | 3859 SpdyFramer framer; |
| 3828 framer.set_visitor(&visitor); | 3860 framer.set_visitor(&visitor); |
| 3829 framer.set_debug_visitor(&debug_visitor); | 3861 framer.set_debug_visitor(&debug_visitor); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3855 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3887 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3856 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3888 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3857 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3889 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3858 } while (++flags != 0); | 3890 } while (++flags != 0); |
| 3859 } | 3891 } |
| 3860 | 3892 |
| 3861 // TODO(mlavan): Add TEST_F(SpdyFramerTest, AltSvcFrameFlags) | 3893 // TODO(mlavan): Add TEST_F(SpdyFramerTest, AltSvcFrameFlags) |
| 3862 | 3894 |
| 3863 // TODO(hkhalil): Add TEST_F(SpdyFramerTest, BlockedFrameFlags) | 3895 // TODO(hkhalil): Add TEST_F(SpdyFramerTest, BlockedFrameFlags) |
| 3864 | 3896 |
| 3865 TEST_F(SpdyFramerTest, SettingsFlagsAndId) { | 3897 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { |
| 3866 const uint32_t kId = 0x020304; | 3898 const uint32_t kId = 0x020304; |
| 3867 const uint32_t kFlags = 0x01; | 3899 const uint32_t kFlags = 0x01; |
| 3868 const uint32_t kWireFormat = base::HostToNet32(0x01020304); | 3900 const uint32_t kWireFormat = base::HostToNet32(0x01020304); |
| 3869 | 3901 |
| 3870 SettingsFlagsAndId id_and_flags = | 3902 SettingsFlagsAndId id_and_flags = |
| 3871 SettingsFlagsAndId::FromWireFormat(kWireFormat); | 3903 SettingsFlagsAndId::FromWireFormat(kWireFormat); |
| 3872 EXPECT_EQ(kId, id_and_flags.id()); | 3904 EXPECT_EQ(kId, id_and_flags.id()); |
| 3873 EXPECT_EQ(kFlags, id_and_flags.flags()); | 3905 EXPECT_EQ(kFlags, id_and_flags.flags()); |
| 3874 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat()); | 3906 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat()); |
| 3875 } | 3907 } |
| 3876 | 3908 |
| 3877 // Test handling of a RST_STREAM with out-of-bounds status codes. | 3909 // Test handling of a RST_STREAM with out-of-bounds status codes. |
| 3878 TEST_F(SpdyFramerTest, RstStreamStatusBounds) { | 3910 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
| 3879 const unsigned char kH2RstStreamInvalid[] = { | 3911 const unsigned char kH2RstStreamInvalid[] = { |
| 3880 0x00, 0x00, 0x04, // Length: 4 | 3912 0x00, 0x00, 0x04, // Length: 4 |
| 3881 0x03, // Type: RST_STREAM | 3913 0x03, // Type: RST_STREAM |
| 3882 0x00, // Flags: none | 3914 0x00, // Flags: none |
| 3883 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3915 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3884 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 3916 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 3885 }; | 3917 }; |
| 3886 const unsigned char kH2RstStreamNumStatusCodes[] = { | 3918 const unsigned char kH2RstStreamNumStatusCodes[] = { |
| 3887 0x00, 0x00, 0x04, // Length: 4 | 3919 0x00, 0x00, 0x04, // Length: 4 |
| 3888 0x03, // Type: RST_STREAM | 3920 0x03, // Type: RST_STREAM |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3906 | 3938 |
| 3907 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 3939 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 3908 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), | 3940 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), |
| 3909 arraysize(kH2RstStreamNumStatusCodes)); | 3941 arraysize(kH2RstStreamNumStatusCodes)); |
| 3910 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3942 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3911 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3943 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3912 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3944 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3913 } | 3945 } |
| 3914 | 3946 |
| 3915 // Test handling of GOAWAY frames with out-of-bounds status code. | 3947 // Test handling of GOAWAY frames with out-of-bounds status code. |
| 3916 TEST_F(SpdyFramerTest, GoAwayStatusBounds) { | 3948 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { |
| 3917 SpdyFramer framer; | 3949 SpdyFramer framer; |
| 3918 const unsigned char kH2FrameData[] = { | 3950 const unsigned char kH2FrameData[] = { |
| 3919 0x00, 0x00, 0x0a, // Length: 10 | 3951 0x00, 0x00, 0x0a, // Length: 10 |
| 3920 0x07, // Type: GOAWAY | 3952 0x07, // Type: GOAWAY |
| 3921 0x00, // Flags: none | 3953 0x00, // Flags: none |
| 3922 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3954 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 3923 0x00, 0x00, 0x00, 0x01, // Last: 1 | 3955 0x00, 0x00, 0x00, 0x01, // Last: 1 |
| 3924 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff | 3956 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff |
| 3925 0x47, 0x41, // Description | 3957 0x47, 0x41, // Description |
| 3926 }; | 3958 }; |
| 3927 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3959 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3928 framer.set_visitor(&visitor); | 3960 framer.set_visitor(&visitor); |
| 3929 | 3961 |
| 3930 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_INTERNAL_ERROR)); | 3962 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_INTERNAL_ERROR)); |
| 3931 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), | 3963 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), |
| 3932 arraysize(kH2FrameData)); | 3964 arraysize(kH2FrameData)); |
| 3933 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3965 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3934 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3966 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3935 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3967 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3936 } | 3968 } |
| 3937 | 3969 |
| 3938 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 3970 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
| 3939 TEST_F(SpdyFramerTest, GoAwayStreamIdBounds) { | 3971 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
| 3940 const unsigned char kH2FrameData[] = { | 3972 const unsigned char kH2FrameData[] = { |
| 3941 0x00, 0x00, 0x08, // Length: 8 | 3973 0x00, 0x00, 0x08, // Length: 8 |
| 3942 0x07, // Type: GOAWAY | 3974 0x07, // Type: GOAWAY |
| 3943 0x00, // Flags: none | 3975 0x00, // Flags: none |
| 3944 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3976 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 3945 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) | 3977 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) |
| 3946 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 3978 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 3947 }; | 3979 }; |
| 3948 | 3980 |
| 3949 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3981 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3950 SpdyFramer framer; | 3982 SpdyFramer framer; |
| 3951 framer.set_visitor(&visitor); | 3983 framer.set_visitor(&visitor); |
| 3952 | 3984 |
| 3953 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); | 3985 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); |
| 3954 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), | 3986 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), |
| 3955 arraysize(kH2FrameData)); | 3987 arraysize(kH2FrameData)); |
| 3956 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3988 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3957 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3989 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3958 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3990 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3959 } | 3991 } |
| 3960 | 3992 |
| 3961 TEST_F(SpdyFramerTest, OnBlocked) { | 3993 TEST_P(SpdyFramerTest, OnBlocked) { |
| 3962 const SpdyStreamId kStreamId = 0; | 3994 const SpdyStreamId kStreamId = 0; |
| 3963 | 3995 |
| 3964 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3996 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3965 SpdyFramer framer; | 3997 SpdyFramer framer; |
| 3966 framer.set_visitor(&visitor); | 3998 framer.set_visitor(&visitor); |
| 3967 | 3999 |
| 3968 EXPECT_CALL(visitor, OnBlocked(kStreamId)); | 4000 EXPECT_CALL(visitor, OnBlocked(kStreamId)); |
| 3969 | 4001 |
| 3970 SpdyBlockedIR blocked_ir(0); | 4002 SpdyBlockedIR blocked_ir(0); |
| 3971 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 4003 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
| 3972 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); | 4004 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); |
| 3973 | 4005 |
| 3974 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4006 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3975 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4007 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3976 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4008 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3977 } | 4009 } |
| 3978 | 4010 |
| 3979 TEST_F(SpdyFramerTest, OnAltSvc) { | 4011 TEST_P(SpdyFramerTest, OnAltSvc) { |
| 3980 const SpdyStreamId kStreamId = 1; | 4012 const SpdyStreamId kStreamId = 1; |
| 3981 | 4013 |
| 3982 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4014 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3983 SpdyFramer framer; | 4015 SpdyFramer framer; |
| 3984 framer.set_visitor(&visitor); | 4016 framer.set_visitor(&visitor); |
| 3985 | 4017 |
| 3986 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4018 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 3987 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4019 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 3988 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4020 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 3989 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4021 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 3990 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4022 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 3991 altsvc_vector.push_back(altsvc1); | 4023 altsvc_vector.push_back(altsvc1); |
| 3992 altsvc_vector.push_back(altsvc2); | 4024 altsvc_vector.push_back(altsvc2); |
| 3993 EXPECT_CALL(visitor, | 4025 EXPECT_CALL(visitor, |
| 3994 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); | 4026 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); |
| 3995 | 4027 |
| 3996 SpdyAltSvcIR altsvc_ir(1); | 4028 SpdyAltSvcIR altsvc_ir(1); |
| 3997 altsvc_ir.set_origin("o_r|g!n"); | 4029 altsvc_ir.set_origin("o_r|g!n"); |
| 3998 altsvc_ir.add_altsvc(altsvc1); | 4030 altsvc_ir.add_altsvc(altsvc1); |
| 3999 altsvc_ir.add_altsvc(altsvc2); | 4031 altsvc_ir.add_altsvc(altsvc2); |
| 4000 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4032 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4001 framer.ProcessInput(frame.data(), frame.size()); | 4033 framer.ProcessInput(frame.data(), frame.size()); |
| 4002 | 4034 |
| 4003 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4035 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4004 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4036 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4005 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4037 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4006 } | 4038 } |
| 4007 | 4039 |
| 4008 TEST_F(SpdyFramerTest, OnAltSvcNoOrigin) { | 4040 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
| 4009 const SpdyStreamId kStreamId = 1; | 4041 const SpdyStreamId kStreamId = 1; |
| 4010 | 4042 |
| 4011 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4043 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4012 SpdyFramer framer; | 4044 SpdyFramer framer; |
| 4013 framer.set_visitor(&visitor); | 4045 framer.set_visitor(&visitor); |
| 4014 | 4046 |
| 4015 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4047 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4016 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4048 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4017 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4049 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4018 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4050 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4019 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4051 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4020 altsvc_vector.push_back(altsvc1); | 4052 altsvc_vector.push_back(altsvc1); |
| 4021 altsvc_vector.push_back(altsvc2); | 4053 altsvc_vector.push_back(altsvc2); |
| 4022 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); | 4054 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); |
| 4023 | 4055 |
| 4024 SpdyAltSvcIR altsvc_ir(1); | 4056 SpdyAltSvcIR altsvc_ir(1); |
| 4025 altsvc_ir.add_altsvc(altsvc1); | 4057 altsvc_ir.add_altsvc(altsvc1); |
| 4026 altsvc_ir.add_altsvc(altsvc2); | 4058 altsvc_ir.add_altsvc(altsvc2); |
| 4027 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4059 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4028 framer.ProcessInput(frame.data(), frame.size()); | 4060 framer.ProcessInput(frame.data(), frame.size()); |
| 4029 | 4061 |
| 4030 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4062 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4031 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4063 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4032 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4064 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4033 } | 4065 } |
| 4034 | 4066 |
| 4035 TEST_F(SpdyFramerTest, OnAltSvcEmptyProtocolId) { | 4067 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { |
| 4036 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4068 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4037 SpdyFramer framer; | 4069 SpdyFramer framer; |
| 4038 framer.set_visitor(&visitor); | 4070 framer.set_visitor(&visitor); |
| 4039 | 4071 |
| 4040 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 4072 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 4041 | 4073 |
| 4042 SpdyAltSvcIR altsvc_ir(1); | 4074 SpdyAltSvcIR altsvc_ir(1); |
| 4043 altsvc_ir.set_origin("o1"); | 4075 altsvc_ir.set_origin("o1"); |
| 4044 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4076 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 4045 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 4077 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 4046 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4078 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 4047 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); | 4079 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); |
| 4048 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4080 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4049 framer.ProcessInput(frame.data(), frame.size()); | 4081 framer.ProcessInput(frame.data(), frame.size()); |
| 4050 | 4082 |
| 4051 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4083 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4052 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 4084 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4053 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4085 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4054 } | 4086 } |
| 4055 | 4087 |
| 4056 TEST_F(SpdyFramerTest, OnAltSvcBadLengths) { | 4088 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
| 4057 const SpdyStreamId kStreamId = 1; | 4089 const SpdyStreamId kStreamId = 1; |
| 4058 | 4090 |
| 4059 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4091 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4060 SpdyFramer framer; | 4092 SpdyFramer framer; |
| 4061 framer.set_visitor(&visitor); | 4093 framer.set_visitor(&visitor); |
| 4062 | 4094 |
| 4063 SpdyAltSvcWireFormat::AlternativeService altsvc( | 4095 SpdyAltSvcWireFormat::AlternativeService altsvc( |
| 4064 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); | 4096 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); |
| 4065 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4097 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4066 altsvc_vector.push_back(altsvc); | 4098 altsvc_vector.push_back(altsvc); |
| 4067 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); | 4099 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); |
| 4068 | 4100 |
| 4069 SpdyAltSvcIR altsvc_ir(1); | 4101 SpdyAltSvcIR altsvc_ir(1); |
| 4070 altsvc_ir.set_origin("o1"); | 4102 altsvc_ir.set_origin("o1"); |
| 4071 altsvc_ir.add_altsvc(altsvc); | 4103 altsvc_ir.add_altsvc(altsvc); |
| 4072 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4104 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4073 framer.ProcessInput(frame.data(), frame.size()); | 4105 framer.ProcessInput(frame.data(), frame.size()); |
| 4074 | 4106 |
| 4075 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4107 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4076 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4108 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4077 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4109 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4078 } | 4110 } |
| 4079 | 4111 |
| 4080 // Tests handling of ALTSVC frames delivered in small chunks. | 4112 // Tests handling of ALTSVC frames delivered in small chunks. |
| 4081 TEST_F(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 4113 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
| 4082 SpdyFramer framer; | 4114 SpdyFramer framer; |
| 4083 SpdyAltSvcIR altsvc_ir(1); | 4115 SpdyAltSvcIR altsvc_ir(1); |
| 4084 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4116 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4085 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4117 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4086 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4118 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4087 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4119 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4088 altsvc_ir.add_altsvc(altsvc1); | 4120 altsvc_ir.add_altsvc(altsvc1); |
| 4089 altsvc_ir.add_altsvc(altsvc2); | 4121 altsvc_ir.add_altsvc(altsvc2); |
| 4090 | 4122 |
| 4091 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); | 4123 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4105 framed_data += to_read; | 4137 framed_data += to_read; |
| 4106 } | 4138 } |
| 4107 EXPECT_EQ(0, visitor.error_count_); | 4139 EXPECT_EQ(0, visitor.error_count_); |
| 4108 EXPECT_EQ(1, visitor.altsvc_count_); | 4140 EXPECT_EQ(1, visitor.altsvc_count_); |
| 4109 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); | 4141 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); |
| 4110 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); | 4142 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); |
| 4111 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); | 4143 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); |
| 4112 } | 4144 } |
| 4113 | 4145 |
| 4114 // Tests handling of PRIORITY frames. | 4146 // Tests handling of PRIORITY frames. |
| 4115 TEST_F(SpdyFramerTest, ReadPriority) { | 4147 TEST_P(SpdyFramerTest, ReadPriority) { |
| 4116 SpdyFramer framer; | 4148 SpdyFramer framer; |
| 4117 SpdyPriorityIR priority(3, 1, 256, false); | 4149 SpdyPriorityIR priority(3, 1, 256, false); |
| 4118 SpdySerializedFrame frame(framer.SerializePriority(priority)); | 4150 SpdySerializedFrame frame(framer.SerializePriority(priority)); |
| 4119 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4151 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4120 framer.set_visitor(&visitor); | 4152 framer.set_visitor(&visitor); |
| 4121 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); | 4153 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); |
| 4122 framer.ProcessInput(frame.data(), frame.size()); | 4154 framer.ProcessInput(frame.data(), frame.size()); |
| 4123 | 4155 |
| 4124 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4156 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4125 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4157 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4126 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4158 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4127 // TODO(mlavan): once we actually maintain a priority tree, | 4159 // TODO(mlavan): once we actually maintain a priority tree, |
| 4128 // check that state is adjusted correctly. | 4160 // check that state is adjusted correctly. |
| 4129 } | 4161 } |
| 4130 | 4162 |
| 4131 // Tests handling of PRIORITY frame with incorrect size. | 4163 // Tests handling of PRIORITY frame with incorrect size. |
| 4132 TEST_F(SpdyFramerTest, ReadIncorrectlySizedPriority) { | 4164 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
| 4133 // PRIORITY frame of size 4, which isn't correct. | 4165 // PRIORITY frame of size 4, which isn't correct. |
| 4134 const unsigned char kFrameData[] = { | 4166 const unsigned char kFrameData[] = { |
| 4135 0x00, 0x00, 0x04, // Length: 4 | 4167 0x00, 0x00, 0x04, // Length: 4 |
| 4136 0x02, // Type: PRIORITY | 4168 0x02, // Type: PRIORITY |
| 4137 0x00, // Flags: none | 4169 0x00, // Flags: none |
| 4138 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4170 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4139 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) | 4171 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) |
| 4140 }; | 4172 }; |
| 4141 | 4173 |
| 4142 TestSpdyVisitor visitor; | 4174 TestSpdyVisitor visitor; |
| 4143 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4175 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4144 | 4176 |
| 4145 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4177 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4146 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4178 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4147 visitor.framer_.error_code()) | 4179 visitor.framer_.error_code()) |
| 4148 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4180 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4149 } | 4181 } |
| 4150 | 4182 |
| 4151 // Tests handling of PING frame with incorrect size. | 4183 // Tests handling of PING frame with incorrect size. |
| 4152 TEST_F(SpdyFramerTest, ReadIncorrectlySizedPing) { | 4184 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPing) { |
| 4153 // PING frame of size 4, which isn't correct. | 4185 // PING frame of size 4, which isn't correct. |
| 4154 const unsigned char kFrameData[] = { | 4186 const unsigned char kFrameData[] = { |
| 4155 0x00, 0x00, 0x04, // Length: 4 | 4187 0x00, 0x00, 0x04, // Length: 4 |
| 4156 0x06, // Type: PING | 4188 0x06, // Type: PING |
| 4157 0x00, // Flags: none | 4189 0x00, // Flags: none |
| 4158 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 4190 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 4159 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) | 4191 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) |
| 4160 }; | 4192 }; |
| 4161 | 4193 |
| 4162 TestSpdyVisitor visitor; | 4194 TestSpdyVisitor visitor; |
| 4163 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4195 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4164 | 4196 |
| 4165 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4197 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4166 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4198 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4167 visitor.framer_.error_code()) | 4199 visitor.framer_.error_code()) |
| 4168 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4200 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4169 } | 4201 } |
| 4170 | 4202 |
| 4171 // Tests handling of WINDOW_UPDATE frame with incorrect size. | 4203 // Tests handling of WINDOW_UPDATE frame with incorrect size. |
| 4172 TEST_F(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { | 4204 TEST_P(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { |
| 4173 // WINDOW_UPDATE frame of size 3, which isn't correct. | 4205 // WINDOW_UPDATE frame of size 3, which isn't correct. |
| 4174 const unsigned char kFrameData[] = { | 4206 const unsigned char kFrameData[] = { |
| 4175 0x00, 0x00, 0x03, // Length: 3 | 4207 0x00, 0x00, 0x03, // Length: 3 |
| 4176 0x08, // Type: WINDOW_UPDATE | 4208 0x08, // Type: WINDOW_UPDATE |
| 4177 0x00, // Flags: none | 4209 0x00, // Flags: none |
| 4178 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4210 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4179 0x00, 0x00, 0x01, // WindowUpdate (Truncated) | 4211 0x00, 0x00, 0x01, // WindowUpdate (Truncated) |
| 4180 }; | 4212 }; |
| 4181 | 4213 |
| 4182 TestSpdyVisitor visitor; | 4214 TestSpdyVisitor visitor; |
| 4183 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4215 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4184 | 4216 |
| 4185 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4217 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4186 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4218 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4187 visitor.framer_.error_code()) | 4219 visitor.framer_.error_code()) |
| 4188 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4220 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4189 } | 4221 } |
| 4190 | 4222 |
| 4191 // Tests handling of RST_STREAM frame with incorrect size. | 4223 // Tests handling of RST_STREAM frame with incorrect size. |
| 4192 TEST_F(SpdyFramerTest, ReadIncorrectlySizedRstStream) { | 4224 TEST_P(SpdyFramerTest, ReadIncorrectlySizedRstStream) { |
| 4193 // RST_STREAM frame of size 3, which isn't correct. | 4225 // RST_STREAM frame of size 3, which isn't correct. |
| 4194 const unsigned char kFrameData[] = { | 4226 const unsigned char kFrameData[] = { |
| 4195 0x00, 0x00, 0x03, // Length: 3 | 4227 0x00, 0x00, 0x03, // Length: 3 |
| 4196 0x03, // Type: RST_STREAM | 4228 0x03, // Type: RST_STREAM |
| 4197 0x00, // Flags: none | 4229 0x00, // Flags: none |
| 4198 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4230 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4199 0x00, 0x00, 0x01, // RstStream (Truncated) | 4231 0x00, 0x00, 0x01, // RstStream (Truncated) |
| 4200 }; | 4232 }; |
| 4201 | 4233 |
| 4202 TestSpdyVisitor visitor; | 4234 TestSpdyVisitor visitor; |
| 4203 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4235 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4204 | 4236 |
| 4205 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4237 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4206 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4238 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4207 visitor.framer_.error_code()) | 4239 visitor.framer_.error_code()) |
| 4208 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4240 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4209 } | 4241 } |
| 4210 | 4242 |
| 4211 // Test that SpdyFramer processes, by default, all passed input in one call | 4243 // Test that SpdyFramer processes, by default, all passed input in one call |
| 4212 // to ProcessInput (i.e. will not be calling set_process_single_input_frame()). | 4244 // to ProcessInput (i.e. will not be calling set_process_single_input_frame()). |
| 4213 TEST_F(SpdyFramerTest, ProcessAllInput) { | 4245 TEST_P(SpdyFramerTest, ProcessAllInput) { |
| 4214 SpdyFramer framer; | 4246 SpdyFramer framer; |
| 4215 std::unique_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor); | 4247 std::unique_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor); |
| 4216 framer.set_visitor(visitor.get()); | 4248 framer.set_visitor(visitor.get()); |
| 4217 | 4249 |
| 4218 // Create two input frames. | 4250 // Create two input frames. |
| 4219 SpdyHeadersIR headers(1); | 4251 SpdyHeadersIR headers(1); |
| 4220 headers.SetHeader("alpha", "beta"); | 4252 headers.SetHeader("alpha", "beta"); |
| 4221 headers.SetHeader("gamma", "charlie"); | 4253 headers.SetHeader("gamma", "charlie"); |
| 4222 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 4254 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| 4223 SpdySerializedFrame headers_frame( | 4255 SpdySerializedFrame headers_frame( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4252 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4284 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4253 EXPECT_EQ(1, visitor->headers_frame_count_); | 4285 EXPECT_EQ(1, visitor->headers_frame_count_); |
| 4254 EXPECT_EQ(1, visitor->data_frame_count_); | 4286 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4255 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4287 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4256 } | 4288 } |
| 4257 | 4289 |
| 4258 // Test that SpdyFramer stops after processing a full frame if | 4290 // Test that SpdyFramer stops after processing a full frame if |
| 4259 // process_single_input_frame is set. Input to ProcessInput has two frames, but | 4291 // process_single_input_frame is set. Input to ProcessInput has two frames, but |
| 4260 // only processes the first when we give it the first frame split at any point, | 4292 // only processes the first when we give it the first frame split at any point, |
| 4261 // or give it more than one frame in the input buffer. | 4293 // or give it more than one frame in the input buffer. |
| 4262 TEST_F(SpdyFramerTest, ProcessAtMostOneFrame) { | 4294 TEST_P(SpdyFramerTest, ProcessAtMostOneFrame) { |
| 4263 SpdyFramer framer; | 4295 SpdyFramer framer; |
| 4264 framer.set_process_single_input_frame(true); | 4296 framer.set_process_single_input_frame(true); |
| 4265 std::unique_ptr<TestSpdyVisitor> visitor; | 4297 std::unique_ptr<TestSpdyVisitor> visitor; |
| 4266 | 4298 |
| 4267 // Create two input frames. | 4299 // Create two input frames. |
| 4268 const char four_score[] = "Four score and ..."; | 4300 const char four_score[] = "Four score and ..."; |
| 4269 SpdyDataIR four_score_ir(1, four_score); | 4301 SpdyDataIR four_score_ir(1, four_score); |
| 4270 SpdySerializedFrame four_score_frame(framer.SerializeData(four_score_ir)); | 4302 SpdySerializedFrame four_score_frame(framer.SerializeData(four_score_ir)); |
| 4271 | 4303 |
| 4272 SpdyHeadersIR headers(2); | 4304 SpdyHeadersIR headers(2); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4334 | 4366 |
| 4335 EXPECT_EQ(1, visitor->data_frame_count_); | 4367 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4336 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4368 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4337 EXPECT_EQ(0, visitor->headers_frame_count_); | 4369 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4338 } | 4370 } |
| 4339 } | 4371 } |
| 4340 | 4372 |
| 4341 } // namespace test | 4373 } // namespace test |
| 4342 | 4374 |
| 4343 } // namespace net | 4375 } // namespace net |
| OLD | NEW |