| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // | 60 // |
| 61 // Returns a new decompressed SpdySerializedFrame. | 61 // Returns a new decompressed SpdySerializedFrame. |
| 62 template <class SpdyFrameType> | 62 template <class SpdyFrameType> |
| 63 static SpdySerializedFrame DecompressFrame(SpdyFramer* framer, | 63 static SpdySerializedFrame DecompressFrame(SpdyFramer* framer, |
| 64 const SpdyFrameType& frame) { | 64 const SpdyFrameType& frame) { |
| 65 DecompressionVisitor visitor; | 65 DecompressionVisitor visitor; |
| 66 framer->set_visitor(&visitor); | 66 framer->set_visitor(&visitor); |
| 67 CHECK_EQ(frame.size(), framer->ProcessInput(frame.data(), frame.size())); | 67 CHECK_EQ(frame.size(), framer->ProcessInput(frame.data(), frame.size())); |
| 68 CHECK_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer->state()); | 68 CHECK_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer->state()); |
| 69 framer->set_visitor(nullptr); | 69 framer->set_visitor(nullptr); |
| 70 SpdyFramer serializer(framer->protocol_version()); | 70 SpdyFramer serializer; |
| 71 serializer.set_enable_compression(false); | 71 serializer.set_enable_compression(false); |
| 72 return serializer.SerializeFrame(visitor.GetFrame()); | 72 return serializer.SerializeFrame(visitor.GetFrame()); |
| 73 } | 73 } |
| 74 | 74 |
| 75 class DecompressionVisitor : public SpdyFramerVisitorInterface { | 75 class DecompressionVisitor : public SpdyFramerVisitorInterface { |
| 76 public: | 76 public: |
| 77 DecompressionVisitor() : finished_(false) {} | 77 DecompressionVisitor() : finished_(false) {} |
| 78 | 78 |
| 79 const SpdyFrameIR& GetFrame() const { | 79 const SpdyFrameIR& GetFrame() const { |
| 80 CHECK(finished_); | 80 CHECK(finished_); |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 263 } |
| 264 }; | 264 }; |
| 265 | 265 |
| 266 class TestSpdyVisitor : public SpdyFramerVisitorInterface, | 266 class TestSpdyVisitor : public SpdyFramerVisitorInterface, |
| 267 public SpdyFramerDebugVisitorInterface { | 267 public SpdyFramerDebugVisitorInterface { |
| 268 public: | 268 public: |
| 269 // This is larger than our max frame size because header blocks that | 269 // This is larger than our max frame size because header blocks that |
| 270 // are too long can spill over into CONTINUATION frames. | 270 // are too long can spill over into CONTINUATION frames. |
| 271 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; | 271 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; |
| 272 | 272 |
| 273 explicit TestSpdyVisitor(SpdyMajorVersion version) | 273 TestSpdyVisitor() |
| 274 : framer_(version), | 274 : use_compression_(false), |
| 275 use_compression_(false), | |
| 276 error_count_(0), | 275 error_count_(0), |
| 277 headers_frame_count_(0), | 276 headers_frame_count_(0), |
| 278 push_promise_frame_count_(0), | 277 push_promise_frame_count_(0), |
| 279 goaway_count_(0), | 278 goaway_count_(0), |
| 280 setting_count_(0), | 279 setting_count_(0), |
| 281 settings_ack_sent_(0), | 280 settings_ack_sent_(0), |
| 282 settings_ack_received_(0), | 281 settings_ack_received_(0), |
| 283 continuation_count_(0), | 282 continuation_count_(0), |
| 284 altsvc_count_(0), | 283 altsvc_count_(0), |
| 285 priority_count_(0), | 284 priority_count_(0), |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 (rand() % std::min(input_remaining, kMaxReadSize)) + 1; | 506 (rand() % std::min(input_remaining, kMaxReadSize)) + 1; |
| 508 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); | 507 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); |
| 509 input_remaining -= bytes_processed; | 508 input_remaining -= bytes_processed; |
| 510 input_ptr += bytes_processed; | 509 input_ptr += bytes_processed; |
| 511 } | 510 } |
| 512 } | 511 } |
| 513 | 512 |
| 514 void InitHeaderStreaming(SpdyFrameType header_control_type, | 513 void InitHeaderStreaming(SpdyFrameType header_control_type, |
| 515 SpdyStreamId stream_id) { | 514 SpdyStreamId stream_id) { |
| 516 if (!SpdyConstants::IsValidFrameType( | 515 if (!SpdyConstants::IsValidFrameType( |
| 517 framer_.protocol_version(), | 516 SpdyConstants::SerializeFrameType(header_control_type))) { |
| 518 SpdyConstants::SerializeFrameType(framer_.protocol_version(), | |
| 519 header_control_type))) { | |
| 520 DLOG(FATAL) << "Attempted to init header streaming with " | 517 DLOG(FATAL) << "Attempted to init header streaming with " |
| 521 << "invalid control frame type: " << header_control_type; | 518 << "invalid control frame type: " << header_control_type; |
| 522 } | 519 } |
| 523 memset(header_buffer_.get(), 0, header_buffer_size_); | 520 memset(header_buffer_.get(), 0, header_buffer_size_); |
| 524 header_buffer_length_ = 0; | 521 header_buffer_length_ = 0; |
| 525 header_stream_id_ = stream_id; | 522 header_stream_id_ = stream_id; |
| 526 header_control_type_ = header_control_type; | 523 header_control_type_ = header_control_type; |
| 527 header_buffer_valid_ = true; | 524 header_buffer_valid_ = true; |
| 528 DCHECK_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 525 DCHECK_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
| 529 } | 526 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 }; | 595 }; |
| 599 | 596 |
| 600 // Retrieves serialized headers from a HEADERS frame. | 597 // Retrieves serialized headers from a HEADERS frame. |
| 601 StringPiece GetSerializedHeaders(const SpdySerializedFrame& frame, | 598 StringPiece GetSerializedHeaders(const SpdySerializedFrame& frame, |
| 602 const SpdyFramer& framer) { | 599 const SpdyFramer& framer) { |
| 603 SpdyFrameReader reader(frame.data(), frame.size()); | 600 SpdyFrameReader reader(frame.data(), frame.size()); |
| 604 reader.Seek(3); // Seek past the frame length. | 601 reader.Seek(3); // Seek past the frame length. |
| 605 | 602 |
| 606 uint8_t serialized_type; | 603 uint8_t serialized_type; |
| 607 reader.ReadUInt8(&serialized_type); | 604 reader.ReadUInt8(&serialized_type); |
| 608 SpdyFrameType type = | 605 SpdyFrameType type = SpdyConstants::ParseFrameType(serialized_type); |
| 609 SpdyConstants::ParseFrameType(framer.protocol_version(), serialized_type); | |
| 610 DCHECK_EQ(HEADERS, type); | 606 DCHECK_EQ(HEADERS, type); |
| 611 uint8_t flags; | 607 uint8_t flags; |
| 612 reader.ReadUInt8(&flags); | 608 reader.ReadUInt8(&flags); |
| 613 | 609 |
| 614 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), | 610 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), |
| 615 frame.size() - framer.GetHeadersMinimumSize()); | 611 frame.size() - framer.GetHeadersMinimumSize()); |
| 616 } | 612 } |
| 617 | 613 |
| 618 class SpdyFramerTest : public ::testing::Test { | 614 class SpdyFramerTest : public ::testing::Test { |
| 619 protected: | 615 protected: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 630 void CompareFrames(const string& description, | 626 void CompareFrames(const string& description, |
| 631 const SpdySerializedFrame& expected_frame, | 627 const SpdySerializedFrame& expected_frame, |
| 632 const SpdySerializedFrame& actual_frame) { | 628 const SpdySerializedFrame& actual_frame) { |
| 633 CompareCharArraysWithHexError( | 629 CompareCharArraysWithHexError( |
| 634 description, | 630 description, |
| 635 reinterpret_cast<const unsigned char*>(expected_frame.data()), | 631 reinterpret_cast<const unsigned char*>(expected_frame.data()), |
| 636 expected_frame.size(), | 632 expected_frame.size(), |
| 637 reinterpret_cast<const unsigned char*>(actual_frame.data()), | 633 reinterpret_cast<const unsigned char*>(actual_frame.data()), |
| 638 actual_frame.size()); | 634 actual_frame.size()); |
| 639 } | 635 } |
| 640 | |
| 641 // Version of SPDY protocol to be used. | |
| 642 SpdyMajorVersion spdy_version_ = HTTP2; | |
| 643 }; | 636 }; |
| 644 | 637 |
| 645 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 638 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
| 646 TEST_F(SpdyFramerTest, HeaderBlockInBuffer) { | 639 TEST_F(SpdyFramerTest, HeaderBlockInBuffer) { |
| 647 SpdyFramer framer(spdy_version_); | 640 SpdyFramer framer; |
| 648 framer.set_enable_compression(false); | 641 framer.set_enable_compression(false); |
| 649 | 642 |
| 650 // Encode the header block into a Headers frame. | 643 // Encode the header block into a Headers frame. |
| 651 SpdyHeadersIR headers(1); | 644 SpdyHeadersIR headers(1); |
| 652 headers.SetHeader("alpha", "beta"); | 645 headers.SetHeader("alpha", "beta"); |
| 653 headers.SetHeader("gamma", "charlie"); | 646 headers.SetHeader("gamma", "charlie"); |
| 654 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 647 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| 655 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 648 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 656 | 649 |
| 657 TestSpdyVisitor visitor(spdy_version_); | 650 TestSpdyVisitor visitor; |
| 658 visitor.use_compression_ = false; | 651 visitor.use_compression_ = false; |
| 659 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 652 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 660 frame.size()); | 653 frame.size()); |
| 661 | 654 |
| 662 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 655 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 663 EXPECT_EQ(headers.header_block(), visitor.headers_); | 656 EXPECT_EQ(headers.header_block(), visitor.headers_); |
| 664 } | 657 } |
| 665 | 658 |
| 666 // Test that if there's not a full frame, we fail to parse it. | 659 // Test that if there's not a full frame, we fail to parse it. |
| 667 TEST_F(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { | 660 TEST_F(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { |
| 668 SpdyFramer framer(spdy_version_); | 661 SpdyFramer framer; |
| 669 framer.set_enable_compression(false); | 662 framer.set_enable_compression(false); |
| 670 | 663 |
| 671 // Encode the header block into a Headers frame. | 664 // Encode the header block into a Headers frame. |
| 672 SpdyHeadersIR headers(1); | 665 SpdyHeadersIR headers(1); |
| 673 headers.SetHeader("alpha", "beta"); | 666 headers.SetHeader("alpha", "beta"); |
| 674 headers.SetHeader("gamma", "charlie"); | 667 headers.SetHeader("gamma", "charlie"); |
| 675 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 668 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 676 | 669 |
| 677 TestSpdyVisitor visitor(spdy_version_); | 670 TestSpdyVisitor visitor; |
| 678 visitor.use_compression_ = false; | 671 visitor.use_compression_ = false; |
| 679 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 672 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 680 frame.size() - 2); | 673 frame.size() - 2); |
| 681 | 674 |
| 682 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 675 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 683 EXPECT_EQ(0u, visitor.headers_.size()); | 676 EXPECT_EQ(0u, visitor.headers_.size()); |
| 684 } | 677 } |
| 685 | 678 |
| 686 // Test that we treat incoming upper-case or mixed-case header values as | 679 // Test that we treat incoming upper-case or mixed-case header values as |
| 687 // malformed. | 680 // malformed. |
| 688 TEST_F(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { | 681 TEST_F(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { |
| 689 SpdyFramer framer(spdy_version_); | 682 SpdyFramer framer; |
| 690 framer.set_enable_compression(false); | 683 framer.set_enable_compression(false); |
| 691 | 684 |
| 692 SpdyFrameBuilder frame(1024, spdy_version_); | 685 SpdyFrameBuilder frame(1024); |
| 693 frame.BeginNewFrame(framer, HEADERS, 0, 1); | 686 frame.BeginNewFrame(framer, HEADERS, 0, 1); |
| 694 frame.WriteUInt32(1); | 687 frame.WriteUInt32(1); |
| 695 frame.WriteStringPiece32("Name1"); | 688 frame.WriteStringPiece32("Name1"); |
| 696 frame.WriteStringPiece32("value1"); | 689 frame.WriteStringPiece32("value1"); |
| 697 frame.RewriteLength(framer); | 690 frame.RewriteLength(framer); |
| 698 | 691 |
| 699 SpdyFrameBuilder frame2(1024, spdy_version_); | 692 SpdyFrameBuilder frame2(1024); |
| 700 frame2.BeginNewFrame(framer, HEADERS, 0, 1); | 693 frame2.BeginNewFrame(framer, HEADERS, 0, 1); |
| 701 frame2.WriteUInt32(2); | 694 frame2.WriteUInt32(2); |
| 702 frame2.WriteStringPiece32("name1"); | 695 frame2.WriteStringPiece32("name1"); |
| 703 frame2.WriteStringPiece32("value1"); | 696 frame2.WriteStringPiece32("value1"); |
| 704 frame2.WriteStringPiece32("nAmE2"); | 697 frame2.WriteStringPiece32("nAmE2"); |
| 705 frame2.WriteStringPiece32("value2"); | 698 frame2.WriteStringPiece32("value2"); |
| 706 frame2.RewriteLength(framer); | 699 frame2.RewriteLength(framer); |
| 707 | 700 |
| 708 SpdySerializedFrame control_frame(frame.take()); | 701 SpdySerializedFrame control_frame(frame.take()); |
| 709 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); | 702 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); |
| 710 SpdySerializedFrame control_frame2(frame2.take()); | 703 SpdySerializedFrame control_frame2(frame2.take()); |
| 711 StringPiece serialized_headers2 = | 704 StringPiece serialized_headers2 = |
| 712 GetSerializedHeaders(control_frame2, framer); | 705 GetSerializedHeaders(control_frame2, framer); |
| 713 | 706 |
| 714 SpdyHeaderBlock new_headers; | 707 SpdyHeaderBlock new_headers; |
| 715 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 708 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 716 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 709 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 717 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 710 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 718 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); | 711 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); |
| 719 } | 712 } |
| 720 | 713 |
| 721 // Test that we can encode and decode stream dependency values in a header | 714 // Test that we can encode and decode stream dependency values in a header |
| 722 // frame. | 715 // frame. |
| 723 TEST_F(SpdyFramerTest, HeaderStreamDependencyValues) { | 716 TEST_F(SpdyFramerTest, HeaderStreamDependencyValues) { |
| 724 SpdyFramer framer(spdy_version_); | 717 SpdyFramer framer; |
| 725 framer.set_enable_compression(false); | 718 framer.set_enable_compression(false); |
| 726 | 719 |
| 727 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; | 720 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; |
| 728 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { | 721 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { |
| 729 const bool exclusive_test_array[] = {true, false}; | 722 const bool exclusive_test_array[] = {true, false}; |
| 730 for (bool exclusive : exclusive_test_array) { | 723 for (bool exclusive : exclusive_test_array) { |
| 731 SpdyHeadersIR headers(1); | 724 SpdyHeadersIR headers(1); |
| 732 headers.set_has_priority(true); | 725 headers.set_has_priority(true); |
| 733 headers.set_parent_stream_id(parent_stream_id); | 726 headers.set_parent_stream_id(parent_stream_id); |
| 734 headers.set_exclusive(exclusive); | 727 headers.set_exclusive(exclusive); |
| 735 SpdySerializedFrame frame( | 728 SpdySerializedFrame frame( |
| 736 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 729 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 737 | 730 |
| 738 TestSpdyVisitor visitor(spdy_version_); | 731 TestSpdyVisitor visitor; |
| 739 visitor.use_compression_ = false; | 732 visitor.use_compression_ = false; |
| 740 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 733 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 741 frame.size()); | 734 frame.size()); |
| 742 | 735 |
| 743 EXPECT_TRUE(visitor.header_has_priority_); | 736 EXPECT_TRUE(visitor.header_has_priority_); |
| 744 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); | 737 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); |
| 745 EXPECT_EQ(exclusive, visitor.header_exclusive_); | 738 EXPECT_EQ(exclusive, visitor.header_exclusive_); |
| 746 } | 739 } |
| 747 } | 740 } |
| 748 } | 741 } |
| 749 | 742 |
| 750 // Test that if we receive a frame with payload length field at the | 743 // Test that if we receive a frame with payload length field at the |
| 751 // advertised max size, we do not set an error in ProcessInput. | 744 // advertised max size, we do not set an error in ProcessInput. |
| 752 TEST_F(SpdyFramerTest, AcceptMaxFrameSizeSetting) { | 745 TEST_F(SpdyFramerTest, AcceptMaxFrameSizeSetting) { |
| 753 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 746 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 754 SpdyFramer framer(spdy_version_); | 747 SpdyFramer framer; |
| 755 framer.set_visitor(&visitor); | 748 framer.set_visitor(&visitor); |
| 756 | 749 |
| 757 // DATA frame with maximum allowed payload length. | 750 // DATA frame with maximum allowed payload length. |
| 758 unsigned char kH2FrameData[] = { | 751 unsigned char kH2FrameData[] = { |
| 759 0x00, 0x40, 0x00, // Length: 2^14 | 752 0x00, 0x40, 0x00, // Length: 2^14 |
| 760 0x00, // Type: HEADERS | 753 0x00, // Type: HEADERS |
| 761 0x00, // Flags: None | 754 0x00, // Flags: None |
| 762 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 755 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 763 0x00, 0x00, 0x00, 0x00, // Junk payload | 756 0x00, 0x00, 0x00, 0x00, // Junk payload |
| 764 }; | 757 }; |
| 765 | 758 |
| 766 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 759 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
| 767 sizeof(kH2FrameData), false); | 760 sizeof(kH2FrameData), false); |
| 768 | 761 |
| 769 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); | 762 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); |
| 770 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); | 763 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); |
| 771 framer.ProcessInput(frame.data(), frame.size()); | 764 framer.ProcessInput(frame.data(), frame.size()); |
| 772 EXPECT_FALSE(framer.HasError()); | 765 EXPECT_FALSE(framer.HasError()); |
| 773 } | 766 } |
| 774 | 767 |
| 775 // Test that if we receive a frame with payload length larger than the | 768 // Test that if we receive a frame with payload length larger than the |
| 776 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. | 769 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. |
| 777 TEST_F(SpdyFramerTest, ExceedMaxFrameSizeSetting) { | 770 TEST_F(SpdyFramerTest, ExceedMaxFrameSizeSetting) { |
| 778 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 771 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 779 SpdyFramer framer(spdy_version_); | 772 SpdyFramer framer; |
| 780 framer.set_visitor(&visitor); | 773 framer.set_visitor(&visitor); |
| 781 | 774 |
| 782 // DATA frame with too large payload length. | 775 // DATA frame with too large payload length. |
| 783 unsigned char kH2FrameData[] = { | 776 unsigned char kH2FrameData[] = { |
| 784 0x00, 0x40, 0x01, // Length: 2^14 + 1 | 777 0x00, 0x40, 0x01, // Length: 2^14 + 1 |
| 785 0x00, // Type: HEADERS | 778 0x00, // Type: HEADERS |
| 786 0x00, // Flags: None | 779 0x00, // Flags: None |
| 787 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 780 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 788 0x00, 0x00, 0x00, 0x00, // Junk payload | 781 0x00, 0x00, 0x00, 0x00, // Junk payload |
| 789 }; | 782 }; |
| 790 | 783 |
| 791 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 784 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
| 792 sizeof(kH2FrameData), false); | 785 sizeof(kH2FrameData), false); |
| 793 | 786 |
| 794 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 787 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 795 framer.ProcessInput(frame.data(), frame.size()); | 788 framer.ProcessInput(frame.data(), frame.size()); |
| 796 EXPECT_TRUE(framer.HasError()); | 789 EXPECT_TRUE(framer.HasError()); |
| 797 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) | 790 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) |
| 798 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 791 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 799 } | 792 } |
| 800 | 793 |
| 801 // Test that if we receive a DATA frame with padding length larger than the | 794 // Test that if we receive a DATA frame with padding length larger than the |
| 802 // payload length, we set an error of SPDY_INVALID_PADDING | 795 // payload length, we set an error of SPDY_INVALID_PADDING |
| 803 TEST_F(SpdyFramerTest, OversizedDataPaddingError) { | 796 TEST_F(SpdyFramerTest, OversizedDataPaddingError) { |
| 804 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 797 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 805 SpdyFramer framer(spdy_version_); | 798 SpdyFramer framer; |
| 806 framer.set_visitor(&visitor); | 799 framer.set_visitor(&visitor); |
| 807 | 800 |
| 808 // DATA frame with invalid padding length. | 801 // DATA frame with invalid padding length. |
| 809 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 802 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
| 810 // MSVC, where |char| is signed by default, which would not compile because of | 803 // MSVC, where |char| is signed by default, which would not compile because of |
| 811 // the element exceeding 127. | 804 // the element exceeding 127. |
| 812 unsigned char kH2FrameData[] = { | 805 unsigned char kH2FrameData[] = { |
| 813 0x00, 0x00, 0x05, // Length: 5 | 806 0x00, 0x00, 0x05, // Length: 5 |
| 814 0x00, // Type: DATA | 807 0x00, // Type: DATA |
| 815 0x09, // Flags: END_STREAM|PADDED | 808 0x09, // Flags: END_STREAM|PADDED |
| (...skipping 14 matching lines...) Expand all Loading... |
| 830 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 823 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 831 EXPECT_TRUE(framer.HasError()); | 824 EXPECT_TRUE(framer.HasError()); |
| 832 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 825 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 833 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 826 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 834 } | 827 } |
| 835 | 828 |
| 836 // Test that if we receive a DATA frame with padding length not larger than the | 829 // Test that if we receive a DATA frame with padding length not larger than the |
| 837 // payload length, we do not set an error of SPDY_INVALID_PADDING | 830 // payload length, we do not set an error of SPDY_INVALID_PADDING |
| 838 TEST_F(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { | 831 TEST_F(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { |
| 839 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 832 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 840 SpdyFramer framer(spdy_version_); | 833 SpdyFramer framer; |
| 841 framer.set_visitor(&visitor); | 834 framer.set_visitor(&visitor); |
| 842 | 835 |
| 843 // DATA frame with valid Padding length | 836 // DATA frame with valid Padding length |
| 844 char kH2FrameData[] = { | 837 char kH2FrameData[] = { |
| 845 0x00, 0x00, 0x05, // Length: 5 | 838 0x00, 0x00, 0x05, // Length: 5 |
| 846 0x00, // Type: DATA | 839 0x00, // Type: DATA |
| 847 0x08, // Flags: PADDED | 840 0x08, // Flags: PADDED |
| 848 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 841 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 849 0x04, // PadLen: 4 trailing bytes | 842 0x04, // PadLen: 4 trailing bytes |
| 850 0x00, 0x00, 0x00, 0x00, // Padding | 843 0x00, 0x00, 0x00, 0x00, // Padding |
| (...skipping 14 matching lines...) Expand all Loading... |
| 865 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 858 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 866 EXPECT_FALSE(framer.HasError()); | 859 EXPECT_FALSE(framer.HasError()); |
| 867 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 860 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 868 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 861 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 869 } | 862 } |
| 870 | 863 |
| 871 // Test that if we receive a HEADERS frame with padding length larger than the | 864 // Test that if we receive a HEADERS frame with padding length larger than the |
| 872 // payload length, we set an error of SPDY_INVALID_PADDING | 865 // payload length, we set an error of SPDY_INVALID_PADDING |
| 873 TEST_F(SpdyFramerTest, OversizedHeadersPaddingError) { | 866 TEST_F(SpdyFramerTest, OversizedHeadersPaddingError) { |
| 874 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 867 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 875 SpdyFramer framer(spdy_version_); | 868 SpdyFramer framer; |
| 876 framer.set_visitor(&visitor); | 869 framer.set_visitor(&visitor); |
| 877 | 870 |
| 878 // HEADERS frame with invalid padding length. | 871 // HEADERS frame with invalid padding length. |
| 879 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 872 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
| 880 // MSVC, where |char| is signed by default, which would not compile because of | 873 // MSVC, where |char| is signed by default, which would not compile because of |
| 881 // the element exceeding 127. | 874 // the element exceeding 127. |
| 882 unsigned char kH2FrameData[] = { | 875 unsigned char kH2FrameData[] = { |
| 883 0x00, 0x00, 0x05, // Length: 5 | 876 0x00, 0x00, 0x05, // Length: 5 |
| 884 0x01, // Type: HEADERS | 877 0x01, // Type: HEADERS |
| 885 0x08, // Flags: PADDED | 878 0x08, // Flags: PADDED |
| (...skipping 11 matching lines...) Expand all Loading... |
| 897 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 890 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 898 EXPECT_TRUE(framer.HasError()); | 891 EXPECT_TRUE(framer.HasError()); |
| 899 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 892 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
| 900 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 893 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 901 } | 894 } |
| 902 | 895 |
| 903 // Test that if we receive a HEADERS frame with padding length not larger | 896 // Test that if we receive a HEADERS frame with padding length not larger |
| 904 // than the payload length, we do not set an error of SPDY_INVALID_PADDING | 897 // than the payload length, we do not set an error of SPDY_INVALID_PADDING |
| 905 TEST_F(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { | 898 TEST_F(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { |
| 906 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 899 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 907 SpdyFramer framer(spdy_version_); | 900 SpdyFramer framer; |
| 908 framer.set_visitor(&visitor); | 901 framer.set_visitor(&visitor); |
| 909 | 902 |
| 910 // HEADERS frame with invalid Padding length | 903 // HEADERS frame with invalid Padding length |
| 911 char kH2FrameData[] = { | 904 char kH2FrameData[] = { |
| 912 0x00, 0x00, 0x05, // Length: 5 | 905 0x00, 0x00, 0x05, // Length: 5 |
| 913 0x01, // Type: HEADERS | 906 0x01, // Type: HEADERS |
| 914 0x08, // Flags: PADDED | 907 0x08, // Flags: PADDED |
| 915 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 908 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 916 0x04, // PadLen: 4 trailing bytes | 909 0x04, // PadLen: 4 trailing bytes |
| 917 0x00, 0x00, 0x00, 0x00, // Padding | 910 0x00, 0x00, 0x00, 0x00, // Padding |
| 918 }; | 911 }; |
| 919 | 912 |
| 920 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 913 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 921 | 914 |
| 922 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); | 915 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); |
| 923 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | 916 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); |
| 924 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 917 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 925 EXPECT_FALSE(framer.HasError()); | 918 EXPECT_FALSE(framer.HasError()); |
| 926 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 919 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 927 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 920 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 928 } | 921 } |
| 929 | 922 |
| 930 // Test that if we receive a DATA with stream ID zero, we signal an error | 923 // Test that if we receive a DATA with stream ID zero, we signal an error |
| 931 // (but don't crash). | 924 // (but don't crash). |
| 932 TEST_F(SpdyFramerTest, DataWithStreamIdZero) { | 925 TEST_F(SpdyFramerTest, DataWithStreamIdZero) { |
| 933 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 926 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 934 SpdyFramer framer(spdy_version_); | 927 SpdyFramer framer; |
| 935 framer.set_visitor(&visitor); | 928 framer.set_visitor(&visitor); |
| 936 | 929 |
| 937 const char bytes[] = "hello"; | 930 const char bytes[] = "hello"; |
| 938 SpdyDataIR data_ir(0, bytes); | 931 SpdyDataIR data_ir(0, bytes); |
| 939 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 932 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 940 | 933 |
| 941 // We shouldn't have to read the whole frame before we signal an error. | 934 // We shouldn't have to read the whole frame before we signal an error. |
| 942 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 935 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 943 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 936 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 944 EXPECT_TRUE(framer.HasError()); | 937 EXPECT_TRUE(framer.HasError()); |
| 945 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 938 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 946 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 939 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 947 } | 940 } |
| 948 | 941 |
| 949 // Test that if we receive a HEADERS with stream ID zero, we signal an error | 942 // Test that if we receive a HEADERS with stream ID zero, we signal an error |
| 950 // (but don't crash). | 943 // (but don't crash). |
| 951 TEST_F(SpdyFramerTest, HeadersWithStreamIdZero) { | 944 TEST_F(SpdyFramerTest, HeadersWithStreamIdZero) { |
| 952 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 945 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 953 SpdyFramer framer(spdy_version_); | 946 SpdyFramer framer; |
| 954 framer.set_visitor(&visitor); | 947 framer.set_visitor(&visitor); |
| 955 | 948 |
| 956 SpdyHeadersIR headers(0); | 949 SpdyHeadersIR headers(0); |
| 957 headers.SetHeader("alpha", "beta"); | 950 headers.SetHeader("alpha", "beta"); |
| 958 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 951 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 959 | 952 |
| 960 // We shouldn't have to read the whole frame before we signal an error. | 953 // We shouldn't have to read the whole frame before we signal an error. |
| 961 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 954 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 962 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 955 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 963 EXPECT_TRUE(framer.HasError()); | 956 EXPECT_TRUE(framer.HasError()); |
| 964 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 957 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 965 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 958 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 966 } | 959 } |
| 967 | 960 |
| 968 // Test that if we receive a PRIORITY with stream ID zero, we signal an error | 961 // Test that if we receive a PRIORITY with stream ID zero, we signal an error |
| 969 // (but don't crash). | 962 // (but don't crash). |
| 970 TEST_F(SpdyFramerTest, PriorityWithStreamIdZero) { | 963 TEST_F(SpdyFramerTest, PriorityWithStreamIdZero) { |
| 971 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 964 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 972 SpdyFramer framer(spdy_version_); | 965 SpdyFramer framer; |
| 973 framer.set_visitor(&visitor); | 966 framer.set_visitor(&visitor); |
| 974 | 967 |
| 975 SpdyPriorityIR priority_ir(0, 1, 16, true); | 968 SpdyPriorityIR priority_ir(0, 1, 16, true); |
| 976 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 969 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
| 977 | 970 |
| 978 // We shouldn't have to read the whole frame before we signal an error. | 971 // We shouldn't have to read the whole frame before we signal an error. |
| 979 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 972 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 980 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 973 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 981 EXPECT_TRUE(framer.HasError()); | 974 EXPECT_TRUE(framer.HasError()); |
| 982 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 975 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 983 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 976 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 984 } | 977 } |
| 985 | 978 |
| 986 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error | 979 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error |
| 987 // (but don't crash). | 980 // (but don't crash). |
| 988 TEST_F(SpdyFramerTest, RstStreamWithStreamIdZero) { | 981 TEST_F(SpdyFramerTest, RstStreamWithStreamIdZero) { |
| 989 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 982 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 990 SpdyFramer framer(spdy_version_); | 983 SpdyFramer framer; |
| 991 framer.set_visitor(&visitor); | 984 framer.set_visitor(&visitor); |
| 992 | 985 |
| 993 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); | 986 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); |
| 994 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); | 987 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); |
| 995 | 988 |
| 996 // We shouldn't have to read the whole frame before we signal an error. | 989 // We shouldn't have to read the whole frame before we signal an error. |
| 997 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 990 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 998 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 991 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 999 EXPECT_TRUE(framer.HasError()); | 992 EXPECT_TRUE(framer.HasError()); |
| 1000 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 993 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1001 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 994 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1002 } | 995 } |
| 1003 | 996 |
| 1004 // Test that if we receive a SETTINGS with stream ID other than zero, | 997 // Test that if we receive a SETTINGS with stream ID other than zero, |
| 1005 // we signal an error (but don't crash). | 998 // we signal an error (but don't crash). |
| 1006 TEST_F(SpdyFramerTest, SettingsWithStreamIdNotZero) { | 999 TEST_F(SpdyFramerTest, SettingsWithStreamIdNotZero) { |
| 1007 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1000 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1008 SpdyFramer framer(spdy_version_); | 1001 SpdyFramer framer; |
| 1009 framer.set_visitor(&visitor); | 1002 framer.set_visitor(&visitor); |
| 1010 | 1003 |
| 1011 // Settings frame with invalid StreamID of 0x01 | 1004 // Settings frame with invalid StreamID of 0x01 |
| 1012 char kH2FrameData[] = { | 1005 char kH2FrameData[] = { |
| 1013 0x00, 0x00, 0x06, // Length: 6 | 1006 0x00, 0x00, 0x06, // Length: 6 |
| 1014 0x04, // Type: SETTINGS | 1007 0x04, // Type: SETTINGS |
| 1015 0x00, // Flags: none | 1008 0x00, // Flags: none |
| 1016 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1009 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1017 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1010 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| 1018 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 | 1011 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 |
| 1019 }; | 1012 }; |
| 1020 | 1013 |
| 1021 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1014 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1022 | 1015 |
| 1023 // We shouldn't have to read the whole frame before we signal an error. | 1016 // We shouldn't have to read the whole frame before we signal an error. |
| 1024 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1017 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1025 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1018 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1026 EXPECT_TRUE(framer.HasError()); | 1019 EXPECT_TRUE(framer.HasError()); |
| 1027 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1020 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1028 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1021 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1029 } | 1022 } |
| 1030 | 1023 |
| 1031 // Test that if we receive a GOAWAY with stream ID other than zero, | 1024 // Test that if we receive a GOAWAY with stream ID other than zero, |
| 1032 // we signal an error (but don't crash). | 1025 // we signal an error (but don't crash). |
| 1033 TEST_F(SpdyFramerTest, GoawayWithStreamIdNotZero) { | 1026 TEST_F(SpdyFramerTest, GoawayWithStreamIdNotZero) { |
| 1034 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1027 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1035 SpdyFramer framer(spdy_version_); | 1028 SpdyFramer framer; |
| 1036 framer.set_visitor(&visitor); | 1029 framer.set_visitor(&visitor); |
| 1037 | 1030 |
| 1038 // GOAWAY frame with invalid StreamID of 0x01 | 1031 // GOAWAY frame with invalid StreamID of 0x01 |
| 1039 char kH2FrameData[] = { | 1032 char kH2FrameData[] = { |
| 1040 0x00, 0x00, 0x0a, // Length: 10 | 1033 0x00, 0x00, 0x0a, // Length: 10 |
| 1041 0x07, // Type: GOAWAY | 1034 0x07, // Type: GOAWAY |
| 1042 0x00, // Flags: none | 1035 0x00, // Flags: none |
| 1043 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1036 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1044 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1037 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 1045 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1038 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 1046 0x47, 0x41, // Description | 1039 0x47, 0x41, // Description |
| 1047 }; | 1040 }; |
| 1048 | 1041 |
| 1049 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1042 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1050 | 1043 |
| 1051 // We shouldn't have to read the whole frame before we signal an error. | 1044 // We shouldn't have to read the whole frame before we signal an error. |
| 1052 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1045 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1053 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1046 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1054 EXPECT_TRUE(framer.HasError()); | 1047 EXPECT_TRUE(framer.HasError()); |
| 1055 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1048 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1056 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1049 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1057 } | 1050 } |
| 1058 | 1051 |
| 1059 // Test that if we receive a CONTINUATION with stream ID zero, we signal an | 1052 // Test that if we receive a CONTINUATION with stream ID zero, we signal an |
| 1060 // SPDY_INVALID_STREAM_ID. | 1053 // SPDY_INVALID_STREAM_ID. |
| 1061 TEST_F(SpdyFramerTest, ContinuationWithStreamIdZero) { | 1054 TEST_F(SpdyFramerTest, ContinuationWithStreamIdZero) { |
| 1062 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1055 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1063 SpdyFramer framer(spdy_version_); | 1056 SpdyFramer framer; |
| 1064 framer.set_visitor(&visitor); | 1057 framer.set_visitor(&visitor); |
| 1065 | 1058 |
| 1066 SpdyContinuationIR continuation(0); | 1059 SpdyContinuationIR continuation(0); |
| 1067 auto some_nonsense_encoding = | 1060 auto some_nonsense_encoding = |
| 1068 base::MakeUnique<string>("some nonsense encoding"); | 1061 base::MakeUnique<string>("some nonsense encoding"); |
| 1069 continuation.take_encoding(std::move(some_nonsense_encoding)); | 1062 continuation.take_encoding(std::move(some_nonsense_encoding)); |
| 1070 continuation.set_end_headers(true); | 1063 continuation.set_end_headers(true); |
| 1071 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 1064 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 1072 | 1065 |
| 1073 // We shouldn't have to read the whole frame before we signal an error. | 1066 // We shouldn't have to read the whole frame before we signal an error. |
| 1074 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1067 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1075 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1068 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1076 EXPECT_TRUE(framer.HasError()); | 1069 EXPECT_TRUE(framer.HasError()); |
| 1077 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1070 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1078 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1071 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1079 } | 1072 } |
| 1080 | 1073 |
| 1081 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 1074 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an |
| 1082 // SPDY_INVALID_STREAM_ID. | 1075 // SPDY_INVALID_STREAM_ID. |
| 1083 TEST_F(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 1076 TEST_F(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
| 1084 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1077 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1085 SpdyFramer framer(spdy_version_); | 1078 SpdyFramer framer; |
| 1086 framer.set_visitor(&visitor); | 1079 framer.set_visitor(&visitor); |
| 1087 | 1080 |
| 1088 SpdyPushPromiseIR push_promise(0, 4); | 1081 SpdyPushPromiseIR push_promise(0, 4); |
| 1089 push_promise.SetHeader("alpha", "beta"); | 1082 push_promise.SetHeader("alpha", "beta"); |
| 1090 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1083 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 1091 | 1084 |
| 1092 // We shouldn't have to read the whole frame before we signal an error. | 1085 // We shouldn't have to read the whole frame before we signal an error. |
| 1093 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1086 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1094 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1087 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1095 EXPECT_TRUE(framer.HasError()); | 1088 EXPECT_TRUE(framer.HasError()); |
| 1096 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1089 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
| 1097 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1090 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1098 } | 1091 } |
| 1099 | 1092 |
| 1100 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 1093 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
| 1101 // signal SPDY_INVALID_STREAM_ID. | 1094 // signal SPDY_INVALID_STREAM_ID. |
| 1102 TEST_F(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 1095 TEST_F(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
| 1103 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1096 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1104 SpdyFramer framer(spdy_version_); | 1097 SpdyFramer framer; |
| 1105 framer.set_visitor(&visitor); | 1098 framer.set_visitor(&visitor); |
| 1106 | 1099 |
| 1107 SpdyPushPromiseIR push_promise(3, 0); | 1100 SpdyPushPromiseIR push_promise(3, 0); |
| 1108 push_promise.SetHeader("alpha", "beta"); | 1101 push_promise.SetHeader("alpha", "beta"); |
| 1109 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1102 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 1110 | 1103 |
| 1111 // We shouldn't have to read the whole frame before we signal an error. | 1104 // We shouldn't have to read the whole frame before we signal an error. |
| 1112 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1105 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1113 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1106 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1114 EXPECT_TRUE(framer.HasError()); | 1107 EXPECT_TRUE(framer.HasError()); |
| 1115 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 1108 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 1116 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1109 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 1117 } | 1110 } |
| 1118 | 1111 |
| 1119 TEST_F(SpdyFramerTest, DuplicateHeader) { | 1112 TEST_F(SpdyFramerTest, DuplicateHeader) { |
| 1120 SpdyFramer framer(spdy_version_); | 1113 SpdyFramer framer; |
| 1121 // Frame builder with plentiful buffer size. | 1114 // Frame builder with plentiful buffer size. |
| 1122 SpdyFrameBuilder frame(1024, spdy_version_); | 1115 SpdyFrameBuilder frame(1024); |
| 1123 frame.BeginNewFrame(framer, HEADERS, 0, 3); | 1116 frame.BeginNewFrame(framer, HEADERS, 0, 3); |
| 1124 | 1117 |
| 1125 frame.WriteUInt32(2); // Number of headers. | 1118 frame.WriteUInt32(2); // Number of headers. |
| 1126 frame.WriteStringPiece32("name"); | 1119 frame.WriteStringPiece32("name"); |
| 1127 frame.WriteStringPiece32("value1"); | 1120 frame.WriteStringPiece32("value1"); |
| 1128 frame.WriteStringPiece32("name"); | 1121 frame.WriteStringPiece32("name"); |
| 1129 frame.WriteStringPiece32("value2"); | 1122 frame.WriteStringPiece32("value2"); |
| 1130 // write the length | 1123 // write the length |
| 1131 frame.RewriteLength(framer); | 1124 frame.RewriteLength(framer); |
| 1132 | 1125 |
| 1133 SpdyHeaderBlock new_headers; | 1126 SpdyHeaderBlock new_headers; |
| 1134 framer.set_enable_compression(false); | 1127 framer.set_enable_compression(false); |
| 1135 SpdySerializedFrame control_frame(frame.take()); | 1128 SpdySerializedFrame control_frame(frame.take()); |
| 1136 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); | 1129 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); |
| 1137 // This should fail because duplicate headers are verboten by the spec. | 1130 // This should fail because duplicate headers are verboten by the spec. |
| 1138 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 1131 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 1139 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 1132 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 1140 } | 1133 } |
| 1141 | 1134 |
| 1142 TEST_F(SpdyFramerTest, MultiValueHeader) { | 1135 TEST_F(SpdyFramerTest, MultiValueHeader) { |
| 1143 SpdyFramer framer(spdy_version_); | 1136 SpdyFramer framer; |
| 1144 // Frame builder with plentiful buffer size. | 1137 // Frame builder with plentiful buffer size. |
| 1145 SpdyFrameBuilder frame(1024, spdy_version_); | 1138 SpdyFrameBuilder frame(1024); |
| 1146 frame.BeginNewFrame(framer, HEADERS, | 1139 frame.BeginNewFrame(framer, HEADERS, |
| 1147 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); | 1140 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); |
| 1148 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. | 1141 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. |
| 1149 frame.WriteUInt8(255); // Priority weight. | 1142 frame.WriteUInt8(255); // Priority weight. |
| 1150 | 1143 |
| 1151 string value("value1\0value2", 13); | 1144 string value("value1\0value2", 13); |
| 1152 // TODO(jgraettinger): If this pattern appears again, move to test class. | 1145 // TODO(jgraettinger): If this pattern appears again, move to test class. |
| 1153 SpdyHeaderBlock header_set; | 1146 SpdyHeaderBlock header_set; |
| 1154 header_set["name"] = value; | 1147 header_set["name"] = value; |
| 1155 string buffer; | 1148 string buffer; |
| 1156 HpackEncoder encoder(ObtainHpackHuffmanTable()); | 1149 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
| 1157 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); | 1150 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); |
| 1158 frame.WriteBytes(&buffer[0], buffer.size()); | 1151 frame.WriteBytes(&buffer[0], buffer.size()); |
| 1159 // write the length | 1152 // write the length |
| 1160 frame.RewriteLength(framer); | 1153 frame.RewriteLength(framer); |
| 1161 | 1154 |
| 1162 framer.set_enable_compression(false); | 1155 framer.set_enable_compression(false); |
| 1163 SpdySerializedFrame control_frame(frame.take()); | 1156 SpdySerializedFrame control_frame(frame.take()); |
| 1164 | 1157 |
| 1165 TestSpdyVisitor visitor(spdy_version_); | 1158 TestSpdyVisitor visitor; |
| 1166 visitor.use_compression_ = false; | 1159 visitor.use_compression_ = false; |
| 1167 visitor.SimulateInFramer( | 1160 visitor.SimulateInFramer( |
| 1168 reinterpret_cast<unsigned char*>(control_frame.data()), | 1161 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 1169 control_frame.size()); | 1162 control_frame.size()); |
| 1170 | 1163 |
| 1171 EXPECT_THAT(visitor.headers_, | 1164 EXPECT_THAT(visitor.headers_, |
| 1172 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); | 1165 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); |
| 1173 } | 1166 } |
| 1174 | 1167 |
| 1175 TEST_F(SpdyFramerTest, CompressEmptyHeaders) { | 1168 TEST_F(SpdyFramerTest, CompressEmptyHeaders) { |
| 1176 // See crbug.com/172383 | 1169 // See crbug.com/172383 |
| 1177 SpdyHeadersIR headers(1); | 1170 SpdyHeadersIR headers(1); |
| 1178 headers.SetHeader("server", "SpdyServer 1.0"); | 1171 headers.SetHeader("server", "SpdyServer 1.0"); |
| 1179 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 1172 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| 1180 headers.SetHeader("status", "200"); | 1173 headers.SetHeader("status", "200"); |
| 1181 headers.SetHeader("version", "HTTP/1.1"); | 1174 headers.SetHeader("version", "HTTP/1.1"); |
| 1182 headers.SetHeader("content-type", "text/html"); | 1175 headers.SetHeader("content-type", "text/html"); |
| 1183 headers.SetHeader("content-length", "12"); | 1176 headers.SetHeader("content-length", "12"); |
| 1184 headers.SetHeader("x-empty-header", ""); | 1177 headers.SetHeader("x-empty-header", ""); |
| 1185 | 1178 |
| 1186 SpdyFramer framer(spdy_version_); | 1179 SpdyFramer framer; |
| 1187 framer.set_enable_compression(true); | 1180 framer.set_enable_compression(true); |
| 1188 SpdySerializedFrame frame1( | 1181 SpdySerializedFrame frame1( |
| 1189 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1182 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 1190 } | 1183 } |
| 1191 | 1184 |
| 1192 TEST_F(SpdyFramerTest, Basic) { | 1185 TEST_F(SpdyFramerTest, Basic) { |
| 1193 // Send HEADERS frames with PRIORITY and END_HEADERS set. | 1186 // Send HEADERS frames with PRIORITY and END_HEADERS set. |
| 1194 // frame-format off | 1187 // frame-format off |
| 1195 const unsigned char kH2Input[] = { | 1188 const unsigned char kH2Input[] = { |
| 1196 0x00, 0x00, 0x05, // Length: 5 | 1189 0x00, 0x00, 0x05, // Length: 5 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 1239 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 1247 | 1240 |
| 1248 0x00, 0x00, 0x04, // Length: 4 | 1241 0x00, 0x00, 0x04, // Length: 4 |
| 1249 0x03, // Type: RST_STREAM | 1242 0x03, // Type: RST_STREAM |
| 1250 0x00, // Flags: none | 1243 0x00, // Flags: none |
| 1251 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 1244 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 1252 0x00, 0x00, 0x00, 0x08, // Error: CANCEL | 1245 0x00, 0x00, 0x00, 0x08, // Error: CANCEL |
| 1253 }; | 1246 }; |
| 1254 // frame-format on | 1247 // frame-format on |
| 1255 | 1248 |
| 1256 TestSpdyVisitor visitor(spdy_version_); | 1249 TestSpdyVisitor visitor; |
| 1257 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | 1250 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
| 1258 | 1251 |
| 1259 EXPECT_EQ(24, visitor.data_bytes_); | 1252 EXPECT_EQ(24, visitor.data_bytes_); |
| 1260 EXPECT_EQ(0, visitor.error_count_); | 1253 EXPECT_EQ(0, visitor.error_count_); |
| 1261 EXPECT_EQ(2, visitor.fin_frame_count_); | 1254 EXPECT_EQ(2, visitor.fin_frame_count_); |
| 1262 | 1255 |
| 1263 EXPECT_EQ(3, visitor.headers_frame_count_); | 1256 EXPECT_EQ(3, visitor.headers_frame_count_); |
| 1264 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); | 1257 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); |
| 1265 | 1258 |
| 1266 EXPECT_EQ(0, visitor.fin_flag_count_); | 1259 EXPECT_EQ(0, visitor.fin_flag_count_); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1296 0xde, 0xad, 0xbe, 0xef, // | 1289 0xde, 0xad, 0xbe, 0xef, // |
| 1297 | 1290 |
| 1298 0x00, 0x00, 0x04, // Length: 4 | 1291 0x00, 0x00, 0x04, // Length: 4 |
| 1299 0x00, // Type: DATA | 1292 0x00, // Type: DATA |
| 1300 0x01, // Flags: END_STREAM | 1293 0x01, // Flags: END_STREAM |
| 1301 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1294 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1302 0xde, 0xad, 0xbe, 0xef, // Payload | 1295 0xde, 0xad, 0xbe, 0xef, // Payload |
| 1303 }; | 1296 }; |
| 1304 // frame-format on | 1297 // frame-format on |
| 1305 | 1298 |
| 1306 TestSpdyVisitor visitor(spdy_version_); | 1299 TestSpdyVisitor visitor; |
| 1307 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | 1300 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
| 1308 | 1301 |
| 1309 EXPECT_EQ(0, visitor.error_count_); | 1302 EXPECT_EQ(0, visitor.error_count_); |
| 1310 EXPECT_EQ(2, visitor.headers_frame_count_); | 1303 EXPECT_EQ(2, visitor.headers_frame_count_); |
| 1311 EXPECT_EQ(16, visitor.data_bytes_); | 1304 EXPECT_EQ(16, visitor.data_bytes_); |
| 1312 EXPECT_EQ(0, visitor.fin_frame_count_); | 1305 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1313 EXPECT_EQ(0, visitor.fin_flag_count_); | 1306 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1314 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1307 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1315 EXPECT_EQ(2, visitor.data_frame_count_); | 1308 EXPECT_EQ(2, visitor.data_frame_count_); |
| 1316 } | 1309 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1327 0x82, // Weight: 131 | 1320 0x82, // Weight: 131 |
| 1328 | 1321 |
| 1329 0x00, 0x00, 0x01, // Length: 1 | 1322 0x00, 0x00, 0x01, // Length: 1 |
| 1330 0x01, // Type: HEADERS | 1323 0x01, // Type: HEADERS |
| 1331 0x05, // Flags: END_STREAM|END_HEADERS | 1324 0x05, // Flags: END_STREAM|END_HEADERS |
| 1332 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1325 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1333 0x8c, // :status: 200 | 1326 0x8c, // :status: 200 |
| 1334 }; | 1327 }; |
| 1335 // frame-format on | 1328 // frame-format on |
| 1336 | 1329 |
| 1337 TestSpdyVisitor visitor(spdy_version_); | 1330 TestSpdyVisitor visitor; |
| 1338 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | 1331 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
| 1339 | 1332 |
| 1340 EXPECT_EQ(0, visitor.error_count_); | 1333 EXPECT_EQ(0, visitor.error_count_); |
| 1341 EXPECT_EQ(2, visitor.headers_frame_count_); | 1334 EXPECT_EQ(2, visitor.headers_frame_count_); |
| 1342 EXPECT_EQ(0, visitor.data_bytes_); | 1335 EXPECT_EQ(0, visitor.data_bytes_); |
| 1343 EXPECT_EQ(0, visitor.fin_frame_count_); | 1336 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1344 EXPECT_EQ(1, visitor.fin_flag_count_); | 1337 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 1345 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1338 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1346 EXPECT_EQ(0, visitor.data_frame_count_); | 1339 EXPECT_EQ(0, visitor.data_frame_count_); |
| 1347 } | 1340 } |
| 1348 | 1341 |
| 1349 // Verify we can decompress the stream even if handed over to the | 1342 // Verify we can decompress the stream even if handed over to the |
| 1350 // framer 1 byte at a time. | 1343 // framer 1 byte at a time. |
| 1351 TEST_F(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { | 1344 TEST_F(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { |
| 1352 SpdyFramer framer(spdy_version_); | 1345 SpdyFramer framer; |
| 1353 | 1346 |
| 1354 framer.set_enable_compression(true); | 1347 framer.set_enable_compression(true); |
| 1355 | 1348 |
| 1356 const char kHeader1[] = "header1"; | 1349 const char kHeader1[] = "header1"; |
| 1357 const char kHeader2[] = "header2"; | 1350 const char kHeader2[] = "header2"; |
| 1358 const char kValue1[] = "value1"; | 1351 const char kValue1[] = "value1"; |
| 1359 const char kValue2[] = "value2"; | 1352 const char kValue2[] = "value2"; |
| 1360 | 1353 |
| 1361 SpdyHeadersIR headers(1); | 1354 SpdyHeadersIR headers(1); |
| 1362 headers.SetHeader(kHeader1, kValue1); | 1355 headers.SetHeader(kHeader1, kValue1); |
| 1363 headers.SetHeader(kHeader2, kValue2); | 1356 headers.SetHeader(kHeader2, kValue2); |
| 1364 SpdySerializedFrame headers_frame( | 1357 SpdySerializedFrame headers_frame( |
| 1365 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1358 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 1366 | 1359 |
| 1367 const char bytes[] = "this is a test test test test test!"; | 1360 const char bytes[] = "this is a test test test test test!"; |
| 1368 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); | 1361 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); |
| 1369 data_ir.set_fin(true); | 1362 data_ir.set_fin(true); |
| 1370 SpdySerializedFrame send_frame(framer.SerializeData(data_ir)); | 1363 SpdySerializedFrame send_frame(framer.SerializeData(data_ir)); |
| 1371 | 1364 |
| 1372 // Run the inputs through the framer. | 1365 // Run the inputs through the framer. |
| 1373 TestSpdyVisitor visitor(spdy_version_); | 1366 TestSpdyVisitor visitor; |
| 1374 visitor.use_compression_ = true; | 1367 visitor.use_compression_ = true; |
| 1375 const unsigned char* data; | 1368 const unsigned char* data; |
| 1376 data = reinterpret_cast<const unsigned char*>(headers_frame.data()); | 1369 data = reinterpret_cast<const unsigned char*>(headers_frame.data()); |
| 1377 for (size_t idx = 0; idx < headers_frame.size(); ++idx) { | 1370 for (size_t idx = 0; idx < headers_frame.size(); ++idx) { |
| 1378 visitor.SimulateInFramer(data + idx, 1); | 1371 visitor.SimulateInFramer(data + idx, 1); |
| 1379 ASSERT_EQ(0, visitor.error_count_); | 1372 ASSERT_EQ(0, visitor.error_count_); |
| 1380 } | 1373 } |
| 1381 data = reinterpret_cast<const unsigned char*>(send_frame.data()); | 1374 data = reinterpret_cast<const unsigned char*>(send_frame.data()); |
| 1382 for (size_t idx = 0; idx < send_frame.size(); ++idx) { | 1375 for (size_t idx = 0; idx < send_frame.size(); ++idx) { |
| 1383 visitor.SimulateInFramer(data + idx, 1); | 1376 visitor.SimulateInFramer(data + idx, 1); |
| 1384 ASSERT_EQ(0, visitor.error_count_); | 1377 ASSERT_EQ(0, visitor.error_count_); |
| 1385 } | 1378 } |
| 1386 | 1379 |
| 1387 EXPECT_EQ(0, visitor.error_count_); | 1380 EXPECT_EQ(0, visitor.error_count_); |
| 1388 EXPECT_EQ(1, visitor.headers_frame_count_); | 1381 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 1389 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); | 1382 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); |
| 1390 EXPECT_EQ(0, visitor.fin_frame_count_); | 1383 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1391 EXPECT_EQ(0, visitor.fin_flag_count_); | 1384 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1392 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1385 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 1393 EXPECT_EQ(1, visitor.data_frame_count_); | 1386 EXPECT_EQ(1, visitor.data_frame_count_); |
| 1394 } | 1387 } |
| 1395 | 1388 |
| 1396 TEST_F(SpdyFramerTest, WindowUpdateFrame) { | 1389 TEST_F(SpdyFramerTest, WindowUpdateFrame) { |
| 1397 SpdyFramer framer(spdy_version_); | 1390 SpdyFramer framer; |
| 1398 SpdySerializedFrame frame( | 1391 SpdySerializedFrame frame( |
| 1399 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); | 1392 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); |
| 1400 | 1393 |
| 1401 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; | 1394 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; |
| 1402 const unsigned char kH2FrameData[] = { | 1395 const unsigned char kH2FrameData[] = { |
| 1403 0x00, 0x00, 0x04, // Length: 4 | 1396 0x00, 0x00, 0x04, // Length: 4 |
| 1404 0x08, // Type: WINDOW_UPDATE | 1397 0x08, // Type: WINDOW_UPDATE |
| 1405 0x00, // Flags: none | 1398 0x00, // Flags: none |
| 1406 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1399 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1407 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 | 1400 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 |
| 1408 }; | 1401 }; |
| 1409 | 1402 |
| 1410 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1403 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1411 } | 1404 } |
| 1412 | 1405 |
| 1413 TEST_F(SpdyFramerTest, CreateDataFrame) { | 1406 TEST_F(SpdyFramerTest, CreateDataFrame) { |
| 1414 SpdyFramer framer(spdy_version_); | 1407 SpdyFramer framer; |
| 1415 | 1408 |
| 1416 { | 1409 { |
| 1417 const char kDescription[] = "'hello' data frame, no FIN"; | 1410 const char kDescription[] = "'hello' data frame, no FIN"; |
| 1418 // frame-format off | 1411 // frame-format off |
| 1419 const unsigned char kH2FrameData[] = { | 1412 const unsigned char kH2FrameData[] = { |
| 1420 0x00, 0x00, 0x05, // Length: 5 | 1413 0x00, 0x00, 0x05, // Length: 5 |
| 1421 0x00, // Type: DATA | 1414 0x00, // Type: DATA |
| 1422 0x00, // Flags: none | 1415 0x00, // Flags: none |
| 1423 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1416 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1424 'h', 'e', 'l', 'l', // Payload | 1417 'h', 'e', 'l', 'l', // Payload |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 0x6f, // | 1599 0x6f, // |
| 1607 }; | 1600 }; |
| 1608 SpdyDataIR data_ir(0x7fffffff, "hello"); | 1601 SpdyDataIR data_ir(0x7fffffff, "hello"); |
| 1609 data_ir.set_fin(true); | 1602 data_ir.set_fin(true); |
| 1610 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1603 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 1611 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1604 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1612 } | 1605 } |
| 1613 } | 1606 } |
| 1614 | 1607 |
| 1615 TEST_F(SpdyFramerTest, CreateRstStream) { | 1608 TEST_F(SpdyFramerTest, CreateRstStream) { |
| 1616 SpdyFramer framer(spdy_version_); | 1609 SpdyFramer framer; |
| 1617 | 1610 |
| 1618 { | 1611 { |
| 1619 const char kDescription[] = "RST_STREAM frame"; | 1612 const char kDescription[] = "RST_STREAM frame"; |
| 1620 const unsigned char kH2FrameData[] = { | 1613 const unsigned char kH2FrameData[] = { |
| 1621 0x00, 0x00, 0x04, // Length: 4 | 1614 0x00, 0x00, 0x04, // Length: 4 |
| 1622 0x03, // Type: RST_STREAM | 1615 0x03, // Type: RST_STREAM |
| 1623 0x00, // Flags: none | 1616 0x00, // Flags: none |
| 1624 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1617 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1625 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR | 1618 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR |
| 1626 }; | 1619 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1652 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1645 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
| 1653 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1646 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
| 1654 }; | 1647 }; |
| 1655 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); | 1648 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); |
| 1656 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1649 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 1657 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1650 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1658 } | 1651 } |
| 1659 } | 1652 } |
| 1660 | 1653 |
| 1661 TEST_F(SpdyFramerTest, CreateSettings) { | 1654 TEST_F(SpdyFramerTest, CreateSettings) { |
| 1662 SpdyFramer framer(spdy_version_); | 1655 SpdyFramer framer; |
| 1663 | 1656 |
| 1664 { | 1657 { |
| 1665 const char kDescription[] = "Network byte order SETTINGS frame"; | 1658 const char kDescription[] = "Network byte order SETTINGS frame"; |
| 1666 | 1659 |
| 1667 const unsigned char kH2FrameData[] = { | 1660 const unsigned char kH2FrameData[] = { |
| 1668 0x00, 0x00, 0x06, // Length: 6 | 1661 0x00, 0x00, 0x06, // Length: 6 |
| 1669 0x04, // Type: SETTINGS | 1662 0x04, // Type: SETTINGS |
| 1670 0x00, // Flags: none | 1663 0x00, // Flags: none |
| 1671 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1664 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1672 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1665 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1699 0x00, 0x00, 0x00, 0x07, // Value: 7 | 1692 0x00, 0x00, 0x00, 0x07, // Value: 7 |
| 1700 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1693 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| 1701 0x00, 0x00, 0x00, 0x08, // Value: 8 | 1694 0x00, 0x00, 0x00, 0x08, // Value: 8 |
| 1702 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 1695 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 1703 0x00, 0x00, 0x00, 0x05, // Value: 5 | 1696 0x00, 0x00, 0x00, 0x05, // Value: 5 |
| 1704 0x00, 0x02, // Param: ENABLE_PUSH | 1697 0x00, 0x02, // Param: ENABLE_PUSH |
| 1705 0x00, 0x00, 0x00, 0x06, // Value: 6 | 1698 0x00, 0x00, 0x00, 0x06, // Value: 6 |
| 1706 }; | 1699 }; |
| 1707 | 1700 |
| 1708 SpdySettingsIR settings_ir; | 1701 SpdySettingsIR settings_ir; |
| 1709 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), | 1702 settings_ir.AddSetting(SpdyConstants::ParseSettingId(1), |
| 1710 false, // persist | 1703 false, // persist |
| 1711 false, // persisted | 1704 false, // persisted |
| 1712 5); | 1705 5); |
| 1713 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), | 1706 settings_ir.AddSetting(SpdyConstants::ParseSettingId(2), |
| 1714 false, // persist | 1707 false, // persist |
| 1715 false, // persisted | 1708 false, // persisted |
| 1716 6); | 1709 6); |
| 1717 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), | 1710 settings_ir.AddSetting(SpdyConstants::ParseSettingId(3), |
| 1718 false, // persist | 1711 false, // persist |
| 1719 false, // persisted | 1712 false, // persisted |
| 1720 7); | 1713 7); |
| 1721 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4), | 1714 settings_ir.AddSetting(SpdyConstants::ParseSettingId(4), |
| 1722 false, // persist | 1715 false, // persist |
| 1723 false, // persisted | 1716 false, // persisted |
| 1724 8); | 1717 8); |
| 1725 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1718 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 1726 | 1719 |
| 1727 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1720 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1728 } | 1721 } |
| 1729 | 1722 |
| 1730 { | 1723 { |
| 1731 const char kDescription[] = "Empty SETTINGS frame"; | 1724 const char kDescription[] = "Empty SETTINGS frame"; |
| 1732 | 1725 |
| 1733 const unsigned char kH2FrameData[] = { | 1726 const unsigned char kH2FrameData[] = { |
| 1734 0x00, 0x00, 0x00, // Length: 0 | 1727 0x00, 0x00, 0x00, // Length: 0 |
| 1735 0x04, // Type: SETTINGS | 1728 0x04, // Type: SETTINGS |
| 1736 0x00, // Flags: none | 1729 0x00, // Flags: none |
| 1737 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1730 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1738 }; | 1731 }; |
| 1739 SpdySettingsIR settings_ir; | 1732 SpdySettingsIR settings_ir; |
| 1740 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1733 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 1741 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1734 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1742 } | 1735 } |
| 1743 } | 1736 } |
| 1744 | 1737 |
| 1745 TEST_F(SpdyFramerTest, CreatePingFrame) { | 1738 TEST_F(SpdyFramerTest, CreatePingFrame) { |
| 1746 SpdyFramer framer(spdy_version_); | 1739 SpdyFramer framer; |
| 1747 | 1740 |
| 1748 { | 1741 { |
| 1749 const char kDescription[] = "PING frame"; | 1742 const char kDescription[] = "PING frame"; |
| 1750 const unsigned char kH2FrameData[] = { | 1743 const unsigned char kH2FrameData[] = { |
| 1751 0x00, 0x00, 0x08, // Length: 8 | 1744 0x00, 0x00, 0x08, // Length: 8 |
| 1752 0x06, // Type: PING | 1745 0x06, // Type: PING |
| 1753 0x00, // Flags: none | 1746 0x00, // Flags: none |
| 1754 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1747 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1755 0x12, 0x34, 0x56, 0x78, // Opaque | 1748 0x12, 0x34, 0x56, 0x78, // Opaque |
| 1756 0x9a, 0xbc, 0xde, 0xff, // Data | 1749 0x9a, 0xbc, 0xde, 0xff, // Data |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1773 | 1766 |
| 1774 // Tests SpdyPingIR when the ping is an ack. | 1767 // Tests SpdyPingIR when the ping is an ack. |
| 1775 ping_ir.set_is_ack(true); | 1768 ping_ir.set_is_ack(true); |
| 1776 frame = framer.SerializePing(ping_ir); | 1769 frame = framer.SerializePing(ping_ir); |
| 1777 CompareFrame(kDescription, frame, kH2FrameDataWithAck, | 1770 CompareFrame(kDescription, frame, kH2FrameDataWithAck, |
| 1778 arraysize(kH2FrameDataWithAck)); | 1771 arraysize(kH2FrameDataWithAck)); |
| 1779 } | 1772 } |
| 1780 } | 1773 } |
| 1781 | 1774 |
| 1782 TEST_F(SpdyFramerTest, CreateGoAway) { | 1775 TEST_F(SpdyFramerTest, CreateGoAway) { |
| 1783 SpdyFramer framer(spdy_version_); | 1776 SpdyFramer framer; |
| 1784 | 1777 |
| 1785 { | 1778 { |
| 1786 const char kDescription[] = "GOAWAY frame"; | 1779 const char kDescription[] = "GOAWAY frame"; |
| 1787 const unsigned char kH2FrameData[] = { | 1780 const unsigned char kH2FrameData[] = { |
| 1788 0x00, 0x00, 0x0a, // Length: 10 | 1781 0x00, 0x00, 0x0a, // Length: 10 |
| 1789 0x07, // Type: GOAWAY | 1782 0x07, // Type: GOAWAY |
| 1790 0x00, // Flags: none | 1783 0x00, // Flags: none |
| 1791 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1784 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1792 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1785 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 1793 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1786 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1809 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1802 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
| 1810 0x47, 0x41, // Description | 1803 0x47, 0x41, // Description |
| 1811 }; | 1804 }; |
| 1812 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); | 1805 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); |
| 1813 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 1806 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
| 1814 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1807 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1815 } | 1808 } |
| 1816 } | 1809 } |
| 1817 | 1810 |
| 1818 TEST_F(SpdyFramerTest, CreateHeadersUncompressed) { | 1811 TEST_F(SpdyFramerTest, CreateHeadersUncompressed) { |
| 1819 SpdyFramer framer(spdy_version_); | 1812 SpdyFramer framer; |
| 1820 framer.set_enable_compression(false); | 1813 framer.set_enable_compression(false); |
| 1821 | 1814 |
| 1822 { | 1815 { |
| 1823 const char kDescription[] = "HEADERS frame, no FIN"; | 1816 const char kDescription[] = "HEADERS frame, no FIN"; |
| 1824 // frame-format off | 1817 // frame-format off |
| 1825 const unsigned char kH2FrameData[] = { | 1818 const unsigned char kH2FrameData[] = { |
| 1826 0x00, 0x00, 0x12, // Length: 18 | 1819 0x00, 0x00, 0x12, // Length: 18 |
| 1827 0x01, // Type: HEADERS | 1820 0x01, // Type: HEADERS |
| 1828 0x04, // Flags: END_HEADERS | 1821 0x04, // Flags: END_HEADERS |
| 1829 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1822 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2061 SpdySerializedFrame frame( | 2054 SpdySerializedFrame frame( |
| 2062 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2055 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2063 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 2056 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 2064 } | 2057 } |
| 2065 } | 2058 } |
| 2066 | 2059 |
| 2067 // TODO(phajdan.jr): Clean up after we no longer need | 2060 // TODO(phajdan.jr): Clean up after we no longer need |
| 2068 // to workaround http://crbug.com/139744. | 2061 // to workaround http://crbug.com/139744. |
| 2069 #if !defined(USE_SYSTEM_ZLIB) | 2062 #if !defined(USE_SYSTEM_ZLIB) |
| 2070 TEST_F(SpdyFramerTest, CreateHeadersCompressed) { | 2063 TEST_F(SpdyFramerTest, CreateHeadersCompressed) { |
| 2071 SpdyFramer framer(spdy_version_); | 2064 SpdyFramer framer; |
| 2072 framer.set_enable_compression(true); | 2065 framer.set_enable_compression(true); |
| 2073 | 2066 |
| 2074 { | 2067 { |
| 2075 SpdyHeadersIR headers_ir(1); | 2068 SpdyHeadersIR headers_ir(1); |
| 2076 headers_ir.SetHeader("bar", "foo"); | 2069 headers_ir.SetHeader("bar", "foo"); |
| 2077 headers_ir.SetHeader("foo", "bar"); | 2070 headers_ir.SetHeader("foo", "bar"); |
| 2078 SpdySerializedFrame frame( | 2071 SpdySerializedFrame frame( |
| 2079 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2072 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2080 // Deflate compression doesn't apply to HPACK. | 2073 // Deflate compression doesn't apply to HPACK. |
| 2081 } | 2074 } |
| 2082 } | 2075 } |
| 2083 #endif // !defined(USE_SYSTEM_ZLIB) | 2076 #endif // !defined(USE_SYSTEM_ZLIB) |
| 2084 | 2077 |
| 2085 TEST_F(SpdyFramerTest, CreateWindowUpdate) { | 2078 TEST_F(SpdyFramerTest, CreateWindowUpdate) { |
| 2086 SpdyFramer framer(spdy_version_); | 2079 SpdyFramer framer; |
| 2087 | 2080 |
| 2088 { | 2081 { |
| 2089 const char kDescription[] = "WINDOW_UPDATE frame"; | 2082 const char kDescription[] = "WINDOW_UPDATE frame"; |
| 2090 const unsigned char kH2FrameData[] = { | 2083 const unsigned char kH2FrameData[] = { |
| 2091 0x00, 0x00, 0x04, // Length: 4 | 2084 0x00, 0x00, 0x04, // Length: 4 |
| 2092 0x08, // Type: WINDOW_UPDATE | 2085 0x08, // Type: WINDOW_UPDATE |
| 2093 0x00, // Flags: none | 2086 0x00, // Flags: none |
| 2094 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2087 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 2095 0x00, 0x00, 0x00, 0x01, // Increment: 1 | 2088 0x00, 0x00, 0x00, 0x01, // Increment: 1 |
| 2096 }; | 2089 }; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2122 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2115 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 2123 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff | 2116 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff |
| 2124 }; | 2117 }; |
| 2125 SpdySerializedFrame frame( | 2118 SpdySerializedFrame frame( |
| 2126 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2119 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
| 2127 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 2120 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 2128 } | 2121 } |
| 2129 } | 2122 } |
| 2130 | 2123 |
| 2131 TEST_F(SpdyFramerTest, SerializeBlocked) { | 2124 TEST_F(SpdyFramerTest, SerializeBlocked) { |
| 2132 SpdyFramer framer(spdy_version_); | 2125 SpdyFramer framer; |
| 2133 | 2126 |
| 2134 const char kDescription[] = "BLOCKED frame"; | 2127 const char kDescription[] = "BLOCKED frame"; |
| 2135 const unsigned char kType = static_cast<unsigned char>( | 2128 const unsigned char kType = |
| 2136 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); | 2129 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(BLOCKED)); |
| 2137 const unsigned char kFrameData[] = { | 2130 const unsigned char kFrameData[] = { |
| 2138 0x00, 0x00, 0x00, // Length: 0 | 2131 0x00, 0x00, 0x00, // Length: 0 |
| 2139 kType, // Type: BLOCKED | 2132 kType, // Type: BLOCKED |
| 2140 0x00, // Flags: none | 2133 0x00, // Flags: none |
| 2141 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2134 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2142 }; | 2135 }; |
| 2143 SpdyBlockedIR blocked_ir(0); | 2136 SpdyBlockedIR blocked_ir(0); |
| 2144 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 2137 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
| 2145 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2138 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2146 } | 2139 } |
| 2147 | 2140 |
| 2148 TEST_F(SpdyFramerTest, CreateBlocked) { | 2141 TEST_F(SpdyFramerTest, CreateBlocked) { |
| 2149 SpdyFramer framer(spdy_version_); | 2142 SpdyFramer framer; |
| 2150 | 2143 |
| 2151 const char kDescription[] = "BLOCKED frame"; | 2144 const char kDescription[] = "BLOCKED frame"; |
| 2152 const SpdyStreamId kStreamId = 3; | 2145 const SpdyStreamId kStreamId = 3; |
| 2153 | 2146 |
| 2154 SpdySerializedFrame frame_serialized( | 2147 SpdySerializedFrame frame_serialized( |
| 2155 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2148 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
| 2156 SpdyBlockedIR blocked_ir(kStreamId); | 2149 SpdyBlockedIR blocked_ir(kStreamId); |
| 2157 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); | 2150 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); |
| 2158 | 2151 |
| 2159 CompareFrames(kDescription, frame_serialized, frame_created); | 2152 CompareFrames(kDescription, frame_serialized, frame_created); |
| 2160 } | 2153 } |
| 2161 | 2154 |
| 2162 TEST_F(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2155 TEST_F(SpdyFramerTest, CreatePushPromiseUncompressed) { |
| 2163 { | 2156 { |
| 2164 // Test framing PUSH_PROMISE without padding. | 2157 // Test framing PUSH_PROMISE without padding. |
| 2165 SpdyFramer framer(spdy_version_); | 2158 SpdyFramer framer; |
| 2166 framer.set_enable_compression(false); | 2159 framer.set_enable_compression(false); |
| 2167 const char kDescription[] = "PUSH_PROMISE frame without padding"; | 2160 const char kDescription[] = "PUSH_PROMISE frame without padding"; |
| 2168 | 2161 |
| 2169 // frame-format off | 2162 // frame-format off |
| 2170 const unsigned char kFrameData[] = { | 2163 const unsigned char kFrameData[] = { |
| 2171 0x00, 0x00, 0x16, // Length: 22 | 2164 0x00, 0x00, 0x16, // Length: 22 |
| 2172 0x05, // Type: PUSH_PROMISE | 2165 0x05, // Type: PUSH_PROMISE |
| 2173 0x04, // Flags: END_HEADERS | 2166 0x04, // Flags: END_HEADERS |
| 2174 0x00, 0x00, 0x00, 0x29, // Stream: 41 | 2167 0x00, 0x00, 0x00, 0x29, // Stream: 41 |
| 2175 0x00, 0x00, 0x00, 0x3a, // Promise: 58 | 2168 0x00, 0x00, 0x00, 0x3a, // Promise: 58 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2190 | 2183 |
| 2191 SpdyPushPromiseIR push_promise(41, 58); | 2184 SpdyPushPromiseIR push_promise(41, 58); |
| 2192 push_promise.SetHeader("bar", "foo"); | 2185 push_promise.SetHeader("bar", "foo"); |
| 2193 push_promise.SetHeader("foo", "bar"); | 2186 push_promise.SetHeader("foo", "bar"); |
| 2194 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2187 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2195 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2188 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2196 } | 2189 } |
| 2197 | 2190 |
| 2198 { | 2191 { |
| 2199 // Test framing PUSH_PROMISE with one byte of padding. | 2192 // Test framing PUSH_PROMISE with one byte of padding. |
| 2200 SpdyFramer framer(spdy_version_); | 2193 SpdyFramer framer; |
| 2201 framer.set_enable_compression(false); | 2194 framer.set_enable_compression(false); |
| 2202 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding"; | 2195 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding"; |
| 2203 | 2196 |
| 2204 // frame-format off | 2197 // frame-format off |
| 2205 const unsigned char kFrameData[] = { | 2198 const unsigned char kFrameData[] = { |
| 2206 0x00, 0x00, 0x17, // Length: 23 | 2199 0x00, 0x00, 0x17, // Length: 23 |
| 2207 0x05, // Type: PUSH_PROMISE | 2200 0x05, // Type: PUSH_PROMISE |
| 2208 0x0c, // Flags: END_HEADERS|PADDED | 2201 0x0c, // Flags: END_HEADERS|PADDED |
| 2209 0x00, 0x00, 0x00, 0x29, // Stream: 41 | 2202 0x00, 0x00, 0x00, 0x29, // Stream: 41 |
| 2210 0x00, // PadLen: 0 trailing bytes | 2203 0x00, // PadLen: 0 trailing bytes |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2227 SpdyPushPromiseIR push_promise(41, 58); | 2220 SpdyPushPromiseIR push_promise(41, 58); |
| 2228 push_promise.set_padding_len(1); | 2221 push_promise.set_padding_len(1); |
| 2229 push_promise.SetHeader("bar", "foo"); | 2222 push_promise.SetHeader("bar", "foo"); |
| 2230 push_promise.SetHeader("foo", "bar"); | 2223 push_promise.SetHeader("foo", "bar"); |
| 2231 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2224 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2232 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2225 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2233 } | 2226 } |
| 2234 | 2227 |
| 2235 { | 2228 { |
| 2236 // Test framing PUSH_PROMISE with 177 bytes of padding. | 2229 // Test framing PUSH_PROMISE with 177 bytes of padding. |
| 2237 SpdyFramer framer(spdy_version_); | 2230 SpdyFramer framer; |
| 2238 framer.set_enable_compression(false); | 2231 framer.set_enable_compression(false); |
| 2239 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding"; | 2232 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding"; |
| 2240 | 2233 |
| 2241 // frame-format off | 2234 // frame-format off |
| 2242 // clang-format off | 2235 // clang-format off |
| 2243 const unsigned char kFrameData[] = { | 2236 const unsigned char kFrameData[] = { |
| 2244 0x00, 0x00, 0xc7, // Length: 199 | 2237 0x00, 0x00, 0xc7, // Length: 199 |
| 2245 0x05, // Type: PUSH_PROMISE | 2238 0x05, // Type: PUSH_PROMISE |
| 2246 0x0c, // Flags: END_HEADERS|PADDED | 2239 0x0c, // Flags: END_HEADERS|PADDED |
| 2247 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2240 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2285 push_promise.set_padding_len(177); | 2278 push_promise.set_padding_len(177); |
| 2286 push_promise.SetHeader("bar", "foo"); | 2279 push_promise.SetHeader("bar", "foo"); |
| 2287 push_promise.SetHeader("foo", "bar"); | 2280 push_promise.SetHeader("foo", "bar"); |
| 2288 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2281 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 2289 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2282 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2290 } | 2283 } |
| 2291 } | 2284 } |
| 2292 | 2285 |
| 2293 // Regression test for https://crbug.com/464748. | 2286 // Regression test for https://crbug.com/464748. |
| 2294 TEST_F(SpdyFramerTest, GetNumberRequiredContinuationFrames) { | 2287 TEST_F(SpdyFramerTest, GetNumberRequiredContinuationFrames) { |
| 2295 SpdyFramer framer(spdy_version_); | 2288 SpdyFramer framer; |
| 2296 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2289 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2297 &framer, 16383 + 16374)); | 2290 &framer, 16383 + 16374)); |
| 2298 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2291 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2299 &framer, 16383 + 16374 + 1)); | 2292 &framer, 16383 + 16374 + 1)); |
| 2300 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2293 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2301 &framer, 16383 + 2 * 16374)); | 2294 &framer, 16383 + 2 * 16374)); |
| 2302 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2295 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
| 2303 &framer, 16383 + 2 * 16374 + 1)); | 2296 &framer, 16383 + 2 * 16374 + 1)); |
| 2304 } | 2297 } |
| 2305 | 2298 |
| 2306 TEST_F(SpdyFramerTest, CreateContinuationUncompressed) { | 2299 TEST_F(SpdyFramerTest, CreateContinuationUncompressed) { |
| 2307 SpdyFramer framer(spdy_version_); | 2300 SpdyFramer framer; |
| 2308 framer.set_enable_compression(false); | 2301 framer.set_enable_compression(false); |
| 2309 const char kDescription[] = "CONTINUATION frame"; | 2302 const char kDescription[] = "CONTINUATION frame"; |
| 2310 | 2303 |
| 2311 // frame-format off | 2304 // frame-format off |
| 2312 const unsigned char kFrameData[] = { | 2305 const unsigned char kFrameData[] = { |
| 2313 0x00, 0x00, 0x12, // Length: 18 | 2306 0x00, 0x00, 0x12, // Length: 18 |
| 2314 0x09, // Type: CONTINUATION | 2307 0x09, // Type: CONTINUATION |
| 2315 0x04, // Flags: END_HEADERS | 2308 0x04, // Flags: END_HEADERS |
| 2316 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2309 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| 2317 | 2310 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2341 continuation.set_end_headers(true); | 2334 continuation.set_end_headers(true); |
| 2342 | 2335 |
| 2343 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 2336 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 2344 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2337 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2345 } | 2338 } |
| 2346 | 2339 |
| 2347 // Test that if we send an unexpected CONTINUATION | 2340 // Test that if we send an unexpected CONTINUATION |
| 2348 // we signal an error (but don't crash). | 2341 // we signal an error (but don't crash). |
| 2349 TEST_F(SpdyFramerTest, SendUnexpectedContinuation) { | 2342 TEST_F(SpdyFramerTest, SendUnexpectedContinuation) { |
| 2350 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2343 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 2351 SpdyFramer framer(spdy_version_); | 2344 SpdyFramer framer; |
| 2352 framer.set_visitor(&visitor); | 2345 framer.set_visitor(&visitor); |
| 2353 | 2346 |
| 2354 // frame-format off | 2347 // frame-format off |
| 2355 char kH2FrameData[] = { | 2348 char kH2FrameData[] = { |
| 2356 0x00, 0x00, 0x12, // Length: 18 | 2349 0x00, 0x00, 0x12, // Length: 18 |
| 2357 0x09, // Type: CONTINUATION | 2350 0x09, // Type: CONTINUATION |
| 2358 0x04, // Flags: END_HEADERS | 2351 0x04, // Flags: END_HEADERS |
| 2359 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2352 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| 2360 | 2353 |
| 2361 0x00, // Unindexed Entry | 2354 0x00, // Unindexed Entry |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2380 EXPECT_TRUE(framer.HasError()); | 2373 EXPECT_TRUE(framer.HasError()); |
| 2381 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) | 2374 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) |
| 2382 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2375 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 2383 } | 2376 } |
| 2384 | 2377 |
| 2385 TEST_F(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { | 2378 TEST_F(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { |
| 2386 { | 2379 { |
| 2387 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of | 2380 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of |
| 2388 // padding, cannot hold all the data payload, which is overflowed to the | 2381 // padding, cannot hold all the data payload, which is overflowed to the |
| 2389 // consecutive CONTINUATION frame. | 2382 // consecutive CONTINUATION frame. |
| 2390 SpdyFramer framer(spdy_version_); | 2383 SpdyFramer framer; |
| 2391 framer.set_enable_compression(false); | 2384 framer.set_enable_compression(false); |
| 2392 const char kDescription[] = | 2385 const char kDescription[] = |
| 2393 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; | 2386 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; |
| 2394 | 2387 |
| 2395 // frame-format off | 2388 // frame-format off |
| 2396 const unsigned char kPartialPushPromiseFrameData[] = { | 2389 const unsigned char kPartialPushPromiseFrameData[] = { |
| 2397 0x00, 0x3f, 0xf6, // Length: 16374 | 2390 0x00, 0x3f, 0xf6, // Length: 16374 |
| 2398 0x05, // Type: PUSH_PROMISE | 2391 0x05, // Type: PUSH_PROMISE |
| 2399 0x08, // Flags: PADDED | 2392 0x08, // Flags: PADDED |
| 2400 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2393 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 | 2470 |
| 2478 // Compare the CONTINUATION frame against the template. | 2471 // Compare the CONTINUATION frame against the template. |
| 2479 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); | 2472 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); |
| 2480 CompareCharArraysWithHexError( | 2473 CompareCharArraysWithHexError( |
| 2481 kDescription, frame_data, arraysize(kContinuationFrameData), | 2474 kDescription, frame_data, arraysize(kContinuationFrameData), |
| 2482 kContinuationFrameData, arraysize(kContinuationFrameData)); | 2475 kContinuationFrameData, arraysize(kContinuationFrameData)); |
| 2483 } | 2476 } |
| 2484 } | 2477 } |
| 2485 | 2478 |
| 2486 TEST_F(SpdyFramerTest, CreateAltSvc) { | 2479 TEST_F(SpdyFramerTest, CreateAltSvc) { |
| 2487 SpdyFramer framer(spdy_version_); | 2480 SpdyFramer framer; |
| 2488 | 2481 |
| 2489 const char kDescription[] = "ALTSVC frame"; | 2482 const char kDescription[] = "ALTSVC frame"; |
| 2490 const char kType = static_cast<unsigned char>( | 2483 const char kType = |
| 2491 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | 2484 static_cast<unsigned char>(SpdyConstants::SerializeFrameType(ALTSVC)); |
| 2492 const unsigned char kFrameData[] = { | 2485 const unsigned char kFrameData[] = { |
| 2493 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', | 2486 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', |
| 2494 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', | 2487 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', |
| 2495 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', | 2488 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', |
| 2496 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', | 2489 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', |
| 2497 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', | 2490 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', |
| 2498 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', | 2491 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', |
| 2499 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; | 2492 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; |
| 2500 SpdyAltSvcIR altsvc_ir(3); | 2493 SpdyAltSvcIR altsvc_ir(3); |
| 2501 altsvc_ir.set_origin("origin"); | 2494 altsvc_ir.set_origin("origin"); |
| 2502 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2495 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2503 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 2496 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 2504 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2497 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2505 "p\"=i:d", "h_\\o\"st", 123, 42, | 2498 "p\"=i:d", "h_\\o\"st", 123, 42, |
| 2506 SpdyAltSvcWireFormat::VersionVector{24})); | 2499 SpdyAltSvcWireFormat::VersionVector{24})); |
| 2507 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 2500 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 2508 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2501 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2509 } | 2502 } |
| 2510 | 2503 |
| 2511 TEST_F(SpdyFramerTest, CreatePriority) { | 2504 TEST_F(SpdyFramerTest, CreatePriority) { |
| 2512 SpdyFramer framer(spdy_version_); | 2505 SpdyFramer framer; |
| 2513 | 2506 |
| 2514 const char kDescription[] = "PRIORITY frame"; | 2507 const char kDescription[] = "PRIORITY frame"; |
| 2515 const unsigned char kFrameData[] = { | 2508 const unsigned char kFrameData[] = { |
| 2516 0x00, 0x00, 0x05, // Length: 5 | 2509 0x00, 0x00, 0x05, // Length: 5 |
| 2517 0x02, // Type: PRIORITY | 2510 0x02, // Type: PRIORITY |
| 2518 0x00, // Flags: none | 2511 0x00, // Flags: none |
| 2519 0x00, 0x00, 0x00, 0x02, // Stream: 2 | 2512 0x00, 0x00, 0x00, 0x02, // Stream: 2 |
| 2520 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) | 2513 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) |
| 2521 0x10, // Weight: 17 | 2514 0x10, // Weight: 17 |
| 2522 }; | 2515 }; |
| 2523 SpdyPriorityIR priority_ir(2, 1, 17, true); | 2516 SpdyPriorityIR priority_ir(2, 1, 17, true); |
| 2524 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 2517 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
| 2525 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2518 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2526 SpdyPriorityIR priority2(2); | 2519 SpdyPriorityIR priority2(2); |
| 2527 priority2.set_parent_stream_id(1); | 2520 priority2.set_parent_stream_id(1); |
| 2528 priority2.set_weight(17); | 2521 priority2.set_weight(17); |
| 2529 priority2.set_exclusive(true); | 2522 priority2.set_exclusive(true); |
| 2530 frame = framer.SerializeFrame(priority2); | 2523 frame = framer.SerializeFrame(priority2); |
| 2531 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2524 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
| 2532 } | 2525 } |
| 2533 | 2526 |
| 2534 TEST_F(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { | 2527 TEST_F(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { |
| 2535 SpdyFramer framer(spdy_version_); | 2528 SpdyFramer framer; |
| 2536 SpdyHeadersIR headers_ir(1); | 2529 SpdyHeadersIR headers_ir(1); |
| 2537 headers_ir.SetHeader("alpha", "beta"); | 2530 headers_ir.SetHeader("alpha", "beta"); |
| 2538 headers_ir.SetHeader("gamma", "delta"); | 2531 headers_ir.SetHeader("gamma", "delta"); |
| 2539 SpdySerializedFrame control_frame( | 2532 SpdySerializedFrame control_frame( |
| 2540 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2533 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2541 TestSpdyVisitor visitor(spdy_version_); | 2534 TestSpdyVisitor visitor; |
| 2542 visitor.use_compression_ = true; | 2535 visitor.use_compression_ = true; |
| 2543 visitor.SimulateInFramer( | 2536 visitor.SimulateInFramer( |
| 2544 reinterpret_cast<unsigned char*>(control_frame.data()), | 2537 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2545 control_frame.size()); | 2538 control_frame.size()); |
| 2546 EXPECT_EQ(1, visitor.headers_frame_count_); | 2539 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2547 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2540 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
| 2548 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2541 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2549 EXPECT_EQ(0, visitor.end_of_stream_count_); | 2542 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 2550 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2543 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
| 2551 } | 2544 } |
| 2552 | 2545 |
| 2553 TEST_F(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { | 2546 TEST_F(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { |
| 2554 SpdyFramer framer(spdy_version_); | 2547 SpdyFramer framer; |
| 2555 SpdyHeadersIR headers_ir(1); | 2548 SpdyHeadersIR headers_ir(1); |
| 2556 headers_ir.set_fin(true); | 2549 headers_ir.set_fin(true); |
| 2557 headers_ir.SetHeader("alpha", "beta"); | 2550 headers_ir.SetHeader("alpha", "beta"); |
| 2558 headers_ir.SetHeader("gamma", "delta"); | 2551 headers_ir.SetHeader("gamma", "delta"); |
| 2559 SpdySerializedFrame control_frame( | 2552 SpdySerializedFrame control_frame( |
| 2560 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2553 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 2561 TestSpdyVisitor visitor(spdy_version_); | 2554 TestSpdyVisitor visitor; |
| 2562 visitor.use_compression_ = true; | 2555 visitor.use_compression_ = true; |
| 2563 visitor.SimulateInFramer( | 2556 visitor.SimulateInFramer( |
| 2564 reinterpret_cast<unsigned char*>(control_frame.data()), | 2557 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2565 control_frame.size()); | 2558 control_frame.size()); |
| 2566 EXPECT_EQ(1, visitor.headers_frame_count_); | 2559 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2567 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2560 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
| 2568 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2561 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2569 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2562 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 2570 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2563 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
| 2571 } | 2564 } |
| 2572 | 2565 |
| 2573 TEST_F(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { | 2566 TEST_F(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
| 2574 SpdyFramer framer(spdy_version_); | 2567 SpdyFramer framer; |
| 2575 framer.set_enable_compression(false); | 2568 framer.set_enable_compression(false); |
| 2576 SpdyHeadersIR headers(1); | 2569 SpdyHeadersIR headers(1); |
| 2577 headers.set_padding_len(256); | 2570 headers.set_padding_len(256); |
| 2578 | 2571 |
| 2579 // Exact payload length will change with HPACK, but this should be long | 2572 // Exact payload length will change with HPACK, but this should be long |
| 2580 // enough to cause an overflow. | 2573 // enough to cause an overflow. |
| 2581 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2574 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2582 string big_value(kBigValueSize, 'x'); | 2575 string big_value(kBigValueSize, 'x'); |
| 2583 headers.SetHeader("aa", big_value); | 2576 headers.SetHeader("aa", big_value); |
| 2584 SpdySerializedFrame control_frame( | 2577 SpdySerializedFrame control_frame( |
| 2585 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2578 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 2586 EXPECT_GT(control_frame.size(), | 2579 EXPECT_GT(control_frame.size(), |
| 2587 TestSpdyVisitor::sent_control_frame_max_size()); | 2580 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2588 | 2581 |
| 2589 TestSpdyVisitor visitor(spdy_version_); | 2582 TestSpdyVisitor visitor; |
| 2590 visitor.SimulateInFramer( | 2583 visitor.SimulateInFramer( |
| 2591 reinterpret_cast<unsigned char*>(control_frame.data()), | 2584 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2592 control_frame.size()); | 2585 control_frame.size()); |
| 2593 EXPECT_TRUE(visitor.header_buffer_valid_); | 2586 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2594 EXPECT_EQ(0, visitor.error_count_); | 2587 EXPECT_EQ(0, visitor.error_count_); |
| 2595 EXPECT_EQ(1, visitor.headers_frame_count_); | 2588 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2596 EXPECT_EQ(1, visitor.continuation_count_); | 2589 EXPECT_EQ(1, visitor.continuation_count_); |
| 2597 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2590 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2598 } | 2591 } |
| 2599 | 2592 |
| 2600 TEST_F(SpdyFramerTest, MultipleContinuationFramesWithIterator) { | 2593 TEST_F(SpdyFramerTest, MultipleContinuationFramesWithIterator) { |
| 2601 SpdyFramer framer(spdy_version_); | 2594 SpdyFramer framer; |
| 2602 framer.set_enable_compression(false); | 2595 framer.set_enable_compression(false); |
| 2603 auto headers = base::MakeUnique<SpdyHeadersIR>(1); | 2596 auto headers = base::MakeUnique<SpdyHeadersIR>(1); |
| 2604 headers->set_padding_len(256); | 2597 headers->set_padding_len(256); |
| 2605 | 2598 |
| 2606 // Exact payload length will change with HPACK, but this should be long | 2599 // Exact payload length will change with HPACK, but this should be long |
| 2607 // enough to cause an overflow. | 2600 // enough to cause an overflow. |
| 2608 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2601 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2609 string big_valuex(kBigValueSize, 'x'); | 2602 string big_valuex(kBigValueSize, 'x'); |
| 2610 headers->SetHeader("aa", big_valuex); | 2603 headers->SetHeader("aa", big_valuex); |
| 2611 string big_valuez(kBigValueSize, 'z'); | 2604 string big_valuez(kBigValueSize, 'z'); |
| 2612 headers->SetHeader("bb", big_valuez); | 2605 headers->SetHeader("bb", big_valuez); |
| 2613 | 2606 |
| 2614 SpdyFramer::SpdyHeaderFrameIterator frame_it(&framer, std::move(headers)); | 2607 SpdyFramer::SpdyHeaderFrameIterator frame_it(&framer, std::move(headers)); |
| 2615 | 2608 |
| 2616 EXPECT_TRUE(frame_it.HasNextFrame()); | 2609 EXPECT_TRUE(frame_it.HasNextFrame()); |
| 2617 SpdySerializedFrame headers_frame(frame_it.NextFrame()); | 2610 SpdySerializedFrame headers_frame(frame_it.NextFrame()); |
| 2618 EXPECT_EQ(headers_frame.size(), | 2611 EXPECT_EQ(headers_frame.size(), |
| 2619 TestSpdyVisitor::sent_control_frame_max_size()); | 2612 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2620 | 2613 |
| 2621 TestSpdyVisitor visitor(spdy_version_); | 2614 TestSpdyVisitor visitor; |
| 2622 visitor.SimulateInFramer( | 2615 visitor.SimulateInFramer( |
| 2623 reinterpret_cast<unsigned char*>(headers_frame.data()), | 2616 reinterpret_cast<unsigned char*>(headers_frame.data()), |
| 2624 headers_frame.size()); | 2617 headers_frame.size()); |
| 2625 EXPECT_TRUE(visitor.header_buffer_valid_); | 2618 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2626 EXPECT_EQ(0, visitor.error_count_); | 2619 EXPECT_EQ(0, visitor.error_count_); |
| 2627 EXPECT_EQ(1, visitor.headers_frame_count_); | 2620 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2628 EXPECT_EQ(0, visitor.continuation_count_); | 2621 EXPECT_EQ(0, visitor.continuation_count_); |
| 2629 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2622 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2630 | 2623 |
| 2631 EXPECT_TRUE(frame_it.HasNextFrame()); | 2624 EXPECT_TRUE(frame_it.HasNextFrame()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2653 EXPECT_TRUE(visitor.header_buffer_valid_); | 2646 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2654 EXPECT_EQ(0, visitor.error_count_); | 2647 EXPECT_EQ(0, visitor.error_count_); |
| 2655 EXPECT_EQ(1, visitor.headers_frame_count_); | 2648 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 2656 EXPECT_EQ(2, visitor.continuation_count_); | 2649 EXPECT_EQ(2, visitor.continuation_count_); |
| 2657 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2650 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2658 | 2651 |
| 2659 EXPECT_FALSE(frame_it.HasNextFrame()); | 2652 EXPECT_FALSE(frame_it.HasNextFrame()); |
| 2660 } | 2653 } |
| 2661 | 2654 |
| 2662 TEST_F(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 2655 TEST_F(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
| 2663 SpdyFramer framer(spdy_version_); | 2656 SpdyFramer framer; |
| 2664 framer.set_enable_compression(false); | 2657 framer.set_enable_compression(false); |
| 2665 SpdyPushPromiseIR push_promise(1, 2); | 2658 SpdyPushPromiseIR push_promise(1, 2); |
| 2666 push_promise.set_padding_len(256); | 2659 push_promise.set_padding_len(256); |
| 2667 | 2660 |
| 2668 // Exact payload length will change with HPACK, but this should be long | 2661 // Exact payload length will change with HPACK, but this should be long |
| 2669 // enough to cause an overflow. | 2662 // enough to cause an overflow. |
| 2670 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2663 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
| 2671 string big_value(kBigValueSize, 'x'); | 2664 string big_value(kBigValueSize, 'x'); |
| 2672 push_promise.SetHeader("aa", big_value); | 2665 push_promise.SetHeader("aa", big_value); |
| 2673 SpdySerializedFrame control_frame(framer.SerializePushPromise(push_promise)); | 2666 SpdySerializedFrame control_frame(framer.SerializePushPromise(push_promise)); |
| 2674 EXPECT_GT(control_frame.size(), | 2667 EXPECT_GT(control_frame.size(), |
| 2675 TestSpdyVisitor::sent_control_frame_max_size()); | 2668 TestSpdyVisitor::sent_control_frame_max_size()); |
| 2676 | 2669 |
| 2677 TestSpdyVisitor visitor(spdy_version_); | 2670 TestSpdyVisitor visitor; |
| 2678 visitor.SimulateInFramer( | 2671 visitor.SimulateInFramer( |
| 2679 reinterpret_cast<unsigned char*>(control_frame.data()), | 2672 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2680 control_frame.size()); | 2673 control_frame.size()); |
| 2681 EXPECT_TRUE(visitor.header_buffer_valid_); | 2674 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 2682 EXPECT_EQ(0, visitor.error_count_); | 2675 EXPECT_EQ(0, visitor.error_count_); |
| 2683 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 2676 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
| 2684 EXPECT_EQ(1, visitor.continuation_count_); | 2677 EXPECT_EQ(1, visitor.continuation_count_); |
| 2685 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2678 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 2686 } | 2679 } |
| 2687 | 2680 |
| 2688 // Check that the framer stops delivering header data chunks once the visitor | 2681 // Check that the framer stops delivering header data chunks once the visitor |
| 2689 // declares it doesn't want any more. This is important to guard against | 2682 // declares it doesn't want any more. This is important to guard against |
| 2690 // "zip bomb" types of attacks. | 2683 // "zip bomb" types of attacks. |
| 2691 TEST_F(SpdyFramerTest, ControlFrameMuchTooLarge) { | 2684 TEST_F(SpdyFramerTest, ControlFrameMuchTooLarge) { |
| 2692 const size_t kHeaderBufferChunks = 4; | 2685 const size_t kHeaderBufferChunks = 4; |
| 2693 const size_t kHeaderBufferSize = | 2686 const size_t kHeaderBufferSize = |
| 2694 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 2687 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
| 2695 const size_t kBigValueSize = kHeaderBufferSize * 2; | 2688 const size_t kBigValueSize = kHeaderBufferSize * 2; |
| 2696 string big_value(kBigValueSize, 'x'); | 2689 string big_value(kBigValueSize, 'x'); |
| 2697 SpdyFramer framer(spdy_version_); | 2690 SpdyFramer framer; |
| 2698 SpdyHeadersIR headers(1); | 2691 SpdyHeadersIR headers(1); |
| 2699 headers.set_fin(true); | 2692 headers.set_fin(true); |
| 2700 headers.SetHeader("aa", big_value); | 2693 headers.SetHeader("aa", big_value); |
| 2701 SpdySerializedFrame control_frame( | 2694 SpdySerializedFrame control_frame( |
| 2702 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2695 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 2703 TestSpdyVisitor visitor(spdy_version_); | 2696 TestSpdyVisitor visitor; |
| 2704 visitor.set_header_buffer_size(kHeaderBufferSize); | 2697 visitor.set_header_buffer_size(kHeaderBufferSize); |
| 2705 visitor.use_compression_ = true; | 2698 visitor.use_compression_ = true; |
| 2706 visitor.SimulateInFramer( | 2699 visitor.SimulateInFramer( |
| 2707 reinterpret_cast<unsigned char*>(control_frame.data()), | 2700 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2708 control_frame.size()); | 2701 control_frame.size()); |
| 2709 // It's up to the visitor to ignore extraneous header data; the framer | 2702 // It's up to the visitor to ignore extraneous header data; the framer |
| 2710 // won't throw an error. | 2703 // won't throw an error. |
| 2711 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); | 2704 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); |
| 2712 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2705 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 2713 } | 2706 } |
| 2714 | 2707 |
| 2715 TEST_F(SpdyFramerTest, ControlFrameSizesAreValidated) { | 2708 TEST_F(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 2716 SpdyFramer framer(spdy_version_); | 2709 SpdyFramer framer; |
| 2717 // Create a GoAway frame that has a few extra bytes at the end. | 2710 // Create a GoAway frame that has a few extra bytes at the end. |
| 2718 // We create enough overhead to overflow the framer's control frame buffer. | 2711 // We create enough overhead to overflow the framer's control frame buffer. |
| 2719 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); | 2712 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); |
| 2720 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; | 2713 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; |
| 2721 | 2714 |
| 2722 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may | 2715 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may |
| 2723 // carry opaque data. Verify that minimal length is tested. | 2716 // carry opaque data. Verify that minimal length is tested. |
| 2724 ASSERT_GT(framer.GetGoAwayMinimumSize(), framer.GetFrameHeaderSize()); | 2717 ASSERT_GT(framer.GetGoAwayMinimumSize(), SpdyConstants::kFrameHeaderSize); |
| 2725 const size_t less_than_min_length = | 2718 const size_t less_than_min_length = |
| 2726 framer.GetGoAwayMinimumSize() - framer.GetFrameHeaderSize() - 1; | 2719 framer.GetGoAwayMinimumSize() - SpdyConstants::kFrameHeaderSize - 1; |
| 2727 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); | 2720 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); |
| 2728 const unsigned char kH2Len = static_cast<unsigned char>(less_than_min_length); | 2721 const unsigned char kH2Len = static_cast<unsigned char>(less_than_min_length); |
| 2729 const unsigned char kH2FrameData[] = { | 2722 const unsigned char kH2FrameData[] = { |
| 2730 0x00, 0x00, kH2Len, // Length: min length - 1 | 2723 0x00, 0x00, kH2Len, // Length: min length - 1 |
| 2731 0x07, // Type: GOAWAY | 2724 0x07, // Type: GOAWAY |
| 2732 0x00, // Flags: none | 2725 0x00, // Flags: none |
| 2733 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2726 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2734 0x00, 0x00, 0x00, 0x00, // Last: 0 | 2727 0x00, 0x00, 0x00, 0x00, // Last: 0 |
| 2735 0x00, 0x00, 0x00, // Truncated Status Field | 2728 0x00, 0x00, 0x00, // Truncated Status Field |
| 2736 }; | 2729 }; |
| 2737 const size_t pad_length = | 2730 const size_t pad_length = |
| 2738 length + framer.GetFrameHeaderSize() - sizeof(kH2FrameData); | 2731 length + SpdyConstants::kFrameHeaderSize - sizeof(kH2FrameData); |
| 2739 string pad(pad_length, 'A'); | 2732 string pad(pad_length, 'A'); |
| 2740 TestSpdyVisitor visitor(spdy_version_); | 2733 TestSpdyVisitor visitor; |
| 2741 | 2734 |
| 2742 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2735 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2743 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), | 2736 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 2744 pad.length()); | 2737 pad.length()); |
| 2745 | 2738 |
| 2746 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2739 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
| 2747 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 2740 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 2748 visitor.framer_.error_code()) | 2741 visitor.framer_.error_code()) |
| 2749 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2742 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2750 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. | 2743 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. |
| 2751 } | 2744 } |
| 2752 | 2745 |
| 2753 TEST_F(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 2746 TEST_F(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 2754 SpdyFramer framer(spdy_version_); | 2747 SpdyFramer framer; |
| 2755 SpdySettingsIR settings_ir; | 2748 SpdySettingsIR settings_ir; |
| 2756 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2749 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2757 SetFrameLength(&control_frame, 0, spdy_version_); | 2750 SetFrameLength(&control_frame, 0); |
| 2758 TestSpdyVisitor visitor(spdy_version_); | 2751 TestSpdyVisitor visitor; |
| 2759 visitor.use_compression_ = false; | 2752 visitor.use_compression_ = false; |
| 2760 visitor.SimulateInFramer( | 2753 visitor.SimulateInFramer( |
| 2761 reinterpret_cast<unsigned char*>(control_frame.data()), | 2754 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2762 framer.GetFrameHeaderSize()); | 2755 framer.GetFrameHeaderSize()); |
| 2763 // Zero-len settings frames are permitted as of HTTP/2. | 2756 // Zero-len settings frames are permitted as of HTTP/2. |
| 2764 EXPECT_EQ(0, visitor.error_count_); | 2757 EXPECT_EQ(0, visitor.error_count_); |
| 2765 } | 2758 } |
| 2766 | 2759 |
| 2767 // Tests handling of SETTINGS frames with invalid length. | 2760 // Tests handling of SETTINGS frames with invalid length. |
| 2768 TEST_F(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 2761 TEST_F(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| 2769 SpdyFramer framer(spdy_version_); | 2762 SpdyFramer framer; |
| 2770 SpdySettingsIR settings_ir; | 2763 SpdySettingsIR settings_ir; |
| 2771 | 2764 |
| 2772 // Add a setting to pad the frame so that we don't get a buffer overflow when | 2765 // Add a setting to pad the frame so that we don't get a buffer overflow when |
| 2773 // calling SimulateInFramer() below. | 2766 // calling SimulateInFramer() below. |
| 2774 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, | 2767 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, |
| 2775 0x00000002); | 2768 0x00000002); |
| 2776 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2769 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2777 const size_t kNewLength = 14; | 2770 const size_t kNewLength = 14; |
| 2778 SetFrameLength(&control_frame, kNewLength, spdy_version_); | 2771 SetFrameLength(&control_frame, kNewLength); |
| 2779 TestSpdyVisitor visitor(spdy_version_); | 2772 TestSpdyVisitor visitor; |
| 2780 visitor.use_compression_ = false; | 2773 visitor.use_compression_ = false; |
| 2781 visitor.SimulateInFramer( | 2774 visitor.SimulateInFramer( |
| 2782 reinterpret_cast<unsigned char*>(control_frame.data()), | 2775 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2783 framer.GetFrameHeaderSize() + kNewLength); | 2776 framer.GetFrameHeaderSize() + kNewLength); |
| 2784 // Should generate an error, since its not possible to have a | 2777 // Should generate an error, since its not possible to have a |
| 2785 // settings frame of length kNewLength. | 2778 // settings frame of length kNewLength. |
| 2786 EXPECT_EQ(1, visitor.error_count_); | 2779 EXPECT_EQ(1, visitor.error_count_); |
| 2787 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 2780 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 2788 visitor.framer_.error_code()) | 2781 visitor.framer_.error_code()) |
| 2789 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2782 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2790 } | 2783 } |
| 2791 | 2784 |
| 2792 // Tests handling of SETTINGS frames larger than the frame buffer size. | 2785 // Tests handling of SETTINGS frames larger than the frame buffer size. |
| 2793 TEST_F(SpdyFramerTest, ReadLargeSettingsFrame) { | 2786 TEST_F(SpdyFramerTest, ReadLargeSettingsFrame) { |
| 2794 SpdyFramer framer(spdy_version_); | 2787 SpdyFramer framer; |
| 2795 SpdySettingsIR settings_ir; | 2788 SpdySettingsIR settings_ir; |
| 2796 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), | 2789 settings_ir.AddSetting(SpdyConstants::ParseSettingId(1), |
| 2797 false, // persist | 2790 false, // persist |
| 2798 false, // persisted | 2791 false, // persisted |
| 2799 5); | 2792 5); |
| 2800 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), | 2793 settings_ir.AddSetting(SpdyConstants::ParseSettingId(2), |
| 2801 false, // persist | 2794 false, // persist |
| 2802 false, // persisted | 2795 false, // persisted |
| 2803 6); | 2796 6); |
| 2804 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), | 2797 settings_ir.AddSetting(SpdyConstants::ParseSettingId(3), |
| 2805 false, // persist | 2798 false, // persist |
| 2806 false, // persisted | 2799 false, // persisted |
| 2807 7); | 2800 7); |
| 2808 | 2801 |
| 2809 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2802 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2810 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); | 2803 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); |
| 2811 TestSpdyVisitor visitor(spdy_version_); | 2804 TestSpdyVisitor visitor; |
| 2812 visitor.use_compression_ = false; | 2805 visitor.use_compression_ = false; |
| 2813 | 2806 |
| 2814 // Read all at once. | 2807 // Read all at once. |
| 2815 visitor.SimulateInFramer( | 2808 visitor.SimulateInFramer( |
| 2816 reinterpret_cast<unsigned char*>(control_frame.data()), | 2809 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2817 control_frame.size()); | 2810 control_frame.size()); |
| 2818 EXPECT_EQ(0, visitor.error_count_); | 2811 EXPECT_EQ(0, visitor.error_count_); |
| 2819 EXPECT_EQ(3, visitor.setting_count_); | 2812 EXPECT_EQ(3, visitor.setting_count_); |
| 2820 EXPECT_EQ(1, visitor.settings_ack_sent_); | 2813 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 2821 | 2814 |
| 2822 // Read data in small chunks. | 2815 // Read data in small chunks. |
| 2823 size_t framed_data = 0; | 2816 size_t framed_data = 0; |
| 2824 size_t unframed_data = control_frame.size(); | 2817 size_t unframed_data = control_frame.size(); |
| 2825 size_t kReadChunkSize = 5; // Read five bytes at a time. | 2818 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 2826 while (unframed_data > 0) { | 2819 while (unframed_data > 0) { |
| 2827 size_t to_read = std::min(kReadChunkSize, unframed_data); | 2820 size_t to_read = std::min(kReadChunkSize, unframed_data); |
| 2828 visitor.SimulateInFramer( | 2821 visitor.SimulateInFramer( |
| 2829 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), | 2822 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), |
| 2830 to_read); | 2823 to_read); |
| 2831 unframed_data -= to_read; | 2824 unframed_data -= to_read; |
| 2832 framed_data += to_read; | 2825 framed_data += to_read; |
| 2833 } | 2826 } |
| 2834 EXPECT_EQ(0, visitor.error_count_); | 2827 EXPECT_EQ(0, visitor.error_count_); |
| 2835 EXPECT_EQ(3 * 2, visitor.setting_count_); | 2828 EXPECT_EQ(3 * 2, visitor.setting_count_); |
| 2836 EXPECT_EQ(2, visitor.settings_ack_sent_); | 2829 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| 2837 } | 2830 } |
| 2838 | 2831 |
| 2839 // Tests handling of SETTINGS frame with duplicate entries. | 2832 // Tests handling of SETTINGS frame with duplicate entries. |
| 2840 TEST_F(SpdyFramerTest, ReadDuplicateSettings) { | 2833 TEST_F(SpdyFramerTest, ReadDuplicateSettings) { |
| 2841 SpdyFramer framer(spdy_version_); | 2834 SpdyFramer framer; |
| 2842 | 2835 |
| 2843 const unsigned char kH2FrameData[] = { | 2836 const unsigned char kH2FrameData[] = { |
| 2844 0x00, 0x00, 0x12, // Length: 18 | 2837 0x00, 0x00, 0x12, // Length: 18 |
| 2845 0x04, // Type: SETTINGS | 2838 0x04, // Type: SETTINGS |
| 2846 0x00, // Flags: none | 2839 0x00, // Flags: none |
| 2847 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2840 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2848 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2841 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2849 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2842 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2850 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2843 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2851 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2844 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2852 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2845 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 2853 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2846 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2854 }; | 2847 }; |
| 2855 | 2848 |
| 2856 TestSpdyVisitor visitor(spdy_version_); | 2849 TestSpdyVisitor visitor; |
| 2857 visitor.use_compression_ = false; | 2850 visitor.use_compression_ = false; |
| 2858 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2851 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2859 | 2852 |
| 2860 // In HTTP/2, duplicate settings are allowed; | 2853 // In HTTP/2, duplicate settings are allowed; |
| 2861 // each setting replaces the previous value for that setting. | 2854 // each setting replaces the previous value for that setting. |
| 2862 EXPECT_EQ(3, visitor.setting_count_); | 2855 EXPECT_EQ(3, visitor.setting_count_); |
| 2863 EXPECT_EQ(0, visitor.error_count_); | 2856 EXPECT_EQ(0, visitor.error_count_); |
| 2864 EXPECT_EQ(1, visitor.settings_ack_sent_); | 2857 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 2865 } | 2858 } |
| 2866 | 2859 |
| 2867 // Tests handling of SETTINGS frame with a setting we don't recognize. | 2860 // Tests handling of SETTINGS frame with a setting we don't recognize. |
| 2868 TEST_F(SpdyFramerTest, ReadUnknownSettingsId) { | 2861 TEST_F(SpdyFramerTest, ReadUnknownSettingsId) { |
| 2869 SpdyFramer framer(spdy_version_); | 2862 SpdyFramer framer; |
| 2870 const unsigned char kH2FrameData[] = { | 2863 const unsigned char kH2FrameData[] = { |
| 2871 0x00, 0x00, 0x06, // Length: 6 | 2864 0x00, 0x00, 0x06, // Length: 6 |
| 2872 0x04, // Type: SETTINGS | 2865 0x04, // Type: SETTINGS |
| 2873 0x00, // Flags: none | 2866 0x00, // Flags: none |
| 2874 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2867 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2875 0x00, 0x10, // Param: 16 | 2868 0x00, 0x10, // Param: 16 |
| 2876 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2869 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2877 }; | 2870 }; |
| 2878 | 2871 |
| 2879 TestSpdyVisitor visitor(spdy_version_); | 2872 TestSpdyVisitor visitor; |
| 2880 visitor.use_compression_ = false; | 2873 visitor.use_compression_ = false; |
| 2881 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2874 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2882 | 2875 |
| 2883 // In HTTP/2, we ignore unknown settings because of extensions. | 2876 // In HTTP/2, we ignore unknown settings because of extensions. |
| 2884 EXPECT_EQ(0, visitor.setting_count_); | 2877 EXPECT_EQ(0, visitor.setting_count_); |
| 2885 EXPECT_EQ(0, visitor.error_count_); | 2878 EXPECT_EQ(0, visitor.error_count_); |
| 2886 } | 2879 } |
| 2887 | 2880 |
| 2888 // Tests handling of SETTINGS frame with entries out of order. | 2881 // Tests handling of SETTINGS frame with entries out of order. |
| 2889 TEST_F(SpdyFramerTest, ReadOutOfOrderSettings) { | 2882 TEST_F(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 2890 SpdyFramer framer(spdy_version_); | 2883 SpdyFramer framer; |
| 2891 const unsigned char kH2FrameData[] = { | 2884 const unsigned char kH2FrameData[] = { |
| 2892 0x00, 0x00, 0x12, // Length: 18 | 2885 0x00, 0x00, 0x12, // Length: 18 |
| 2893 0x04, // Type: SETTINGS | 2886 0x04, // Type: SETTINGS |
| 2894 0x00, // Flags: none | 2887 0x00, // Flags: none |
| 2895 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2888 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2896 0x00, 0x02, // Param: ENABLE_PUSH | 2889 0x00, 0x02, // Param: ENABLE_PUSH |
| 2897 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2890 0x00, 0x00, 0x00, 0x02, // Value: 2 |
| 2898 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2891 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 2899 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2892 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2900 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2893 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 2901 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2894 0x00, 0x00, 0x00, 0x03, // Value: 3 |
| 2902 }; | 2895 }; |
| 2903 | 2896 |
| 2904 TestSpdyVisitor visitor(spdy_version_); | 2897 TestSpdyVisitor visitor; |
| 2905 visitor.use_compression_ = false; | 2898 visitor.use_compression_ = false; |
| 2906 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | 2899 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
| 2907 | 2900 |
| 2908 // In HTTP/2, settings are allowed in any order. | 2901 // In HTTP/2, settings are allowed in any order. |
| 2909 EXPECT_EQ(3, visitor.setting_count_); | 2902 EXPECT_EQ(3, visitor.setting_count_); |
| 2910 EXPECT_EQ(0, visitor.error_count_); | 2903 EXPECT_EQ(0, visitor.error_count_); |
| 2911 } | 2904 } |
| 2912 | 2905 |
| 2913 TEST_F(SpdyFramerTest, ProcessSettingsAckFrame) { | 2906 TEST_F(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 2914 SpdyFramer framer(spdy_version_); | 2907 SpdyFramer framer; |
| 2915 | 2908 |
| 2916 const unsigned char kFrameData[] = { | 2909 const unsigned char kFrameData[] = { |
| 2917 0x00, 0x00, 0x00, // Length: 0 | 2910 0x00, 0x00, 0x00, // Length: 0 |
| 2918 0x04, // Type: SETTINGS | 2911 0x04, // Type: SETTINGS |
| 2919 0x01, // Flags: ACK | 2912 0x01, // Flags: ACK |
| 2920 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2913 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 2921 }; | 2914 }; |
| 2922 | 2915 |
| 2923 TestSpdyVisitor visitor(spdy_version_); | 2916 TestSpdyVisitor visitor; |
| 2924 visitor.use_compression_ = false; | 2917 visitor.use_compression_ = false; |
| 2925 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 2918 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 2926 | 2919 |
| 2927 EXPECT_EQ(0, visitor.error_count_); | 2920 EXPECT_EQ(0, visitor.error_count_); |
| 2928 EXPECT_EQ(0, visitor.setting_count_); | 2921 EXPECT_EQ(0, visitor.setting_count_); |
| 2929 EXPECT_EQ(1, visitor.settings_ack_received_); | 2922 EXPECT_EQ(1, visitor.settings_ack_received_); |
| 2930 } | 2923 } |
| 2931 | 2924 |
| 2932 TEST_F(SpdyFramerTest, ProcessDataFrameWithPadding) { | 2925 TEST_F(SpdyFramerTest, ProcessDataFrameWithPadding) { |
| 2933 const int kPaddingLen = 119; | 2926 const int kPaddingLen = 119; |
| 2934 const char data_payload[] = "hello"; | 2927 const char data_payload[] = "hello"; |
| 2935 | 2928 |
| 2936 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2929 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 2937 SpdyFramer framer(spdy_version_); | 2930 SpdyFramer framer; |
| 2938 framer.set_visitor(&visitor); | 2931 framer.set_visitor(&visitor); |
| 2939 | 2932 |
| 2940 SpdyDataIR data_ir(1, data_payload); | 2933 SpdyDataIR data_ir(1, data_payload); |
| 2941 data_ir.set_padding_len(kPaddingLen); | 2934 data_ir.set_padding_len(kPaddingLen); |
| 2942 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 2935 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 2943 | 2936 |
| 2944 int bytes_consumed = 0; | 2937 int bytes_consumed = 0; |
| 2945 | 2938 |
| 2946 // Send the frame header. | 2939 // Send the frame header. |
| 2947 EXPECT_CALL(visitor, | 2940 EXPECT_CALL(visitor, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2981 bytes_consumed += 100; | 2974 bytes_consumed += 100; |
| 2982 | 2975 |
| 2983 // Send rest of the padding payload. | 2976 // Send rest of the padding payload. |
| 2984 EXPECT_CALL(visitor, OnStreamPadding(1, 18)); | 2977 EXPECT_CALL(visitor, OnStreamPadding(1, 18)); |
| 2985 CHECK_EQ(18u, framer.ProcessInput(frame.data() + bytes_consumed, 18)); | 2978 CHECK_EQ(18u, framer.ProcessInput(frame.data() + bytes_consumed, 18)); |
| 2986 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READY_FOR_FRAME); | 2979 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READY_FOR_FRAME); |
| 2987 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 2980 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 2988 } | 2981 } |
| 2989 | 2982 |
| 2990 TEST_F(SpdyFramerTest, ReadWindowUpdate) { | 2983 TEST_F(SpdyFramerTest, ReadWindowUpdate) { |
| 2991 SpdyFramer framer(spdy_version_); | 2984 SpdyFramer framer; |
| 2992 SpdySerializedFrame control_frame( | 2985 SpdySerializedFrame control_frame( |
| 2993 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 2986 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 2994 TestSpdyVisitor visitor(spdy_version_); | 2987 TestSpdyVisitor visitor; |
| 2995 visitor.SimulateInFramer( | 2988 visitor.SimulateInFramer( |
| 2996 reinterpret_cast<unsigned char*>(control_frame.data()), | 2989 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2997 control_frame.size()); | 2990 control_frame.size()); |
| 2998 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 2991 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 2999 EXPECT_EQ(2, visitor.last_window_update_delta_); | 2992 EXPECT_EQ(2, visitor.last_window_update_delta_); |
| 3000 } | 2993 } |
| 3001 | 2994 |
| 3002 TEST_F(SpdyFramerTest, ReadCompressedPushPromise) { | 2995 TEST_F(SpdyFramerTest, ReadCompressedPushPromise) { |
| 3003 SpdyFramer framer(spdy_version_); | 2996 SpdyFramer framer; |
| 3004 SpdyPushPromiseIR push_promise(42, 57); | 2997 SpdyPushPromiseIR push_promise(42, 57); |
| 3005 push_promise.SetHeader("foo", "bar"); | 2998 push_promise.SetHeader("foo", "bar"); |
| 3006 push_promise.SetHeader("bar", "foofoo"); | 2999 push_promise.SetHeader("bar", "foofoo"); |
| 3007 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 3000 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 3008 TestSpdyVisitor visitor(spdy_version_); | 3001 TestSpdyVisitor visitor; |
| 3009 visitor.use_compression_ = true; | 3002 visitor.use_compression_ = true; |
| 3010 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 3003 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 3011 frame.size()); | 3004 frame.size()); |
| 3012 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3005 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3013 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3006 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3014 EXPECT_EQ(push_promise.header_block(), visitor.headers_); | 3007 EXPECT_EQ(push_promise.header_block(), visitor.headers_); |
| 3015 } | 3008 } |
| 3016 | 3009 |
| 3017 TEST_F(SpdyFramerTest, ReadHeadersWithContinuation) { | 3010 TEST_F(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3018 // frame-format off | 3011 // frame-format off |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3049 'o', 'o', 'k', 'i', 'e', // Name (continued) | 3042 'o', 'o', 'k', 'i', 'e', // Name (continued) |
| 3050 0x00, // Value Len: 0 | 3043 0x00, // Value Len: 0 |
| 3051 0x00, // Unindexed Entry | 3044 0x00, // Unindexed Entry |
| 3052 0x04, // Name Len: 4 | 3045 0x04, // Name Len: 4 |
| 3053 'n', 'a', 'm', 'e', // Name | 3046 'n', 'a', 'm', 'e', // Name |
| 3054 0x05, // Value Len: 5 | 3047 0x05, // Value Len: 5 |
| 3055 'v', 'a', 'l', 'u', 'e', // Value | 3048 'v', 'a', 'l', 'u', 'e', // Value |
| 3056 }; | 3049 }; |
| 3057 // frame-format on | 3050 // frame-format on |
| 3058 | 3051 |
| 3059 SpdyFramer framer(spdy_version_); | 3052 SpdyFramer framer; |
| 3060 TestSpdyVisitor visitor(spdy_version_); | 3053 TestSpdyVisitor visitor; |
| 3061 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3054 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3062 | 3055 |
| 3063 EXPECT_EQ(0, visitor.error_count_); | 3056 EXPECT_EQ(0, visitor.error_count_); |
| 3064 EXPECT_EQ(1, visitor.headers_frame_count_); | 3057 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3065 EXPECT_EQ(2, visitor.continuation_count_); | 3058 EXPECT_EQ(2, visitor.continuation_count_); |
| 3066 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3059 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3067 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3060 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 3068 | 3061 |
| 3069 EXPECT_THAT( | 3062 EXPECT_THAT( |
| 3070 visitor.headers_, | 3063 visitor.headers_, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3105 'o', 'o', 'k', 'i', 'e', // Name (continued) | 3098 'o', 'o', 'k', 'i', 'e', // Name (continued) |
| 3106 0x00, // Value Len: 0 | 3099 0x00, // Value Len: 0 |
| 3107 0x00, // Unindexed Entry | 3100 0x00, // Unindexed Entry |
| 3108 0x04, // Name Len: 4 | 3101 0x04, // Name Len: 4 |
| 3109 'n', 'a', 'm', 'e', // Name | 3102 'n', 'a', 'm', 'e', // Name |
| 3110 0x05, // Value Len: 5 | 3103 0x05, // Value Len: 5 |
| 3111 'v', 'a', 'l', 'u', 'e', // Value | 3104 'v', 'a', 'l', 'u', 'e', // Value |
| 3112 }; | 3105 }; |
| 3113 // frame-format on | 3106 // frame-format on |
| 3114 | 3107 |
| 3115 SpdyFramer framer(spdy_version_); | 3108 SpdyFramer framer; |
| 3116 TestSpdyVisitor visitor(spdy_version_); | 3109 TestSpdyVisitor visitor; |
| 3117 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3110 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3118 | 3111 |
| 3119 EXPECT_EQ(0, visitor.error_count_); | 3112 EXPECT_EQ(0, visitor.error_count_); |
| 3120 EXPECT_EQ(1, visitor.headers_frame_count_); | 3113 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3121 EXPECT_EQ(2, visitor.continuation_count_); | 3114 EXPECT_EQ(2, visitor.continuation_count_); |
| 3122 EXPECT_EQ(1, visitor.fin_flag_count_); | 3115 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3123 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3116 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3124 EXPECT_EQ(1, visitor.end_of_stream_count_); | 3117 EXPECT_EQ(1, visitor.end_of_stream_count_); |
| 3125 | 3118 |
| 3126 EXPECT_THAT( | 3119 EXPECT_THAT( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3153 0x00, 0x00, 0x12, 0x09, // CONTINUATION | 3146 0x00, 0x00, 0x12, 0x09, // CONTINUATION |
| 3154 0x04, 0x00, 0x00, 0x00, // END_HEADERS | 3147 0x04, 0x00, 0x00, 0x00, // END_HEADERS |
| 3155 0x01, 'o', 'o', 'k', // Stream 1 | 3148 0x01, 'o', 'o', 'k', // Stream 1 |
| 3156 'i', 'e', 0x00, 0x00, | 3149 'i', 'e', 0x00, 0x00, |
| 3157 0x04, 'n', 'a', 'm', | 3150 0x04, 'n', 'a', 'm', |
| 3158 'e', 0x05, 'v', 'a', | 3151 'e', 0x05, 'v', 'a', |
| 3159 'l', 'u', 'e', | 3152 'l', 'u', 'e', |
| 3160 }; | 3153 }; |
| 3161 // frame-format on | 3154 // frame-format on |
| 3162 | 3155 |
| 3163 SpdyFramer framer(spdy_version_); | 3156 SpdyFramer framer; |
| 3164 TestSpdyVisitor visitor(spdy_version_); | 3157 TestSpdyVisitor visitor; |
| 3165 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3158 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3166 | 3159 |
| 3167 EXPECT_EQ(0, visitor.error_count_); | 3160 EXPECT_EQ(0, visitor.error_count_); |
| 3168 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3161 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
| 3169 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3162 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
| 3170 EXPECT_EQ(2, visitor.continuation_count_); | 3163 EXPECT_EQ(2, visitor.continuation_count_); |
| 3171 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3164 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3172 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3165 EXPECT_EQ(0, visitor.end_of_stream_count_); |
| 3173 | 3166 |
| 3174 EXPECT_THAT( | 3167 EXPECT_THAT( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3194 0xa9, // Type: UnknownFrameType(169) | 3187 0xa9, // Type: UnknownFrameType(169) |
| 3195 0x00, // Flags: none | 3188 0x00, // Flags: none |
| 3196 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3189 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3197 0x00, 0x06, 0x63, 0x6f, // Payload | 3190 0x00, 0x06, 0x63, 0x6f, // Payload |
| 3198 0x6f, 0x6b, 0x69, 0x65, // | 3191 0x6f, 0x6b, 0x69, 0x65, // |
| 3199 0x08, 0x62, 0x61, 0x7a, // | 3192 0x08, 0x62, 0x61, 0x7a, // |
| 3200 0x3d, 0x62, 0x69, 0x6e, // | 3193 0x3d, 0x62, 0x69, 0x6e, // |
| 3201 0x67, 0x00, 0x06, 0x63, // | 3194 0x67, 0x00, 0x06, 0x63, // |
| 3202 }; | 3195 }; |
| 3203 | 3196 |
| 3204 SpdyFramer framer(spdy_version_); | 3197 SpdyFramer framer; |
| 3205 TestSpdyVisitor visitor(spdy_version_); | 3198 TestSpdyVisitor visitor; |
| 3206 // Assume the unknown frame is allowed | 3199 // Assume the unknown frame is allowed |
| 3207 visitor.on_unknown_frame_result_ = true; | 3200 visitor.on_unknown_frame_result_ = true; |
| 3208 framer.set_visitor(&visitor); | 3201 framer.set_visitor(&visitor); |
| 3209 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3202 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3210 | 3203 |
| 3211 EXPECT_EQ(1, visitor.error_count_); | 3204 EXPECT_EQ(1, visitor.error_count_); |
| 3212 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3205 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3213 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3206 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3214 EXPECT_EQ(1, visitor.headers_frame_count_); | 3207 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3215 EXPECT_EQ(0, visitor.continuation_count_); | 3208 EXPECT_EQ(0, visitor.continuation_count_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3231 0x09, // Type: CONTINUATION | 3224 0x09, // Type: CONTINUATION |
| 3232 0x00, // Flags: none | 3225 0x00, // Flags: none |
| 3233 0x00, 0x00, 0x00, 0x02, // Stream: 2 | 3226 0x00, 0x00, 0x00, 0x02, // Stream: 2 |
| 3234 0x00, 0x06, 0x63, 0x6f, // HPACK | 3227 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3235 0x6f, 0x6b, 0x69, 0x65, // | 3228 0x6f, 0x6b, 0x69, 0x65, // |
| 3236 0x08, 0x62, 0x61, 0x7a, // | 3229 0x08, 0x62, 0x61, 0x7a, // |
| 3237 0x3d, 0x62, 0x69, 0x6e, // | 3230 0x3d, 0x62, 0x69, 0x6e, // |
| 3238 0x67, 0x00, 0x06, 0x63, // | 3231 0x67, 0x00, 0x06, 0x63, // |
| 3239 }; | 3232 }; |
| 3240 | 3233 |
| 3241 SpdyFramer framer(spdy_version_); | 3234 SpdyFramer framer; |
| 3242 TestSpdyVisitor visitor(spdy_version_); | 3235 TestSpdyVisitor visitor; |
| 3243 framer.set_visitor(&visitor); | 3236 framer.set_visitor(&visitor); |
| 3244 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3237 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3245 | 3238 |
| 3246 EXPECT_EQ(1, visitor.error_count_); | 3239 EXPECT_EQ(1, visitor.error_count_); |
| 3247 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3240 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3248 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3241 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3249 EXPECT_EQ(1, visitor.headers_frame_count_); | 3242 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3250 EXPECT_EQ(0, visitor.continuation_count_); | 3243 EXPECT_EQ(0, visitor.continuation_count_); |
| 3251 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3244 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3252 } | 3245 } |
| 3253 | 3246 |
| 3254 TEST_F(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3247 TEST_F(SpdyFramerTest, ReadContinuationOutOfOrder) { |
| 3255 const unsigned char kInput[] = { | 3248 const unsigned char kInput[] = { |
| 3256 0x00, 0x00, 0x18, // Length: 24 | 3249 0x00, 0x00, 0x18, // Length: 24 |
| 3257 0x09, // Type: CONTINUATION | 3250 0x09, // Type: CONTINUATION |
| 3258 0x00, // Flags: none | 3251 0x00, // Flags: none |
| 3259 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3252 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3260 0x00, 0x06, 0x63, 0x6f, // HPACK | 3253 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3261 0x6f, 0x6b, 0x69, 0x65, // | 3254 0x6f, 0x6b, 0x69, 0x65, // |
| 3262 0x07, 0x66, 0x6f, 0x6f, // | 3255 0x07, 0x66, 0x6f, 0x6f, // |
| 3263 0x3d, 0x62, 0x61, 0x72, // | 3256 0x3d, 0x62, 0x61, 0x72, // |
| 3264 }; | 3257 }; |
| 3265 | 3258 |
| 3266 SpdyFramer framer(spdy_version_); | 3259 SpdyFramer framer; |
| 3267 TestSpdyVisitor visitor(spdy_version_); | 3260 TestSpdyVisitor visitor; |
| 3268 framer.set_visitor(&visitor); | 3261 framer.set_visitor(&visitor); |
| 3269 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3262 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3270 | 3263 |
| 3271 EXPECT_EQ(1, visitor.error_count_); | 3264 EXPECT_EQ(1, visitor.error_count_); |
| 3272 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3265 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3273 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3266 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3274 EXPECT_EQ(0, visitor.continuation_count_); | 3267 EXPECT_EQ(0, visitor.continuation_count_); |
| 3275 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3268 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3276 } | 3269 } |
| 3277 | 3270 |
| 3278 TEST_F(SpdyFramerTest, ExpectContinuationReceiveData) { | 3271 TEST_F(SpdyFramerTest, ExpectContinuationReceiveData) { |
| 3279 const unsigned char kInput[] = { | 3272 const unsigned char kInput[] = { |
| 3280 0x00, 0x00, 0x10, // Length: 16 | 3273 0x00, 0x00, 0x10, // Length: 16 |
| 3281 0x01, // Type: HEADERS | 3274 0x01, // Type: HEADERS |
| 3282 0x00, // Flags: none | 3275 0x00, // Flags: none |
| 3283 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3276 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3284 0x00, 0x06, 0x63, 0x6f, // HPACK | 3277 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3285 0x6f, 0x6b, 0x69, 0x65, // | 3278 0x6f, 0x6b, 0x69, 0x65, // |
| 3286 0x07, 0x66, 0x6f, 0x6f, // | 3279 0x07, 0x66, 0x6f, 0x6f, // |
| 3287 0x3d, 0x62, 0x61, 0x72, // | 3280 0x3d, 0x62, 0x61, 0x72, // |
| 3288 | 3281 |
| 3289 0x00, 0x00, 0x00, // Length: 0 | 3282 0x00, 0x00, 0x00, // Length: 0 |
| 3290 0x00, // Type: DATA | 3283 0x00, // Type: DATA |
| 3291 0x01, // Flags: END_STREAM | 3284 0x01, // Flags: END_STREAM |
| 3292 0x00, 0x00, 0x00, 0x04, // Stream: 4 | 3285 0x00, 0x00, 0x00, 0x04, // Stream: 4 |
| 3293 | 3286 |
| 3294 0xde, 0xad, 0xbe, 0xef, // Truncated Frame Header | 3287 0xde, 0xad, 0xbe, 0xef, // Truncated Frame Header |
| 3295 }; | 3288 }; |
| 3296 | 3289 |
| 3297 SpdyFramer framer(spdy_version_); | 3290 SpdyFramer framer; |
| 3298 TestSpdyVisitor visitor(spdy_version_); | 3291 TestSpdyVisitor visitor; |
| 3299 framer.set_visitor(&visitor); | 3292 framer.set_visitor(&visitor); |
| 3300 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3293 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3301 | 3294 |
| 3302 EXPECT_EQ(1, visitor.error_count_); | 3295 EXPECT_EQ(1, visitor.error_count_); |
| 3303 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3296 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3304 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3297 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3305 EXPECT_EQ(1, visitor.headers_frame_count_); | 3298 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3306 EXPECT_EQ(0, visitor.continuation_count_); | 3299 EXPECT_EQ(0, visitor.continuation_count_); |
| 3307 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3300 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3308 EXPECT_EQ(0, visitor.data_frame_count_); | 3301 EXPECT_EQ(0, visitor.data_frame_count_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3322 0x00, 0x00, 0x10, // Length: 16 | 3315 0x00, 0x00, 0x10, // Length: 16 |
| 3323 0x01, // Type: HEADERS | 3316 0x01, // Type: HEADERS |
| 3324 0x00, // Flags: none | 3317 0x00, // Flags: none |
| 3325 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3318 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3326 0x00, 0x06, 0x63, 0x6f, // HPACK | 3319 0x00, 0x06, 0x63, 0x6f, // HPACK |
| 3327 0x6f, 0x6b, 0x69, 0x65, // | 3320 0x6f, 0x6b, 0x69, 0x65, // |
| 3328 0x07, 0x66, 0x6f, 0x6f, // | 3321 0x07, 0x66, 0x6f, 0x6f, // |
| 3329 0x3d, 0x62, 0x61, 0x72, // | 3322 0x3d, 0x62, 0x61, 0x72, // |
| 3330 }; | 3323 }; |
| 3331 | 3324 |
| 3332 SpdyFramer framer(spdy_version_); | 3325 SpdyFramer framer; |
| 3333 TestSpdyVisitor visitor(spdy_version_); | 3326 TestSpdyVisitor visitor; |
| 3334 framer.set_visitor(&visitor); | 3327 framer.set_visitor(&visitor); |
| 3335 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3328 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3336 | 3329 |
| 3337 EXPECT_EQ(1, visitor.error_count_); | 3330 EXPECT_EQ(1, visitor.error_count_); |
| 3338 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3331 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3339 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3332 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 3340 EXPECT_EQ(1, visitor.headers_frame_count_); | 3333 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3341 EXPECT_EQ(0, visitor.continuation_count_); | 3334 EXPECT_EQ(0, visitor.continuation_count_); |
| 3342 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3335 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3343 EXPECT_EQ(0, visitor.data_frame_count_); | 3336 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3344 } | 3337 } |
| 3345 | 3338 |
| 3346 TEST_F(SpdyFramerTest, ReadGarbage) { | 3339 TEST_F(SpdyFramerTest, ReadGarbage) { |
| 3347 SpdyFramer framer(spdy_version_); | 3340 SpdyFramer framer; |
| 3348 unsigned char garbage_frame[256]; | 3341 unsigned char garbage_frame[256]; |
| 3349 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 3342 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 3350 TestSpdyVisitor visitor(spdy_version_); | 3343 TestSpdyVisitor visitor; |
| 3351 visitor.use_compression_ = false; | 3344 visitor.use_compression_ = false; |
| 3352 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 3345 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 3353 EXPECT_EQ(1, visitor.error_count_); | 3346 EXPECT_EQ(1, visitor.error_count_); |
| 3354 } | 3347 } |
| 3355 | 3348 |
| 3356 TEST_F(SpdyFramerTest, ReadUnknownExtensionFrame) { | 3349 TEST_F(SpdyFramerTest, ReadUnknownExtensionFrame) { |
| 3357 SpdyFramer framer(spdy_version_); | 3350 SpdyFramer framer; |
| 3358 | 3351 |
| 3359 // The unrecognized frame type should still have a valid length. | 3352 // The unrecognized frame type should still have a valid length. |
| 3360 const unsigned char unknown_frame[] = { | 3353 const unsigned char unknown_frame[] = { |
| 3361 0x00, 0x00, 0x08, // Length: 8 | 3354 0x00, 0x00, 0x08, // Length: 8 |
| 3362 0xff, // Type: UnknownFrameType(255) | 3355 0xff, // Type: UnknownFrameType(255) |
| 3363 0xff, // Flags: 0xff | 3356 0xff, // Flags: 0xff |
| 3364 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3357 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3365 0xff, 0xff, 0xff, 0xff, // Payload | 3358 0xff, 0xff, 0xff, 0xff, // Payload |
| 3366 0xff, 0xff, 0xff, 0xff, // | 3359 0xff, 0xff, 0xff, 0xff, // |
| 3367 }; | 3360 }; |
| 3368 TestSpdyVisitor visitor(spdy_version_); | 3361 TestSpdyVisitor visitor; |
| 3369 | 3362 |
| 3370 // Simulate the case where the stream id validation checks out. | 3363 // Simulate the case where the stream id validation checks out. |
| 3371 visitor.on_unknown_frame_result_ = true; | 3364 visitor.on_unknown_frame_result_ = true; |
| 3372 visitor.use_compression_ = false; | 3365 visitor.use_compression_ = false; |
| 3373 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); | 3366 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); |
| 3374 EXPECT_EQ(0, visitor.error_count_); | 3367 EXPECT_EQ(0, visitor.error_count_); |
| 3375 | 3368 |
| 3376 // Follow it up with a valid control frame to make sure we handle | 3369 // Follow it up with a valid control frame to make sure we handle |
| 3377 // subsequent frames correctly. | 3370 // subsequent frames correctly. |
| 3378 SpdySettingsIR settings_ir; | 3371 SpdySettingsIR settings_ir; |
| 3379 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), | 3372 settings_ir.AddSetting(SpdyConstants::ParseSettingId(1), |
| 3380 false, // persist | 3373 false, // persist |
| 3381 false, // persisted | 3374 false, // persisted |
| 3382 10); | 3375 10); |
| 3383 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3376 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3384 visitor.SimulateInFramer( | 3377 visitor.SimulateInFramer( |
| 3385 reinterpret_cast<unsigned char*>(control_frame.data()), | 3378 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3386 control_frame.size()); | 3379 control_frame.size()); |
| 3387 EXPECT_EQ(0, visitor.error_count_); | 3380 EXPECT_EQ(0, visitor.error_count_); |
| 3388 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3381 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); |
| 3389 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3382 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); |
| 3390 } | 3383 } |
| 3391 | 3384 |
| 3392 TEST_F(SpdyFramerTest, ReadGarbageWithValidLength) { | 3385 TEST_F(SpdyFramerTest, ReadGarbageWithValidLength) { |
| 3393 SpdyFramer framer(spdy_version_); | 3386 SpdyFramer framer; |
| 3394 const unsigned char kFrameData[] = { | 3387 const unsigned char kFrameData[] = { |
| 3395 0x00, 0x00, 0x08, // Length: 8 | 3388 0x00, 0x00, 0x08, // Length: 8 |
| 3396 0xff, // Type: UnknownFrameType(255) | 3389 0xff, // Type: UnknownFrameType(255) |
| 3397 0xff, // Flags: 0xff | 3390 0xff, // Flags: 0xff |
| 3398 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3391 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3399 0xff, 0xff, 0xff, 0xff, // Payload | 3392 0xff, 0xff, 0xff, 0xff, // Payload |
| 3400 0xff, 0xff, 0xff, 0xff, // | 3393 0xff, 0xff, 0xff, 0xff, // |
| 3401 }; | 3394 }; |
| 3402 TestSpdyVisitor visitor(spdy_version_); | 3395 TestSpdyVisitor visitor; |
| 3403 visitor.use_compression_ = false; | 3396 visitor.use_compression_ = false; |
| 3404 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 3397 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
| 3405 EXPECT_EQ(1, visitor.error_count_); | 3398 EXPECT_EQ(1, visitor.error_count_); |
| 3406 } | 3399 } |
| 3407 | 3400 |
| 3408 TEST_F(SpdyFramerTest, ReadGarbageHPACKEncoding) { | 3401 TEST_F(SpdyFramerTest, ReadGarbageHPACKEncoding) { |
| 3409 const unsigned char kInput[] = { | 3402 const unsigned char kInput[] = { |
| 3410 0x00, 0x12, 0x01, // Length: 4609 | 3403 0x00, 0x12, 0x01, // Length: 4609 |
| 3411 0x04, // Type: SETTINGS | 3404 0x04, // Type: SETTINGS |
| 3412 0x00, // Flags: none | 3405 0x00, // Flags: none |
| 3413 0x00, 0x00, 0x01, 0xef, // Stream: 495 | 3406 0x00, 0x00, 0x01, 0xef, // Stream: 495 |
| 3414 0xef, 0xff, // Param: 61439 | 3407 0xef, 0xff, // Param: 61439 |
| 3415 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3408 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
| 3416 0xff, 0xff, // Param: 0xffff | 3409 0xff, 0xff, // Param: 0xffff |
| 3417 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3410 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
| 3418 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) | 3411 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) |
| 3419 0xff, // | 3412 0xff, // |
| 3420 }; | 3413 }; |
| 3421 | 3414 |
| 3422 TestSpdyVisitor visitor(spdy_version_); | 3415 TestSpdyVisitor visitor; |
| 3423 visitor.SimulateInFramer(kInput, arraysize(kInput)); | 3416 visitor.SimulateInFramer(kInput, arraysize(kInput)); |
| 3424 EXPECT_EQ(1, visitor.error_count_); | 3417 EXPECT_EQ(1, visitor.error_count_); |
| 3425 } | 3418 } |
| 3426 | 3419 |
| 3427 TEST_F(SpdyFramerTest, SizesTest) { | 3420 TEST_F(SpdyFramerTest, SizesTest) { |
| 3428 SpdyFramer framer(spdy_version_); | 3421 SpdyFramer framer; |
| 3429 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); | 3422 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); |
| 3430 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); | 3423 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); |
| 3431 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); | 3424 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); |
| 3432 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); | 3425 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); |
| 3433 EXPECT_EQ(17u, framer.GetPingSize()); | 3426 EXPECT_EQ(17u, framer.GetPingSize()); |
| 3434 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); | 3427 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); |
| 3435 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); | 3428 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); |
| 3436 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); | 3429 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); |
| 3437 EXPECT_EQ(9u, framer.GetBlockedSize()); | 3430 EXPECT_EQ(9u, framer.GetBlockedSize()); |
| 3438 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); | 3431 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3543 | 3536 |
| 3544 TEST_F(SpdyFramerTest, DataFrameFlagsV4) { | 3537 TEST_F(SpdyFramerTest, DataFrameFlagsV4) { |
| 3545 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; | 3538 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; |
| 3546 | 3539 |
| 3547 uint8_t flags = 0; | 3540 uint8_t flags = 0; |
| 3548 do { | 3541 do { |
| 3549 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3542 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3550 << static_cast<int>(flags)); | 3543 << static_cast<int>(flags)); |
| 3551 | 3544 |
| 3552 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3545 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3553 SpdyFramer framer(spdy_version_); | 3546 SpdyFramer framer; |
| 3554 framer.set_visitor(&visitor); | 3547 framer.set_visitor(&visitor); |
| 3555 | 3548 |
| 3556 SpdyDataIR data_ir(1, "hello"); | 3549 SpdyDataIR data_ir(1, "hello"); |
| 3557 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 3550 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
| 3558 SetFrameFlags(&frame, flags, spdy_version_); | 3551 SetFrameFlags(&frame, flags); |
| 3559 | 3552 |
| 3560 if (flags & ~valid_data_flags) { | 3553 if (flags & ~valid_data_flags) { |
| 3561 EXPECT_CALL(visitor, OnError(_)); | 3554 EXPECT_CALL(visitor, OnError(_)); |
| 3562 } else { | 3555 } else { |
| 3563 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 3556 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
| 3564 if (flags & DATA_FLAG_PADDED) { | 3557 if (flags & DATA_FLAG_PADDED) { |
| 3565 // The first byte of payload is parsed as padding length, but 'h' | 3558 // The first byte of payload is parsed as padding length, but 'h' |
| 3566 // (0x68) is too large a padding length for a 5 byte payload. | 3559 // (0x68) is too large a padding length for a 5 byte payload. |
| 3567 EXPECT_CALL(visitor, OnStreamPadding(_, 1)); | 3560 EXPECT_CALL(visitor, OnStreamPadding(_, 1)); |
| 3568 // Expect Error since the frame ends prematurely. | 3561 // Expect Error since the frame ends prematurely. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3592 } while (++flags != 0); | 3585 } while (++flags != 0); |
| 3593 } | 3586 } |
| 3594 | 3587 |
| 3595 TEST_F(SpdyFramerTest, RstStreamFrameFlags) { | 3588 TEST_F(SpdyFramerTest, RstStreamFrameFlags) { |
| 3596 uint8_t flags = 0; | 3589 uint8_t flags = 0; |
| 3597 do { | 3590 do { |
| 3598 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3591 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3599 << static_cast<int>(flags)); | 3592 << static_cast<int>(flags)); |
| 3600 | 3593 |
| 3601 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3594 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3602 SpdyFramer framer(spdy_version_); | 3595 SpdyFramer framer; |
| 3603 framer.set_visitor(&visitor); | 3596 framer.set_visitor(&visitor); |
| 3604 | 3597 |
| 3605 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); | 3598 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); |
| 3606 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 3599 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 3607 SetFrameFlags(&frame, flags, spdy_version_); | 3600 SetFrameFlags(&frame, flags); |
| 3608 | 3601 |
| 3609 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); | 3602 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); |
| 3610 | 3603 |
| 3611 framer.ProcessInput(frame.data(), frame.size()); | 3604 framer.ProcessInput(frame.data(), frame.size()); |
| 3612 | 3605 |
| 3613 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3606 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3614 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3607 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3615 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3608 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3616 } while (++flags != 0); | 3609 } while (++flags != 0); |
| 3617 } | 3610 } |
| 3618 | 3611 |
| 3619 TEST_F(SpdyFramerTest, SettingsFrameFlags) { | 3612 TEST_F(SpdyFramerTest, SettingsFrameFlags) { |
| 3620 uint8_t flags = 0; | 3613 uint8_t flags = 0; |
| 3621 do { | 3614 do { |
| 3622 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3615 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3623 << static_cast<int>(flags)); | 3616 << static_cast<int>(flags)); |
| 3624 | 3617 |
| 3625 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3618 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3626 SpdyFramer framer(spdy_version_); | 3619 SpdyFramer framer; |
| 3627 framer.set_visitor(&visitor); | 3620 framer.set_visitor(&visitor); |
| 3628 | 3621 |
| 3629 SpdySettingsIR settings_ir; | 3622 SpdySettingsIR settings_ir; |
| 3630 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); | 3623 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); |
| 3631 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 3624 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 3632 SetFrameFlags(&frame, flags, spdy_version_); | 3625 SetFrameFlags(&frame, flags); |
| 3633 | 3626 |
| 3634 if (flags & SETTINGS_FLAG_ACK) { | 3627 if (flags & SETTINGS_FLAG_ACK) { |
| 3635 EXPECT_CALL(visitor, OnError(_)); | 3628 EXPECT_CALL(visitor, OnError(_)); |
| 3636 } else { | 3629 } else { |
| 3637 EXPECT_CALL(visitor, OnSettings(flags & SETTINGS_FLAG_ACK)); | 3630 EXPECT_CALL(visitor, OnSettings(flags & SETTINGS_FLAG_ACK)); |
| 3638 EXPECT_CALL(visitor, OnSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 16)); | 3631 EXPECT_CALL(visitor, OnSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 16)); |
| 3639 EXPECT_CALL(visitor, OnSettingsEnd()); | 3632 EXPECT_CALL(visitor, OnSettingsEnd()); |
| 3640 } | 3633 } |
| 3641 | 3634 |
| 3642 framer.ProcessInput(frame.data(), frame.size()); | 3635 framer.ProcessInput(frame.data(), frame.size()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3654 } while (++flags != 0); | 3647 } while (++flags != 0); |
| 3655 } | 3648 } |
| 3656 | 3649 |
| 3657 TEST_F(SpdyFramerTest, GoawayFrameFlags) { | 3650 TEST_F(SpdyFramerTest, GoawayFrameFlags) { |
| 3658 uint8_t flags = 0; | 3651 uint8_t flags = 0; |
| 3659 do { | 3652 do { |
| 3660 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3653 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3661 << static_cast<int>(flags)); | 3654 << static_cast<int>(flags)); |
| 3662 | 3655 |
| 3663 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3656 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3664 SpdyFramer framer(spdy_version_); | 3657 SpdyFramer framer; |
| 3665 framer.set_visitor(&visitor); | 3658 framer.set_visitor(&visitor); |
| 3666 | 3659 |
| 3667 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); | 3660 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); |
| 3668 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 3661 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
| 3669 SetFrameFlags(&frame, flags, spdy_version_); | 3662 SetFrameFlags(&frame, flags); |
| 3670 | 3663 |
| 3671 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); | 3664 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); |
| 3672 | 3665 |
| 3673 framer.ProcessInput(frame.data(), frame.size()); | 3666 framer.ProcessInput(frame.data(), frame.size()); |
| 3674 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3667 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3675 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3668 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3676 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3669 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3677 } while (++flags != 0); | 3670 } while (++flags != 0); |
| 3678 } | 3671 } |
| 3679 | 3672 |
| 3680 TEST_F(SpdyFramerTest, HeadersFrameFlags) { | 3673 TEST_F(SpdyFramerTest, HeadersFrameFlags) { |
| 3681 uint8_t flags = 0; | 3674 uint8_t flags = 0; |
| 3682 do { | 3675 do { |
| 3683 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3676 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3684 << static_cast<int>(flags)); | 3677 << static_cast<int>(flags)); |
| 3685 | 3678 |
| 3686 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3679 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3687 SpdyFramer framer(spdy_version_); | 3680 SpdyFramer framer; |
| 3688 framer.set_visitor(&visitor); | 3681 framer.set_visitor(&visitor); |
| 3689 | 3682 |
| 3690 SpdyHeadersIR headers_ir(57); | 3683 SpdyHeadersIR headers_ir(57); |
| 3691 if (flags & HEADERS_FLAG_PRIORITY) { | 3684 if (flags & HEADERS_FLAG_PRIORITY) { |
| 3692 headers_ir.set_weight(3); | 3685 headers_ir.set_weight(3); |
| 3693 headers_ir.set_has_priority(true); | 3686 headers_ir.set_has_priority(true); |
| 3694 headers_ir.set_parent_stream_id(5); | 3687 headers_ir.set_parent_stream_id(5); |
| 3695 headers_ir.set_exclusive(true); | 3688 headers_ir.set_exclusive(true); |
| 3696 } | 3689 } |
| 3697 headers_ir.SetHeader("foo", "bar"); | 3690 headers_ir.SetHeader("foo", "bar"); |
| 3698 SpdySerializedFrame frame( | 3691 SpdySerializedFrame frame( |
| 3699 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 3692 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 3700 uint8_t set_flags = flags & ~HEADERS_FLAG_PADDED; | 3693 uint8_t set_flags = flags & ~HEADERS_FLAG_PADDED; |
| 3701 SetFrameFlags(&frame, set_flags, spdy_version_); | 3694 SetFrameFlags(&frame, set_flags); |
| 3702 | 3695 |
| 3703 // Expected callback values | 3696 // Expected callback values |
| 3704 SpdyStreamId stream_id = 57; | 3697 SpdyStreamId stream_id = 57; |
| 3705 bool has_priority = false; | 3698 bool has_priority = false; |
| 3706 SpdyPriority priority = 0; | 3699 SpdyPriority priority = 0; |
| 3707 SpdyStreamId parent_stream_id = 0; | 3700 SpdyStreamId parent_stream_id = 0; |
| 3708 bool exclusive = false; | 3701 bool exclusive = false; |
| 3709 bool fin = flags & CONTROL_FLAG_FIN; | 3702 bool fin = flags & CONTROL_FLAG_FIN; |
| 3710 bool end = flags & HEADERS_FLAG_END_HEADERS; | 3703 bool end = flags & HEADERS_FLAG_END_HEADERS; |
| 3711 if (flags & HEADERS_FLAG_PRIORITY) { | 3704 if (flags & HEADERS_FLAG_PRIORITY) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3734 } while (++flags != 0); | 3727 } while (++flags != 0); |
| 3735 } | 3728 } |
| 3736 | 3729 |
| 3737 TEST_F(SpdyFramerTest, PingFrameFlags) { | 3730 TEST_F(SpdyFramerTest, PingFrameFlags) { |
| 3738 uint8_t flags = 0; | 3731 uint8_t flags = 0; |
| 3739 do { | 3732 do { |
| 3740 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3733 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3741 << static_cast<int>(flags)); | 3734 << static_cast<int>(flags)); |
| 3742 | 3735 |
| 3743 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3736 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3744 SpdyFramer framer(spdy_version_); | 3737 SpdyFramer framer; |
| 3745 framer.set_visitor(&visitor); | 3738 framer.set_visitor(&visitor); |
| 3746 | 3739 |
| 3747 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); | 3740 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); |
| 3748 SetFrameFlags(&frame, flags, spdy_version_); | 3741 SetFrameFlags(&frame, flags); |
| 3749 | 3742 |
| 3750 if (flags & PING_FLAG_ACK) { | 3743 if (flags & PING_FLAG_ACK) { |
| 3751 EXPECT_CALL(visitor, OnPing(42, true)); | 3744 EXPECT_CALL(visitor, OnPing(42, true)); |
| 3752 } else { | 3745 } else { |
| 3753 EXPECT_CALL(visitor, OnPing(42, false)); | 3746 EXPECT_CALL(visitor, OnPing(42, false)); |
| 3754 } | 3747 } |
| 3755 | 3748 |
| 3756 framer.ProcessInput(frame.data(), frame.size()); | 3749 framer.ProcessInput(frame.data(), frame.size()); |
| 3757 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3750 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3758 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3751 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3759 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3752 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3760 } while (++flags != 0); | 3753 } while (++flags != 0); |
| 3761 } | 3754 } |
| 3762 | 3755 |
| 3763 TEST_F(SpdyFramerTest, WindowUpdateFrameFlags) { | 3756 TEST_F(SpdyFramerTest, WindowUpdateFrameFlags) { |
| 3764 uint8_t flags = 0; | 3757 uint8_t flags = 0; |
| 3765 do { | 3758 do { |
| 3766 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3759 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3767 << static_cast<int>(flags)); | 3760 << static_cast<int>(flags)); |
| 3768 | 3761 |
| 3769 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3762 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3770 SpdyFramer framer(spdy_version_); | 3763 SpdyFramer framer; |
| 3771 framer.set_visitor(&visitor); | 3764 framer.set_visitor(&visitor); |
| 3772 | 3765 |
| 3773 SpdySerializedFrame frame( | 3766 SpdySerializedFrame frame( |
| 3774 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); | 3767 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); |
| 3775 SetFrameFlags(&frame, flags, spdy_version_); | 3768 SetFrameFlags(&frame, flags); |
| 3776 | 3769 |
| 3777 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 3770 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
| 3778 | 3771 |
| 3779 framer.ProcessInput(frame.data(), frame.size()); | 3772 framer.ProcessInput(frame.data(), frame.size()); |
| 3780 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3773 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3781 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3774 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3782 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3775 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3783 } while (++flags != 0); | 3776 } while (++flags != 0); |
| 3784 } | 3777 } |
| 3785 | 3778 |
| 3786 TEST_F(SpdyFramerTest, PushPromiseFrameFlags) { | 3779 TEST_F(SpdyFramerTest, PushPromiseFrameFlags) { |
| 3787 const SpdyStreamId client_id = 123; // Must be odd. | 3780 const SpdyStreamId client_id = 123; // Must be odd. |
| 3788 const SpdyStreamId promised_id = 22; // Must be even. | 3781 const SpdyStreamId promised_id = 22; // Must be even. |
| 3789 uint8_t flags = 0; | 3782 uint8_t flags = 0; |
| 3790 do { | 3783 do { |
| 3791 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3784 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3792 << static_cast<int>(flags)); | 3785 << static_cast<int>(flags)); |
| 3793 | 3786 |
| 3794 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3787 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3795 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3788 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 3796 SpdyFramer framer(spdy_version_); | 3789 SpdyFramer framer; |
| 3797 framer.set_visitor(&visitor); | 3790 framer.set_visitor(&visitor); |
| 3798 framer.set_debug_visitor(&debug_visitor); | 3791 framer.set_debug_visitor(&debug_visitor); |
| 3799 | 3792 |
| 3800 EXPECT_CALL(debug_visitor, | 3793 EXPECT_CALL(debug_visitor, |
| 3801 OnSendCompressedFrame(client_id, PUSH_PROMISE, _, _)); | 3794 OnSendCompressedFrame(client_id, PUSH_PROMISE, _, _)); |
| 3802 | 3795 |
| 3803 SpdyPushPromiseIR push_promise(client_id, promised_id); | 3796 SpdyPushPromiseIR push_promise(client_id, promised_id); |
| 3804 push_promise.SetHeader("foo", "bar"); | 3797 push_promise.SetHeader("foo", "bar"); |
| 3805 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 3798 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
| 3806 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, | 3799 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
| 3807 // and implement framing. | 3800 // and implement framing. |
| 3808 SetFrameFlags(&frame, flags & ~HEADERS_FLAG_PADDED, spdy_version_); | 3801 SetFrameFlags(&frame, flags & ~HEADERS_FLAG_PADDED); |
| 3809 | 3802 |
| 3810 bool end = flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE; | 3803 bool end = flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE; |
| 3811 EXPECT_CALL(debug_visitor, | 3804 EXPECT_CALL(debug_visitor, |
| 3812 OnReceiveCompressedFrame(client_id, PUSH_PROMISE, _)); | 3805 OnReceiveCompressedFrame(client_id, PUSH_PROMISE, _)); |
| 3813 EXPECT_CALL(visitor, OnPushPromise(client_id, promised_id, end)); | 3806 EXPECT_CALL(visitor, OnPushPromise(client_id, promised_id, end)); |
| 3814 EXPECT_CALL(visitor, OnHeaderFrameStart(client_id)).Times(1); | 3807 EXPECT_CALL(visitor, OnHeaderFrameStart(client_id)).Times(1); |
| 3815 if (end) { | 3808 if (end) { |
| 3816 EXPECT_CALL(visitor, OnHeaderFrameEnd(client_id, _)).Times(1); | 3809 EXPECT_CALL(visitor, OnHeaderFrameEnd(client_id, _)).Times(1); |
| 3817 } | 3810 } |
| 3818 | 3811 |
| 3819 framer.ProcessInput(frame.data(), frame.size()); | 3812 framer.ProcessInput(frame.data(), frame.size()); |
| 3820 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3813 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3821 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3814 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3822 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3815 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3823 } while (++flags != 0); | 3816 } while (++flags != 0); |
| 3824 } | 3817 } |
| 3825 | 3818 |
| 3826 TEST_F(SpdyFramerTest, ContinuationFrameFlags) { | 3819 TEST_F(SpdyFramerTest, ContinuationFrameFlags) { |
| 3827 uint8_t flags = 0; | 3820 uint8_t flags = 0; |
| 3828 do { | 3821 do { |
| 3829 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3822 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
| 3830 << static_cast<int>(flags)); | 3823 << static_cast<int>(flags)); |
| 3831 | 3824 |
| 3832 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3825 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3833 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3826 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 3834 SpdyFramer framer(spdy_version_); | 3827 SpdyFramer framer; |
| 3835 framer.set_visitor(&visitor); | 3828 framer.set_visitor(&visitor); |
| 3836 framer.set_debug_visitor(&debug_visitor); | 3829 framer.set_debug_visitor(&debug_visitor); |
| 3837 | 3830 |
| 3838 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); | 3831 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); |
| 3839 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); | 3832 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); |
| 3840 EXPECT_CALL(visitor, OnHeaders(42, false, 0, 0, false, false, false)); | 3833 EXPECT_CALL(visitor, OnHeaders(42, false, 0, 0, false, false, false)); |
| 3841 EXPECT_CALL(visitor, OnHeaderFrameStart(42)).Times(1); | 3834 EXPECT_CALL(visitor, OnHeaderFrameStart(42)).Times(1); |
| 3842 | 3835 |
| 3843 SpdyHeadersIR headers_ir(42); | 3836 SpdyHeadersIR headers_ir(42); |
| 3844 headers_ir.SetHeader("foo", "bar"); | 3837 headers_ir.SetHeader("foo", "bar"); |
| 3845 SpdySerializedFrame frame0( | 3838 SpdySerializedFrame frame0( |
| 3846 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 3839 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
| 3847 SetFrameFlags(&frame0, 0, spdy_version_); | 3840 SetFrameFlags(&frame0, 0); |
| 3848 | 3841 |
| 3849 SpdyContinuationIR continuation(42); | 3842 SpdyContinuationIR continuation(42); |
| 3850 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 3843 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 3851 SetFrameFlags(&frame, flags, spdy_version_); | 3844 SetFrameFlags(&frame, flags); |
| 3852 | 3845 |
| 3853 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); | 3846 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); |
| 3854 EXPECT_CALL(visitor, OnContinuation(42, flags & HEADERS_FLAG_END_HEADERS)); | 3847 EXPECT_CALL(visitor, OnContinuation(42, flags & HEADERS_FLAG_END_HEADERS)); |
| 3855 bool end = flags & HEADERS_FLAG_END_HEADERS; | 3848 bool end = flags & HEADERS_FLAG_END_HEADERS; |
| 3856 if (end) { | 3849 if (end) { |
| 3857 EXPECT_CALL(visitor, OnHeaderFrameEnd(42, _)).Times(1); | 3850 EXPECT_CALL(visitor, OnHeaderFrameEnd(42, _)).Times(1); |
| 3858 } | 3851 } |
| 3859 | 3852 |
| 3860 framer.ProcessInput(frame0.data(), frame0.size()); | 3853 framer.ProcessInput(frame0.data(), frame0.size()); |
| 3861 framer.ProcessInput(frame.data(), frame.size()); | 3854 framer.ProcessInput(frame.data(), frame.size()); |
| 3862 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3855 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3863 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3856 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3864 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3857 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3865 } while (++flags != 0); | 3858 } while (++flags != 0); |
| 3866 } | 3859 } |
| 3867 | 3860 |
| 3868 // TODO(mlavan): Add TEST_F(SpdyFramerTest, AltSvcFrameFlags) | 3861 // TODO(mlavan): Add TEST_F(SpdyFramerTest, AltSvcFrameFlags) |
| 3869 | 3862 |
| 3870 // TODO(hkhalil): Add TEST_F(SpdyFramerTest, BlockedFrameFlags) | 3863 // TODO(hkhalil): Add TEST_F(SpdyFramerTest, BlockedFrameFlags) |
| 3871 | 3864 |
| 3872 TEST_F(SpdyFramerTest, SettingsFlagsAndId) { | 3865 TEST_F(SpdyFramerTest, SettingsFlagsAndId) { |
| 3873 const uint32_t kId = 0x020304; | 3866 const uint32_t kId = 0x020304; |
| 3874 const uint32_t kFlags = 0x01; | 3867 const uint32_t kFlags = 0x01; |
| 3875 const uint32_t kWireFormat = base::HostToNet32(0x01020304); | 3868 const uint32_t kWireFormat = base::HostToNet32(0x01020304); |
| 3876 | 3869 |
| 3877 SettingsFlagsAndId id_and_flags = | 3870 SettingsFlagsAndId id_and_flags = |
| 3878 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 3871 SettingsFlagsAndId::FromWireFormat(kWireFormat); |
| 3879 EXPECT_EQ(kId, id_and_flags.id()); | 3872 EXPECT_EQ(kId, id_and_flags.id()); |
| 3880 EXPECT_EQ(kFlags, id_and_flags.flags()); | 3873 EXPECT_EQ(kFlags, id_and_flags.flags()); |
| 3881 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 3874 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat()); |
| 3882 } | 3875 } |
| 3883 | 3876 |
| 3884 // Test handling of a RST_STREAM with out-of-bounds status codes. | 3877 // Test handling of a RST_STREAM with out-of-bounds status codes. |
| 3885 TEST_F(SpdyFramerTest, RstStreamStatusBounds) { | 3878 TEST_F(SpdyFramerTest, RstStreamStatusBounds) { |
| 3886 const unsigned char kH2RstStreamInvalid[] = { | 3879 const unsigned char kH2RstStreamInvalid[] = { |
| 3887 0x00, 0x00, 0x04, // Length: 4 | 3880 0x00, 0x00, 0x04, // Length: 4 |
| 3888 0x03, // Type: RST_STREAM | 3881 0x03, // Type: RST_STREAM |
| 3889 0x00, // Flags: none | 3882 0x00, // Flags: none |
| 3890 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3883 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3891 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 3884 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 3892 }; | 3885 }; |
| 3893 const unsigned char kH2RstStreamNumStatusCodes[] = { | 3886 const unsigned char kH2RstStreamNumStatusCodes[] = { |
| 3894 0x00, 0x00, 0x04, // Length: 4 | 3887 0x00, 0x00, 0x04, // Length: 4 |
| 3895 0x03, // Type: RST_STREAM | 3888 0x03, // Type: RST_STREAM |
| 3896 0x00, // Flags: none | 3889 0x00, // Flags: none |
| 3897 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3890 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3898 0x00, 0x00, 0x00, 0xff, // Error: 255 | 3891 0x00, 0x00, 0x00, 0xff, // Error: 255 |
| 3899 }; | 3892 }; |
| 3900 | 3893 |
| 3901 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3894 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3902 SpdyFramer framer(spdy_version_); | 3895 SpdyFramer framer; |
| 3903 framer.set_visitor(&visitor); | 3896 framer.set_visitor(&visitor); |
| 3904 | 3897 |
| 3905 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); | 3898 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); |
| 3906 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamInvalid), | 3899 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamInvalid), |
| 3907 arraysize(kH2RstStreamInvalid)); | 3900 arraysize(kH2RstStreamInvalid)); |
| 3908 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3901 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3909 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3902 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3910 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3903 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3911 | 3904 |
| 3912 framer.Reset(); | 3905 framer.Reset(); |
| 3913 | 3906 |
| 3914 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); | 3907 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
| 3915 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), | 3908 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), |
| 3916 arraysize(kH2RstStreamNumStatusCodes)); | 3909 arraysize(kH2RstStreamNumStatusCodes)); |
| 3917 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3910 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3918 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3911 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3919 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3912 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3920 } | 3913 } |
| 3921 | 3914 |
| 3922 // Test handling of GOAWAY frames with out-of-bounds status code. | 3915 // Test handling of GOAWAY frames with out-of-bounds status code. |
| 3923 TEST_F(SpdyFramerTest, GoAwayStatusBounds) { | 3916 TEST_F(SpdyFramerTest, GoAwayStatusBounds) { |
| 3924 SpdyFramer framer(spdy_version_); | 3917 SpdyFramer framer; |
| 3925 const unsigned char kH2FrameData[] = { | 3918 const unsigned char kH2FrameData[] = { |
| 3926 0x00, 0x00, 0x0a, // Length: 10 | 3919 0x00, 0x00, 0x0a, // Length: 10 |
| 3927 0x07, // Type: GOAWAY | 3920 0x07, // Type: GOAWAY |
| 3928 0x00, // Flags: none | 3921 0x00, // Flags: none |
| 3929 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3922 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 3930 0x00, 0x00, 0x00, 0x01, // Last: 1 | 3923 0x00, 0x00, 0x00, 0x01, // Last: 1 |
| 3931 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff | 3924 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff |
| 3932 0x47, 0x41, // Description | 3925 0x47, 0x41, // Description |
| 3933 }; | 3926 }; |
| 3934 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3927 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3947 const unsigned char kH2FrameData[] = { | 3940 const unsigned char kH2FrameData[] = { |
| 3948 0x00, 0x00, 0x08, // Length: 8 | 3941 0x00, 0x00, 0x08, // Length: 8 |
| 3949 0x07, // Type: GOAWAY | 3942 0x07, // Type: GOAWAY |
| 3950 0x00, // Flags: none | 3943 0x00, // Flags: none |
| 3951 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3944 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 3952 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) | 3945 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) |
| 3953 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 3946 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 3954 }; | 3947 }; |
| 3955 | 3948 |
| 3956 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3949 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3957 SpdyFramer framer(spdy_version_); | 3950 SpdyFramer framer; |
| 3958 framer.set_visitor(&visitor); | 3951 framer.set_visitor(&visitor); |
| 3959 | 3952 |
| 3960 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); | 3953 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); |
| 3961 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), | 3954 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), |
| 3962 arraysize(kH2FrameData)); | 3955 arraysize(kH2FrameData)); |
| 3963 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3956 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3964 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3957 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3965 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3958 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3966 } | 3959 } |
| 3967 | 3960 |
| 3968 TEST_F(SpdyFramerTest, OnBlocked) { | 3961 TEST_F(SpdyFramerTest, OnBlocked) { |
| 3969 const SpdyStreamId kStreamId = 0; | 3962 const SpdyStreamId kStreamId = 0; |
| 3970 | 3963 |
| 3971 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3964 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3972 SpdyFramer framer(spdy_version_); | 3965 SpdyFramer framer; |
| 3973 framer.set_visitor(&visitor); | 3966 framer.set_visitor(&visitor); |
| 3974 | 3967 |
| 3975 EXPECT_CALL(visitor, OnBlocked(kStreamId)); | 3968 EXPECT_CALL(visitor, OnBlocked(kStreamId)); |
| 3976 | 3969 |
| 3977 SpdyBlockedIR blocked_ir(0); | 3970 SpdyBlockedIR blocked_ir(0); |
| 3978 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 3971 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
| 3979 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); | 3972 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); |
| 3980 | 3973 |
| 3981 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3974 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 3982 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3975 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 3983 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3976 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3984 } | 3977 } |
| 3985 | 3978 |
| 3986 TEST_F(SpdyFramerTest, OnAltSvc) { | 3979 TEST_F(SpdyFramerTest, OnAltSvc) { |
| 3987 const SpdyStreamId kStreamId = 1; | 3980 const SpdyStreamId kStreamId = 1; |
| 3988 | 3981 |
| 3989 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3982 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3990 SpdyFramer framer(spdy_version_); | 3983 SpdyFramer framer; |
| 3991 framer.set_visitor(&visitor); | 3984 framer.set_visitor(&visitor); |
| 3992 | 3985 |
| 3993 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 3986 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 3994 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 3987 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 3995 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 3988 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 3996 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 3989 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 3997 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 3990 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 3998 altsvc_vector.push_back(altsvc1); | 3991 altsvc_vector.push_back(altsvc1); |
| 3999 altsvc_vector.push_back(altsvc2); | 3992 altsvc_vector.push_back(altsvc2); |
| 4000 EXPECT_CALL(visitor, | 3993 EXPECT_CALL(visitor, |
| 4001 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); | 3994 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); |
| 4002 | 3995 |
| 4003 SpdyAltSvcIR altsvc_ir(1); | 3996 SpdyAltSvcIR altsvc_ir(1); |
| 4004 altsvc_ir.set_origin("o_r|g!n"); | 3997 altsvc_ir.set_origin("o_r|g!n"); |
| 4005 altsvc_ir.add_altsvc(altsvc1); | 3998 altsvc_ir.add_altsvc(altsvc1); |
| 4006 altsvc_ir.add_altsvc(altsvc2); | 3999 altsvc_ir.add_altsvc(altsvc2); |
| 4007 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4000 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4008 framer.ProcessInput(frame.data(), frame.size()); | 4001 framer.ProcessInput(frame.data(), frame.size()); |
| 4009 | 4002 |
| 4010 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4003 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4011 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4004 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4012 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4005 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4013 } | 4006 } |
| 4014 | 4007 |
| 4015 TEST_F(SpdyFramerTest, OnAltSvcNoOrigin) { | 4008 TEST_F(SpdyFramerTest, OnAltSvcNoOrigin) { |
| 4016 const SpdyStreamId kStreamId = 1; | 4009 const SpdyStreamId kStreamId = 1; |
| 4017 | 4010 |
| 4018 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4011 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4019 SpdyFramer framer(spdy_version_); | 4012 SpdyFramer framer; |
| 4020 framer.set_visitor(&visitor); | 4013 framer.set_visitor(&visitor); |
| 4021 | 4014 |
| 4022 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4015 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4023 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4016 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4024 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4017 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4025 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4018 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4026 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4019 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4027 altsvc_vector.push_back(altsvc1); | 4020 altsvc_vector.push_back(altsvc1); |
| 4028 altsvc_vector.push_back(altsvc2); | 4021 altsvc_vector.push_back(altsvc2); |
| 4029 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); | 4022 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); |
| 4030 | 4023 |
| 4031 SpdyAltSvcIR altsvc_ir(1); | 4024 SpdyAltSvcIR altsvc_ir(1); |
| 4032 altsvc_ir.add_altsvc(altsvc1); | 4025 altsvc_ir.add_altsvc(altsvc1); |
| 4033 altsvc_ir.add_altsvc(altsvc2); | 4026 altsvc_ir.add_altsvc(altsvc2); |
| 4034 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4027 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4035 framer.ProcessInput(frame.data(), frame.size()); | 4028 framer.ProcessInput(frame.data(), frame.size()); |
| 4036 | 4029 |
| 4037 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4030 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4038 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4031 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4039 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4032 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4040 } | 4033 } |
| 4041 | 4034 |
| 4042 TEST_F(SpdyFramerTest, OnAltSvcEmptyProtocolId) { | 4035 TEST_F(SpdyFramerTest, OnAltSvcEmptyProtocolId) { |
| 4043 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4036 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4044 SpdyFramer framer(spdy_version_); | 4037 SpdyFramer framer; |
| 4045 framer.set_visitor(&visitor); | 4038 framer.set_visitor(&visitor); |
| 4046 | 4039 |
| 4047 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 4040 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 4048 | 4041 |
| 4049 SpdyAltSvcIR altsvc_ir(1); | 4042 SpdyAltSvcIR altsvc_ir(1); |
| 4050 altsvc_ir.set_origin("o1"); | 4043 altsvc_ir.set_origin("o1"); |
| 4051 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4044 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 4052 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 4045 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 4053 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4046 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 4054 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); | 4047 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); |
| 4055 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4048 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4056 framer.ProcessInput(frame.data(), frame.size()); | 4049 framer.ProcessInput(frame.data(), frame.size()); |
| 4057 | 4050 |
| 4058 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4051 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4059 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 4052 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4060 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4053 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4061 } | 4054 } |
| 4062 | 4055 |
| 4063 TEST_F(SpdyFramerTest, OnAltSvcBadLengths) { | 4056 TEST_F(SpdyFramerTest, OnAltSvcBadLengths) { |
| 4064 const SpdyStreamId kStreamId = 1; | 4057 const SpdyStreamId kStreamId = 1; |
| 4065 | 4058 |
| 4066 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4059 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4067 SpdyFramer framer(spdy_version_); | 4060 SpdyFramer framer; |
| 4068 framer.set_visitor(&visitor); | 4061 framer.set_visitor(&visitor); |
| 4069 | 4062 |
| 4070 SpdyAltSvcWireFormat::AlternativeService altsvc( | 4063 SpdyAltSvcWireFormat::AlternativeService altsvc( |
| 4071 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); | 4064 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); |
| 4072 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4065 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
| 4073 altsvc_vector.push_back(altsvc); | 4066 altsvc_vector.push_back(altsvc); |
| 4074 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); | 4067 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); |
| 4075 | 4068 |
| 4076 SpdyAltSvcIR altsvc_ir(1); | 4069 SpdyAltSvcIR altsvc_ir(1); |
| 4077 altsvc_ir.set_origin("o1"); | 4070 altsvc_ir.set_origin("o1"); |
| 4078 altsvc_ir.add_altsvc(altsvc); | 4071 altsvc_ir.add_altsvc(altsvc); |
| 4079 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4072 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
| 4080 framer.ProcessInput(frame.data(), frame.size()); | 4073 framer.ProcessInput(frame.data(), frame.size()); |
| 4081 | 4074 |
| 4082 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4075 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4083 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4076 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4084 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4077 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4085 } | 4078 } |
| 4086 | 4079 |
| 4087 // Tests handling of ALTSVC frames delivered in small chunks. | 4080 // Tests handling of ALTSVC frames delivered in small chunks. |
| 4088 TEST_F(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 4081 TEST_F(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
| 4089 SpdyFramer framer(spdy_version_); | 4082 SpdyFramer framer; |
| 4090 SpdyAltSvcIR altsvc_ir(1); | 4083 SpdyAltSvcIR altsvc_ir(1); |
| 4091 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4084 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
| 4092 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4085 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
| 4093 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4086 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
| 4094 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4087 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
| 4095 altsvc_ir.add_altsvc(altsvc1); | 4088 altsvc_ir.add_altsvc(altsvc1); |
| 4096 altsvc_ir.add_altsvc(altsvc2); | 4089 altsvc_ir.add_altsvc(altsvc2); |
| 4097 | 4090 |
| 4098 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); | 4091 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); |
| 4099 TestSpdyVisitor visitor(spdy_version_); | 4092 TestSpdyVisitor visitor; |
| 4100 visitor.use_compression_ = false; | 4093 visitor.use_compression_ = false; |
| 4101 | 4094 |
| 4102 // Read data in small chunks. | 4095 // Read data in small chunks. |
| 4103 size_t framed_data = 0; | 4096 size_t framed_data = 0; |
| 4104 size_t unframed_data = control_frame.size(); | 4097 size_t unframed_data = control_frame.size(); |
| 4105 size_t kReadChunkSize = 5; // Read five bytes at a time. | 4098 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 4106 while (unframed_data > 0) { | 4099 while (unframed_data > 0) { |
| 4107 size_t to_read = std::min(kReadChunkSize, unframed_data); | 4100 size_t to_read = std::min(kReadChunkSize, unframed_data); |
| 4108 visitor.SimulateInFramer( | 4101 visitor.SimulateInFramer( |
| 4109 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), | 4102 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), |
| 4110 to_read); | 4103 to_read); |
| 4111 unframed_data -= to_read; | 4104 unframed_data -= to_read; |
| 4112 framed_data += to_read; | 4105 framed_data += to_read; |
| 4113 } | 4106 } |
| 4114 EXPECT_EQ(0, visitor.error_count_); | 4107 EXPECT_EQ(0, visitor.error_count_); |
| 4115 EXPECT_EQ(1, visitor.altsvc_count_); | 4108 EXPECT_EQ(1, visitor.altsvc_count_); |
| 4116 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); | 4109 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); |
| 4117 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); | 4110 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); |
| 4118 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); | 4111 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); |
| 4119 } | 4112 } |
| 4120 | 4113 |
| 4121 // Tests handling of PRIORITY frames. | 4114 // Tests handling of PRIORITY frames. |
| 4122 TEST_F(SpdyFramerTest, ReadPriority) { | 4115 TEST_F(SpdyFramerTest, ReadPriority) { |
| 4123 SpdyFramer framer(spdy_version_); | 4116 SpdyFramer framer; |
| 4124 SpdyPriorityIR priority(3, 1, 256, false); | 4117 SpdyPriorityIR priority(3, 1, 256, false); |
| 4125 SpdySerializedFrame frame(framer.SerializePriority(priority)); | 4118 SpdySerializedFrame frame(framer.SerializePriority(priority)); |
| 4126 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4119 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4127 framer.set_visitor(&visitor); | 4120 framer.set_visitor(&visitor); |
| 4128 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); | 4121 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); |
| 4129 framer.ProcessInput(frame.data(), frame.size()); | 4122 framer.ProcessInput(frame.data(), frame.size()); |
| 4130 | 4123 |
| 4131 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4124 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4132 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4125 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4133 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4126 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4134 // TODO(mlavan): once we actually maintain a priority tree, | 4127 // TODO(mlavan): once we actually maintain a priority tree, |
| 4135 // check that state is adjusted correctly. | 4128 // check that state is adjusted correctly. |
| 4136 } | 4129 } |
| 4137 | 4130 |
| 4138 // Tests handling of PRIORITY frame with incorrect size. | 4131 // Tests handling of PRIORITY frame with incorrect size. |
| 4139 TEST_F(SpdyFramerTest, ReadIncorrectlySizedPriority) { | 4132 TEST_F(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
| 4140 // PRIORITY frame of size 4, which isn't correct. | 4133 // PRIORITY frame of size 4, which isn't correct. |
| 4141 const unsigned char kFrameData[] = { | 4134 const unsigned char kFrameData[] = { |
| 4142 0x00, 0x00, 0x04, // Length: 4 | 4135 0x00, 0x00, 0x04, // Length: 4 |
| 4143 0x02, // Type: PRIORITY | 4136 0x02, // Type: PRIORITY |
| 4144 0x00, // Flags: none | 4137 0x00, // Flags: none |
| 4145 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4138 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4146 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) | 4139 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) |
| 4147 }; | 4140 }; |
| 4148 | 4141 |
| 4149 TestSpdyVisitor visitor(spdy_version_); | 4142 TestSpdyVisitor visitor; |
| 4150 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4143 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4151 | 4144 |
| 4152 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4145 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4153 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4146 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4154 visitor.framer_.error_code()) | 4147 visitor.framer_.error_code()) |
| 4155 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4148 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4156 } | 4149 } |
| 4157 | 4150 |
| 4158 // Tests handling of PING frame with incorrect size. | 4151 // Tests handling of PING frame with incorrect size. |
| 4159 TEST_F(SpdyFramerTest, ReadIncorrectlySizedPing) { | 4152 TEST_F(SpdyFramerTest, ReadIncorrectlySizedPing) { |
| 4160 // PING frame of size 4, which isn't correct. | 4153 // PING frame of size 4, which isn't correct. |
| 4161 const unsigned char kFrameData[] = { | 4154 const unsigned char kFrameData[] = { |
| 4162 0x00, 0x00, 0x04, // Length: 4 | 4155 0x00, 0x00, 0x04, // Length: 4 |
| 4163 0x06, // Type: PING | 4156 0x06, // Type: PING |
| 4164 0x00, // Flags: none | 4157 0x00, // Flags: none |
| 4165 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 4158 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 4166 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) | 4159 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) |
| 4167 }; | 4160 }; |
| 4168 | 4161 |
| 4169 TestSpdyVisitor visitor(spdy_version_); | 4162 TestSpdyVisitor visitor; |
| 4170 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4163 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4171 | 4164 |
| 4172 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4165 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4173 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4166 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4174 visitor.framer_.error_code()) | 4167 visitor.framer_.error_code()) |
| 4175 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4168 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4176 } | 4169 } |
| 4177 | 4170 |
| 4178 // Tests handling of WINDOW_UPDATE frame with incorrect size. | 4171 // Tests handling of WINDOW_UPDATE frame with incorrect size. |
| 4179 TEST_F(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { | 4172 TEST_F(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { |
| 4180 // WINDOW_UPDATE frame of size 3, which isn't correct. | 4173 // WINDOW_UPDATE frame of size 3, which isn't correct. |
| 4181 const unsigned char kFrameData[] = { | 4174 const unsigned char kFrameData[] = { |
| 4182 0x00, 0x00, 0x03, // Length: 3 | 4175 0x00, 0x00, 0x03, // Length: 3 |
| 4183 0x08, // Type: WINDOW_UPDATE | 4176 0x08, // Type: WINDOW_UPDATE |
| 4184 0x00, // Flags: none | 4177 0x00, // Flags: none |
| 4185 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4178 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4186 0x00, 0x00, 0x01, // WindowUpdate (Truncated) | 4179 0x00, 0x00, 0x01, // WindowUpdate (Truncated) |
| 4187 }; | 4180 }; |
| 4188 | 4181 |
| 4189 TestSpdyVisitor visitor(spdy_version_); | 4182 TestSpdyVisitor visitor; |
| 4190 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4183 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4191 | 4184 |
| 4192 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4185 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4193 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4186 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4194 visitor.framer_.error_code()) | 4187 visitor.framer_.error_code()) |
| 4195 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4188 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4196 } | 4189 } |
| 4197 | 4190 |
| 4198 // Tests handling of RST_STREAM frame with incorrect size. | 4191 // Tests handling of RST_STREAM frame with incorrect size. |
| 4199 TEST_F(SpdyFramerTest, ReadIncorrectlySizedRstStream) { | 4192 TEST_F(SpdyFramerTest, ReadIncorrectlySizedRstStream) { |
| 4200 // RST_STREAM frame of size 3, which isn't correct. | 4193 // RST_STREAM frame of size 3, which isn't correct. |
| 4201 const unsigned char kFrameData[] = { | 4194 const unsigned char kFrameData[] = { |
| 4202 0x00, 0x00, 0x03, // Length: 3 | 4195 0x00, 0x00, 0x03, // Length: 3 |
| 4203 0x03, // Type: RST_STREAM | 4196 0x03, // Type: RST_STREAM |
| 4204 0x00, // Flags: none | 4197 0x00, // Flags: none |
| 4205 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4198 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| 4206 0x00, 0x00, 0x01, // RstStream (Truncated) | 4199 0x00, 0x00, 0x01, // RstStream (Truncated) |
| 4207 }; | 4200 }; |
| 4208 | 4201 |
| 4209 TestSpdyVisitor visitor(spdy_version_); | 4202 TestSpdyVisitor visitor; |
| 4210 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4203 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 4211 | 4204 |
| 4212 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4205 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 4213 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4206 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 4214 visitor.framer_.error_code()) | 4207 visitor.framer_.error_code()) |
| 4215 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4208 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 4216 } | 4209 } |
| 4217 | 4210 |
| 4218 // 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 |
| 4219 // 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()). |
| 4220 TEST_F(SpdyFramerTest, ProcessAllInput) { | 4213 TEST_F(SpdyFramerTest, ProcessAllInput) { |
| 4221 SpdyFramer framer(spdy_version_); | 4214 SpdyFramer framer; |
| 4222 std::unique_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); | 4215 std::unique_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor); |
| 4223 framer.set_visitor(visitor.get()); | 4216 framer.set_visitor(visitor.get()); |
| 4224 | 4217 |
| 4225 // Create two input frames. | 4218 // Create two input frames. |
| 4226 SpdyHeadersIR headers(1); | 4219 SpdyHeadersIR headers(1); |
| 4227 headers.SetHeader("alpha", "beta"); | 4220 headers.SetHeader("alpha", "beta"); |
| 4228 headers.SetHeader("gamma", "charlie"); | 4221 headers.SetHeader("gamma", "charlie"); |
| 4229 headers.SetHeader("cookie", "key1=value1; key2=value2"); | 4222 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
| 4230 SpdySerializedFrame headers_frame( | 4223 SpdySerializedFrame headers_frame( |
| 4231 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 4224 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
| 4232 | 4225 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4260 EXPECT_EQ(1, visitor->headers_frame_count_); | 4253 EXPECT_EQ(1, visitor->headers_frame_count_); |
| 4261 EXPECT_EQ(1, visitor->data_frame_count_); | 4254 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4262 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4255 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4263 } | 4256 } |
| 4264 | 4257 |
| 4265 // Test that SpdyFramer stops after processing a full frame if | 4258 // Test that SpdyFramer stops after processing a full frame if |
| 4266 // process_single_input_frame is set. Input to ProcessInput has two frames, but | 4259 // process_single_input_frame is set. Input to ProcessInput has two frames, but |
| 4267 // only processes the first when we give it the first frame split at any point, | 4260 // only processes the first when we give it the first frame split at any point, |
| 4268 // or give it more than one frame in the input buffer. | 4261 // or give it more than one frame in the input buffer. |
| 4269 TEST_F(SpdyFramerTest, ProcessAtMostOneFrame) { | 4262 TEST_F(SpdyFramerTest, ProcessAtMostOneFrame) { |
| 4270 SpdyFramer framer(spdy_version_); | 4263 SpdyFramer framer; |
| 4271 framer.set_process_single_input_frame(true); | 4264 framer.set_process_single_input_frame(true); |
| 4272 std::unique_ptr<TestSpdyVisitor> visitor; | 4265 std::unique_ptr<TestSpdyVisitor> visitor; |
| 4273 | 4266 |
| 4274 // Create two input frames. | 4267 // Create two input frames. |
| 4275 const char four_score[] = "Four score and ..."; | 4268 const char four_score[] = "Four score and ..."; |
| 4276 SpdyDataIR four_score_ir(1, four_score); | 4269 SpdyDataIR four_score_ir(1, four_score); |
| 4277 SpdySerializedFrame four_score_frame(framer.SerializeData(four_score_ir)); | 4270 SpdySerializedFrame four_score_frame(framer.SerializeData(four_score_ir)); |
| 4278 | 4271 |
| 4279 SpdyHeadersIR headers(2); | 4272 SpdyHeadersIR headers(2); |
| 4280 headers.SetHeader("alpha", "beta"); | 4273 headers.SetHeader("alpha", "beta"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4298 input_buffer.append(frame1.data(), frame1_size); | 4291 input_buffer.append(frame1.data(), frame1_size); |
| 4299 input_buffer.append(frame2.data(), frame2_size); | 4292 input_buffer.append(frame2.data(), frame2_size); |
| 4300 | 4293 |
| 4301 const char* buf = input_buffer.data(); | 4294 const char* buf = input_buffer.data(); |
| 4302 const size_t buf_size = input_buffer.size(); | 4295 const size_t buf_size = input_buffer.size(); |
| 4303 | 4296 |
| 4304 VLOG(1) << "buf_size = " << buf_size; | 4297 VLOG(1) << "buf_size = " << buf_size; |
| 4305 | 4298 |
| 4306 for (size_t first_size = 0; first_size <= buf_size; ++first_size) { | 4299 for (size_t first_size = 0; first_size <= buf_size; ++first_size) { |
| 4307 VLOG(1) << "first_size = " << first_size; | 4300 VLOG(1) << "first_size = " << first_size; |
| 4308 visitor.reset(new TestSpdyVisitor(spdy_version_)); | 4301 visitor.reset(new TestSpdyVisitor); |
| 4309 framer.set_visitor(visitor.get()); | 4302 framer.set_visitor(visitor.get()); |
| 4310 | 4303 |
| 4311 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4304 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4312 | 4305 |
| 4313 size_t processed_first = framer.ProcessInput(buf, first_size); | 4306 size_t processed_first = framer.ProcessInput(buf, first_size); |
| 4314 if (first_size < frame1_size) { | 4307 if (first_size < frame1_size) { |
| 4315 EXPECT_EQ(first_size, processed_first); | 4308 EXPECT_EQ(first_size, processed_first); |
| 4316 | 4309 |
| 4317 if (first_size == 0) { | 4310 if (first_size == 0) { |
| 4318 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4311 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 4341 | 4334 |
| 4342 EXPECT_EQ(1, visitor->data_frame_count_); | 4335 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4343 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4336 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4344 EXPECT_EQ(0, visitor->headers_frame_count_); | 4337 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4345 } | 4338 } |
| 4346 } | 4339 } |
| 4347 | 4340 |
| 4348 } // namespace test | 4341 } // namespace test |
| 4349 | 4342 |
| 4350 } // namespace net | 4343 } // namespace net |
| OLD | NEW |