| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // | 62 // |
| 63 // Returns a new decompressed SpdySerializedFrame. | 63 // Returns a new decompressed SpdySerializedFrame. |
| 64 template <class SpdyFrameType> | 64 template <class SpdyFrameType> |
| 65 static SpdySerializedFrame DecompressFrame(SpdyFramer* framer, | 65 static SpdySerializedFrame DecompressFrame(SpdyFramer* framer, |
| 66 const SpdyFrameType& frame) { | 66 const SpdyFrameType& frame) { |
| 67 DecompressionVisitor visitor; | 67 DecompressionVisitor visitor; |
| 68 framer->set_visitor(&visitor); | 68 framer->set_visitor(&visitor); |
| 69 CHECK_EQ(frame.size(), framer->ProcessInput(frame.data(), frame.size())); | 69 CHECK_EQ(frame.size(), framer->ProcessInput(frame.data(), frame.size())); |
| 70 CHECK_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer->state()); | 70 CHECK_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer->state()); |
| 71 framer->set_visitor(nullptr); | 71 framer->set_visitor(nullptr); |
| 72 SpdyFramer serializer; | 72 SpdyFramer serializer(SpdyFramer::DISABLE_COMPRESSION); |
| 73 serializer.set_enable_compression(false); | |
| 74 return serializer.SerializeFrame(visitor.GetFrame()); | 73 return serializer.SerializeFrame(visitor.GetFrame()); |
| 75 } | 74 } |
| 76 | 75 |
| 77 class DecompressionVisitor : public SpdyFramerVisitorInterface { | 76 class DecompressionVisitor : public SpdyFramerVisitorInterface { |
| 78 public: | 77 public: |
| 79 DecompressionVisitor() : finished_(false) {} | 78 DecompressionVisitor() : finished_(false) {} |
| 80 | 79 |
| 81 const SpdyFrameIR& GetFrame() const { | 80 const SpdyFrameIR& GetFrame() const { |
| 82 CHECK(finished_); | 81 CHECK(finished_); |
| 83 return *frame_; | 82 return *frame_; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 264 } |
| 266 }; | 265 }; |
| 267 | 266 |
| 268 class TestSpdyVisitor : public SpdyFramerVisitorInterface, | 267 class TestSpdyVisitor : public SpdyFramerVisitorInterface, |
| 269 public SpdyFramerDebugVisitorInterface { | 268 public SpdyFramerDebugVisitorInterface { |
| 270 public: | 269 public: |
| 271 // This is larger than our max frame size because header blocks that | 270 // This is larger than our max frame size because header blocks that |
| 272 // are too long can spill over into CONTINUATION frames. | 271 // are too long can spill over into CONTINUATION frames. |
| 273 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; | 272 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; |
| 274 | 273 |
| 275 TestSpdyVisitor() | 274 explicit TestSpdyVisitor(SpdyFramer::CompressionOption option) |
| 276 : use_compression_(false), | 275 : framer_(option), |
| 277 error_count_(0), | 276 error_count_(0), |
| 278 headers_frame_count_(0), | 277 headers_frame_count_(0), |
| 279 push_promise_frame_count_(0), | 278 push_promise_frame_count_(0), |
| 280 goaway_count_(0), | 279 goaway_count_(0), |
| 281 setting_count_(0), | 280 setting_count_(0), |
| 282 settings_ack_sent_(0), | 281 settings_ack_sent_(0), |
| 283 settings_ack_received_(0), | 282 settings_ack_received_(0), |
| 284 continuation_count_(0), | 283 continuation_count_(0), |
| 285 altsvc_count_(0), | 284 altsvc_count_(0), |
| 286 priority_count_(0), | 285 priority_count_(0), |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 void OnReceiveCompressedFrame(SpdyStreamId stream_id, | 486 void OnReceiveCompressedFrame(SpdyStreamId stream_id, |
| 488 SpdyFrameType type, | 487 SpdyFrameType type, |
| 489 size_t frame_len) override { | 488 size_t frame_len) override { |
| 490 VLOG(1) << "OnReceiveCompressedFrame(" << stream_id << ", " << type << ", " | 489 VLOG(1) << "OnReceiveCompressedFrame(" << stream_id << ", " << type << ", " |
| 491 << frame_len << ")"; | 490 << frame_len << ")"; |
| 492 last_frame_len_ = frame_len; | 491 last_frame_len_ = frame_len; |
| 493 } | 492 } |
| 494 | 493 |
| 495 // Convenience function which runs a framer simulation with particular input. | 494 // Convenience function which runs a framer simulation with particular input. |
| 496 void SimulateInFramer(const unsigned char* input, size_t size) { | 495 void SimulateInFramer(const unsigned char* input, size_t size) { |
| 497 framer_.set_enable_compression(use_compression_); | |
| 498 framer_.set_visitor(this); | 496 framer_.set_visitor(this); |
| 499 size_t input_remaining = size; | 497 size_t input_remaining = size; |
| 500 const char* input_ptr = reinterpret_cast<const char*>(input); | 498 const char* input_ptr = reinterpret_cast<const char*>(input); |
| 501 while (input_remaining > 0 && | 499 while (input_remaining > 0 && |
| 502 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { | 500 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { |
| 503 // To make the tests more interesting, we feed random (and small) chunks | 501 // To make the tests more interesting, we feed random (and small) chunks |
| 504 // into the framer. This simulates getting strange-sized reads from | 502 // into the framer. This simulates getting strange-sized reads from |
| 505 // the socket. | 503 // the socket. |
| 506 const size_t kMaxReadSize = 32; | 504 const size_t kMaxReadSize = 32; |
| 507 size_t bytes_read = | 505 size_t bytes_read = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 // excluding the size of the header. | 541 // excluding the size of the header. |
| 544 static size_t received_control_frame_max_size() { | 542 static size_t received_control_frame_max_size() { |
| 545 return kSpdyInitialFrameSizeLimit; | 543 return kSpdyInitialFrameSizeLimit; |
| 546 } | 544 } |
| 547 | 545 |
| 548 static size_t header_data_chunk_max_size() { | 546 static size_t header_data_chunk_max_size() { |
| 549 return SpdyFramer::kHeaderDataChunkMaxSize; | 547 return SpdyFramer::kHeaderDataChunkMaxSize; |
| 550 } | 548 } |
| 551 | 549 |
| 552 SpdyFramer framer_; | 550 SpdyFramer framer_; |
| 553 bool use_compression_; | |
| 554 | 551 |
| 555 // Counters from the visitor callbacks. | 552 // Counters from the visitor callbacks. |
| 556 int error_count_; | 553 int error_count_; |
| 557 int headers_frame_count_; | 554 int headers_frame_count_; |
| 558 int push_promise_frame_count_; | 555 int push_promise_frame_count_; |
| 559 int goaway_count_; | 556 int goaway_count_; |
| 560 int setting_count_; | 557 int setting_count_; |
| 561 int settings_ack_sent_; | 558 int settings_ack_sent_; |
| 562 int settings_ack_received_; | 559 int settings_ack_received_; |
| 563 int continuation_count_; | 560 int continuation_count_; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | 667 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, |
| 671 SpdyFramerTest, | 668 SpdyFramerTest, |
| 672 ::testing::Combine(::testing::Values(DECODER_SELF, | 669 ::testing::Combine(::testing::Values(DECODER_SELF, |
| 673 DECODER_NESTED, | 670 DECODER_NESTED, |
| 674 DECODER_HTTP2), | 671 DECODER_HTTP2), |
| 675 ::testing::Values(HPACK_DECODER_1, | 672 ::testing::Values(HPACK_DECODER_1, |
| 676 HPACK_DECODER_2))); | 673 HPACK_DECODER_2))); |
| 677 | 674 |
| 678 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 675 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
| 679 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { | 676 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
| 680 SpdyFramer framer; | 677 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 681 framer.set_enable_compression(false); | |
| 682 | 678 |
| 683 // Encode the header block into a Headers frame. | 679 // Encode the header block into a Headers frame. |
| 684 SpdyHeadersIR headers(1); | 680 SpdyHeadersIR headers(1); |
| 685 headers.SetHeader("alpha", "beta"); | 681 headers.SetHeader("alpha", "beta"); |
| 686 headers.SetHeader("gamma", "charlie"); | 682 headers.SetHeader("gamma", "charlie"); |
| 687 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 683 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| 688 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 684 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 689 | 685 |
| 690 TestSpdyVisitor visitor; | 686 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 691 visitor.use_compression_ = false; | |
| 692 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 687 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 693 frame.size()); | 688 frame.size()); |
| 694 | 689 |
| 695 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 690 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 696 EXPECT_EQ(headers.header_block(), visitor.headers_); | 691 EXPECT_EQ(headers.header_block(), visitor.headers_); |
| 697 } | 692 } |
| 698 | 693 |
| 699 // Test that if there's not a full frame, we fail to parse it. | 694 // Test that if there's not a full frame, we fail to parse it. |
| 700 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { | 695 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { |
| 701 SpdyFramer framer; | 696 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 702 framer.set_enable_compression(false); | |
| 703 | 697 |
| 704 // Encode the header block into a Headers frame. | 698 // Encode the header block into a Headers frame. |
| 705 SpdyHeadersIR headers(1); | 699 SpdyHeadersIR headers(1); |
| 706 headers.SetHeader("alpha", "beta"); | 700 headers.SetHeader("alpha", "beta"); |
| 707 headers.SetHeader("gamma", "charlie"); | 701 headers.SetHeader("gamma", "charlie"); |
| 708 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 702 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 709 | 703 |
| 710 TestSpdyVisitor visitor; | 704 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 711 visitor.use_compression_ = false; | |
| 712 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 705 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 713 frame.size() - 2); | 706 frame.size() - 2); |
| 714 | 707 |
| 715 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 708 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 716 EXPECT_EQ(0u, visitor.headers_.size()); | 709 EXPECT_EQ(0u, visitor.headers_.size()); |
| 717 } | 710 } |
| 718 | 711 |
| 719 // Test that we treat incoming upper-case or mixed-case header values as | 712 // Test that we treat incoming upper-case or mixed-case header values as |
| 720 // malformed. | 713 // malformed. |
| 721 TEST_P(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { | 714 TEST_P(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { |
| 722 SpdyFramer framer; | 715 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 723 framer.set_enable_compression(false); | |
| 724 | 716 |
| 725 SpdyFrameBuilder frame(1024); | 717 SpdyFrameBuilder frame(1024); |
| 726 frame.BeginNewFrame(framer, HEADERS, 0, 1); | 718 frame.BeginNewFrame(framer, HEADERS, 0, 1); |
| 727 frame.WriteUInt32(1); | 719 frame.WriteUInt32(1); |
| 728 frame.WriteStringPiece32("Name1"); | 720 frame.WriteStringPiece32("Name1"); |
| 729 frame.WriteStringPiece32("value1"); | 721 frame.WriteStringPiece32("value1"); |
| 730 frame.RewriteLength(framer); | 722 frame.RewriteLength(framer); |
| 731 | 723 |
| 732 SpdyFrameBuilder frame2(1024); | 724 SpdyFrameBuilder frame2(1024); |
| 733 frame2.BeginNewFrame(framer, HEADERS, 0, 1); | 725 frame2.BeginNewFrame(framer, HEADERS, 0, 1); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 747 SpdyHeaderBlock new_headers; | 739 SpdyHeaderBlock new_headers; |
| 748 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 740 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 749 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 741 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 750 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 742 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 751 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); | 743 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); |
| 752 } | 744 } |
| 753 | 745 |
| 754 // 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 |
| 755 // frame. | 747 // frame. |
| 756 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { | 748 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { |
| 757 SpdyFramer framer; | 749 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 758 framer.set_enable_compression(false); | |
| 759 | 750 |
| 760 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; | 751 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; |
| 761 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { | 752 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { |
| 762 const bool exclusive_test_array[] = {true, false}; | 753 const bool exclusive_test_array[] = {true, false}; |
| 763 for (bool exclusive : exclusive_test_array) { | 754 for (bool exclusive : exclusive_test_array) { |
| 764 SpdyHeadersIR headers(1); | 755 SpdyHeadersIR headers(1); |
| 765 headers.set_has_priority(true); | 756 headers.set_has_priority(true); |
| 766 headers.set_parent_stream_id(parent_stream_id); | 757 headers.set_parent_stream_id(parent_stream_id); |
| 767 headers.set_exclusive(exclusive); | 758 headers.set_exclusive(exclusive); |
| 768 SpdySerializedFrame frame( | 759 SpdySerializedFrame frame( |
| 769 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 760 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 770 | 761 |
| 771 TestSpdyVisitor visitor; | 762 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 772 visitor.use_compression_ = false; | |
| 773 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 763 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 774 frame.size()); | 764 frame.size()); |
| 775 | 765 |
| 776 EXPECT_TRUE(visitor.header_has_priority_); | 766 EXPECT_TRUE(visitor.header_has_priority_); |
| 777 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); | 767 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); |
| 778 EXPECT_EQ(exclusive, visitor.header_exclusive_); | 768 EXPECT_EQ(exclusive, visitor.header_exclusive_); |
| 779 } | 769 } |
| 780 } | 770 } |
| 781 } | 771 } |
| 782 | 772 |
| 783 // Test that if we receive a frame with payload length field at the | 773 // Test that if we receive a frame with payload length field at the |
| 784 // advertised max size, we do not set an error in ProcessInput. | 774 // advertised max size, we do not set an error in ProcessInput. |
| 785 TEST_P(SpdyFramerTest, AcceptMaxFrameSizeSetting) { | 775 TEST_P(SpdyFramerTest, AcceptMaxFrameSizeSetting) { |
| 786 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 776 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 787 SpdyFramer framer; | 777 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 788 framer.set_visitor(&visitor); | 778 framer.set_visitor(&visitor); |
| 789 | 779 |
| 790 // DATA frame with maximum allowed payload length. | 780 // DATA frame with maximum allowed payload length. |
| 791 unsigned char kH2FrameData[] = { | 781 unsigned char kH2FrameData[] = { |
| 792 0x00, 0x40, 0x00, // Length: 2^14 | 782 0x00, 0x40, 0x00, // Length: 2^14 |
| 793 0x00, // Type: HEADERS | 783 0x00, // Type: HEADERS |
| 794 0x00, // Flags: None | 784 0x00, // Flags: None |
| 795 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 785 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 796 0x00, 0x00, 0x00, 0x00, // Junk payload | 786 0x00, 0x00, 0x00, 0x00, // Junk payload |
| 797 }; | 787 }; |
| 798 | 788 |
| 799 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 789 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
| 800 sizeof(kH2FrameData), false); | 790 sizeof(kH2FrameData), false); |
| 801 | 791 |
| 802 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); | 792 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); |
| 803 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); | 793 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); |
| 804 framer.ProcessInput(frame.data(), frame.size()); | 794 framer.ProcessInput(frame.data(), frame.size()); |
| 805 EXPECT_FALSE(framer.HasError()); | 795 EXPECT_FALSE(framer.HasError()); |
| 806 } | 796 } |
| 807 | 797 |
| 808 // Test that if we receive a frame with payload length larger than the | 798 // Test that if we receive a frame with payload length larger than the |
| 809 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. | 799 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. |
| 810 TEST_P(SpdyFramerTest, ExceedMaxFrameSizeSetting) { | 800 TEST_P(SpdyFramerTest, ExceedMaxFrameSizeSetting) { |
| 811 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 801 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 812 SpdyFramer framer; | 802 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 813 framer.set_visitor(&visitor); | 803 framer.set_visitor(&visitor); |
| 814 | 804 |
| 815 // DATA frame with too large payload length. | 805 // DATA frame with too large payload length. |
| 816 unsigned char kH2FrameData[] = { | 806 unsigned char kH2FrameData[] = { |
| 817 0x00, 0x40, 0x01, // Length: 2^14 + 1 | 807 0x00, 0x40, 0x01, // Length: 2^14 + 1 |
| 818 0x00, // Type: HEADERS | 808 0x00, // Type: HEADERS |
| 819 0x00, // Flags: None | 809 0x00, // Flags: None |
| 820 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 810 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 821 0x00, 0x00, 0x00, 0x00, // Junk payload | 811 0x00, 0x00, 0x00, 0x00, // Junk payload |
| 822 }; | 812 }; |
| 823 | 813 |
| 824 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 814 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
| 825 sizeof(kH2FrameData), false); | 815 sizeof(kH2FrameData), false); |
| 826 | 816 |
| 827 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 817 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 828 framer.ProcessInput(frame.data(), frame.size()); | 818 framer.ProcessInput(frame.data(), frame.size()); |
| 829 EXPECT_TRUE(framer.HasError()); | 819 EXPECT_TRUE(framer.HasError()); |
| 830 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) | 820 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) |
| 831 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 821 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 832 } | 822 } |
| 833 | 823 |
| 834 // Test that if we receive a DATA frame with padding length larger than the | 824 // Test that if we receive a DATA frame with padding length larger than the |
| 835 // payload length, we set an error of SPDY_INVALID_PADDING | 825 // payload length, we set an error of SPDY_INVALID_PADDING |
| 836 TEST_P(SpdyFramerTest, OversizedDataPaddingError) { | 826 TEST_P(SpdyFramerTest, OversizedDataPaddingError) { |
| 837 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 827 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 838 SpdyFramer framer; | 828 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 839 framer.set_visitor(&visitor); | 829 framer.set_visitor(&visitor); |
| 840 | 830 |
| 841 // DATA frame with invalid padding length. | 831 // DATA frame with invalid padding length. |
| 842 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 832 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
| 843 // MSVC, where |char| is signed by default, which would not compile because of | 833 // MSVC, where |char| is signed by default, which would not compile because of |
| 844 // the element exceeding 127. | 834 // the element exceeding 127. |
| 845 unsigned char kH2FrameData[] = { | 835 unsigned char kH2FrameData[] = { |
| 846 0x00, 0x00, 0x05, // Length: 5 | 836 0x00, 0x00, 0x05, // Length: 5 |
| 847 0x00, // Type: DATA | 837 0x00, // Type: DATA |
| 848 0x09, // Flags: END_STREAM|PADDED | 838 0x09, // Flags: END_STREAM|PADDED |
| (...skipping 14 matching lines...) Expand all Loading... |
| 863 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 853 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 864 EXPECT_TRUE(framer.HasError()); | 854 EXPECT_TRUE(framer.HasError()); |
| 865 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 855 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 866 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 856 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 867 } | 857 } |
| 868 | 858 |
| 869 // Test that if we receive a DATA frame with padding length not larger than the | 859 // Test that if we receive a DATA frame with padding length not larger than the |
| 870 // payload length, we do not set an error of SPDY_INVALID_PADDING | 860 // payload length, we do not set an error of SPDY_INVALID_PADDING |
| 871 TEST_P(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { | 861 TEST_P(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { |
| 872 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 862 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 873 SpdyFramer framer; | 863 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 874 framer.set_visitor(&visitor); | 864 framer.set_visitor(&visitor); |
| 875 | 865 |
| 876 // DATA frame with valid Padding length | 866 // DATA frame with valid Padding length |
| 877 char kH2FrameData[] = { | 867 char kH2FrameData[] = { |
| 878 0x00, 0x00, 0x05, // Length: 5 | 868 0x00, 0x00, 0x05, // Length: 5 |
| 879 0x00, // Type: DATA | 869 0x00, // Type: DATA |
| 880 0x08, // Flags: PADDED | 870 0x08, // Flags: PADDED |
| 881 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 871 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 882 0x04, // PadLen: 4 trailing bytes | 872 0x04, // PadLen: 4 trailing bytes |
| 883 0x00, 0x00, 0x00, 0x00, // Padding | 873 0x00, 0x00, 0x00, 0x00, // Padding |
| (...skipping 14 matching lines...) Expand all Loading... |
| 898 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 888 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 899 EXPECT_FALSE(framer.HasError()); | 889 EXPECT_FALSE(framer.HasError()); |
| 900 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 890 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 901 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 891 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 902 } | 892 } |
| 903 | 893 |
| 904 // Test that if we receive a HEADERS frame with padding length larger than the | 894 // Test that if we receive a HEADERS frame with padding length larger than the |
| 905 // payload length, we set an error of SPDY_INVALID_PADDING | 895 // payload length, we set an error of SPDY_INVALID_PADDING |
| 906 TEST_P(SpdyFramerTest, OversizedHeadersPaddingError) { | 896 TEST_P(SpdyFramerTest, OversizedHeadersPaddingError) { |
| 907 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 897 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 908 SpdyFramer framer; | 898 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 909 framer.set_visitor(&visitor); | 899 framer.set_visitor(&visitor); |
| 910 | 900 |
| 911 // HEADERS frame with invalid padding length. | 901 // HEADERS frame with invalid padding length. |
| 912 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 902 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
| 913 // MSVC, where |char| is signed by default, which would not compile because of | 903 // MSVC, where |char| is signed by default, which would not compile because of |
| 914 // the element exceeding 127. | 904 // the element exceeding 127. |
| 915 unsigned char kH2FrameData[] = { | 905 unsigned char kH2FrameData[] = { |
| 916 0x00, 0x00, 0x05, // Length: 5 | 906 0x00, 0x00, 0x05, // Length: 5 |
| 917 0x01, // Type: HEADERS | 907 0x01, // Type: HEADERS |
| 918 0x08, // Flags: PADDED | 908 0x08, // Flags: PADDED |
| (...skipping 11 matching lines...) Expand all Loading... |
| 930 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 920 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 931 EXPECT_TRUE(framer.HasError()); | 921 EXPECT_TRUE(framer.HasError()); |
| 932 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 922 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 933 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 923 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 934 } | 924 } |
| 935 | 925 |
| 936 // Test that if we receive a HEADERS frame with padding length not larger | 926 // Test that if we receive a HEADERS frame with padding length not larger |
| 937 // than the payload length, we do not set an error of SPDY_INVALID_PADDING | 927 // than the payload length, we do not set an error of SPDY_INVALID_PADDING |
| 938 TEST_P(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { | 928 TEST_P(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { |
| 939 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 929 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 940 SpdyFramer framer; | 930 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 941 framer.set_visitor(&visitor); | 931 framer.set_visitor(&visitor); |
| 942 | 932 |
| 943 // HEADERS frame with invalid Padding length | 933 // HEADERS frame with invalid Padding length |
| 944 char kH2FrameData[] = { | 934 char kH2FrameData[] = { |
| 945 0x00, 0x00, 0x05, // Length: 5 | 935 0x00, 0x00, 0x05, // Length: 5 |
| 946 0x01, // Type: HEADERS | 936 0x01, // Type: HEADERS |
| 947 0x08, // Flags: PADDED | 937 0x08, // Flags: PADDED |
| 948 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 938 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 949 0x04, // PadLen: 4 trailing bytes | 939 0x04, // PadLen: 4 trailing bytes |
| 950 0x00, 0x00, 0x00, 0x00, // Padding | 940 0x00, 0x00, 0x00, 0x00, // Padding |
| 951 }; | 941 }; |
| 952 | 942 |
| 953 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 943 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 954 | 944 |
| 955 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); | 945 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); |
| 956 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | 946 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); |
| 957 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 947 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 958 EXPECT_FALSE(framer.HasError()); | 948 EXPECT_FALSE(framer.HasError()); |
| 959 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 949 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 960 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 950 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 961 } | 951 } |
| 962 | 952 |
| 963 // Test that if we receive a DATA with stream ID zero, we signal an error | 953 // Test that if we receive a DATA with stream ID zero, we signal an error |
| 964 // (but don't crash). | 954 // (but don't crash). |
| 965 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { | 955 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { |
| 966 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 956 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 967 SpdyFramer framer; | 957 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 968 framer.set_visitor(&visitor); | 958 framer.set_visitor(&visitor); |
| 969 | 959 |
| 970 const char bytes[] = "hello"; | 960 const char bytes[] = "hello"; |
| 971 SpdyDataIR data_ir(0, bytes); | 961 SpdyDataIR data_ir(0, bytes); |
| 972 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 962 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 973 | 963 |
| 974 // We shouldn't have to read the whole frame before we signal an error. | 964 // We shouldn't have to read the whole frame before we signal an error. |
| 975 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 965 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 976 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 966 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 977 EXPECT_TRUE(framer.HasError()); | 967 EXPECT_TRUE(framer.HasError()); |
| 978 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 968 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 979 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 969 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 980 } | 970 } |
| 981 | 971 |
| 982 // Test that if we receive a HEADERS with stream ID zero, we signal an error | 972 // Test that if we receive a HEADERS with stream ID zero, we signal an error |
| 983 // (but don't crash). | 973 // (but don't crash). |
| 984 TEST_P(SpdyFramerTest, HeadersWithStreamIdZero) { | 974 TEST_P(SpdyFramerTest, HeadersWithStreamIdZero) { |
| 985 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 975 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 986 SpdyFramer framer; | 976 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 987 framer.set_visitor(&visitor); | 977 framer.set_visitor(&visitor); |
| 988 | 978 |
| 989 SpdyHeadersIR headers(0); | 979 SpdyHeadersIR headers(0); |
| 990 headers.SetHeader("alpha", "beta"); | 980 headers.SetHeader("alpha", "beta"); |
| 991 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 981 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 992 | 982 |
| 993 // We shouldn't have to read the whole frame before we signal an error. | 983 // We shouldn't have to read the whole frame before we signal an error. |
| 994 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 984 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 995 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 985 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 996 EXPECT_TRUE(framer.HasError()); | 986 EXPECT_TRUE(framer.HasError()); |
| 997 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 987 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 998 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 988 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 999 } | 989 } |
| 1000 | 990 |
| 1001 // Test that if we receive a PRIORITY with stream ID zero, we signal an error | 991 // Test that if we receive a PRIORITY with stream ID zero, we signal an error |
| 1002 // (but don't crash). | 992 // (but don't crash). |
| 1003 TEST_P(SpdyFramerTest, PriorityWithStreamIdZero) { | 993 TEST_P(SpdyFramerTest, PriorityWithStreamIdZero) { |
| 1004 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 994 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1005 SpdyFramer framer; | 995 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1006 framer.set_visitor(&visitor); | 996 framer.set_visitor(&visitor); |
| 1007 | 997 |
| 1008 SpdyPriorityIR priority_ir(0, 1, 16, true); | 998 SpdyPriorityIR priority_ir(0, 1, 16, true); |
| 1009 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 999 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
| 1010 | 1000 |
| 1011 // We shouldn't have to read the whole frame before we signal an error. | 1001 // We shouldn't have to read the whole frame before we signal an error. |
| 1012 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1002 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1013 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1003 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1014 EXPECT_TRUE(framer.HasError()); | 1004 EXPECT_TRUE(framer.HasError()); |
| 1015 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1005 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1016 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1006 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1017 } | 1007 } |
| 1018 | 1008 |
| 1019 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error | 1009 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error |
| 1020 // (but don't crash). | 1010 // (but don't crash). |
| 1021 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { | 1011 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { |
| 1022 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1012 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1023 SpdyFramer framer; | 1013 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1024 framer.set_visitor(&visitor); | 1014 framer.set_visitor(&visitor); |
| 1025 | 1015 |
| 1026 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); | 1016 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); |
| 1027 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); | 1017 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); |
| 1028 | 1018 |
| 1029 // We shouldn't have to read the whole frame before we signal an error. | 1019 // We shouldn't have to read the whole frame before we signal an error. |
| 1030 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1020 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1031 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1021 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1032 EXPECT_TRUE(framer.HasError()); | 1022 EXPECT_TRUE(framer.HasError()); |
| 1033 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1023 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1034 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1024 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1035 } | 1025 } |
| 1036 | 1026 |
| 1037 // Test that if we receive a SETTINGS with stream ID other than zero, | 1027 // Test that if we receive a SETTINGS with stream ID other than zero, |
| 1038 // we signal an error (but don't crash). | 1028 // we signal an error (but don't crash). |
| 1039 TEST_P(SpdyFramerTest, SettingsWithStreamIdNotZero) { | 1029 TEST_P(SpdyFramerTest, SettingsWithStreamIdNotZero) { |
| 1040 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1030 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1041 SpdyFramer framer; | 1031 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1042 framer.set_visitor(&visitor); | 1032 framer.set_visitor(&visitor); |
| 1043 | 1033 |
| 1044 // Settings frame with invalid StreamID of 0x01 | 1034 // Settings frame with invalid StreamID of 0x01 |
| 1045 char kH2FrameData[] = { | 1035 char kH2FrameData[] = { |
| 1046 0x00, 0x00, 0x06, // Length: 6 | 1036 0x00, 0x00, 0x06, // Length: 6 |
| 1047 0x04, // Type: SETTINGS | 1037 0x04, // Type: SETTINGS |
| 1048 0x00, // Flags: none | 1038 0x00, // Flags: none |
| 1049 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1039 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1050 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1040 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| 1051 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 | 1041 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 |
| 1052 }; | 1042 }; |
| 1053 | 1043 |
| 1054 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1044 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1055 | 1045 |
| 1056 // We shouldn't have to read the whole frame before we signal an error. | 1046 // We shouldn't have to read the whole frame before we signal an error. |
| 1057 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1047 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1058 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1048 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1059 EXPECT_TRUE(framer.HasError()); | 1049 EXPECT_TRUE(framer.HasError()); |
| 1060 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1050 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1061 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1051 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1062 } | 1052 } |
| 1063 | 1053 |
| 1064 // Test that if we receive a GOAWAY with stream ID other than zero, | 1054 // Test that if we receive a GOAWAY with stream ID other than zero, |
| 1065 // we signal an error (but don't crash). | 1055 // we signal an error (but don't crash). |
| 1066 TEST_P(SpdyFramerTest, GoawayWithStreamIdNotZero) { | 1056 TEST_P(SpdyFramerTest, GoawayWithStreamIdNotZero) { |
| 1067 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1057 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1068 SpdyFramer framer; | 1058 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1069 framer.set_visitor(&visitor); | 1059 framer.set_visitor(&visitor); |
| 1070 | 1060 |
| 1071 // GOAWAY frame with invalid StreamID of 0x01 | 1061 // GOAWAY frame with invalid StreamID of 0x01 |
| 1072 char kH2FrameData[] = { | 1062 char kH2FrameData[] = { |
| 1073 0x00, 0x00, 0x0a, // Length: 10 | 1063 0x00, 0x00, 0x0a, // Length: 10 |
| 1074 0x07, // Type: GOAWAY | 1064 0x07, // Type: GOAWAY |
| 1075 0x00, // Flags: none | 1065 0x00, // Flags: none |
| 1076 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1066 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1077 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1067 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 1078 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1068 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 1079 0x47, 0x41, // Description | 1069 0x47, 0x41, // Description |
| 1080 }; | 1070 }; |
| 1081 | 1071 |
| 1082 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1072 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1083 | 1073 |
| 1084 // We shouldn't have to read the whole frame before we signal an error. | 1074 // We shouldn't have to read the whole frame before we signal an error. |
| 1085 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1075 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1086 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1076 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1087 EXPECT_TRUE(framer.HasError()); | 1077 EXPECT_TRUE(framer.HasError()); |
| 1088 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1078 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1089 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1079 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1090 } | 1080 } |
| 1091 | 1081 |
| 1092 // Test that if we receive a CONTINUATION with stream ID zero, we signal an | 1082 // Test that if we receive a CONTINUATION with stream ID zero, we signal an |
| 1093 // SPDY_INVALID_STREAM_ID. | 1083 // SPDY_INVALID_STREAM_ID. |
| 1094 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { | 1084 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { |
| 1095 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1085 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1096 SpdyFramer framer; | 1086 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1097 framer.set_visitor(&visitor); | 1087 framer.set_visitor(&visitor); |
| 1098 | 1088 |
| 1099 SpdyContinuationIR continuation(0); | 1089 SpdyContinuationIR continuation(0); |
| 1100 auto some_nonsense_encoding = | 1090 auto some_nonsense_encoding = |
| 1101 base::MakeUnique<string>("some nonsense encoding"); | 1091 base::MakeUnique<string>("some nonsense encoding"); |
| 1102 continuation.take_encoding(std::move(some_nonsense_encoding)); | 1092 continuation.take_encoding(std::move(some_nonsense_encoding)); |
| 1103 continuation.set_end_headers(true); | 1093 continuation.set_end_headers(true); |
| 1104 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 1094 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 1105 | 1095 |
| 1106 // We shouldn't have to read the whole frame before we signal an error. | 1096 // We shouldn't have to read the whole frame before we signal an error. |
| 1107 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1097 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1108 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1098 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1109 EXPECT_TRUE(framer.HasError()); | 1099 EXPECT_TRUE(framer.HasError()); |
| 1110 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1100 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1111 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1101 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1112 } | 1102 } |
| 1113 | 1103 |
| 1114 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 1104 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an |
| 1115 // SPDY_INVALID_STREAM_ID. | 1105 // SPDY_INVALID_STREAM_ID. |
| 1116 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 1106 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
| 1117 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1107 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1118 SpdyFramer framer; | 1108 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1119 framer.set_visitor(&visitor); | 1109 framer.set_visitor(&visitor); |
| 1120 | 1110 |
| 1121 SpdyPushPromiseIR push_promise(0, 4); | 1111 SpdyPushPromiseIR push_promise(0, 4); |
| 1122 push_promise.SetHeader("alpha", "beta"); | 1112 push_promise.SetHeader("alpha", "beta"); |
| 1123 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1113 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 1124 | 1114 |
| 1125 // We shouldn't have to read the whole frame before we signal an error. | 1115 // We shouldn't have to read the whole frame before we signal an error. |
| 1126 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1116 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1127 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1117 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1128 EXPECT_TRUE(framer.HasError()); | 1118 EXPECT_TRUE(framer.HasError()); |
| 1129 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1119 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1130 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1120 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1131 } | 1121 } |
| 1132 | 1122 |
| 1133 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 1123 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
| 1134 // signal SPDY_INVALID_STREAM_ID. | 1124 // signal SPDY_INVALID_STREAM_ID. |
| 1135 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 1125 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
| 1136 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1126 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1137 SpdyFramer framer; | 1127 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1138 framer.set_visitor(&visitor); | 1128 framer.set_visitor(&visitor); |
| 1139 | 1129 |
| 1140 SpdyPushPromiseIR push_promise(3, 0); | 1130 SpdyPushPromiseIR push_promise(3, 0); |
| 1141 push_promise.SetHeader("alpha", "beta"); | 1131 push_promise.SetHeader("alpha", "beta"); |
| 1142 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1132 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 1143 | 1133 |
| 1144 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1134 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1145 framer.ProcessInput(frame.data(), frame.size()); | 1135 framer.ProcessInput(frame.data(), frame.size()); |
| 1146 EXPECT_TRUE(framer.HasError()); | 1136 EXPECT_TRUE(framer.HasError()); |
| 1147 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 1137 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 1148 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1138 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1149 } | 1139 } |
| 1150 | 1140 |
| 1151 TEST_P(SpdyFramerTest, DuplicateHeader) { | 1141 TEST_P(SpdyFramerTest, DuplicateHeader) { |
| 1152 SpdyFramer framer; | 1142 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 1153 // Frame builder with plentiful buffer size. | 1143 // Frame builder with plentiful buffer size. |
| 1154 SpdyFrameBuilder frame(1024); | 1144 SpdyFrameBuilder frame(1024); |
| 1155 frame.BeginNewFrame(framer, HEADERS, 0, 3); | 1145 frame.BeginNewFrame(framer, HEADERS, 0, 3); |
| 1156 | 1146 |
| 1157 frame.WriteUInt32(2); // Number of headers. | 1147 frame.WriteUInt32(2); // Number of headers. |
| 1158 frame.WriteStringPiece32("name"); | 1148 frame.WriteStringPiece32("name"); |
| 1159 frame.WriteStringPiece32("value1"); | 1149 frame.WriteStringPiece32("value1"); |
| 1160 frame.WriteStringPiece32("name"); | 1150 frame.WriteStringPiece32("name"); |
| 1161 frame.WriteStringPiece32("value2"); | 1151 frame.WriteStringPiece32("value2"); |
| 1162 // write the length | 1152 // write the length |
| 1163 frame.RewriteLength(framer); | 1153 frame.RewriteLength(framer); |
| 1164 | 1154 |
| 1165 SpdyHeaderBlock new_headers; | 1155 SpdyHeaderBlock new_headers; |
| 1166 framer.set_enable_compression(false); | |
| 1167 SpdySerializedFrame control_frame(frame.take()); | 1156 SpdySerializedFrame control_frame(frame.take()); |
| 1168 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); | 1157 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); |
| 1169 // This should fail because duplicate headers are verboten by the spec. | 1158 // This should fail because duplicate headers are verboten by the spec. |
| 1170 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 1159 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 1171 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 1160 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 1172 } | 1161 } |
| 1173 | 1162 |
| 1174 TEST_P(SpdyFramerTest, MultiValueHeader) { | 1163 TEST_P(SpdyFramerTest, MultiValueHeader) { |
| 1175 SpdyFramer framer; | 1164 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 1176 // Frame builder with plentiful buffer size. | 1165 // Frame builder with plentiful buffer size. |
| 1177 SpdyFrameBuilder frame(1024); | 1166 SpdyFrameBuilder frame(1024); |
| 1178 frame.BeginNewFrame(framer, HEADERS, | 1167 frame.BeginNewFrame(framer, HEADERS, |
| 1179 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); | 1168 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); |
| 1180 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. | 1169 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. |
| 1181 frame.WriteUInt8(255); // Priority weight. | 1170 frame.WriteUInt8(255); // Priority weight. |
| 1182 | 1171 |
| 1183 string value("value1\0value2", 13); | 1172 string value("value1\0value2", 13); |
| 1184 // TODO(jgraettinger): If this pattern appears again, move to test class. | 1173 // TODO(jgraettinger): If this pattern appears again, move to test class. |
| 1185 SpdyHeaderBlock header_set; | 1174 SpdyHeaderBlock header_set; |
| 1186 header_set["name"] = value; | 1175 header_set["name"] = value; |
| 1187 string buffer; | 1176 string buffer; |
| 1188 HpackEncoder encoder(ObtainHpackHuffmanTable()); | 1177 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
| 1189 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); | 1178 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); |
| 1190 frame.WriteBytes(&buffer[0], buffer.size()); | 1179 frame.WriteBytes(&buffer[0], buffer.size()); |
| 1191 // write the length | 1180 // write the length |
| 1192 frame.RewriteLength(framer); | 1181 frame.RewriteLength(framer); |
| 1193 | 1182 |
| 1194 framer.set_enable_compression(false); | |
| 1195 SpdySerializedFrame control_frame(frame.take()); | 1183 SpdySerializedFrame control_frame(frame.take()); |
| 1196 | 1184 |
| 1197 TestSpdyVisitor visitor; | 1185 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 1198 visitor.use_compression_ = false; | |
| 1199 visitor.SimulateInFramer( | 1186 visitor.SimulateInFramer( |
| 1200 reinterpret_cast<unsigned char*>(control_frame.data()), | 1187 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 1201 control_frame.size()); | 1188 control_frame.size()); |
| 1202 | 1189 |
| 1203 EXPECT_THAT(visitor.headers_, | 1190 EXPECT_THAT(visitor.headers_, |
| 1204 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); | 1191 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); |
| 1205 } | 1192 } |
| 1206 | 1193 |
| 1207 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { | 1194 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { |
| 1208 // See crbug.com/172383 | 1195 // See crbug.com/172383 |
| 1209 SpdyHeadersIR headers(1); | 1196 SpdyHeadersIR headers(1); |
| 1210 headers.SetHeader("server", "SpdyServer 1.0"); | 1197 headers.SetHeader("server", "SpdyServer 1.0"); |
| 1211 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 1198 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| 1212 headers.SetHeader("status", "200"); | 1199 headers.SetHeader("status", "200"); |
| 1213 headers.SetHeader("version", "HTTP/1.1"); | 1200 headers.SetHeader("version", "HTTP/1.1"); |
| 1214 headers.SetHeader("content-type", "text/html"); | 1201 headers.SetHeader("content-type", "text/html"); |
| 1215 headers.SetHeader("content-length", "12"); | 1202 headers.SetHeader("content-length", "12"); |
| 1216 headers.SetHeader("x-empty-header", ""); | 1203 headers.SetHeader("x-empty-header", ""); |
| 1217 | 1204 |
| 1218 SpdyFramer framer; | 1205 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1219 framer.set_enable_compression(true); | |
| 1220 SpdySerializedFrame frame1( | 1206 SpdySerializedFrame frame1( |
| 1221 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1207 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 1222 } | 1208 } |
| 1223 | 1209 |
| 1224 TEST_P(SpdyFramerTest, Basic) { | 1210 TEST_P(SpdyFramerTest, Basic) { |
| 1225 // Send HEADERS frames with PRIORITY and END_HEADERS set. | 1211 // Send HEADERS frames with PRIORITY and END_HEADERS set. |
| 1226 // frame-format off | 1212 // frame-format off |
| 1227 const unsigned char kH2Input[] = { | 1213 const unsigned char kH2Input[] = { |
| 1228 0x00, 0x00, 0x05, // Length: 5 | 1214 0x00, 0x00, 0x05, // Length: 5 |
| 1229 0x01, // Type: HEADERS | 1215 0x01, // Type: HEADERS |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 1264 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 1279 | 1265 |
| 1280 0x00, 0x00, 0x04, // Length: 4 | 1266 0x00, 0x00, 0x04, // Length: 4 |
| 1281 0x03, // Type: RST_STREAM | 1267 0x03, // Type: RST_STREAM |
| 1282 0x00, // Flags: none | 1268 0x00, // Flags: none |
| 1283 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 1269 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 1284 0x00, 0x00, 0x00, 0x08, // Error: CANCEL | 1270 0x00, 0x00, 0x00, 0x08, // Error: CANCEL |
| 1285 }; | 1271 }; |
| 1286 // frame-format on | 1272 // frame-format on |
| 1287 | 1273 |
| 1288 TestSpdyVisitor visitor; | 1274 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 1289 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | 1275 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
| 1290 | 1276 |
| 1291 EXPECT_EQ(24, visitor.data_bytes_); | 1277 EXPECT_EQ(24, visitor.data_bytes_); |
| 1292 EXPECT_EQ(0, visitor.error_count_); | 1278 EXPECT_EQ(0, visitor.error_count_); |
| 1293 EXPECT_EQ(2, visitor.fin_frame_count_); | 1279 EXPECT_EQ(2, visitor.fin_frame_count_); |
| 1294 | 1280 |
| 1295 EXPECT_EQ(3, visitor.headers_frame_count_); | 1281 EXPECT_EQ(3, visitor.headers_frame_count_); |
| 1296 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); | 1282 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); |
| 1297 | 1283 |
| 1298 EXPECT_EQ(0, visitor.fin_flag_count_); | 1284 EXPECT_EQ(0, visitor.fin_flag_count_); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1328 0xde, 0xad, 0xbe, 0xef, // | 1314 0xde, 0xad, 0xbe, 0xef, // |
| 1329 | 1315 |
| 1330 0x00, 0x00, 0x04, // Length: 4 | 1316 0x00, 0x00, 0x04, // Length: 4 |
| 1331 0x00, // Type: DATA | 1317 0x00, // Type: DATA |
| 1332 0x01, // Flags: END_STREAM | 1318 0x01, // Flags: END_STREAM |
| 1333 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1319 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1334 0xde, 0xad, 0xbe, 0xef, // Payload | 1320 0xde, 0xad, 0xbe, 0xef, // Payload |
| 1335 }; | 1321 }; |
| 1336 // frame-format on | 1322 // frame-format on |
| 1337 | 1323 |
| 1338 TestSpdyVisitor visitor; | 1324 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 1339 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | 1325 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
| 1340 | 1326 |
| 1341 EXPECT_EQ(0, visitor.error_count_); | 1327 EXPECT_EQ(0, visitor.error_count_); |
| 1342 EXPECT_EQ(2, visitor.headers_frame_count_); | 1328 EXPECT_EQ(2, visitor.headers_frame_count_); |
| 1343 EXPECT_EQ(16, visitor.data_bytes_); | 1329 EXPECT_EQ(16, visitor.data_bytes_); |
| 1344 EXPECT_EQ(0, visitor.fin_frame_count_); | 1330 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1345 EXPECT_EQ(0, visitor.fin_flag_count_); | 1331 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1346 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1332 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1347 EXPECT_EQ(2, visitor.data_frame_count_); | 1333 EXPECT_EQ(2, visitor.data_frame_count_); |
| 1348 } | 1334 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1359 0x82, // Weight: 131 | 1345 0x82, // Weight: 131 |
| 1360 | 1346 |
| 1361 0x00, 0x00, 0x01, // Length: 1 | 1347 0x00, 0x00, 0x01, // Length: 1 |
| 1362 0x01, // Type: HEADERS | 1348 0x01, // Type: HEADERS |
| 1363 0x05, // Flags: END_STREAM|END_HEADERS | 1349 0x05, // Flags: END_STREAM|END_HEADERS |
| 1364 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1350 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1365 0x8c, // :status: 200 | 1351 0x8c, // :status: 200 |
| 1366 }; | 1352 }; |
| 1367 // frame-format on | 1353 // frame-format on |
| 1368 | 1354 |
| 1369 TestSpdyVisitor visitor; | 1355 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 1370 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | 1356 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
| 1371 | 1357 |
| 1372 EXPECT_EQ(0, visitor.error_count_); | 1358 EXPECT_EQ(0, visitor.error_count_); |
| 1373 EXPECT_EQ(2, visitor.headers_frame_count_); | 1359 EXPECT_EQ(2, visitor.headers_frame_count_); |
| 1374 EXPECT_EQ(0, visitor.data_bytes_); | 1360 EXPECT_EQ(0, visitor.data_bytes_); |
| 1375 EXPECT_EQ(0, visitor.fin_frame_count_); | 1361 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1376 EXPECT_EQ(1, visitor.fin_flag_count_); | 1362 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 1377 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1363 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1378 EXPECT_EQ(0, visitor.data_frame_count_); | 1364 EXPECT_EQ(0, visitor.data_frame_count_); |
| 1379 } | 1365 } |
| 1380 | 1366 |
| 1381 // Verify we can decompress the stream even if handed over to the | 1367 // Verify we can decompress the stream even if handed over to the |
| 1382 // framer 1 byte at a time. | 1368 // framer 1 byte at a time. |
| 1383 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { | 1369 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { |
| 1384 SpdyFramer framer; | 1370 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1385 | |
| 1386 framer.set_enable_compression(true); | |
| 1387 | 1371 |
| 1388 const char kHeader1[] = "header1"; | 1372 const char kHeader1[] = "header1"; |
| 1389 const char kHeader2[] = "header2"; | 1373 const char kHeader2[] = "header2"; |
| 1390 const char kValue1[] = "value1"; | 1374 const char kValue1[] = "value1"; |
| 1391 const char kValue2[] = "value2"; | 1375 const char kValue2[] = "value2"; |
| 1392 | 1376 |
| 1393 SpdyHeadersIR headers(1); | 1377 SpdyHeadersIR headers(1); |
| 1394 headers.SetHeader(kHeader1, kValue1); | 1378 headers.SetHeader(kHeader1, kValue1); |
| 1395 headers.SetHeader(kHeader2, kValue2); | 1379 headers.SetHeader(kHeader2, kValue2); |
| 1396 SpdySerializedFrame headers_frame( | 1380 SpdySerializedFrame headers_frame( |
| 1397 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1381 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 1398 | 1382 |
| 1399 const char bytes[] = "this is a test test test test test!"; | 1383 const char bytes[] = "this is a test test test test test!"; |
| 1400 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); | 1384 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); |
| 1401 data_ir.set_fin(true); | 1385 data_ir.set_fin(true); |
| 1402 SpdySerializedFrame send_frame(framer.SerializeData(data_ir)); | 1386 SpdySerializedFrame send_frame(framer.SerializeData(data_ir)); |
| 1403 | 1387 |
| 1404 // Run the inputs through the framer. | 1388 // Run the inputs through the framer. |
| 1405 TestSpdyVisitor visitor; | 1389 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 1406 visitor.use_compression_ = true; | |
| 1407 const unsigned char* data; | 1390 const unsigned char* data; |
| 1408 data = reinterpret_cast<const unsigned char*>(headers_frame.data()); | 1391 data = reinterpret_cast<const unsigned char*>(headers_frame.data()); |
| 1409 for (size_t idx = 0; idx < headers_frame.size(); ++idx) { | 1392 for (size_t idx = 0; idx < headers_frame.size(); ++idx) { |
| 1410 visitor.SimulateInFramer(data + idx, 1); | 1393 visitor.SimulateInFramer(data + idx, 1); |
| 1411 ASSERT_EQ(0, visitor.error_count_); | 1394 ASSERT_EQ(0, visitor.error_count_); |
| 1412 } | 1395 } |
| 1413 data = reinterpret_cast<const unsigned char*>(send_frame.data()); | 1396 data = reinterpret_cast<const unsigned char*>(send_frame.data()); |
| 1414 for (size_t idx = 0; idx < send_frame.size(); ++idx) { | 1397 for (size_t idx = 0; idx < send_frame.size(); ++idx) { |
| 1415 visitor.SimulateInFramer(data + idx, 1); | 1398 visitor.SimulateInFramer(data + idx, 1); |
| 1416 ASSERT_EQ(0, visitor.error_count_); | 1399 ASSERT_EQ(0, visitor.error_count_); |
| 1417 } | 1400 } |
| 1418 | 1401 |
| 1419 EXPECT_EQ(0, visitor.error_count_); | 1402 EXPECT_EQ(0, visitor.error_count_); |
| 1420 EXPECT_EQ(1, visitor.headers_frame_count_); | 1403 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 1421 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); | 1404 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); |
| 1422 EXPECT_EQ(0, visitor.fin_frame_count_); | 1405 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1423 EXPECT_EQ(0, visitor.fin_flag_count_); | 1406 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1424 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1407 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1425 EXPECT_EQ(1, visitor.data_frame_count_); | 1408 EXPECT_EQ(1, visitor.data_frame_count_); |
| 1426 } | 1409 } |
| 1427 | 1410 |
| 1428 TEST_P(SpdyFramerTest, WindowUpdateFrame) { | 1411 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
| 1429 SpdyFramer framer; | 1412 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1430 SpdySerializedFrame frame( | 1413 SpdySerializedFrame frame( |
| 1431 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); | 1414 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); |
| 1432 | 1415 |
| 1433 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; | 1416 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; |
| 1434 const unsigned char kH2FrameData[] = { | 1417 const unsigned char kH2FrameData[] = { |
| 1435 0x00, 0x00, 0x04, // Length: 4 | 1418 0x00, 0x00, 0x04, // Length: 4 |
| 1436 0x08, // Type: WINDOW_UPDATE | 1419 0x08, // Type: WINDOW_UPDATE |
| 1437 0x00, // Flags: none | 1420 0x00, // Flags: none |
| 1438 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1421 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1439 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 | 1422 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 |
| 1440 }; | 1423 }; |
| 1441 | 1424 |
| 1442 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1425 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1443 } | 1426 } |
| 1444 | 1427 |
| 1445 TEST_P(SpdyFramerTest, CreateDataFrame) { | 1428 TEST_P(SpdyFramerTest, CreateDataFrame) { |
| 1446 SpdyFramer framer; | 1429 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1447 | 1430 |
| 1448 { | 1431 { |
| 1449 const char kDescription[] = "'hello' data frame, no FIN"; | 1432 const char kDescription[] = "'hello' data frame, no FIN"; |
| 1450 // frame-format off | 1433 // frame-format off |
| 1451 const unsigned char kH2FrameData[] = { | 1434 const unsigned char kH2FrameData[] = { |
| 1452 0x00, 0x00, 0x05, // Length: 5 | 1435 0x00, 0x00, 0x05, // Length: 5 |
| 1453 0x00, // Type: DATA | 1436 0x00, // Type: DATA |
| 1454 0x00, // Flags: none | 1437 0x00, // Flags: none |
| 1455 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1438 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1456 'h', 'e', 'l', 'l', // Payload | 1439 'h', 'e', 'l', 'l', // Payload |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 0x6f, // | 1621 0x6f, // |
| 1639 }; | 1622 }; |
| 1640 SpdyDataIR data_ir(0x7fffffff, "hello"); | 1623 SpdyDataIR data_ir(0x7fffffff, "hello"); |
| 1641 data_ir.set_fin(true); | 1624 data_ir.set_fin(true); |
| 1642 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1625 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 1643 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1626 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1644 } | 1627 } |
| 1645 } | 1628 } |
| 1646 | 1629 |
| 1647 TEST_P(SpdyFramerTest, CreateRstStream) { | 1630 TEST_P(SpdyFramerTest, CreateRstStream) { |
| 1648 SpdyFramer framer; | 1631 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1649 | 1632 |
| 1650 { | 1633 { |
| 1651 const char kDescription[] = "RST_STREAM frame"; | 1634 const char kDescription[] = "RST_STREAM frame"; |
| 1652 const unsigned char kH2FrameData[] = { | 1635 const unsigned char kH2FrameData[] = { |
| 1653 0x00, 0x00, 0x04, // Length: 4 | 1636 0x00, 0x00, 0x04, // Length: 4 |
| 1654 0x03, // Type: RST_STREAM | 1637 0x03, // Type: RST_STREAM |
| 1655 0x00, // Flags: none | 1638 0x00, // Flags: none |
| 1656 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1639 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1657 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR | 1640 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR |
| 1658 }; | 1641 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1684 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1667 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
| 1685 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1668 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
| 1686 }; | 1669 }; |
| 1687 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); | 1670 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); |
| 1688 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1671 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 1689 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1672 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1690 } | 1673 } |
| 1691 } | 1674 } |
| 1692 | 1675 |
| 1693 TEST_P(SpdyFramerTest, CreateSettings) { | 1676 TEST_P(SpdyFramerTest, CreateSettings) { |
| 1694 SpdyFramer framer; | 1677 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1695 | 1678 |
| 1696 { | 1679 { |
| 1697 const char kDescription[] = "Network byte order SETTINGS frame"; | 1680 const char kDescription[] = "Network byte order SETTINGS frame"; |
| 1698 | 1681 |
| 1699 const unsigned char kH2FrameData[] = { | 1682 const unsigned char kH2FrameData[] = { |
| 1700 0x00, 0x00, 0x06, // Length: 6 | 1683 0x00, 0x00, 0x06, // Length: 6 |
| 1701 0x04, // Type: SETTINGS | 1684 0x04, // Type: SETTINGS |
| 1702 0x00, // Flags: none | 1685 0x00, // Flags: none |
| 1703 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1686 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1704 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1687 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 0x00, // Flags: none | 1751 0x00, // Flags: none |
| 1769 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1752 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1770 }; | 1753 }; |
| 1771 SpdySettingsIR settings_ir; | 1754 SpdySettingsIR settings_ir; |
| 1772 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1755 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 1773 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1756 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1774 } | 1757 } |
| 1775 } | 1758 } |
| 1776 | 1759 |
| 1777 TEST_P(SpdyFramerTest, CreatePingFrame) { | 1760 TEST_P(SpdyFramerTest, CreatePingFrame) { |
| 1778 SpdyFramer framer; | 1761 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1779 | 1762 |
| 1780 { | 1763 { |
| 1781 const char kDescription[] = "PING frame"; | 1764 const char kDescription[] = "PING frame"; |
| 1782 const unsigned char kH2FrameData[] = { | 1765 const unsigned char kH2FrameData[] = { |
| 1783 0x00, 0x00, 0x08, // Length: 8 | 1766 0x00, 0x00, 0x08, // Length: 8 |
| 1784 0x06, // Type: PING | 1767 0x06, // Type: PING |
| 1785 0x00, // Flags: none | 1768 0x00, // Flags: none |
| 1786 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1769 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1787 0x12, 0x34, 0x56, 0x78, // Opaque | 1770 0x12, 0x34, 0x56, 0x78, // Opaque |
| 1788 0x9a, 0xbc, 0xde, 0xff, // Data | 1771 0x9a, 0xbc, 0xde, 0xff, // Data |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1805 | 1788 |
| 1806 // Tests SpdyPingIR when the ping is an ack. | 1789 // Tests SpdyPingIR when the ping is an ack. |
| 1807 ping_ir.set_is_ack(true); | 1790 ping_ir.set_is_ack(true); |
| 1808 frame = framer.SerializePing(ping_ir); | 1791 frame = framer.SerializePing(ping_ir); |
| 1809 CompareFrame(kDescription, frame, kH2FrameDataWithAck, | 1792 CompareFrame(kDescription, frame, kH2FrameDataWithAck, |
| 1810 arraysize(kH2FrameDataWithAck)); | 1793 arraysize(kH2FrameDataWithAck)); |
| 1811 } | 1794 } |
| 1812 } | 1795 } |
| 1813 | 1796 |
| 1814 TEST_P(SpdyFramerTest, CreateGoAway) { | 1797 TEST_P(SpdyFramerTest, CreateGoAway) { |
| 1815 SpdyFramer framer; | 1798 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1816 | 1799 |
| 1817 { | 1800 { |
| 1818 const char kDescription[] = "GOAWAY frame"; | 1801 const char kDescription[] = "GOAWAY frame"; |
| 1819 const unsigned char kH2FrameData[] = { | 1802 const unsigned char kH2FrameData[] = { |
| 1820 0x00, 0x00, 0x0a, // Length: 10 | 1803 0x00, 0x00, 0x0a, // Length: 10 |
| 1821 0x07, // Type: GOAWAY | 1804 0x07, // Type: GOAWAY |
| 1822 0x00, // Flags: none | 1805 0x00, // Flags: none |
| 1823 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1806 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1824 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1807 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 1825 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1808 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1841 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1824 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
| 1842 0x47, 0x41, // Description | 1825 0x47, 0x41, // Description |
| 1843 }; | 1826 }; |
| 1844 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); | 1827 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); |
| 1845 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 1828 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
| 1846 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1829 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1847 } | 1830 } |
| 1848 } | 1831 } |
| 1849 | 1832 |
| 1850 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { | 1833 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { |
| 1851 SpdyFramer framer; | 1834 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 1852 framer.set_enable_compression(false); | |
| 1853 | 1835 |
| 1854 { | 1836 { |
| 1855 const char kDescription[] = "HEADERS frame, no FIN"; | 1837 const char kDescription[] = "HEADERS frame, no FIN"; |
| 1856 // frame-format off | 1838 // frame-format off |
| 1857 const unsigned char kH2FrameData[] = { | 1839 const unsigned char kH2FrameData[] = { |
| 1858 0x00, 0x00, 0x12, // Length: 18 | 1840 0x00, 0x00, 0x12, // Length: 18 |
| 1859 0x01, // Type: HEADERS | 1841 0x01, // Type: HEADERS |
| 1860 0x04, // Flags: END_HEADERS | 1842 0x04, // Flags: END_HEADERS |
| 1861 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1843 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1862 | 1844 |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 SpdySerializedFrame frame( | 2075 SpdySerializedFrame frame( |
| 2094 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2076 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2095 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 2077 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 2096 } | 2078 } |
| 2097 } | 2079 } |
| 2098 | 2080 |
| 2099 // TODO(phajdan.jr): Clean up after we no longer need | 2081 // TODO(phajdan.jr): Clean up after we no longer need |
| 2100 // to workaround http://crbug.com/139744. | 2082 // to workaround http://crbug.com/139744. |
| 2101 #if !defined(USE_SYSTEM_ZLIB) | 2083 #if !defined(USE_SYSTEM_ZLIB) |
| 2102 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { | 2084 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
| 2103 SpdyFramer framer; | 2085 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2104 framer.set_enable_compression(true); | |
| 2105 | 2086 |
| 2106 { | 2087 { |
| 2107 SpdyHeadersIR headers_ir(1); | 2088 SpdyHeadersIR headers_ir(1); |
| 2108 headers_ir.SetHeader("bar", "foo"); | 2089 headers_ir.SetHeader("bar", "foo"); |
| 2109 headers_ir.SetHeader("foo", "bar"); | 2090 headers_ir.SetHeader("foo", "bar"); |
| 2110 SpdySerializedFrame frame( | 2091 SpdySerializedFrame frame( |
| 2111 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2092 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2112 // Deflate compression doesn't apply to HPACK. | 2093 // Deflate compression doesn't apply to HPACK. |
| 2113 } | 2094 } |
| 2114 } | 2095 } |
| 2115 #endif // !defined(USE_SYSTEM_ZLIB) | 2096 #endif // !defined(USE_SYSTEM_ZLIB) |
| 2116 | 2097 |
| 2117 TEST_P(SpdyFramerTest, CreateWindowUpdate) { | 2098 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
| 2118 SpdyFramer framer; | 2099 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2119 | 2100 |
| 2120 { | 2101 { |
| 2121 const char kDescription[] = "WINDOW_UPDATE frame"; | 2102 const char kDescription[] = "WINDOW_UPDATE frame"; |
| 2122 const unsigned char kH2FrameData[] = { | 2103 const unsigned char kH2FrameData[] = { |
| 2123 0x00, 0x00, 0x04, // Length: 4 | 2104 0x00, 0x00, 0x04, // Length: 4 |
| 2124 0x08, // Type: WINDOW_UPDATE | 2105 0x08, // Type: WINDOW_UPDATE |
| 2125 0x00, // Flags: none | 2106 0x00, // Flags: none |
| 2126 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2107 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 2127 0x00, 0x00, 0x00, 0x01, // Increment: 1 | 2108 0x00, 0x00, 0x00, 0x01, // Increment: 1 |
| 2128 }; | 2109 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2154 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2135 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 2155 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff | 2136 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff |
| 2156 }; | 2137 }; |
| 2157 SpdySerializedFrame frame( | 2138 SpdySerializedFrame frame( |
| 2158 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2139 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
| 2159 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 2140 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 2160 } | 2141 } |
| 2161 } | 2142 } |
| 2162 | 2143 |
| 2163 TEST_P(SpdyFramerTest, SerializeBlocked) { | 2144 TEST_P(SpdyFramerTest, SerializeBlocked) { |
| 2164 SpdyFramer framer; | 2145 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2165 | 2146 |
| 2166 const char kDescription[] = "BLOCKED frame"; | 2147 const char kDescription[] = "BLOCKED frame"; |
| 2167 const unsigned char kType = | 2148 const unsigned char kType = |
| 2168 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(BLOCKED)); | 2149 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(BLOCKED)); |
| 2169 const unsigned char kFrameData[] = { | 2150 const unsigned char kFrameData[] = { |
| 2170 0x00, 0x00, 0x00, // Length: 0 | 2151 0x00, 0x00, 0x00, // Length: 0 |
| 2171 kType, // Type: BLOCKED | 2152 kType, // Type: BLOCKED |
| 2172 0x00, // Flags: none | 2153 0x00, // Flags: none |
| 2173 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2154 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2174 }; | 2155 }; |
| 2175 SpdyBlockedIR blocked_ir(0); | 2156 SpdyBlockedIR blocked_ir(0); |
| 2176 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 2157 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
| 2177 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2158 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2178 } | 2159 } |
| 2179 | 2160 |
| 2180 TEST_P(SpdyFramerTest, CreateBlocked) { | 2161 TEST_P(SpdyFramerTest, CreateBlocked) { |
| 2181 SpdyFramer framer; | 2162 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2182 | 2163 |
| 2183 const char kDescription[] = "BLOCKED frame"; | 2164 const char kDescription[] = "BLOCKED frame"; |
| 2184 const SpdyStreamId kStreamId = 3; | 2165 const SpdyStreamId kStreamId = 3; |
| 2185 | 2166 |
| 2186 SpdySerializedFrame frame_serialized( | 2167 SpdySerializedFrame frame_serialized( |
| 2187 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2168 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
| 2188 SpdyBlockedIR blocked_ir(kStreamId); | 2169 SpdyBlockedIR blocked_ir(kStreamId); |
| 2189 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); | 2170 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); |
| 2190 | 2171 |
| 2191 CompareFrames(kDescription, frame_serialized, frame_created); | 2172 CompareFrames(kDescription, frame_serialized, frame_created); |
| 2192 } | 2173 } |
| 2193 | 2174 |
| 2194 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2175 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
| 2195 { | 2176 { |
| 2196 // Test framing PUSH_PROMISE without padding. | 2177 // Test framing PUSH_PROMISE without padding. |
| 2197 SpdyFramer framer; | 2178 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2198 framer.set_enable_compression(false); | |
| 2199 const char kDescription[] = "PUSH_PROMISE frame without padding"; | 2179 const char kDescription[] = "PUSH_PROMISE frame without padding"; |
| 2200 | 2180 |
| 2201 // frame-format off | 2181 // frame-format off |
| 2202 const unsigned char kFrameData[] = { | 2182 const unsigned char kFrameData[] = { |
| 2203 0x00, 0x00, 0x16, // Length: 22 | 2183 0x00, 0x00, 0x16, // Length: 22 |
| 2204 0x05, // Type: PUSH_PROMISE | 2184 0x05, // Type: PUSH_PROMISE |
| 2205 0x04, // Flags: END_HEADERS | 2185 0x04, // Flags: END_HEADERS |
| 2206 0x00, 0x00, 0x00, 0x29, // Stream: 41 | 2186 0x00, 0x00, 0x00, 0x29, // Stream: 41 |
| 2207 0x00, 0x00, 0x00, 0x3a, // Promise: 58 | 2187 0x00, 0x00, 0x00, 0x3a, // Promise: 58 |
| 2208 | 2188 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2222 | 2202 |
| 2223 SpdyPushPromiseIR push_promise(41, 58); | 2203 SpdyPushPromiseIR push_promise(41, 58); |
| 2224 push_promise.SetHeader("bar", "foo"); | 2204 push_promise.SetHeader("bar", "foo"); |
| 2225 push_promise.SetHeader("foo", "bar"); | 2205 push_promise.SetHeader("foo", "bar"); |
| 2226 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2206 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2227 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2207 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2228 } | 2208 } |
| 2229 | 2209 |
| 2230 { | 2210 { |
| 2231 // Test framing PUSH_PROMISE with one byte of padding. | 2211 // Test framing PUSH_PROMISE with one byte of padding. |
| 2232 SpdyFramer framer; | 2212 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2233 framer.set_enable_compression(false); | |
| 2234 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding"; | 2213 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding"; |
| 2235 | 2214 |
| 2236 // frame-format off | 2215 // frame-format off |
| 2237 const unsigned char kFrameData[] = { | 2216 const unsigned char kFrameData[] = { |
| 2238 0x00, 0x00, 0x17, // Length: 23 | 2217 0x00, 0x00, 0x17, // Length: 23 |
| 2239 0x05, // Type: PUSH_PROMISE | 2218 0x05, // Type: PUSH_PROMISE |
| 2240 0x0c, // Flags: END_HEADERS|PADDED | 2219 0x0c, // Flags: END_HEADERS|PADDED |
| 2241 0x00, 0x00, 0x00, 0x29, // Stream: 41 | 2220 0x00, 0x00, 0x00, 0x29, // Stream: 41 |
| 2242 0x00, // PadLen: 0 trailing bytes | 2221 0x00, // PadLen: 0 trailing bytes |
| 2243 0x00, 0x00, 0x00, 0x3a, // Promise: 58 | 2222 0x00, 0x00, 0x00, 0x3a, // Promise: 58 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2259 SpdyPushPromiseIR push_promise(41, 58); | 2238 SpdyPushPromiseIR push_promise(41, 58); |
| 2260 push_promise.set_padding_len(1); | 2239 push_promise.set_padding_len(1); |
| 2261 push_promise.SetHeader("bar", "foo"); | 2240 push_promise.SetHeader("bar", "foo"); |
| 2262 push_promise.SetHeader("foo", "bar"); | 2241 push_promise.SetHeader("foo", "bar"); |
| 2263 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2242 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2264 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2243 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2265 } | 2244 } |
| 2266 | 2245 |
| 2267 { | 2246 { |
| 2268 // Test framing PUSH_PROMISE with 177 bytes of padding. | 2247 // Test framing PUSH_PROMISE with 177 bytes of padding. |
| 2269 SpdyFramer framer; | 2248 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2270 framer.set_enable_compression(false); | |
| 2271 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding"; | 2249 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding"; |
| 2272 | 2250 |
| 2273 // frame-format off | 2251 // frame-format off |
| 2274 // clang-format off | 2252 // clang-format off |
| 2275 const unsigned char kFrameData[] = { | 2253 const unsigned char kFrameData[] = { |
| 2276 0x00, 0x00, 0xc7, // Length: 199 | 2254 0x00, 0x00, 0xc7, // Length: 199 |
| 2277 0x05, // Type: PUSH_PROMISE | 2255 0x05, // Type: PUSH_PROMISE |
| 2278 0x0c, // Flags: END_HEADERS|PADDED | 2256 0x0c, // Flags: END_HEADERS|PADDED |
| 2279 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2257 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| 2280 0xb0, // PadLen: 176 trailing bytes | 2258 0xb0, // PadLen: 176 trailing bytes |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2317 push_promise.set_padding_len(177); | 2295 push_promise.set_padding_len(177); |
| 2318 push_promise.SetHeader("bar", "foo"); | 2296 push_promise.SetHeader("bar", "foo"); |
| 2319 push_promise.SetHeader("foo", "bar"); | 2297 push_promise.SetHeader("foo", "bar"); |
| 2320 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2298 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2321 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2299 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2322 } | 2300 } |
| 2323 } | 2301 } |
| 2324 | 2302 |
| 2325 // Regression test for https://crbug.com/464748. | 2303 // Regression test for https://crbug.com/464748. |
| 2326 TEST_P(SpdyFramerTest, GetNumberRequiredContinuationFrames) { | 2304 TEST_P(SpdyFramerTest, GetNumberRequiredContinuationFrames) { |
| 2327 SpdyFramer framer; | 2305 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2328 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2306 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2329 &framer, 16383 + 16374)); | 2307 &framer, 16383 + 16374)); |
| 2330 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2308 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2331 &framer, 16383 + 16374 + 1)); | 2309 &framer, 16383 + 16374 + 1)); |
| 2332 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2310 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2333 &framer, 16383 + 2 * 16374)); | 2311 &framer, 16383 + 2 * 16374)); |
| 2334 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2312 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2335 &framer, 16383 + 2 * 16374 + 1)); | 2313 &framer, 16383 + 2 * 16374 + 1)); |
| 2336 } | 2314 } |
| 2337 | 2315 |
| 2338 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { | 2316 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
| 2339 SpdyFramer framer; | 2317 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2340 framer.set_enable_compression(false); | |
| 2341 const char kDescription[] = "CONTINUATION frame"; | 2318 const char kDescription[] = "CONTINUATION frame"; |
| 2342 | 2319 |
| 2343 // frame-format off | 2320 // frame-format off |
| 2344 const unsigned char kFrameData[] = { | 2321 const unsigned char kFrameData[] = { |
| 2345 0x00, 0x00, 0x12, // Length: 18 | 2322 0x00, 0x00, 0x12, // Length: 18 |
| 2346 0x09, // Type: CONTINUATION | 2323 0x09, // Type: CONTINUATION |
| 2347 0x04, // Flags: END_HEADERS | 2324 0x04, // Flags: END_HEADERS |
| 2348 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2325 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| 2349 | 2326 |
| 2350 0x00, // Unindexed Entry | 2327 0x00, // Unindexed Entry |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2373 continuation.set_end_headers(true); | 2350 continuation.set_end_headers(true); |
| 2374 | 2351 |
| 2375 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 2352 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 2376 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2353 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2377 } | 2354 } |
| 2378 | 2355 |
| 2379 // Test that if we send an unexpected CONTINUATION | 2356 // Test that if we send an unexpected CONTINUATION |
| 2380 // we signal an error (but don't crash). | 2357 // we signal an error (but don't crash). |
| 2381 TEST_P(SpdyFramerTest, SendUnexpectedContinuation) { | 2358 TEST_P(SpdyFramerTest, SendUnexpectedContinuation) { |
| 2382 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2359 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 2383 SpdyFramer framer; | 2360 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2384 framer.set_visitor(&visitor); | 2361 framer.set_visitor(&visitor); |
| 2385 | 2362 |
| 2386 // frame-format off | 2363 // frame-format off |
| 2387 char kH2FrameData[] = { | 2364 char kH2FrameData[] = { |
| 2388 0x00, 0x00, 0x12, // Length: 18 | 2365 0x00, 0x00, 0x12, // Length: 18 |
| 2389 0x09, // Type: CONTINUATION | 2366 0x09, // Type: CONTINUATION |
| 2390 0x04, // Flags: END_HEADERS | 2367 0x04, // Flags: END_HEADERS |
| 2391 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2368 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| 2392 | 2369 |
| 2393 0x00, // Unindexed Entry | 2370 0x00, // Unindexed Entry |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2412 EXPECT_TRUE(framer.HasError()); | 2389 EXPECT_TRUE(framer.HasError()); |
| 2413 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) | 2390 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) |
| 2414 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2391 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 2415 } | 2392 } |
| 2416 | 2393 |
| 2417 TEST_P(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { | 2394 TEST_P(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { |
| 2418 { | 2395 { |
| 2419 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of | 2396 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of |
| 2420 // padding, cannot hold all the data payload, which is overflowed to the | 2397 // padding, cannot hold all the data payload, which is overflowed to the |
| 2421 // consecutive CONTINUATION frame. | 2398 // consecutive CONTINUATION frame. |
| 2422 SpdyFramer framer; | 2399 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2423 framer.set_enable_compression(false); | |
| 2424 const char kDescription[] = | 2400 const char kDescription[] = |
| 2425 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; | 2401 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; |
| 2426 | 2402 |
| 2427 // frame-format off | 2403 // frame-format off |
| 2428 const unsigned char kPartialPushPromiseFrameData[] = { | 2404 const unsigned char kPartialPushPromiseFrameData[] = { |
| 2429 0x00, 0x3f, 0xf6, // Length: 16374 | 2405 0x00, 0x3f, 0xf6, // Length: 16374 |
| 2430 0x05, // Type: PUSH_PROMISE | 2406 0x05, // Type: PUSH_PROMISE |
| 2431 0x08, // Flags: PADDED | 2407 0x08, // Flags: PADDED |
| 2432 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2408 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| 2433 0x00, // PadLen: 0 trailing bytes | 2409 0x00, // PadLen: 0 trailing bytes |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 | 2485 |
| 2510 // Compare the CONTINUATION frame against the template. | 2486 // Compare the CONTINUATION frame against the template. |
| 2511 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); | 2487 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); |
| 2512 CompareCharArraysWithHexError( | 2488 CompareCharArraysWithHexError( |
| 2513 kDescription, frame_data, arraysize(kContinuationFrameData), | 2489 kDescription, frame_data, arraysize(kContinuationFrameData), |
| 2514 kContinuationFrameData, arraysize(kContinuationFrameData)); | 2490 kContinuationFrameData, arraysize(kContinuationFrameData)); |
| 2515 } | 2491 } |
| 2516 } | 2492 } |
| 2517 | 2493 |
| 2518 TEST_P(SpdyFramerTest, CreateAltSvc) { | 2494 TEST_P(SpdyFramerTest, CreateAltSvc) { |
| 2519 SpdyFramer framer; | 2495 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2520 | 2496 |
| 2521 const char kDescription[] = "ALTSVC frame"; | 2497 const char kDescription[] = "ALTSVC frame"; |
| 2522 const char kType = | 2498 const char kType = |
| 2523 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(ALTSVC)); | 2499 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(ALTSVC)); |
| 2524 const unsigned char kFrameData[] = { | 2500 const unsigned char kFrameData[] = { |
| 2525 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', | 2501 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', |
| 2526 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', | 2502 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', |
| 2527 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', | 2503 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', |
| 2528 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', | 2504 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', |
| 2529 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', | 2505 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', |
| 2530 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', | 2506 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', |
| 2531 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; | 2507 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; |
| 2532 SpdyAltSvcIR altsvc_ir(3); | 2508 SpdyAltSvcIR altsvc_ir(3); |
| 2533 altsvc_ir.set_origin("origin"); | 2509 altsvc_ir.set_origin("origin"); |
| 2534 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2510 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2535 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 2511 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 2536 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2512 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2537 "p\"=i:d", "h_\\o\"st", 123, 42, | 2513 "p\"=i:d", "h_\\o\"st", 123, 42, |
| 2538 SpdyAltSvcWireFormat::VersionVector{24})); | 2514 SpdyAltSvcWireFormat::VersionVector{24})); |
| 2539 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 2515 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 2540 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2516 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2541 } | 2517 } |
| 2542 | 2518 |
| 2543 TEST_P(SpdyFramerTest, CreatePriority) { | 2519 TEST_P(SpdyFramerTest, CreatePriority) { |
| 2544 SpdyFramer framer; | 2520 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2545 | 2521 |
| 2546 const char kDescription[] = "PRIORITY frame"; | 2522 const char kDescription[] = "PRIORITY frame"; |
| 2547 const unsigned char kFrameData[] = { | 2523 const unsigned char kFrameData[] = { |
| 2548 0x00, 0x00, 0x05, // Length: 5 | 2524 0x00, 0x00, 0x05, // Length: 5 |
| 2549 0x02, // Type: PRIORITY | 2525 0x02, // Type: PRIORITY |
| 2550 0x00, // Flags: none | 2526 0x00, // Flags: none |
| 2551 0x00, 0x00, 0x00, 0x02, // Stream: 2 | 2527 0x00, 0x00, 0x00, 0x02, // Stream: 2 |
| 2552 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) | 2528 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) |
| 2553 0x10, // Weight: 17 | 2529 0x10, // Weight: 17 |
| 2554 }; | 2530 }; |
| 2555 SpdyPriorityIR priority_ir(2, 1, 17, true); | 2531 SpdyPriorityIR priority_ir(2, 1, 17, true); |
| 2556 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 2532 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
| 2557 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2533 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2558 SpdyPriorityIR priority2(2); | 2534 SpdyPriorityIR priority2(2); |
| 2559 priority2.set_parent_stream_id(1); | 2535 priority2.set_parent_stream_id(1); |
| 2560 priority2.set_weight(17); | 2536 priority2.set_weight(17); |
| 2561 priority2.set_exclusive(true); | 2537 priority2.set_exclusive(true); |
| 2562 frame = framer.SerializeFrame(priority2); | 2538 frame = framer.SerializeFrame(priority2); |
| 2563 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2539 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2564 } | 2540 } |
| 2565 | 2541 |
| 2566 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { | 2542 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { |
| 2567 SpdyFramer framer; | 2543 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2568 SpdyHeadersIR headers_ir(1); | 2544 SpdyHeadersIR headers_ir(1); |
| 2569 headers_ir.SetHeader("alpha", "beta"); | 2545 headers_ir.SetHeader("alpha", "beta"); |
| 2570 headers_ir.SetHeader("gamma", "delta"); | 2546 headers_ir.SetHeader("gamma", "delta"); |
| 2571 SpdySerializedFrame control_frame( | 2547 SpdySerializedFrame control_frame( |
| 2572 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2548 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2573 TestSpdyVisitor visitor; | 2549 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 2574 visitor.use_compression_ = true; | |
| 2575 visitor.SimulateInFramer( | 2550 visitor.SimulateInFramer( |
| 2576 reinterpret_cast<unsigned char*>(control_frame.data()), | 2551 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2577 control_frame.size()); | 2552 control_frame.size()); |
| 2578 EXPECT_EQ(1, visitor.headers_frame_count_); | 2553 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2579 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2554 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
| 2580 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2555 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2581 EXPECT_EQ(0, visitor.end_of_stream_count_); | 2556 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 2582 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2557 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
| 2583 } | 2558 } |
| 2584 | 2559 |
| 2585 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { | 2560 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { |
| 2586 SpdyFramer framer; | 2561 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2587 SpdyHeadersIR headers_ir(1); | 2562 SpdyHeadersIR headers_ir(1); |
| 2588 headers_ir.set_fin(true); | 2563 headers_ir.set_fin(true); |
| 2589 headers_ir.SetHeader("alpha", "beta"); | 2564 headers_ir.SetHeader("alpha", "beta"); |
| 2590 headers_ir.SetHeader("gamma", "delta"); | 2565 headers_ir.SetHeader("gamma", "delta"); |
| 2591 SpdySerializedFrame control_frame( | 2566 SpdySerializedFrame control_frame( |
| 2592 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2567 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2593 TestSpdyVisitor visitor; | 2568 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 2594 visitor.use_compression_ = true; | |
| 2595 visitor.SimulateInFramer( | 2569 visitor.SimulateInFramer( |
| 2596 reinterpret_cast<unsigned char*>(control_frame.data()), | 2570 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2597 control_frame.size()); | 2571 control_frame.size()); |
| 2598 EXPECT_EQ(1, visitor.headers_frame_count_); | 2572 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2599 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2573 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
| 2600 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2574 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2601 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2575 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 2602 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2576 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
| 2603 } | 2577 } |
| 2604 | 2578 |
| 2605 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { | 2579 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
| 2606 SpdyFramer framer; | 2580 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2607 framer.set_enable_compression(false); | |
| 2608 SpdyHeadersIR headers(1); | 2581 SpdyHeadersIR headers(1); |
| 2609 headers.set_padding_len(256); | 2582 headers.set_padding_len(256); |
| 2610 | 2583 |
| 2611 // Exact payload length will change with HPACK, but this should be long | 2584 // Exact payload length will change with HPACK, but this should be long |
| 2612 // enough to cause an overflow. | 2585 // enough to cause an overflow. |
| 2613 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2586 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2614 string big_value(kBigValueSize, 'x'); | 2587 string big_value(kBigValueSize, 'x'); |
| 2615 headers.SetHeader("aa", big_value); | 2588 headers.SetHeader("aa", big_value); |
| 2616 SpdySerializedFrame control_frame( | 2589 SpdySerializedFrame control_frame( |
| 2617 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2590 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 2618 EXPECT_GT(control_frame.size(), | 2591 EXPECT_GT(control_frame.size(), |
| 2619 TestSpdyVisitor::sent_control_frame_max_size()); | 2592 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2620 | 2593 |
| 2621 TestSpdyVisitor visitor; | 2594 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2622 visitor.SimulateInFramer( | 2595 visitor.SimulateInFramer( |
| 2623 reinterpret_cast<unsigned char*>(control_frame.data()), | 2596 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2624 control_frame.size()); | 2597 control_frame.size()); |
| 2625 EXPECT_TRUE(visitor.header_buffer_valid_); | 2598 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2626 EXPECT_EQ(0, visitor.error_count_); | 2599 EXPECT_EQ(0, visitor.error_count_); |
| 2627 EXPECT_EQ(1, visitor.headers_frame_count_); | 2600 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2628 EXPECT_EQ(1, visitor.continuation_count_); | 2601 EXPECT_EQ(1, visitor.continuation_count_); |
| 2629 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2602 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2630 } | 2603 } |
| 2631 | 2604 |
| 2632 TEST_P(SpdyFramerTest, MultipleContinuationFramesWithIterator) { | 2605 TEST_P(SpdyFramerTest, MultipleContinuationFramesWithIterator) { |
| 2633 SpdyFramer framer; | 2606 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2634 framer.set_enable_compression(false); | |
| 2635 auto headers = base::MakeUnique<SpdyHeadersIR>(1); | 2607 auto headers = base::MakeUnique<SpdyHeadersIR>(1); |
| 2636 headers->set_padding_len(256); | 2608 headers->set_padding_len(256); |
| 2637 | 2609 |
| 2638 // Exact payload length will change with HPACK, but this should be long | 2610 // Exact payload length will change with HPACK, but this should be long |
| 2639 // enough to cause an overflow. | 2611 // enough to cause an overflow. |
| 2640 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2612 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2641 string big_valuex(kBigValueSize, 'x'); | 2613 string big_valuex(kBigValueSize, 'x'); |
| 2642 headers->SetHeader("aa", big_valuex); | 2614 headers->SetHeader("aa", big_valuex); |
| 2643 string big_valuez(kBigValueSize, 'z'); | 2615 string big_valuez(kBigValueSize, 'z'); |
| 2644 headers->SetHeader("bb", big_valuez); | 2616 headers->SetHeader("bb", big_valuez); |
| 2645 | 2617 |
| 2646 SpdyFramer::SpdyHeaderFrameIterator frame_it(&framer, std::move(headers)); | 2618 SpdyFramer::SpdyHeaderFrameIterator frame_it(&framer, std::move(headers)); |
| 2647 | 2619 |
| 2648 EXPECT_TRUE(frame_it.HasNextFrame()); | 2620 EXPECT_TRUE(frame_it.HasNextFrame()); |
| 2649 SpdySerializedFrame headers_frame(frame_it.NextFrame()); | 2621 SpdySerializedFrame headers_frame(frame_it.NextFrame()); |
| 2650 EXPECT_EQ(headers_frame.size(), | 2622 EXPECT_EQ(headers_frame.size(), |
| 2651 TestSpdyVisitor::sent_control_frame_max_size()); | 2623 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2652 | 2624 |
| 2653 TestSpdyVisitor visitor; | 2625 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2654 visitor.SimulateInFramer( | 2626 visitor.SimulateInFramer( |
| 2655 reinterpret_cast<unsigned char*>(headers_frame.data()), | 2627 reinterpret_cast<unsigned char*>(headers_frame.data()), |
| 2656 headers_frame.size()); | 2628 headers_frame.size()); |
| 2657 EXPECT_TRUE(visitor.header_buffer_valid_); | 2629 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2658 EXPECT_EQ(0, visitor.error_count_); | 2630 EXPECT_EQ(0, visitor.error_count_); |
| 2659 EXPECT_EQ(1, visitor.headers_frame_count_); | 2631 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2660 EXPECT_EQ(0, visitor.continuation_count_); | 2632 EXPECT_EQ(0, visitor.continuation_count_); |
| 2661 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2633 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2662 | 2634 |
| 2663 EXPECT_TRUE(frame_it.HasNextFrame()); | 2635 EXPECT_TRUE(frame_it.HasNextFrame()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2685 EXPECT_TRUE(visitor.header_buffer_valid_); | 2657 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2686 EXPECT_EQ(0, visitor.error_count_); | 2658 EXPECT_EQ(0, visitor.error_count_); |
| 2687 EXPECT_EQ(1, visitor.headers_frame_count_); | 2659 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2688 EXPECT_EQ(2, visitor.continuation_count_); | 2660 EXPECT_EQ(2, visitor.continuation_count_); |
| 2689 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2661 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2690 | 2662 |
| 2691 EXPECT_FALSE(frame_it.HasNextFrame()); | 2663 EXPECT_FALSE(frame_it.HasNextFrame()); |
| 2692 } | 2664 } |
| 2693 | 2665 |
| 2694 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 2666 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
| 2695 SpdyFramer framer; | 2667 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 2696 framer.set_enable_compression(false); | |
| 2697 SpdyPushPromiseIR push_promise(1, 2); | 2668 SpdyPushPromiseIR push_promise(1, 2); |
| 2698 push_promise.set_padding_len(256); | 2669 push_promise.set_padding_len(256); |
| 2699 | 2670 |
| 2700 // Exact payload length will change with HPACK, but this should be long | 2671 // Exact payload length will change with HPACK, but this should be long |
| 2701 // enough to cause an overflow. | 2672 // enough to cause an overflow. |
| 2702 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2673 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2703 string big_value(kBigValueSize, 'x'); | 2674 string big_value(kBigValueSize, 'x'); |
| 2704 push_promise.SetHeader("aa", big_value); | 2675 push_promise.SetHeader("aa", big_value); |
| 2705 SpdySerializedFrame control_frame(framer.SerializePushPromise(push_promise)); | 2676 SpdySerializedFrame control_frame(framer.SerializePushPromise(push_promise)); |
| 2706 EXPECT_GT(control_frame.size(), | 2677 EXPECT_GT(control_frame.size(), |
| 2707 TestSpdyVisitor::sent_control_frame_max_size()); | 2678 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2708 | 2679 |
| 2709 TestSpdyVisitor visitor; | 2680 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2710 visitor.SimulateInFramer( | 2681 visitor.SimulateInFramer( |
| 2711 reinterpret_cast<unsigned char*>(control_frame.data()), | 2682 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2712 control_frame.size()); | 2683 control_frame.size()); |
| 2713 EXPECT_TRUE(visitor.header_buffer_valid_); | 2684 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2714 EXPECT_EQ(0, visitor.error_count_); | 2685 EXPECT_EQ(0, visitor.error_count_); |
| 2715 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 2686 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
| 2716 EXPECT_EQ(1, visitor.continuation_count_); | 2687 EXPECT_EQ(1, visitor.continuation_count_); |
| 2717 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2688 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2718 } | 2689 } |
| 2719 | 2690 |
| 2720 // Check that the framer stops delivering header data chunks once the visitor | 2691 // Check that the framer stops delivering header data chunks once the visitor |
| 2721 // declares it doesn't want any more. This is important to guard against | 2692 // declares it doesn't want any more. This is important to guard against |
| 2722 // "zip bomb" types of attacks. | 2693 // "zip bomb" types of attacks. |
| 2723 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { | 2694 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { |
| 2724 const size_t kHeaderBufferChunks = 4; | 2695 const size_t kHeaderBufferChunks = 4; |
| 2725 const size_t kHeaderBufferSize = | 2696 const size_t kHeaderBufferSize = |
| 2726 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 2697 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
| 2727 const size_t kBigValueSize = kHeaderBufferSize * 2; | 2698 const size_t kBigValueSize = kHeaderBufferSize * 2; |
| 2728 string big_value(kBigValueSize, 'x'); | 2699 string big_value(kBigValueSize, 'x'); |
| 2729 SpdyFramer framer; | 2700 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2730 SpdyHeadersIR headers(1); | 2701 SpdyHeadersIR headers(1); |
| 2731 headers.set_fin(true); | 2702 headers.set_fin(true); |
| 2732 headers.SetHeader("aa", big_value); | 2703 headers.SetHeader("aa", big_value); |
| 2733 SpdySerializedFrame control_frame( | 2704 SpdySerializedFrame control_frame( |
| 2734 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2705 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 2735 TestSpdyVisitor visitor; | 2706 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 2736 visitor.set_header_buffer_size(kHeaderBufferSize); | 2707 visitor.set_header_buffer_size(kHeaderBufferSize); |
| 2737 visitor.use_compression_ = true; | |
| 2738 visitor.SimulateInFramer( | 2708 visitor.SimulateInFramer( |
| 2739 reinterpret_cast<unsigned char*>(control_frame.data()), | 2709 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2740 control_frame.size()); | 2710 control_frame.size()); |
| 2741 // It's up to the visitor to ignore extraneous header data; the framer | 2711 // It's up to the visitor to ignore extraneous header data; the framer |
| 2742 // won't throw an error. | 2712 // won't throw an error. |
| 2743 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); | 2713 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); |
| 2744 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2714 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 2745 } | 2715 } |
| 2746 | 2716 |
| 2747 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { | 2717 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 2748 SpdyFramer framer; | 2718 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2749 // Create a GoAway frame that has a few extra bytes at the end. | 2719 // Create a GoAway frame that has a few extra bytes at the end. |
| 2750 // We create enough overhead to overflow the framer's control frame buffer. | 2720 // We create enough overhead to overflow the framer's control frame buffer. |
| 2751 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); | 2721 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); |
| 2752 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; | 2722 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; |
| 2753 | 2723 |
| 2754 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may | 2724 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may |
| 2755 // carry opaque data. Verify that minimal length is tested. | 2725 // carry opaque data. Verify that minimal length is tested. |
| 2756 ASSERT_GT(framer.GetGoAwayMinimumSize(), SpdyConstants::kFrameHeaderSize); | 2726 ASSERT_GT(framer.GetGoAwayMinimumSize(), SpdyConstants::kFrameHeaderSize); |
| 2757 const size_t less_than_min_length = | 2727 const size_t less_than_min_length = |
| 2758 framer.GetGoAwayMinimumSize() - SpdyConstants::kFrameHeaderSize - 1; | 2728 framer.GetGoAwayMinimumSize() - SpdyConstants::kFrameHeaderSize - 1; |
| 2759 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); | 2729 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); |
| 2760 const unsigned char kH2Len = static_cast<unsigned char>(less_than_min_length); | 2730 const unsigned char kH2Len = static_cast<unsigned char>(less_than_min_length); |
| 2761 const unsigned char kH2FrameData[] = { | 2731 const unsigned char kH2FrameData[] = { |
| 2762 0x00, 0x00, kH2Len, // Length: min length - 1 | 2732 0x00, 0x00, kH2Len, // Length: min length - 1 |
| 2763 0x07, // Type: GOAWAY | 2733 0x07, // Type: GOAWAY |
| 2764 0x00, // Flags: none | 2734 0x00, // Flags: none |
| 2765 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2735 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2766 0x00, 0x00, 0x00, 0x00, // Last: 0 | 2736 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 2767 0x00, 0x00, 0x00, // Truncated Status Field | 2737 0x00, 0x00, 0x00, // Truncated Status Field |
| 2768 }; | 2738 }; |
| 2769 const size_t pad_length = | 2739 const size_t pad_length = |
| 2770 length + SpdyConstants::kFrameHeaderSize - sizeof(kH2FrameData); | 2740 length + SpdyConstants::kFrameHeaderSize - sizeof(kH2FrameData); |
| 2771 string pad(pad_length, 'A'); | 2741 string pad(pad_length, 'A'); |
| 2772 TestSpdyVisitor visitor; | 2742 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2773 | 2743 |
| 2774 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2744 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2775 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), | 2745 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 2776 pad.length()); | 2746 pad.length()); |
| 2777 | 2747 |
| 2778 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2748 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
| 2779 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 2749 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 2780 visitor.framer_.error_code()) | 2750 visitor.framer_.error_code()) |
| 2781 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2751 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2782 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. | 2752 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. |
| 2783 } | 2753 } |
| 2784 | 2754 |
| 2785 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 2755 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 2786 SpdyFramer framer; | 2756 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2787 SpdySettingsIR settings_ir; | 2757 SpdySettingsIR settings_ir; |
| 2788 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2758 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2789 SetFrameLength(&control_frame, 0); | 2759 SetFrameLength(&control_frame, 0); |
| 2790 TestSpdyVisitor visitor; | 2760 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2791 visitor.use_compression_ = false; | |
| 2792 visitor.SimulateInFramer( | 2761 visitor.SimulateInFramer( |
| 2793 reinterpret_cast<unsigned char*>(control_frame.data()), | 2762 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2794 framer.GetFrameHeaderSize()); | 2763 framer.GetFrameHeaderSize()); |
| 2795 // Zero-len settings frames are permitted as of HTTP/2. | 2764 // Zero-len settings frames are permitted as of HTTP/2. |
| 2796 EXPECT_EQ(0, visitor.error_count_); | 2765 EXPECT_EQ(0, visitor.error_count_); |
| 2797 } | 2766 } |
| 2798 | 2767 |
| 2799 // Tests handling of SETTINGS frames with invalid length. | 2768 // Tests handling of SETTINGS frames with invalid length. |
| 2800 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 2769 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| 2801 SpdyFramer framer; | 2770 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2802 SpdySettingsIR settings_ir; | 2771 SpdySettingsIR settings_ir; |
| 2803 | 2772 |
| 2804 // Add settings to more than fill the frame so that we don't get a buffer | 2773 // Add settings to more than fill the frame so that we don't get a buffer |
| 2805 // overflow when calling SimulateInFramer() below. These settings must be | 2774 // overflow when calling SimulateInFramer() below. These settings must be |
| 2806 // distinct parameters because SpdySettingsIR has a map for settings, and will | 2775 // distinct parameters because SpdySettingsIR has a map for settings, and will |
| 2807 // collapse multiple copies of the same parameter. | 2776 // collapse multiple copies of the same parameter. |
| 2808 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, | 2777 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, |
| 2809 0x00000002); | 2778 0x00000002); |
| 2810 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, false, false, | 2779 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, false, false, |
| 2811 0x00000002); | 2780 0x00000002); |
| 2812 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2781 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2813 const size_t kNewLength = 8; | 2782 const size_t kNewLength = 8; |
| 2814 SetFrameLength(&control_frame, kNewLength); | 2783 SetFrameLength(&control_frame, kNewLength); |
| 2815 TestSpdyVisitor visitor; | 2784 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2816 visitor.use_compression_ = false; | |
| 2817 visitor.SimulateInFramer( | 2785 visitor.SimulateInFramer( |
| 2818 reinterpret_cast<unsigned char*>(control_frame.data()), | 2786 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2819 framer.GetFrameHeaderSize() + kNewLength); | 2787 framer.GetFrameHeaderSize() + kNewLength); |
| 2820 // Should generate an error, since its not possible to have a | 2788 // Should generate an error, since its not possible to have a |
| 2821 // settings frame of length kNewLength. | 2789 // settings frame of length kNewLength. |
| 2822 EXPECT_EQ(1, visitor.error_count_); | 2790 EXPECT_EQ(1, visitor.error_count_); |
| 2823 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 2791 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 2824 visitor.framer_.error_code()) | 2792 visitor.framer_.error_code()) |
| 2825 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2793 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2826 } | 2794 } |
| 2827 | 2795 |
| 2828 // Tests handling of SETTINGS frames larger than the frame buffer size. | 2796 // Tests handling of SETTINGS frames larger than the frame buffer size. |
| 2829 TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { | 2797 TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { |
| 2830 SpdyFramer framer; | 2798 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2831 SpdySettingsIR settings_ir; | 2799 SpdySettingsIR settings_ir; |
| 2832 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, | 2800 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, |
| 2833 false, // persist | 2801 false, // persist |
| 2834 false, // persisted | 2802 false, // persisted |
| 2835 5); | 2803 5); |
| 2836 settings_ir.AddSetting(SETTINGS_ENABLE_PUSH, | 2804 settings_ir.AddSetting(SETTINGS_ENABLE_PUSH, |
| 2837 false, // persist | 2805 false, // persist |
| 2838 false, // persisted | 2806 false, // persisted |
| 2839 6); | 2807 6); |
| 2840 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, | 2808 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, |
| 2841 false, // persist | 2809 false, // persist |
| 2842 false, // persisted | 2810 false, // persisted |
| 2843 7); | 2811 7); |
| 2844 | 2812 |
| 2845 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2813 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2846 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); | 2814 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); |
| 2847 TestSpdyVisitor visitor; | 2815 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2848 visitor.use_compression_ = false; | |
| 2849 | 2816 |
| 2850 // Read all at once. | 2817 // Read all at once. |
| 2851 visitor.SimulateInFramer( | 2818 visitor.SimulateInFramer( |
| 2852 reinterpret_cast<unsigned char*>(control_frame.data()), | 2819 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2853 control_frame.size()); | 2820 control_frame.size()); |
| 2854 EXPECT_EQ(0, visitor.error_count_); | 2821 EXPECT_EQ(0, visitor.error_count_); |
| 2855 EXPECT_EQ(3, visitor.setting_count_); | 2822 EXPECT_EQ(3, visitor.setting_count_); |
| 2856 EXPECT_EQ(1, visitor.settings_ack_sent_); | 2823 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 2857 | 2824 |
| 2858 // Read data in small chunks. | 2825 // Read data in small chunks. |
| 2859 size_t framed_data = 0; | 2826 size_t framed_data = 0; |
| 2860 size_t unframed_data = control_frame.size(); | 2827 size_t unframed_data = control_frame.size(); |
| 2861 size_t kReadChunkSize = 5; // Read five bytes at a time. | 2828 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 2862 while (unframed_data > 0) { | 2829 while (unframed_data > 0) { |
| 2863 size_t to_read = std::min(kReadChunkSize, unframed_data); | 2830 size_t to_read = std::min(kReadChunkSize, unframed_data); |
| 2864 visitor.SimulateInFramer( | 2831 visitor.SimulateInFramer( |
| 2865 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), | 2832 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), |
| 2866 to_read); | 2833 to_read); |
| 2867 unframed_data -= to_read; | 2834 unframed_data -= to_read; |
| 2868 framed_data += to_read; | 2835 framed_data += to_read; |
| 2869 } | 2836 } |
| 2870 EXPECT_EQ(0, visitor.error_count_); | 2837 EXPECT_EQ(0, visitor.error_count_); |
| 2871 EXPECT_EQ(3 * 2, visitor.setting_count_); | 2838 EXPECT_EQ(3 * 2, visitor.setting_count_); |
| 2872 EXPECT_EQ(2, visitor.settings_ack_sent_); | 2839 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| 2873 } | 2840 } |
| 2874 | 2841 |
| 2875 // Tests handling of SETTINGS frame with duplicate entries. | 2842 // Tests handling of SETTINGS frame with duplicate entries. |
| 2876 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { | 2843 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 2877 SpdyFramer framer; | 2844 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2878 | 2845 |
| 2879 const unsigned char kH2FrameData[] = { | 2846 const unsigned char kH2FrameData[] = { |
| 2880 0x00, 0x00, 0x12, // Length: 18 | 2847 0x00, 0x00, 0x12, // Length: 18 |
| 2881 0x04, // Type: SETTINGS | 2848 0x04, // Type: SETTINGS |
| 2882 0x00, // Flags: none | 2849 0x00, // Flags: none |
| 2883 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2850 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2884 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2851 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2885 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2852 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2886 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2853 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2887 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2854 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2888 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2855 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 2889 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2856 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2890 }; | 2857 }; |
| 2891 | 2858 |
| 2892 TestSpdyVisitor visitor; | 2859 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2893 visitor.use_compression_ = false; | |
| 2894 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2860 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2895 | 2861 |
| 2896 // In HTTP/2, duplicate settings are allowed; | 2862 // In HTTP/2, duplicate settings are allowed; |
| 2897 // each setting replaces the previous value for that setting. | 2863 // each setting replaces the previous value for that setting. |
| 2898 EXPECT_EQ(3, visitor.setting_count_); | 2864 EXPECT_EQ(3, visitor.setting_count_); |
| 2899 EXPECT_EQ(0, visitor.error_count_); | 2865 EXPECT_EQ(0, visitor.error_count_); |
| 2900 EXPECT_EQ(1, visitor.settings_ack_sent_); | 2866 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 2901 } | 2867 } |
| 2902 | 2868 |
| 2903 // Tests handling of SETTINGS frame with a setting we don't recognize. | 2869 // Tests handling of SETTINGS frame with a setting we don't recognize. |
| 2904 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { | 2870 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { |
| 2905 SpdyFramer framer; | 2871 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2906 const unsigned char kH2FrameData[] = { | 2872 const unsigned char kH2FrameData[] = { |
| 2907 0x00, 0x00, 0x06, // Length: 6 | 2873 0x00, 0x00, 0x06, // Length: 6 |
| 2908 0x04, // Type: SETTINGS | 2874 0x04, // Type: SETTINGS |
| 2909 0x00, // Flags: none | 2875 0x00, // Flags: none |
| 2910 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2876 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2911 0x00, 0x10, // Param: 16 | 2877 0x00, 0x10, // Param: 16 |
| 2912 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2878 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2913 }; | 2879 }; |
| 2914 | 2880 |
| 2915 TestSpdyVisitor visitor; | 2881 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2916 visitor.use_compression_ = false; | |
| 2917 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2882 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2918 | 2883 |
| 2919 // In HTTP/2, we ignore unknown settings because of extensions. | 2884 // In HTTP/2, we ignore unknown settings because of extensions. |
| 2920 EXPECT_EQ(0, visitor.setting_count_); | 2885 EXPECT_EQ(0, visitor.setting_count_); |
| 2921 EXPECT_EQ(0, visitor.error_count_); | 2886 EXPECT_EQ(0, visitor.error_count_); |
| 2922 } | 2887 } |
| 2923 | 2888 |
| 2924 // Tests handling of SETTINGS frame with entries out of order. | 2889 // Tests handling of SETTINGS frame with entries out of order. |
| 2925 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 2890 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 2926 SpdyFramer framer; | 2891 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2927 const unsigned char kH2FrameData[] = { | 2892 const unsigned char kH2FrameData[] = { |
| 2928 0x00, 0x00, 0x12, // Length: 18 | 2893 0x00, 0x00, 0x12, // Length: 18 |
| 2929 0x04, // Type: SETTINGS | 2894 0x04, // Type: SETTINGS |
| 2930 0x00, // Flags: none | 2895 0x00, // Flags: none |
| 2931 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2896 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2932 0x00, 0x02, // Param: ENABLE_PUSH | 2897 0x00, 0x02, // Param: ENABLE_PUSH |
| 2933 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2898 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2934 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2899 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2935 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2900 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2936 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2901 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 2937 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2902 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2938 }; | 2903 }; |
| 2939 | 2904 |
| 2940 TestSpdyVisitor visitor; | 2905 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2941 visitor.use_compression_ = false; | |
| 2942 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2906 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2943 | 2907 |
| 2944 // In HTTP/2, settings are allowed in any order. | 2908 // In HTTP/2, settings are allowed in any order. |
| 2945 EXPECT_EQ(3, visitor.setting_count_); | 2909 EXPECT_EQ(3, visitor.setting_count_); |
| 2946 EXPECT_EQ(0, visitor.error_count_); | 2910 EXPECT_EQ(0, visitor.error_count_); |
| 2947 } | 2911 } |
| 2948 | 2912 |
| 2949 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { | 2913 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 2950 SpdyFramer framer; | 2914 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2951 | 2915 |
| 2952 const unsigned char kFrameData[] = { | 2916 const unsigned char kFrameData[] = { |
| 2953 0x00, 0x00, 0x00, // Length: 0 | 2917 0x00, 0x00, 0x00, // Length: 0 |
| 2954 0x04, // Type: SETTINGS | 2918 0x04, // Type: SETTINGS |
| 2955 0x01, // Flags: ACK | 2919 0x01, // Flags: ACK |
| 2956 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2920 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2957 }; | 2921 }; |
| 2958 | 2922 |
| 2959 TestSpdyVisitor visitor; | 2923 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 2960 visitor.use_compression_ = false; | |
| 2961 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 2924 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 2962 | 2925 |
| 2963 EXPECT_EQ(0, visitor.error_count_); | 2926 EXPECT_EQ(0, visitor.error_count_); |
| 2964 EXPECT_EQ(0, visitor.setting_count_); | 2927 EXPECT_EQ(0, visitor.setting_count_); |
| 2965 EXPECT_EQ(1, visitor.settings_ack_received_); | 2928 EXPECT_EQ(1, visitor.settings_ack_received_); |
| 2966 } | 2929 } |
| 2967 | 2930 |
| 2968 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 2931 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
| 2969 const int kPaddingLen = 119; | 2932 const int kPaddingLen = 119; |
| 2970 const char data_payload[] = "hello"; | 2933 const char data_payload[] = "hello"; |
| 2971 | 2934 |
| 2972 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2935 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 2973 SpdyFramer framer; | 2936 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 2974 framer.set_visitor(&visitor); | 2937 framer.set_visitor(&visitor); |
| 2975 | 2938 |
| 2976 SpdyDataIR data_ir(1, data_payload); | 2939 SpdyDataIR data_ir(1, data_payload); |
| 2977 data_ir.set_padding_len(kPaddingLen); | 2940 data_ir.set_padding_len(kPaddingLen); |
| 2978 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 2941 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 2979 | 2942 |
| 2980 int bytes_consumed = 0; | 2943 int bytes_consumed = 0; |
| 2981 | 2944 |
| 2982 // Send the frame header. | 2945 // Send the frame header. |
| 2983 EXPECT_CALL(visitor, | 2946 EXPECT_CALL(visitor, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3017 bytes_consumed += 100; | 2980 bytes_consumed += 100; |
| 3018 | 2981 |
| 3019 // Send rest of the padding payload. | 2982 // Send rest of the padding payload. |
| 3020 EXPECT_CALL(visitor, OnStreamPadding(1, 18)); | 2983 EXPECT_CALL(visitor, OnStreamPadding(1, 18)); |
| 3021 CHECK_EQ(18u, framer.ProcessInput(frame.data() + bytes_consumed, 18)); | 2984 CHECK_EQ(18u, framer.ProcessInput(frame.data() + bytes_consumed, 18)); |
| 3022 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READY_FOR_FRAME); | 2985 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READY_FOR_FRAME); |
| 3023 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 2986 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 3024 } | 2987 } |
| 3025 | 2988 |
| 3026 TEST_P(SpdyFramerTest, ReadWindowUpdate) { | 2989 TEST_P(SpdyFramerTest, ReadWindowUpdate) { |
| 3027 SpdyFramer framer; | 2990 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3028 SpdySerializedFrame control_frame( | 2991 SpdySerializedFrame control_frame( |
| 3029 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 2992 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 3030 TestSpdyVisitor visitor; | 2993 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3031 visitor.SimulateInFramer( | 2994 visitor.SimulateInFramer( |
| 3032 reinterpret_cast<unsigned char*>(control_frame.data()), | 2995 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3033 control_frame.size()); | 2996 control_frame.size()); |
| 3034 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 2997 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 3035 EXPECT_EQ(2, visitor.last_window_update_delta_); | 2998 EXPECT_EQ(2, visitor.last_window_update_delta_); |
| 3036 } | 2999 } |
| 3037 | 3000 |
| 3038 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { | 3001 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
| 3039 SpdyFramer framer; | 3002 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3040 SpdyPushPromiseIR push_promise(42, 57); | 3003 SpdyPushPromiseIR push_promise(42, 57); |
| 3041 push_promise.SetHeader("foo", "bar"); | 3004 push_promise.SetHeader("foo", "bar"); |
| 3042 push_promise.SetHeader("bar", "foofoo"); | 3005 push_promise.SetHeader("bar", "foofoo"); |
| 3043 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 3006 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 3044 TestSpdyVisitor visitor; | 3007 TestSpdyVisitor visitor(SpdyFramer::ENABLE_COMPRESSION); |
| 3045 visitor.use_compression_ = true; | |
| 3046 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 3008 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 3047 frame.size()); | 3009 frame.size()); |
| 3048 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3010 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3049 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3011 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3050 EXPECT_EQ(push_promise.header_block(), visitor.headers_); | 3012 EXPECT_EQ(push_promise.header_block(), visitor.headers_); |
| 3051 } | 3013 } |
| 3052 | 3014 |
| 3053 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3015 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3054 // frame-format off | 3016 // frame-format off |
| 3055 const unsigned char kInput[] = { | 3017 const unsigned char kInput[] = { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 3085 'o', 'o', 'k', 'i', 'e', // Name (continued) | 3047 'o', 'o', 'k', 'i', 'e', // Name (continued) |
| 3086 0x00, // Value Len: 0 | 3048 0x00, // Value Len: 0 |
| 3087 0x00, // Unindexed Entry | 3049 0x00, // Unindexed Entry |
| 3088 0x04, // Name Len: 4 | 3050 0x04, // Name Len: 4 |
| 3089 'n', 'a', 'm', 'e', // Name | 3051 'n', 'a', 'm', 'e', // Name |
| 3090 0x05, // Value Len: 5 | 3052 0x05, // Value Len: 5 |
| 3091 'v', 'a', 'l', 'u', 'e', // Value | 3053 'v', 'a', 'l', 'u', 'e', // Value |
| 3092 }; | 3054 }; |
| 3093 // frame-format on | 3055 // frame-format on |
| 3094 | 3056 |
| 3095 SpdyFramer framer; | 3057 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3096 TestSpdyVisitor visitor; | |
| 3097 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3058 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3098 | 3059 |
| 3099 EXPECT_EQ(0, visitor.error_count_); | 3060 EXPECT_EQ(0, visitor.error_count_); |
| 3100 EXPECT_EQ(1, visitor.headers_frame_count_); | 3061 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3101 EXPECT_EQ(2, visitor.continuation_count_); | 3062 EXPECT_EQ(2, visitor.continuation_count_); |
| 3102 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3063 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3103 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3064 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 3104 | 3065 |
| 3105 EXPECT_THAT( | 3066 EXPECT_THAT( |
| 3106 visitor.headers_, | 3067 visitor.headers_, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3141 'o', 'o', 'k', 'i', 'e', // Name (continued) | 3102 'o', 'o', 'k', 'i', 'e', // Name (continued) |
| 3142 0x00, // Value Len: 0 | 3103 0x00, // Value Len: 0 |
| 3143 0x00, // Unindexed Entry | 3104 0x00, // Unindexed Entry |
| 3144 0x04, // Name Len: 4 | 3105 0x04, // Name Len: 4 |
| 3145 'n', 'a', 'm', 'e', // Name | 3106 'n', 'a', 'm', 'e', // Name |
| 3146 0x05, // Value Len: 5 | 3107 0x05, // Value Len: 5 |
| 3147 'v', 'a', 'l', 'u', 'e', // Value | 3108 'v', 'a', 'l', 'u', 'e', // Value |
| 3148 }; | 3109 }; |
| 3149 // frame-format on | 3110 // frame-format on |
| 3150 | 3111 |
| 3151 SpdyFramer framer; | 3112 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3152 TestSpdyVisitor visitor; | 3113 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3153 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3114 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3154 | 3115 |
| 3155 EXPECT_EQ(0, visitor.error_count_); | 3116 EXPECT_EQ(0, visitor.error_count_); |
| 3156 EXPECT_EQ(1, visitor.headers_frame_count_); | 3117 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3157 EXPECT_EQ(2, visitor.continuation_count_); | 3118 EXPECT_EQ(2, visitor.continuation_count_); |
| 3158 EXPECT_EQ(1, visitor.fin_flag_count_); | 3119 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3159 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3120 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3160 EXPECT_EQ(1, visitor.end_of_stream_count_); | 3121 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 3161 | 3122 |
| 3162 EXPECT_THAT( | 3123 EXPECT_THAT( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3189 0x00, 0x00, 0x12, 0x09, // CONTINUATION | 3150 0x00, 0x00, 0x12, 0x09, // CONTINUATION |
| 3190 0x04, 0x00, 0x00, 0x00, // END_HEADERS | 3151 0x04, 0x00, 0x00, 0x00, // END_HEADERS |
| 3191 0x01, 'o', 'o', 'k', // Stream 1 | 3152 0x01, 'o', 'o', 'k', // Stream 1 |
| 3192 'i', 'e', 0x00, 0x00, | 3153 'i', 'e', 0x00, 0x00, |
| 3193 0x04, 'n', 'a', 'm', | 3154 0x04, 'n', 'a', 'm', |
| 3194 'e', 0x05, 'v', 'a', | 3155 'e', 0x05, 'v', 'a', |
| 3195 'l', 'u', 'e', | 3156 'l', 'u', 'e', |
| 3196 }; | 3157 }; |
| 3197 // frame-format on | 3158 // frame-format on |
| 3198 | 3159 |
| 3199 SpdyFramer framer; | 3160 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3200 TestSpdyVisitor visitor; | 3161 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3201 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3162 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3202 | 3163 |
| 3203 EXPECT_EQ(0, visitor.error_count_); | 3164 EXPECT_EQ(0, visitor.error_count_); |
| 3204 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3165 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
| 3205 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3166 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
| 3206 EXPECT_EQ(2, visitor.continuation_count_); | 3167 EXPECT_EQ(2, visitor.continuation_count_); |
| 3207 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3168 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3208 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3169 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 3209 | 3170 |
| 3210 EXPECT_THAT( | 3171 EXPECT_THAT( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3230 0xa9, // Type: UnknownFrameType(169) | 3191 0xa9, // Type: UnknownFrameType(169) |
| 3231 0x00, // Flags: none | 3192 0x00, // Flags: none |
| 3232 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3193 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3233 0x00, 0x06, 0x63, 0x6f, // Payload | 3194 0x00, 0x06, 0x63, 0x6f, // Payload |
| 3234 0x6f, 0x6b, 0x69, 0x65, // | 3195 0x6f, 0x6b, 0x69, 0x65, // |
| 3235 0x08, 0x62, 0x61, 0x7a, // | 3196 0x08, 0x62, 0x61, 0x7a, // |
| 3236 0x3d, 0x62, 0x69, 0x6e, // | 3197 0x3d, 0x62, 0x69, 0x6e, // |
| 3237 0x67, 0x00, 0x06, 0x63, // | 3198 0x67, 0x00, 0x06, 0x63, // |
| 3238 }; | 3199 }; |
| 3239 | 3200 |
| 3240 SpdyFramer framer; | 3201 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3241 TestSpdyVisitor visitor; | 3202 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3242 // Assume the unknown frame is allowed | 3203 // Assume the unknown frame is allowed |
| 3243 visitor.on_unknown_frame_result_ = true; | 3204 visitor.on_unknown_frame_result_ = true; |
| 3244 framer.set_visitor(&visitor); | 3205 framer.set_visitor(&visitor); |
| 3245 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3206 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3246 | 3207 |
| 3247 EXPECT_EQ(1, visitor.error_count_); | 3208 EXPECT_EQ(1, visitor.error_count_); |
| 3248 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3209 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3249 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3210 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3250 EXPECT_EQ(1, visitor.headers_frame_count_); | 3211 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3251 EXPECT_EQ(0, visitor.continuation_count_); | 3212 EXPECT_EQ(0, visitor.continuation_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3267 0x09, // Type: CONTINUATION | 3228 0x09, // Type: CONTINUATION |
| 3268 0x00, // Flags: none | 3229 0x00, // Flags: none |
| 3269 0x00, 0x00, 0x00, 0x02, // Stream: 2 | 3230 0x00, 0x00, 0x00, 0x02, // Stream: 2 |
| 3270 0x00, 0x06, 0x63, 0x6f, // HPACK | 3231 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3271 0x6f, 0x6b, 0x69, 0x65, // | 3232 0x6f, 0x6b, 0x69, 0x65, // |
| 3272 0x08, 0x62, 0x61, 0x7a, // | 3233 0x08, 0x62, 0x61, 0x7a, // |
| 3273 0x3d, 0x62, 0x69, 0x6e, // | 3234 0x3d, 0x62, 0x69, 0x6e, // |
| 3274 0x67, 0x00, 0x06, 0x63, // | 3235 0x67, 0x00, 0x06, 0x63, // |
| 3275 }; | 3236 }; |
| 3276 | 3237 |
| 3277 SpdyFramer framer; | 3238 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3278 TestSpdyVisitor visitor; | 3239 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3279 framer.set_visitor(&visitor); | 3240 framer.set_visitor(&visitor); |
| 3280 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3241 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3281 | 3242 |
| 3282 EXPECT_EQ(1, visitor.error_count_); | 3243 EXPECT_EQ(1, visitor.error_count_); |
| 3283 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3244 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3284 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3245 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3285 EXPECT_EQ(1, visitor.headers_frame_count_); | 3246 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3286 EXPECT_EQ(0, visitor.continuation_count_); | 3247 EXPECT_EQ(0, visitor.continuation_count_); |
| 3287 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3248 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3288 } | 3249 } |
| 3289 | 3250 |
| 3290 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3251 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { |
| 3291 const unsigned char kInput[] = { | 3252 const unsigned char kInput[] = { |
| 3292 0x00, 0x00, 0x18, // Length: 24 | 3253 0x00, 0x00, 0x18, // Length: 24 |
| 3293 0x09, // Type: CONTINUATION | 3254 0x09, // Type: CONTINUATION |
| 3294 0x00, // Flags: none | 3255 0x00, // Flags: none |
| 3295 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3256 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3296 0x00, 0x06, 0x63, 0x6f, // HPACK | 3257 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3297 0x6f, 0x6b, 0x69, 0x65, // | 3258 0x6f, 0x6b, 0x69, 0x65, // |
| 3298 0x07, 0x66, 0x6f, 0x6f, // | 3259 0x07, 0x66, 0x6f, 0x6f, // |
| 3299 0x3d, 0x62, 0x61, 0x72, // | 3260 0x3d, 0x62, 0x61, 0x72, // |
| 3300 }; | 3261 }; |
| 3301 | 3262 |
| 3302 SpdyFramer framer; | 3263 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3303 TestSpdyVisitor visitor; | 3264 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3304 framer.set_visitor(&visitor); | 3265 framer.set_visitor(&visitor); |
| 3305 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3266 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3306 | 3267 |
| 3307 EXPECT_EQ(1, visitor.error_count_); | 3268 EXPECT_EQ(1, visitor.error_count_); |
| 3308 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3269 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3309 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3270 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3310 EXPECT_EQ(0, visitor.continuation_count_); | 3271 EXPECT_EQ(0, visitor.continuation_count_); |
| 3311 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3272 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3312 } | 3273 } |
| 3313 | 3274 |
| 3314 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { | 3275 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { |
| 3315 const unsigned char kInput[] = { | 3276 const unsigned char kInput[] = { |
| 3316 0x00, 0x00, 0x10, // Length: 16 | 3277 0x00, 0x00, 0x10, // Length: 16 |
| 3317 0x01, // Type: HEADERS | 3278 0x01, // Type: HEADERS |
| 3318 0x00, // Flags: none | 3279 0x00, // Flags: none |
| 3319 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3280 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3320 0x00, 0x06, 0x63, 0x6f, // HPACK | 3281 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3321 0x6f, 0x6b, 0x69, 0x65, // | 3282 0x6f, 0x6b, 0x69, 0x65, // |
| 3322 0x07, 0x66, 0x6f, 0x6f, // | 3283 0x07, 0x66, 0x6f, 0x6f, // |
| 3323 0x3d, 0x62, 0x61, 0x72, // | 3284 0x3d, 0x62, 0x61, 0x72, // |
| 3324 | 3285 |
| 3325 0x00, 0x00, 0x00, // Length: 0 | 3286 0x00, 0x00, 0x00, // Length: 0 |
| 3326 0x00, // Type: DATA | 3287 0x00, // Type: DATA |
| 3327 0x01, // Flags: END_STREAM | 3288 0x01, // Flags: END_STREAM |
| 3328 0x00, 0x00, 0x00, 0x04, // Stream: 4 | 3289 0x00, 0x00, 0x00, 0x04, // Stream: 4 |
| 3329 | 3290 |
| 3330 0xde, 0xad, 0xbe, 0xef, // Truncated Frame Header | 3291 0xde, 0xad, 0xbe, 0xef, // Truncated Frame Header |
| 3331 }; | 3292 }; |
| 3332 | 3293 |
| 3333 SpdyFramer framer; | 3294 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3334 TestSpdyVisitor visitor; | 3295 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3335 framer.set_visitor(&visitor); | 3296 framer.set_visitor(&visitor); |
| 3336 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3297 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3337 | 3298 |
| 3338 EXPECT_EQ(1, visitor.error_count_); | 3299 EXPECT_EQ(1, visitor.error_count_); |
| 3339 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3300 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3340 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3301 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3341 EXPECT_EQ(1, visitor.headers_frame_count_); | 3302 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3342 EXPECT_EQ(0, visitor.continuation_count_); | 3303 EXPECT_EQ(0, visitor.continuation_count_); |
| 3343 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3304 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3344 EXPECT_EQ(0, visitor.data_frame_count_); | 3305 EXPECT_EQ(0, visitor.data_frame_count_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3358 0x00, 0x00, 0x10, // Length: 16 | 3319 0x00, 0x00, 0x10, // Length: 16 |
| 3359 0x01, // Type: HEADERS | 3320 0x01, // Type: HEADERS |
| 3360 0x00, // Flags: none | 3321 0x00, // Flags: none |
| 3361 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3322 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3362 0x00, 0x06, 0x63, 0x6f, // HPACK | 3323 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3363 0x6f, 0x6b, 0x69, 0x65, // | 3324 0x6f, 0x6b, 0x69, 0x65, // |
| 3364 0x07, 0x66, 0x6f, 0x6f, // | 3325 0x07, 0x66, 0x6f, 0x6f, // |
| 3365 0x3d, 0x62, 0x61, 0x72, // | 3326 0x3d, 0x62, 0x61, 0x72, // |
| 3366 }; | 3327 }; |
| 3367 | 3328 |
| 3368 SpdyFramer framer; | 3329 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3369 TestSpdyVisitor visitor; | 3330 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3370 framer.set_visitor(&visitor); | 3331 framer.set_visitor(&visitor); |
| 3371 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3332 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3372 | 3333 |
| 3373 EXPECT_EQ(1, visitor.error_count_); | 3334 EXPECT_EQ(1, visitor.error_count_); |
| 3374 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3335 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3375 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3336 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3376 EXPECT_EQ(1, visitor.headers_frame_count_); | 3337 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3377 EXPECT_EQ(0, visitor.continuation_count_); | 3338 EXPECT_EQ(0, visitor.continuation_count_); |
| 3378 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3339 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3379 EXPECT_EQ(0, visitor.data_frame_count_); | 3340 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3380 } | 3341 } |
| 3381 | 3342 |
| 3382 TEST_P(SpdyFramerTest, ReadGarbage) { | 3343 TEST_P(SpdyFramerTest, ReadGarbage) { |
| 3383 SpdyFramer framer; | 3344 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3384 unsigned char garbage_frame[256]; | 3345 unsigned char garbage_frame[256]; |
| 3385 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 3346 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 3386 TestSpdyVisitor visitor; | 3347 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3387 visitor.use_compression_ = false; | |
| 3388 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 3348 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 3389 EXPECT_EQ(1, visitor.error_count_); | 3349 EXPECT_EQ(1, visitor.error_count_); |
| 3390 } | 3350 } |
| 3391 | 3351 |
| 3392 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) { | 3352 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) { |
| 3393 SpdyFramer framer; | 3353 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3394 | 3354 |
| 3395 // The unrecognized frame type should still have a valid length. | 3355 // The unrecognized frame type should still have a valid length. |
| 3396 const unsigned char unknown_frame[] = { | 3356 const unsigned char unknown_frame[] = { |
| 3397 0x00, 0x00, 0x08, // Length: 8 | 3357 0x00, 0x00, 0x08, // Length: 8 |
| 3398 0xff, // Type: UnknownFrameType(255) | 3358 0xff, // Type: UnknownFrameType(255) |
| 3399 0xff, // Flags: 0xff | 3359 0xff, // Flags: 0xff |
| 3400 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3360 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3401 0xff, 0xff, 0xff, 0xff, // Payload | 3361 0xff, 0xff, 0xff, 0xff, // Payload |
| 3402 0xff, 0xff, 0xff, 0xff, // | 3362 0xff, 0xff, 0xff, 0xff, // |
| 3403 }; | 3363 }; |
| 3404 TestSpdyVisitor visitor; | 3364 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3405 | 3365 |
| 3406 // Simulate the case where the stream id validation checks out. | 3366 // Simulate the case where the stream id validation checks out. |
| 3407 visitor.on_unknown_frame_result_ = true; | 3367 visitor.on_unknown_frame_result_ = true; |
| 3408 visitor.use_compression_ = false; | |
| 3409 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); | 3368 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); |
| 3410 EXPECT_EQ(0, visitor.error_count_); | 3369 EXPECT_EQ(0, visitor.error_count_); |
| 3411 | 3370 |
| 3412 // Follow it up with a valid control frame to make sure we handle | 3371 // Follow it up with a valid control frame to make sure we handle |
| 3413 // subsequent frames correctly. | 3372 // subsequent frames correctly. |
| 3414 SpdySettingsIR settings_ir; | 3373 SpdySettingsIR settings_ir; |
| 3415 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, | 3374 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, |
| 3416 false, // persist | 3375 false, // persist |
| 3417 false, // persisted | 3376 false, // persisted |
| 3418 10); | 3377 10); |
| 3419 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3378 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3420 visitor.SimulateInFramer( | 3379 visitor.SimulateInFramer( |
| 3421 reinterpret_cast<unsigned char*>(control_frame.data()), | 3380 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3422 control_frame.size()); | 3381 control_frame.size()); |
| 3423 EXPECT_EQ(0, visitor.error_count_); | 3382 EXPECT_EQ(0, visitor.error_count_); |
| 3424 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3383 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); |
| 3425 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3384 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); |
| 3426 } | 3385 } |
| 3427 | 3386 |
| 3428 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { | 3387 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { |
| 3429 SpdyFramer framer; | 3388 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3430 const unsigned char kFrameData[] = { | 3389 const unsigned char kFrameData[] = { |
| 3431 0x00, 0x00, 0x08, // Length: 8 | 3390 0x00, 0x00, 0x08, // Length: 8 |
| 3432 0xff, // Type: UnknownFrameType(255) | 3391 0xff, // Type: UnknownFrameType(255) |
| 3433 0xff, // Flags: 0xff | 3392 0xff, // Flags: 0xff |
| 3434 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3393 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3435 0xff, 0xff, 0xff, 0xff, // Payload | 3394 0xff, 0xff, 0xff, 0xff, // Payload |
| 3436 0xff, 0xff, 0xff, 0xff, // | 3395 0xff, 0xff, 0xff, 0xff, // |
| 3437 }; | 3396 }; |
| 3438 TestSpdyVisitor visitor; | 3397 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3439 visitor.use_compression_ = false; | |
| 3440 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 3398 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
| 3441 EXPECT_EQ(1, visitor.error_count_); | 3399 EXPECT_EQ(1, visitor.error_count_); |
| 3442 } | 3400 } |
| 3443 | 3401 |
| 3444 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { | 3402 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { |
| 3445 const unsigned char kInput[] = { | 3403 const unsigned char kInput[] = { |
| 3446 0x00, 0x12, 0x01, // Length: 4609 | 3404 0x00, 0x12, 0x01, // Length: 4609 |
| 3447 0x04, // Type: SETTINGS | 3405 0x04, // Type: SETTINGS |
| 3448 0x00, // Flags: none | 3406 0x00, // Flags: none |
| 3449 0x00, 0x00, 0x01, 0xef, // Stream: 495 | 3407 0x00, 0x00, 0x01, 0xef, // Stream: 495 |
| 3450 0xef, 0xff, // Param: 61439 | 3408 0xef, 0xff, // Param: 61439 |
| 3451 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3409 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
| 3452 0xff, 0xff, // Param: 0xffff | 3410 0xff, 0xff, // Param: 0xffff |
| 3453 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3411 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
| 3454 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) | 3412 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) |
| 3455 0xff, // | 3413 0xff, // |
| 3456 }; | 3414 }; |
| 3457 | 3415 |
| 3458 TestSpdyVisitor visitor; | 3416 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3459 visitor.SimulateInFramer(kInput, arraysize(kInput)); | 3417 visitor.SimulateInFramer(kInput, arraysize(kInput)); |
| 3460 EXPECT_EQ(1, visitor.error_count_); | 3418 EXPECT_EQ(1, visitor.error_count_); |
| 3461 } | 3419 } |
| 3462 | 3420 |
| 3463 TEST_P(SpdyFramerTest, SizesTest) { | 3421 TEST_P(SpdyFramerTest, SizesTest) { |
| 3464 SpdyFramer framer; | 3422 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3465 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); | 3423 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); |
| 3466 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); | 3424 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); |
| 3467 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); | 3425 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); |
| 3468 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); | 3426 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); |
| 3469 EXPECT_EQ(17u, framer.GetPingSize()); | 3427 EXPECT_EQ(17u, framer.GetPingSize()); |
| 3470 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); | 3428 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); |
| 3471 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); | 3429 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); |
| 3472 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); | 3430 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); |
| 3473 EXPECT_EQ(9u, framer.GetBlockedSize()); | 3431 EXPECT_EQ(9u, framer.GetBlockedSize()); |
| 3474 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); | 3432 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3579 | 3537 |
| 3580 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 3538 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
| 3581 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; | 3539 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; |
| 3582 | 3540 |
| 3583 uint8_t flags = 0; | 3541 uint8_t flags = 0; |
| 3584 do { | 3542 do { |
| 3585 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3543 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3586 << static_cast<int>(flags)); | 3544 << static_cast<int>(flags)); |
| 3587 | 3545 |
| 3588 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3546 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3589 SpdyFramer framer; | 3547 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3590 framer.set_visitor(&visitor); | 3548 framer.set_visitor(&visitor); |
| 3591 | 3549 |
| 3592 SpdyDataIR data_ir(1, "hello"); | 3550 SpdyDataIR data_ir(1, "hello"); |
| 3593 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 3551 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 3594 SetFrameFlags(&frame, flags); | 3552 SetFrameFlags(&frame, flags); |
| 3595 | 3553 |
| 3596 if (flags & ~valid_data_flags) { | 3554 if (flags & ~valid_data_flags) { |
| 3597 EXPECT_CALL(visitor, OnError(_)); | 3555 EXPECT_CALL(visitor, OnError(_)); |
| 3598 } else { | 3556 } else { |
| 3599 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 3557 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3628 } while (++flags != 0); | 3586 } while (++flags != 0); |
| 3629 } | 3587 } |
| 3630 | 3588 |
| 3631 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { | 3589 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { |
| 3632 uint8_t flags = 0; | 3590 uint8_t flags = 0; |
| 3633 do { | 3591 do { |
| 3634 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3592 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3635 << static_cast<int>(flags)); | 3593 << static_cast<int>(flags)); |
| 3636 | 3594 |
| 3637 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3595 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3638 SpdyFramer framer; | 3596 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3639 framer.set_visitor(&visitor); | 3597 framer.set_visitor(&visitor); |
| 3640 | 3598 |
| 3641 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); | 3599 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); |
| 3642 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 3600 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 3643 SetFrameFlags(&frame, flags); | 3601 SetFrameFlags(&frame, flags); |
| 3644 | 3602 |
| 3645 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); | 3603 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); |
| 3646 | 3604 |
| 3647 framer.ProcessInput(frame.data(), frame.size()); | 3605 framer.ProcessInput(frame.data(), frame.size()); |
| 3648 | 3606 |
| 3649 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3607 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3650 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3608 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3651 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3609 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3652 } while (++flags != 0); | 3610 } while (++flags != 0); |
| 3653 } | 3611 } |
| 3654 | 3612 |
| 3655 TEST_P(SpdyFramerTest, SettingsFrameFlags) { | 3613 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
| 3656 uint8_t flags = 0; | 3614 uint8_t flags = 0; |
| 3657 do { | 3615 do { |
| 3658 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3616 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3659 << static_cast<int>(flags)); | 3617 << static_cast<int>(flags)); |
| 3660 | 3618 |
| 3661 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3619 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3662 SpdyFramer framer; | 3620 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3663 framer.set_visitor(&visitor); | 3621 framer.set_visitor(&visitor); |
| 3664 | 3622 |
| 3665 SpdySettingsIR settings_ir; | 3623 SpdySettingsIR settings_ir; |
| 3666 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); | 3624 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); |
| 3667 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 3625 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 3668 SetFrameFlags(&frame, flags); | 3626 SetFrameFlags(&frame, flags); |
| 3669 | 3627 |
| 3670 if (flags & SETTINGS_FLAG_ACK) { | 3628 if (flags & SETTINGS_FLAG_ACK) { |
| 3671 EXPECT_CALL(visitor, OnError(_)); | 3629 EXPECT_CALL(visitor, OnError(_)); |
| 3672 } else { | 3630 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3690 } while (++flags != 0); | 3648 } while (++flags != 0); |
| 3691 } | 3649 } |
| 3692 | 3650 |
| 3693 TEST_P(SpdyFramerTest, GoawayFrameFlags) { | 3651 TEST_P(SpdyFramerTest, GoawayFrameFlags) { |
| 3694 uint8_t flags = 0; | 3652 uint8_t flags = 0; |
| 3695 do { | 3653 do { |
| 3696 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3654 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3697 << static_cast<int>(flags)); | 3655 << static_cast<int>(flags)); |
| 3698 | 3656 |
| 3699 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3657 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3700 SpdyFramer framer; | 3658 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3701 framer.set_visitor(&visitor); | 3659 framer.set_visitor(&visitor); |
| 3702 | 3660 |
| 3703 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); | 3661 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); |
| 3704 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 3662 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
| 3705 SetFrameFlags(&frame, flags); | 3663 SetFrameFlags(&frame, flags); |
| 3706 | 3664 |
| 3707 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); | 3665 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); |
| 3708 | 3666 |
| 3709 framer.ProcessInput(frame.data(), frame.size()); | 3667 framer.ProcessInput(frame.data(), frame.size()); |
| 3710 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3668 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3711 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3669 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3712 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3670 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3713 } while (++flags != 0); | 3671 } while (++flags != 0); |
| 3714 } | 3672 } |
| 3715 | 3673 |
| 3716 TEST_P(SpdyFramerTest, HeadersFrameFlags) { | 3674 TEST_P(SpdyFramerTest, HeadersFrameFlags) { |
| 3717 uint8_t flags = 0; | 3675 uint8_t flags = 0; |
| 3718 do { | 3676 do { |
| 3719 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3677 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3720 << static_cast<int>(flags)); | 3678 << static_cast<int>(flags)); |
| 3721 | 3679 |
| 3722 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3680 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3723 SpdyFramer framer; | 3681 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3724 framer.set_visitor(&visitor); | 3682 framer.set_visitor(&visitor); |
| 3725 | 3683 |
| 3726 SpdyHeadersIR headers_ir(57); | 3684 SpdyHeadersIR headers_ir(57); |
| 3727 if (flags & HEADERS_FLAG_PRIORITY) { | 3685 if (flags & HEADERS_FLAG_PRIORITY) { |
| 3728 headers_ir.set_weight(3); | 3686 headers_ir.set_weight(3); |
| 3729 headers_ir.set_has_priority(true); | 3687 headers_ir.set_has_priority(true); |
| 3730 headers_ir.set_parent_stream_id(5); | 3688 headers_ir.set_parent_stream_id(5); |
| 3731 headers_ir.set_exclusive(true); | 3689 headers_ir.set_exclusive(true); |
| 3732 } | 3690 } |
| 3733 headers_ir.SetHeader("foo", "bar"); | 3691 headers_ir.SetHeader("foo", "bar"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3770 } while (++flags != 0); | 3728 } while (++flags != 0); |
| 3771 } | 3729 } |
| 3772 | 3730 |
| 3773 TEST_P(SpdyFramerTest, PingFrameFlags) { | 3731 TEST_P(SpdyFramerTest, PingFrameFlags) { |
| 3774 uint8_t flags = 0; | 3732 uint8_t flags = 0; |
| 3775 do { | 3733 do { |
| 3776 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3734 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3777 << static_cast<int>(flags)); | 3735 << static_cast<int>(flags)); |
| 3778 | 3736 |
| 3779 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3737 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3780 SpdyFramer framer; | 3738 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3781 framer.set_visitor(&visitor); | 3739 framer.set_visitor(&visitor); |
| 3782 | 3740 |
| 3783 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); | 3741 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); |
| 3784 SetFrameFlags(&frame, flags); | 3742 SetFrameFlags(&frame, flags); |
| 3785 | 3743 |
| 3786 if (flags & PING_FLAG_ACK) { | 3744 if (flags & PING_FLAG_ACK) { |
| 3787 EXPECT_CALL(visitor, OnPing(42, true)); | 3745 EXPECT_CALL(visitor, OnPing(42, true)); |
| 3788 } else { | 3746 } else { |
| 3789 EXPECT_CALL(visitor, OnPing(42, false)); | 3747 EXPECT_CALL(visitor, OnPing(42, false)); |
| 3790 } | 3748 } |
| 3791 | 3749 |
| 3792 framer.ProcessInput(frame.data(), frame.size()); | 3750 framer.ProcessInput(frame.data(), frame.size()); |
| 3793 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3751 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3794 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3752 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3795 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3753 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3796 } while (++flags != 0); | 3754 } while (++flags != 0); |
| 3797 } | 3755 } |
| 3798 | 3756 |
| 3799 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { | 3757 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { |
| 3800 uint8_t flags = 0; | 3758 uint8_t flags = 0; |
| 3801 do { | 3759 do { |
| 3802 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3760 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3803 << static_cast<int>(flags)); | 3761 << static_cast<int>(flags)); |
| 3804 | 3762 |
| 3805 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3763 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3806 SpdyFramer framer; | 3764 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3807 framer.set_visitor(&visitor); | 3765 framer.set_visitor(&visitor); |
| 3808 | 3766 |
| 3809 SpdySerializedFrame frame( | 3767 SpdySerializedFrame frame( |
| 3810 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); | 3768 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); |
| 3811 SetFrameFlags(&frame, flags); | 3769 SetFrameFlags(&frame, flags); |
| 3812 | 3770 |
| 3813 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 3771 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
| 3814 | 3772 |
| 3815 framer.ProcessInput(frame.data(), frame.size()); | 3773 framer.ProcessInput(frame.data(), frame.size()); |
| 3816 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3774 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3817 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3775 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3818 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3776 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3819 } while (++flags != 0); | 3777 } while (++flags != 0); |
| 3820 } | 3778 } |
| 3821 | 3779 |
| 3822 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { | 3780 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { |
| 3823 const SpdyStreamId client_id = 123; // Must be odd. | 3781 const SpdyStreamId client_id = 123; // Must be odd. |
| 3824 const SpdyStreamId promised_id = 22; // Must be even. | 3782 const SpdyStreamId promised_id = 22; // Must be even. |
| 3825 uint8_t flags = 0; | 3783 uint8_t flags = 0; |
| 3826 do { | 3784 do { |
| 3827 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3785 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3828 << static_cast<int>(flags)); | 3786 << static_cast<int>(flags)); |
| 3829 | 3787 |
| 3830 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3788 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3831 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3789 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 3832 SpdyFramer framer; | 3790 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3833 framer.set_visitor(&visitor); | 3791 framer.set_visitor(&visitor); |
| 3834 framer.set_debug_visitor(&debug_visitor); | 3792 framer.set_debug_visitor(&debug_visitor); |
| 3835 | 3793 |
| 3836 EXPECT_CALL(debug_visitor, | 3794 EXPECT_CALL(debug_visitor, |
| 3837 OnSendCompressedFrame(client_id, PUSH_PROMISE, _, _)); | 3795 OnSendCompressedFrame(client_id, PUSH_PROMISE, _, _)); |
| 3838 | 3796 |
| 3839 SpdyPushPromiseIR push_promise(client_id, promised_id); | 3797 SpdyPushPromiseIR push_promise(client_id, promised_id); |
| 3840 push_promise.SetHeader("foo", "bar"); | 3798 push_promise.SetHeader("foo", "bar"); |
| 3841 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 3799 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 3842 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, | 3800 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3860 } | 3818 } |
| 3861 | 3819 |
| 3862 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { | 3820 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { |
| 3863 uint8_t flags = 0; | 3821 uint8_t flags = 0; |
| 3864 do { | 3822 do { |
| 3865 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3823 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3866 << static_cast<int>(flags)); | 3824 << static_cast<int>(flags)); |
| 3867 | 3825 |
| 3868 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3826 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3869 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3827 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 3870 SpdyFramer framer; | 3828 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3871 framer.set_visitor(&visitor); | 3829 framer.set_visitor(&visitor); |
| 3872 framer.set_debug_visitor(&debug_visitor); | 3830 framer.set_debug_visitor(&debug_visitor); |
| 3873 | 3831 |
| 3874 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); | 3832 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); |
| 3875 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); | 3833 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); |
| 3876 EXPECT_CALL(visitor, OnHeaders(42, false, 0, 0, false, false, false)); | 3834 EXPECT_CALL(visitor, OnHeaders(42, false, 0, 0, false, false, false)); |
| 3877 EXPECT_CALL(visitor, OnHeaderFrameStart(42)).Times(1); | 3835 EXPECT_CALL(visitor, OnHeaderFrameStart(42)).Times(1); |
| 3878 | 3836 |
| 3879 SpdyHeadersIR headers_ir(42); | 3837 SpdyHeadersIR headers_ir(42); |
| 3880 headers_ir.SetHeader("foo", "bar"); | 3838 headers_ir.SetHeader("foo", "bar"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3928 }; | 3886 }; |
| 3929 const unsigned char kH2RstStreamNumStatusCodes[] = { | 3887 const unsigned char kH2RstStreamNumStatusCodes[] = { |
| 3930 0x00, 0x00, 0x04, // Length: 4 | 3888 0x00, 0x00, 0x04, // Length: 4 |
| 3931 0x03, // Type: RST_STREAM | 3889 0x03, // Type: RST_STREAM |
| 3932 0x00, // Flags: none | 3890 0x00, // Flags: none |
| 3933 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3891 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3934 0x00, 0x00, 0x00, 0xff, // Error: 255 | 3892 0x00, 0x00, 0x00, 0xff, // Error: 255 |
| 3935 }; | 3893 }; |
| 3936 | 3894 |
| 3937 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3895 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3938 SpdyFramer framer; | 3896 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3939 framer.set_visitor(&visitor); | 3897 framer.set_visitor(&visitor); |
| 3940 | 3898 |
| 3941 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); | 3899 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); |
| 3942 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamInvalid), | 3900 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamInvalid), |
| 3943 arraysize(kH2RstStreamInvalid)); | 3901 arraysize(kH2RstStreamInvalid)); |
| 3944 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3902 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3945 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3903 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3946 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3904 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3947 | 3905 |
| 3948 framer.Reset(); | 3906 framer.Reset(); |
| 3949 | 3907 |
| 3950 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 3908 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 3951 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), | 3909 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), |
| 3952 arraysize(kH2RstStreamNumStatusCodes)); | 3910 arraysize(kH2RstStreamNumStatusCodes)); |
| 3953 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3911 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3954 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3912 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3955 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3913 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3956 } | 3914 } |
| 3957 | 3915 |
| 3958 // Test handling of GOAWAY frames with out-of-bounds status code. | 3916 // Test handling of GOAWAY frames with out-of-bounds status code. |
| 3959 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { | 3917 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { |
| 3960 SpdyFramer framer; | 3918 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3961 const unsigned char kH2FrameData[] = { | 3919 const unsigned char kH2FrameData[] = { |
| 3962 0x00, 0x00, 0x0a, // Length: 10 | 3920 0x00, 0x00, 0x0a, // Length: 10 |
| 3963 0x07, // Type: GOAWAY | 3921 0x07, // Type: GOAWAY |
| 3964 0x00, // Flags: none | 3922 0x00, // Flags: none |
| 3965 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3923 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 3966 0x00, 0x00, 0x00, 0x01, // Last: 1 | 3924 0x00, 0x00, 0x00, 0x01, // Last: 1 |
| 3967 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff | 3925 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff |
| 3968 0x47, 0x41, // Description | 3926 0x47, 0x41, // Description |
| 3969 }; | 3927 }; |
| 3970 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3928 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3983 const unsigned char kH2FrameData[] = { | 3941 const unsigned char kH2FrameData[] = { |
| 3984 0x00, 0x00, 0x08, // Length: 8 | 3942 0x00, 0x00, 0x08, // Length: 8 |
| 3985 0x07, // Type: GOAWAY | 3943 0x07, // Type: GOAWAY |
| 3986 0x00, // Flags: none | 3944 0x00, // Flags: none |
| 3987 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3945 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 3988 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) | 3946 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) |
| 3989 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 3947 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 3990 }; | 3948 }; |
| 3991 | 3949 |
| 3992 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3950 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3993 SpdyFramer framer; | 3951 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3994 framer.set_visitor(&visitor); | 3952 framer.set_visitor(&visitor); |
| 3995 | 3953 |
| 3996 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); | 3954 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); |
| 3997 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), | 3955 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), |
| 3998 arraysize(kH2FrameData)); | 3956 arraysize(kH2FrameData)); |
| 3999 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3957 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4000 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3958 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4001 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3959 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4002 } | 3960 } |
| 4003 | 3961 |
| 4004 TEST_P(SpdyFramerTest, OnBlocked) { | 3962 TEST_P(SpdyFramerTest, OnBlocked) { |
| 4005 const SpdyStreamId kStreamId = 0; | 3963 const SpdyStreamId kStreamId = 0; |
| 4006 | 3964 |
| 4007 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3965 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4008 SpdyFramer framer; | 3966 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4009 framer.set_visitor(&visitor); | 3967 framer.set_visitor(&visitor); |
| 4010 | 3968 |
| 4011 EXPECT_CALL(visitor, OnBlocked(kStreamId)); | 3969 EXPECT_CALL(visitor, OnBlocked(kStreamId)); |
| 4012 | 3970 |
| 4013 SpdyBlockedIR blocked_ir(0); | 3971 SpdyBlockedIR blocked_ir(0); |
| 4014 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 3972 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
| 4015 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); | 3973 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); |
| 4016 | 3974 |
| 4017 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3975 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4018 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3976 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4019 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3977 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4020 } | 3978 } |
| 4021 | 3979 |
| 4022 TEST_P(SpdyFramerTest, OnAltSvc) { | 3980 TEST_P(SpdyFramerTest, OnAltSvc) { |
| 4023 const SpdyStreamId kStreamId = 1; | 3981 const SpdyStreamId kStreamId = 1; |
| 4024 | 3982 |
| 4025 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3983 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4026 SpdyFramer framer; | 3984 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4027 framer.set_visitor(&visitor); | 3985 framer.set_visitor(&visitor); |
| 4028 | 3986 |
| 4029 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 3987 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4030 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 3988 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4031 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 3989 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4032 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 3990 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4033 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 3991 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4034 altsvc_vector.push_back(altsvc1); | 3992 altsvc_vector.push_back(altsvc1); |
| 4035 altsvc_vector.push_back(altsvc2); | 3993 altsvc_vector.push_back(altsvc2); |
| 4036 EXPECT_CALL(visitor, | 3994 EXPECT_CALL(visitor, |
| 4037 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); | 3995 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); |
| 4038 | 3996 |
| 4039 SpdyAltSvcIR altsvc_ir(1); | 3997 SpdyAltSvcIR altsvc_ir(1); |
| 4040 altsvc_ir.set_origin("o_r|g!n"); | 3998 altsvc_ir.set_origin("o_r|g!n"); |
| 4041 altsvc_ir.add_altsvc(altsvc1); | 3999 altsvc_ir.add_altsvc(altsvc1); |
| 4042 altsvc_ir.add_altsvc(altsvc2); | 4000 altsvc_ir.add_altsvc(altsvc2); |
| 4043 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4001 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4044 framer.ProcessInput(frame.data(), frame.size()); | 4002 framer.ProcessInput(frame.data(), frame.size()); |
| 4045 | 4003 |
| 4046 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4004 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4047 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4005 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4048 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4006 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4049 } | 4007 } |
| 4050 | 4008 |
| 4051 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { | 4009 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
| 4052 const SpdyStreamId kStreamId = 1; | 4010 const SpdyStreamId kStreamId = 1; |
| 4053 | 4011 |
| 4054 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4012 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4055 SpdyFramer framer; | 4013 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4056 framer.set_visitor(&visitor); | 4014 framer.set_visitor(&visitor); |
| 4057 | 4015 |
| 4058 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4016 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4059 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4017 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4060 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4018 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4061 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4019 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4062 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4020 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4063 altsvc_vector.push_back(altsvc1); | 4021 altsvc_vector.push_back(altsvc1); |
| 4064 altsvc_vector.push_back(altsvc2); | 4022 altsvc_vector.push_back(altsvc2); |
| 4065 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); | 4023 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); |
| 4066 | 4024 |
| 4067 SpdyAltSvcIR altsvc_ir(1); | 4025 SpdyAltSvcIR altsvc_ir(1); |
| 4068 altsvc_ir.add_altsvc(altsvc1); | 4026 altsvc_ir.add_altsvc(altsvc1); |
| 4069 altsvc_ir.add_altsvc(altsvc2); | 4027 altsvc_ir.add_altsvc(altsvc2); |
| 4070 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4028 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4071 framer.ProcessInput(frame.data(), frame.size()); | 4029 framer.ProcessInput(frame.data(), frame.size()); |
| 4072 | 4030 |
| 4073 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4031 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4074 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4032 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4075 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4033 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4076 } | 4034 } |
| 4077 | 4035 |
| 4078 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { | 4036 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { |
| 4079 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4037 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4080 SpdyFramer framer; | 4038 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4081 framer.set_visitor(&visitor); | 4039 framer.set_visitor(&visitor); |
| 4082 | 4040 |
| 4083 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 4041 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 4084 | 4042 |
| 4085 SpdyAltSvcIR altsvc_ir(1); | 4043 SpdyAltSvcIR altsvc_ir(1); |
| 4086 altsvc_ir.set_origin("o1"); | 4044 altsvc_ir.set_origin("o1"); |
| 4087 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4045 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 4088 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 4046 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 4089 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4047 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 4090 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); | 4048 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); |
| 4091 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4049 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4092 framer.ProcessInput(frame.data(), frame.size()); | 4050 framer.ProcessInput(frame.data(), frame.size()); |
| 4093 | 4051 |
| 4094 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4052 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4095 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 4053 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4096 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4054 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4097 } | 4055 } |
| 4098 | 4056 |
| 4099 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { | 4057 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
| 4100 const SpdyStreamId kStreamId = 1; | 4058 const SpdyStreamId kStreamId = 1; |
| 4101 | 4059 |
| 4102 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4060 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4103 SpdyFramer framer; | 4061 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4104 framer.set_visitor(&visitor); | 4062 framer.set_visitor(&visitor); |
| 4105 | 4063 |
| 4106 SpdyAltSvcWireFormat::AlternativeService altsvc( | 4064 SpdyAltSvcWireFormat::AlternativeService altsvc( |
| 4107 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); | 4065 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); |
| 4108 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4066 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4109 altsvc_vector.push_back(altsvc); | 4067 altsvc_vector.push_back(altsvc); |
| 4110 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); | 4068 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); |
| 4111 | 4069 |
| 4112 SpdyAltSvcIR altsvc_ir(1); | 4070 SpdyAltSvcIR altsvc_ir(1); |
| 4113 altsvc_ir.set_origin("o1"); | 4071 altsvc_ir.set_origin("o1"); |
| 4114 altsvc_ir.add_altsvc(altsvc); | 4072 altsvc_ir.add_altsvc(altsvc); |
| 4115 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4073 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4116 framer.ProcessInput(frame.data(), frame.size()); | 4074 framer.ProcessInput(frame.data(), frame.size()); |
| 4117 | 4075 |
| 4118 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4076 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4119 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4077 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4120 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4078 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4121 } | 4079 } |
| 4122 | 4080 |
| 4123 // Tests handling of ALTSVC frames delivered in small chunks. | 4081 // Tests handling of ALTSVC frames delivered in small chunks. |
| 4124 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 4082 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
| 4125 SpdyFramer framer; | 4083 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4126 SpdyAltSvcIR altsvc_ir(1); | 4084 SpdyAltSvcIR altsvc_ir(1); |
| 4127 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4085 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4128 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4086 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4129 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4087 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4130 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4088 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4131 altsvc_ir.add_altsvc(altsvc1); | 4089 altsvc_ir.add_altsvc(altsvc1); |
| 4132 altsvc_ir.add_altsvc(altsvc2); | 4090 altsvc_ir.add_altsvc(altsvc2); |
| 4133 | 4091 |
| 4134 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); | 4092 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); |
| 4135 TestSpdyVisitor visitor; | 4093 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 4136 visitor.use_compression_ = false; | |
| 4137 | 4094 |
| 4138 // Read data in small chunks. | 4095 // Read data in small chunks. |
| 4139 size_t framed_data = 0; | 4096 size_t framed_data = 0; |
| 4140 size_t unframed_data = control_frame.size(); | 4097 size_t unframed_data = control_frame.size(); |
| 4141 size_t kReadChunkSize = 5; // Read five bytes at a time. | 4098 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 4142 while (unframed_data > 0) { | 4099 while (unframed_data > 0) { |
| 4143 size_t to_read = std::min(kReadChunkSize, unframed_data); | 4100 size_t to_read = std::min(kReadChunkSize, unframed_data); |
| 4144 visitor.SimulateInFramer( | 4101 visitor.SimulateInFramer( |
| 4145 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), | 4102 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), |
| 4146 to_read); | 4103 to_read); |
| 4147 unframed_data -= to_read; | 4104 unframed_data -= to_read; |
| 4148 framed_data += to_read; | 4105 framed_data += to_read; |
| 4149 } | 4106 } |
| 4150 EXPECT_EQ(0, visitor.error_count_); | 4107 EXPECT_EQ(0, visitor.error_count_); |
| 4151 EXPECT_EQ(1, visitor.altsvc_count_); | 4108 EXPECT_EQ(1, visitor.altsvc_count_); |
| 4152 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); | 4109 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); |
| 4153 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); | 4110 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); |
| 4154 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); | 4111 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); |
| 4155 } | 4112 } |
| 4156 | 4113 |
| 4157 // Tests handling of PRIORITY frames. | 4114 // Tests handling of PRIORITY frames. |
| 4158 TEST_P(SpdyFramerTest, ReadPriority) { | 4115 TEST_P(SpdyFramerTest, ReadPriority) { |
| 4159 SpdyFramer framer; | 4116 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4160 SpdyPriorityIR priority(3, 1, 256, false); | 4117 SpdyPriorityIR priority(3, 1, 256, false); |
| 4161 SpdySerializedFrame frame(framer.SerializePriority(priority)); | 4118 SpdySerializedFrame frame(framer.SerializePriority(priority)); |
| 4162 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4119 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4163 framer.set_visitor(&visitor); | 4120 framer.set_visitor(&visitor); |
| 4164 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); | 4121 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); |
| 4165 framer.ProcessInput(frame.data(), frame.size()); | 4122 framer.ProcessInput(frame.data(), frame.size()); |
| 4166 | 4123 |
| 4167 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4124 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4168 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4125 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4169 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4126 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4170 // TODO(mlavan): once we actually maintain a priority tree, | 4127 // TODO(mlavan): once we actually maintain a priority tree, |
| 4171 // check that state is adjusted correctly. | 4128 // check that state is adjusted correctly. |
| 4172 } | 4129 } |
| 4173 | 4130 |
| 4174 // Tests handling of PRIORITY frame with incorrect size. | 4131 // Tests handling of PRIORITY frame with incorrect size. |
| 4175 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { | 4132 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
| 4176 // PRIORITY frame of size 4, which isn't correct. | 4133 // PRIORITY frame of size 4, which isn't correct. |
| 4177 const unsigned char kFrameData[] = { | 4134 const unsigned char kFrameData[] = { |
| 4178 0x00, 0x00, 0x04, // Length: 4 | 4135 0x00, 0x00, 0x04, // Length: 4 |
| 4179 0x02, // Type: PRIORITY | 4136 0x02, // Type: PRIORITY |
| 4180 0x00, // Flags: none | 4137 0x00, // Flags: none |
| 4181 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4138 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4182 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) | 4139 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) |
| 4183 }; | 4140 }; |
| 4184 | 4141 |
| 4185 TestSpdyVisitor visitor; | 4142 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 4186 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4143 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4187 | 4144 |
| 4188 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4145 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4189 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4146 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4190 visitor.framer_.error_code()) | 4147 visitor.framer_.error_code()) |
| 4191 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4148 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4192 } | 4149 } |
| 4193 | 4150 |
| 4194 // Tests handling of PING frame with incorrect size. | 4151 // Tests handling of PING frame with incorrect size. |
| 4195 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPing) { | 4152 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPing) { |
| 4196 // PING frame of size 4, which isn't correct. | 4153 // PING frame of size 4, which isn't correct. |
| 4197 const unsigned char kFrameData[] = { | 4154 const unsigned char kFrameData[] = { |
| 4198 0x00, 0x00, 0x04, // Length: 4 | 4155 0x00, 0x00, 0x04, // Length: 4 |
| 4199 0x06, // Type: PING | 4156 0x06, // Type: PING |
| 4200 0x00, // Flags: none | 4157 0x00, // Flags: none |
| 4201 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 4158 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 4202 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) | 4159 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) |
| 4203 }; | 4160 }; |
| 4204 | 4161 |
| 4205 TestSpdyVisitor visitor; | 4162 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 4206 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4163 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4207 | 4164 |
| 4208 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4165 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4209 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4166 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4210 visitor.framer_.error_code()) | 4167 visitor.framer_.error_code()) |
| 4211 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4168 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4212 } | 4169 } |
| 4213 | 4170 |
| 4214 // Tests handling of WINDOW_UPDATE frame with incorrect size. | 4171 // Tests handling of WINDOW_UPDATE frame with incorrect size. |
| 4215 TEST_P(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { | 4172 TEST_P(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { |
| 4216 // WINDOW_UPDATE frame of size 3, which isn't correct. | 4173 // WINDOW_UPDATE frame of size 3, which isn't correct. |
| 4217 const unsigned char kFrameData[] = { | 4174 const unsigned char kFrameData[] = { |
| 4218 0x00, 0x00, 0x03, // Length: 3 | 4175 0x00, 0x00, 0x03, // Length: 3 |
| 4219 0x08, // Type: WINDOW_UPDATE | 4176 0x08, // Type: WINDOW_UPDATE |
| 4220 0x00, // Flags: none | 4177 0x00, // Flags: none |
| 4221 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4178 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4222 0x00, 0x00, 0x01, // WindowUpdate (Truncated) | 4179 0x00, 0x00, 0x01, // WindowUpdate (Truncated) |
| 4223 }; | 4180 }; |
| 4224 | 4181 |
| 4225 TestSpdyVisitor visitor; | 4182 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 4226 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4183 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4227 | 4184 |
| 4228 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4185 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4229 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4186 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4230 visitor.framer_.error_code()) | 4187 visitor.framer_.error_code()) |
| 4231 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4188 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4232 } | 4189 } |
| 4233 | 4190 |
| 4234 // Tests handling of RST_STREAM frame with incorrect size. | 4191 // Tests handling of RST_STREAM frame with incorrect size. |
| 4235 TEST_P(SpdyFramerTest, ReadIncorrectlySizedRstStream) { | 4192 TEST_P(SpdyFramerTest, ReadIncorrectlySizedRstStream) { |
| 4236 // RST_STREAM frame of size 3, which isn't correct. | 4193 // RST_STREAM frame of size 3, which isn't correct. |
| 4237 const unsigned char kFrameData[] = { | 4194 const unsigned char kFrameData[] = { |
| 4238 0x00, 0x00, 0x03, // Length: 3 | 4195 0x00, 0x00, 0x03, // Length: 3 |
| 4239 0x03, // Type: RST_STREAM | 4196 0x03, // Type: RST_STREAM |
| 4240 0x00, // Flags: none | 4197 0x00, // Flags: none |
| 4241 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4198 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4242 0x00, 0x00, 0x01, // RstStream (Truncated) | 4199 0x00, 0x00, 0x01, // RstStream (Truncated) |
| 4243 }; | 4200 }; |
| 4244 | 4201 |
| 4245 TestSpdyVisitor visitor; | 4202 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 4246 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4203 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4247 | 4204 |
| 4248 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4205 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4249 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4206 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4250 visitor.framer_.error_code()) | 4207 visitor.framer_.error_code()) |
| 4251 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4208 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4252 } | 4209 } |
| 4253 | 4210 |
| 4254 // Test that SpdyFramer processes, by default, all passed input in one call | 4211 // Test that SpdyFramer processes, by default, all passed input in one call |
| 4255 // to ProcessInput (i.e. will not be calling set_process_single_input_frame()). | 4212 // to ProcessInput (i.e. will not be calling set_process_single_input_frame()). |
| 4256 TEST_P(SpdyFramerTest, ProcessAllInput) { | 4213 TEST_P(SpdyFramerTest, ProcessAllInput) { |
| 4257 SpdyFramer framer; | 4214 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4258 std::unique_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor); | 4215 std::unique_ptr<TestSpdyVisitor> visitor( |
| 4216 new TestSpdyVisitor(SpdyFramer::DISABLE_COMPRESSION)); |
| 4259 framer.set_visitor(visitor.get()); | 4217 framer.set_visitor(visitor.get()); |
| 4260 | 4218 |
| 4261 // Create two input frames. | 4219 // Create two input frames. |
| 4262 SpdyHeadersIR headers(1); | 4220 SpdyHeadersIR headers(1); |
| 4263 headers.SetHeader("alpha", "beta"); | 4221 headers.SetHeader("alpha", "beta"); |
| 4264 headers.SetHeader("gamma", "charlie"); | 4222 headers.SetHeader("gamma", "charlie"); |
| 4265 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 4223 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| 4266 SpdySerializedFrame headers_frame( | 4224 SpdySerializedFrame headers_frame( |
| 4267 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 4225 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 4268 | 4226 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4296 EXPECT_EQ(1, visitor->headers_frame_count_); | 4254 EXPECT_EQ(1, visitor->headers_frame_count_); |
| 4297 EXPECT_EQ(1, visitor->data_frame_count_); | 4255 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4298 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4256 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4299 } | 4257 } |
| 4300 | 4258 |
| 4301 // Test that SpdyFramer stops after processing a full frame if | 4259 // Test that SpdyFramer stops after processing a full frame if |
| 4302 // process_single_input_frame is set. Input to ProcessInput has two frames, but | 4260 // process_single_input_frame is set. Input to ProcessInput has two frames, but |
| 4303 // only processes the first when we give it the first frame split at any point, | 4261 // only processes the first when we give it the first frame split at any point, |
| 4304 // or give it more than one frame in the input buffer. | 4262 // or give it more than one frame in the input buffer. |
| 4305 TEST_P(SpdyFramerTest, ProcessAtMostOneFrame) { | 4263 TEST_P(SpdyFramerTest, ProcessAtMostOneFrame) { |
| 4306 SpdyFramer framer; | 4264 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 4307 framer.set_process_single_input_frame(true); | 4265 framer.set_process_single_input_frame(true); |
| 4308 std::unique_ptr<TestSpdyVisitor> visitor; | 4266 std::unique_ptr<TestSpdyVisitor> visitor; |
| 4309 | 4267 |
| 4310 // Create two input frames. | 4268 // Create two input frames. |
| 4311 const char four_score[] = "Four score and ..."; | 4269 const char four_score[] = "Four score and ..."; |
| 4312 SpdyDataIR four_score_ir(1, four_score); | 4270 SpdyDataIR four_score_ir(1, four_score); |
| 4313 SpdySerializedFrame four_score_frame(framer.SerializeData(four_score_ir)); | 4271 SpdySerializedFrame four_score_frame(framer.SerializeData(four_score_ir)); |
| 4314 | 4272 |
| 4315 SpdyHeadersIR headers(2); | 4273 SpdyHeadersIR headers(2); |
| 4316 headers.SetHeader("alpha", "beta"); | 4274 headers.SetHeader("alpha", "beta"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4334 input_buffer.append(frame1.data(), frame1_size); | 4292 input_buffer.append(frame1.data(), frame1_size); |
| 4335 input_buffer.append(frame2.data(), frame2_size); | 4293 input_buffer.append(frame2.data(), frame2_size); |
| 4336 | 4294 |
| 4337 const char* buf = input_buffer.data(); | 4295 const char* buf = input_buffer.data(); |
| 4338 const size_t buf_size = input_buffer.size(); | 4296 const size_t buf_size = input_buffer.size(); |
| 4339 | 4297 |
| 4340 VLOG(1) << "buf_size = " << buf_size; | 4298 VLOG(1) << "buf_size = " << buf_size; |
| 4341 | 4299 |
| 4342 for (size_t first_size = 0; first_size <= buf_size; ++first_size) { | 4300 for (size_t first_size = 0; first_size <= buf_size; ++first_size) { |
| 4343 VLOG(1) << "first_size = " << first_size; | 4301 VLOG(1) << "first_size = " << first_size; |
| 4344 visitor.reset(new TestSpdyVisitor); | 4302 visitor.reset(new TestSpdyVisitor(SpdyFramer::DISABLE_COMPRESSION)); |
| 4345 framer.set_visitor(visitor.get()); | 4303 framer.set_visitor(visitor.get()); |
| 4346 | 4304 |
| 4347 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4305 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4348 | 4306 |
| 4349 size_t processed_first = framer.ProcessInput(buf, first_size); | 4307 size_t processed_first = framer.ProcessInput(buf, first_size); |
| 4350 if (first_size < frame1_size) { | 4308 if (first_size < frame1_size) { |
| 4351 EXPECT_EQ(first_size, processed_first); | 4309 EXPECT_EQ(first_size, processed_first); |
| 4352 | 4310 |
| 4353 if (first_size == 0) { | 4311 if (first_size == 0) { |
| 4354 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4312 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4377 | 4335 |
| 4378 EXPECT_EQ(1, visitor->data_frame_count_); | 4336 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4379 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4337 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4380 EXPECT_EQ(0, visitor->headers_frame_count_); | 4338 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4381 } | 4339 } |
| 4382 } | 4340 } |
| 4383 | 4341 |
| 4384 } // namespace test | 4342 } // namespace test |
| 4385 | 4343 |
| 4386 } // namespace net | 4344 } // namespace net |
| OLD | NEW |