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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 386 |
387 void OnSynStream(SpdyStreamId stream_id, | 387 void OnSynStream(SpdyStreamId stream_id, |
388 SpdyStreamId associated_stream_id, | 388 SpdyStreamId associated_stream_id, |
389 SpdyPriority priority, | 389 SpdyPriority priority, |
390 bool fin, | 390 bool fin, |
391 bool unidirectional) override { | 391 bool unidirectional) override { |
392 VLOG(1) << "OnSynStream(" << stream_id << ", " << associated_stream_id | 392 VLOG(1) << "OnSynStream(" << stream_id << ", " << associated_stream_id |
393 << ", " << priority << ", " << (fin ? 1 : 0) << ", " | 393 << ", " << priority << ", " << (fin ? 1 : 0) << ", " |
394 << (unidirectional ? 1 : 0) << ")"; | 394 << (unidirectional ? 1 : 0) << ")"; |
395 ++syn_frame_count_; | 395 ++syn_frame_count_; |
396 if (framer_.protocol_version() == SPDY3) { | 396 InitHeaderStreaming(HEADERS, stream_id); |
397 InitHeaderStreaming(SYN_STREAM, stream_id); | |
398 } else { | |
399 InitHeaderStreaming(HEADERS, stream_id); | |
400 } | |
401 if (fin) { | 397 if (fin) { |
402 ++fin_flag_count_; | 398 ++fin_flag_count_; |
403 } | 399 } |
404 } | 400 } |
405 | 401 |
406 void OnSynReply(SpdyStreamId stream_id, bool fin) override { | 402 void OnSynReply(SpdyStreamId stream_id, bool fin) override { |
407 ++syn_reply_frame_count_; | 403 ++syn_reply_frame_count_; |
408 if (framer_.protocol_version() == SPDY3) { | 404 InitHeaderStreaming(HEADERS, stream_id); |
409 InitHeaderStreaming(SYN_REPLY, stream_id); | |
410 } else { | |
411 InitHeaderStreaming(HEADERS, stream_id); | |
412 } | |
413 if (fin) { | 405 if (fin) { |
414 ++fin_flag_count_; | 406 ++fin_flag_count_; |
415 } | 407 } |
416 } | 408 } |
417 | 409 |
418 void OnRstStream(SpdyStreamId stream_id, | 410 void OnRstStream(SpdyStreamId stream_id, |
419 SpdyRstStreamStatus status) override { | 411 SpdyRstStreamStatus status) override { |
420 VLOG(1) << "OnRstStream(" << stream_id << ", " << status << ")"; | 412 VLOG(1) << "OnRstStream(" << stream_id << ", " << status << ")"; |
421 ++fin_frame_count_; | 413 ++fin_frame_count_; |
422 } | 414 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 SpdyHeaderBlock headers_; | 646 SpdyHeaderBlock headers_; |
655 bool header_has_priority_; | 647 bool header_has_priority_; |
656 SpdyStreamId header_parent_stream_id_; | 648 SpdyStreamId header_parent_stream_id_; |
657 bool header_exclusive_; | 649 bool header_exclusive_; |
658 }; | 650 }; |
659 | 651 |
660 // Retrieves serialized headers from a HEADERS or SYN_STREAM frame. | 652 // Retrieves serialized headers from a HEADERS or SYN_STREAM frame. |
661 StringPiece GetSerializedHeaders(const SpdySerializedFrame& frame, | 653 StringPiece GetSerializedHeaders(const SpdySerializedFrame& frame, |
662 const SpdyFramer& framer) { | 654 const SpdyFramer& framer) { |
663 SpdyFrameReader reader(frame.data(), frame.size()); | 655 SpdyFrameReader reader(frame.data(), frame.size()); |
664 if (framer.protocol_version() == SPDY3) { | 656 reader.Seek(3); // Seek past the frame length. |
665 reader.Seek(2); // Seek past the frame length. | 657 |
666 } else { | |
667 reader.Seek(3); // Seek past the frame length. | |
668 } | |
669 SpdyFrameType frame_type; | 658 SpdyFrameType frame_type; |
670 if (framer.protocol_version() == SPDY3) { | 659 uint8_t serialized_type; |
671 uint16_t serialized_type; | 660 reader.ReadUInt8(&serialized_type); |
672 reader.ReadUInt16(&serialized_type); | 661 frame_type = |
673 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), | 662 SpdyConstants::ParseFrameType(framer.protocol_version(), serialized_type); |
674 serialized_type); | 663 DCHECK_EQ(HEADERS, frame_type); |
675 DCHECK(frame_type == HEADERS || frame_type == SYN_STREAM) << frame_type; | 664 uint8_t flags; |
676 } else { | 665 reader.ReadUInt8(&flags); |
677 uint8_t serialized_type; | 666 if (flags & HEADERS_FLAG_PRIORITY) { |
678 reader.ReadUInt8(&serialized_type); | 667 frame_type = SYN_STREAM; |
679 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), | |
680 serialized_type); | |
681 DCHECK_EQ(HEADERS, frame_type); | |
682 uint8_t flags; | |
683 reader.ReadUInt8(&flags); | |
684 if (flags & HEADERS_FLAG_PRIORITY) { | |
685 frame_type = SYN_STREAM; | |
686 } | |
687 } | 668 } |
688 | 669 |
689 if (frame_type == SYN_STREAM) { | 670 if (frame_type == SYN_STREAM) { |
690 return StringPiece(frame.data() + framer.GetSynStreamMinimumSize(), | 671 return StringPiece(frame.data() + framer.GetSynStreamMinimumSize(), |
691 frame.size() - framer.GetSynStreamMinimumSize()); | 672 frame.size() - framer.GetSynStreamMinimumSize()); |
692 } else { | 673 } else { |
693 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), | 674 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), |
694 frame.size() - framer.GetHeadersMinimumSize()); | 675 frame.size() - framer.GetHeadersMinimumSize()); |
695 } | 676 } |
696 } | 677 } |
(...skipping 16 matching lines...) Expand all Loading... | |
713 const SpdySerializedFrame& expected_frame, | 694 const SpdySerializedFrame& expected_frame, |
714 const SpdySerializedFrame& actual_frame) { | 695 const SpdySerializedFrame& actual_frame) { |
715 CompareCharArraysWithHexError( | 696 CompareCharArraysWithHexError( |
716 description, | 697 description, |
717 reinterpret_cast<const unsigned char*>(expected_frame.data()), | 698 reinterpret_cast<const unsigned char*>(expected_frame.data()), |
718 expected_frame.size(), | 699 expected_frame.size(), |
719 reinterpret_cast<const unsigned char*>(actual_frame.data()), | 700 reinterpret_cast<const unsigned char*>(actual_frame.data()), |
720 actual_frame.size()); | 701 actual_frame.size()); |
721 } | 702 } |
722 | 703 |
723 bool IsSpdy3() { return spdy_version_ == SPDY3; } | |
724 bool IsHttp2() { return spdy_version_ == HTTP2; } | |
725 | |
726 // Version of SPDY protocol to be used. | 704 // Version of SPDY protocol to be used. |
727 SpdyMajorVersion spdy_version_; | 705 SpdyMajorVersion spdy_version_; |
728 }; | 706 }; |
729 | 707 |
730 // All tests are run with SPDY/3 and HTTP/2. | 708 // All tests are run with HTTP/2, using the existing SpdyFramer. |
731 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | 709 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, |
732 SpdyFramerTest, | 710 SpdyFramerTest, |
733 ::testing::Values(SPDY3, HTTP2)); | 711 ::testing::Values(HTTP2)); |
734 | |
735 // Test that we ignore cookie where both name and value are empty. | |
736 TEST_P(SpdyFramerTest, HeaderBlockWithEmptyCookie) { | |
737 if (!IsSpdy3()) { | |
738 // Not implemented for hpack. | |
739 return; | |
740 } | |
741 | |
742 SpdyFramer framer(spdy_version_); | |
743 framer.set_enable_compression(true); | |
744 SpdyHeadersIR headers(1); | |
745 headers.SetHeader("cookie", | |
746 "=; key=value; ; = ; foo; bar=; ; = ; k2=v2 ; ="); | |
747 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | |
748 | |
749 TestSpdyVisitor visitor(spdy_version_); | |
750 visitor.use_compression_ = true; | |
751 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | |
752 frame.size()); | |
753 | |
754 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | |
755 EXPECT_NE(headers.header_block(), visitor.headers_); | |
756 EXPECT_EQ(1u, visitor.headers_.size()); | |
757 EXPECT_EQ("key=value; foo; bar=; k2=v2 ", visitor.headers_["cookie"]); | |
758 } | |
759 | 712 |
760 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 713 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
761 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { | 714 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
762 SpdyFramer framer(spdy_version_); | 715 SpdyFramer framer(spdy_version_); |
763 framer.set_enable_compression(false); | 716 framer.set_enable_compression(false); |
764 | 717 |
765 // Encode the header block into a Headers frame. | 718 // Encode the header block into a Headers frame. |
766 SpdyHeadersIR headers(1); | 719 SpdyHeadersIR headers(1); |
767 headers.SetHeader("alpha", "beta"); | 720 headers.SetHeader("alpha", "beta"); |
768 headers.SetHeader("gamma", "charlie"); | 721 headers.SetHeader("gamma", "charlie"); |
(...skipping 22 matching lines...) Expand all Loading... | |
791 | 744 |
792 TestSpdyVisitor visitor(spdy_version_); | 745 TestSpdyVisitor visitor(spdy_version_); |
793 visitor.use_compression_ = false; | 746 visitor.use_compression_ = false; |
794 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 747 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
795 frame.size() - 2); | 748 frame.size() - 2); |
796 | 749 |
797 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 750 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
798 EXPECT_EQ(0u, visitor.headers_.size()); | 751 EXPECT_EQ(0u, visitor.headers_.size()); |
799 } | 752 } |
800 | 753 |
801 // Test that we make all header field names (keys) lower case on encoding. | |
802 TEST_P(SpdyFramerTest, HeaderBlockToLowerCase) { | |
803 // The HPACK encoding path does not lowercase field names. | |
804 if (IsHttp2()) { | |
805 return; | |
806 } | |
807 | |
808 SpdyFramer framer(spdy_version_); | |
809 framer.set_enable_compression(true); | |
810 | |
811 // Encode the header block into a Headers frame. | |
812 SpdyHeadersIR headers_ir(1); | |
813 headers_ir.SetHeader("aLpha", "beta"); | |
814 headers_ir.SetHeader("GAMMA", "charlie"); | |
815 headers_ir.SetHeader("foo", "Bar"); // Upper case values are okay. | |
816 SpdySerializedFrame frame( | |
817 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | |
818 TestSpdyVisitor visitor(spdy_version_); | |
819 visitor.use_compression_ = true; | |
820 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | |
821 frame.size()); | |
822 EXPECT_EQ(1, visitor.headers_frame_count_); | |
823 EXPECT_EQ(headers_ir.header_block().size(), visitor.headers_.size()); | |
824 EXPECT_EQ("beta", visitor.headers_["alpha"]); | |
825 EXPECT_EQ("charlie", visitor.headers_["gamma"]); | |
826 EXPECT_EQ("Bar", visitor.headers_["foo"]); | |
827 } | |
828 | |
829 // Test that we treat incoming upper-case or mixed-case header values as | 754 // Test that we treat incoming upper-case or mixed-case header values as |
830 // malformed for HTTP2. | 755 // malformed for HTTP2. |
831 TEST_P(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { | 756 TEST_P(SpdyFramerTest, RejectUpperCaseHeaderBlockValue) { |
832 if (!IsHttp2()) { | |
833 return; | |
834 } | |
835 | |
836 SpdyFramer framer(spdy_version_); | 757 SpdyFramer framer(spdy_version_); |
837 framer.set_enable_compression(false); | 758 framer.set_enable_compression(false); |
838 | 759 |
839 SpdyFrameBuilder frame(1024, spdy_version_); | 760 SpdyFrameBuilder frame(1024, spdy_version_); |
840 frame.BeginNewFrame(framer, HEADERS, 0, 1); | 761 frame.BeginNewFrame(framer, HEADERS, 0, 1); |
841 frame.WriteUInt32(1); | 762 frame.WriteUInt32(1); |
842 frame.WriteStringPiece32("Name1"); | 763 frame.WriteStringPiece32("Name1"); |
843 frame.WriteStringPiece32("value1"); | 764 frame.WriteStringPiece32("value1"); |
844 frame.RewriteLength(framer); | 765 frame.RewriteLength(framer); |
845 | 766 |
(...skipping 15 matching lines...) Expand all Loading... | |
861 SpdyHeaderBlock new_headers; | 782 SpdyHeaderBlock new_headers; |
862 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 783 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
863 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 784 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
864 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 785 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
865 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); | 786 serialized_headers2.data(), serialized_headers2.size(), &new_headers)); |
866 } | 787 } |
867 | 788 |
868 // Test that we can encode and decode stream dependency values in a header | 789 // Test that we can encode and decode stream dependency values in a header |
869 // frame. | 790 // frame. |
870 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { | 791 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { |
871 if (!IsHttp2()) { | |
872 return; | |
873 } | |
874 | |
875 SpdyFramer framer(spdy_version_); | 792 SpdyFramer framer(spdy_version_); |
876 framer.set_enable_compression(false); | 793 framer.set_enable_compression(false); |
877 | 794 |
878 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; | 795 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; |
879 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { | 796 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { |
880 const bool exclusive_test_array[] = {true, false}; | 797 const bool exclusive_test_array[] = {true, false}; |
881 for (bool exclusive : exclusive_test_array) { | 798 for (bool exclusive : exclusive_test_array) { |
882 SpdyHeadersIR headers(1); | 799 SpdyHeadersIR headers(1); |
883 headers.set_has_priority(true); | 800 headers.set_has_priority(true); |
884 headers.set_parent_stream_id(parent_stream_id); | 801 headers.set_parent_stream_id(parent_stream_id); |
885 headers.set_exclusive(exclusive); | 802 headers.set_exclusive(exclusive); |
886 SpdySerializedFrame frame( | 803 SpdySerializedFrame frame( |
887 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 804 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
888 | 805 |
889 TestSpdyVisitor visitor(spdy_version_); | 806 TestSpdyVisitor visitor(spdy_version_); |
890 visitor.use_compression_ = false; | 807 visitor.use_compression_ = false; |
891 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 808 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
892 frame.size()); | 809 frame.size()); |
893 | 810 |
894 EXPECT_TRUE(visitor.header_has_priority_); | 811 EXPECT_TRUE(visitor.header_has_priority_); |
895 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); | 812 EXPECT_EQ(parent_stream_id, visitor.header_parent_stream_id_); |
896 EXPECT_EQ(exclusive, visitor.header_exclusive_); | 813 EXPECT_EQ(exclusive, visitor.header_exclusive_); |
897 } | 814 } |
898 } | 815 } |
899 } | 816 } |
900 | 817 |
901 // Test that if we receive a frame with payload length field at the | 818 // Test that if we receive a frame with payload length field at the |
902 // advertised max size, we do not set an error in ProcessInput. | 819 // advertised max size, we do not set an error in ProcessInput. |
903 TEST_P(SpdyFramerTest, AcceptMaxFrameSizeSetting) { | 820 TEST_P(SpdyFramerTest, AcceptMaxFrameSizeSetting) { |
904 if (!IsHttp2()) { | |
905 return; | |
906 } | |
907 | |
908 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 821 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
909 SpdyFramer framer(spdy_version_); | 822 SpdyFramer framer(spdy_version_); |
910 framer.set_visitor(&visitor); | 823 framer.set_visitor(&visitor); |
911 | 824 |
912 // DATA frame with maximum allowed payload length. | 825 // DATA frame with maximum allowed payload length. |
913 unsigned char kH2FrameData[] = { | 826 unsigned char kH2FrameData[] = { |
914 0x00, 0x40, 0x00, // Length: 2^14 | 827 0x00, 0x40, 0x00, // Length: 2^14 |
915 0x00, // Type: HEADERS | 828 0x00, // Type: HEADERS |
916 0x00, // Flags: None | 829 0x00, // Flags: None |
917 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 830 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
918 0x00, 0x00, 0x00, 0x00, // Junk payload | 831 0x00, 0x00, 0x00, 0x00, // Junk payload |
919 }; | 832 }; |
920 | 833 |
921 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 834 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
922 sizeof(kH2FrameData), false); | 835 sizeof(kH2FrameData), false); |
923 | 836 |
924 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); | 837 EXPECT_CALL(visitor, OnDataFrameHeader(1, 1 << 14, false)); |
925 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); | 838 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 4)); |
926 framer.ProcessInput(frame.data(), frame.size()); | 839 framer.ProcessInput(frame.data(), frame.size()); |
927 EXPECT_FALSE(framer.HasError()); | 840 EXPECT_FALSE(framer.HasError()); |
928 } | 841 } |
929 | 842 |
930 // Test that if we receive a frame with payload length larger than the | 843 // Test that if we receive a frame with payload length larger than the |
931 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. | 844 // advertised max size, we set an error of SPDY_INVALID_CONTROL_FRAME_SIZE. |
932 TEST_P(SpdyFramerTest, ExceedMaxFrameSizeSetting) { | 845 TEST_P(SpdyFramerTest, ExceedMaxFrameSizeSetting) { |
933 if (!IsHttp2()) { | |
934 return; | |
935 } | |
936 | |
937 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 846 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
938 SpdyFramer framer(spdy_version_); | 847 SpdyFramer framer(spdy_version_); |
939 framer.set_visitor(&visitor); | 848 framer.set_visitor(&visitor); |
940 | 849 |
941 // DATA frame with too large payload length. | 850 // DATA frame with too large payload length. |
942 unsigned char kH2FrameData[] = { | 851 unsigned char kH2FrameData[] = { |
943 0x00, 0x40, 0x01, // Length: 2^14 + 1 | 852 0x00, 0x40, 0x01, // Length: 2^14 + 1 |
944 0x00, // Type: HEADERS | 853 0x00, // Type: HEADERS |
945 0x00, // Flags: None | 854 0x00, // Flags: None |
946 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 855 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
947 0x00, 0x00, 0x00, 0x00, // Junk payload | 856 0x00, 0x00, 0x00, 0x00, // Junk payload |
948 }; | 857 }; |
949 | 858 |
950 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), | 859 SpdySerializedFrame frame(reinterpret_cast<char*>(kH2FrameData), |
951 sizeof(kH2FrameData), false); | 860 sizeof(kH2FrameData), false); |
952 | 861 |
953 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 862 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
954 framer.ProcessInput(frame.data(), frame.size()); | 863 framer.ProcessInput(frame.data(), frame.size()); |
955 EXPECT_TRUE(framer.HasError()); | 864 EXPECT_TRUE(framer.HasError()); |
956 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) | 865 EXPECT_EQ(SpdyFramer::SPDY_OVERSIZED_PAYLOAD, framer.error_code()) |
957 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 866 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
958 } | 867 } |
959 | 868 |
960 // Test that if we receive a DATA frame with padding length larger than the | 869 // Test that if we receive a DATA frame with padding length larger than the |
961 // payload length, we set an error of SPDY_INVALID_PADDING | 870 // payload length, we set an error of SPDY_INVALID_PADDING |
962 TEST_P(SpdyFramerTest, OversizedDataPaddingError) { | 871 TEST_P(SpdyFramerTest, OversizedDataPaddingError) { |
963 if (!IsHttp2()) { | |
964 return; | |
965 } | |
966 | |
967 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 872 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
968 SpdyFramer framer(spdy_version_); | 873 SpdyFramer framer(spdy_version_); |
969 framer.set_visitor(&visitor); | 874 framer.set_visitor(&visitor); |
970 | 875 |
971 // DATA frame with invalid padding length. | 876 // DATA frame with invalid padding length. |
972 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 877 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
973 // MSVC, where |char| is signed by default, which would not compile because of | 878 // MSVC, where |char| is signed by default, which would not compile because of |
974 // the element exceeding 127. | 879 // the element exceeding 127. |
975 unsigned char kH2FrameData[] = { | 880 unsigned char kH2FrameData[] = { |
976 0x00, 0x00, 0x05, // Length: 5 | 881 0x00, 0x00, 0x05, // Length: 5 |
(...skipping 15 matching lines...) Expand all Loading... | |
992 } | 897 } |
993 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 898 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
994 EXPECT_TRUE(framer.HasError()); | 899 EXPECT_TRUE(framer.HasError()); |
995 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 900 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
996 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 901 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
997 } | 902 } |
998 | 903 |
999 // Test that if we receive a DATA frame with padding length not larger than the | 904 // Test that if we receive a DATA frame with padding length not larger than the |
1000 // payload length, we do not set an error of SPDY_INVALID_PADDING | 905 // payload length, we do not set an error of SPDY_INVALID_PADDING |
1001 TEST_P(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { | 906 TEST_P(SpdyFramerTest, CorrectlySizedDataPaddingNoError) { |
1002 if (!IsHttp2()) { | |
1003 return; | |
1004 } | |
1005 | |
1006 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 907 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1007 SpdyFramer framer(spdy_version_); | 908 SpdyFramer framer(spdy_version_); |
1008 framer.set_visitor(&visitor); | 909 framer.set_visitor(&visitor); |
1009 | 910 |
1010 // DATA frame with valid Padding length | 911 // DATA frame with valid Padding length |
1011 char kH2FrameData[] = { | 912 char kH2FrameData[] = { |
1012 0x00, 0x00, 0x05, // Length: 5 | 913 0x00, 0x00, 0x05, // Length: 5 |
1013 0x00, // Type: DATA | 914 0x00, // Type: DATA |
1014 0x08, // Flags: PADDED | 915 0x08, // Flags: PADDED |
1015 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 916 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
(...skipping 15 matching lines...) Expand all Loading... | |
1031 | 932 |
1032 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 933 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1033 EXPECT_FALSE(framer.HasError()); | 934 EXPECT_FALSE(framer.HasError()); |
1034 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 935 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
1035 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 936 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1036 } | 937 } |
1037 | 938 |
1038 // Test that if we receive a HEADERS frame with padding length larger than the | 939 // Test that if we receive a HEADERS frame with padding length larger than the |
1039 // payload length, we set an error of SPDY_INVALID_PADDING | 940 // payload length, we set an error of SPDY_INVALID_PADDING |
1040 TEST_P(SpdyFramerTest, OversizedHeadersPaddingError) { | 941 TEST_P(SpdyFramerTest, OversizedHeadersPaddingError) { |
1041 if (!IsHttp2()) { | |
1042 return; | |
1043 } | |
1044 | |
1045 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 942 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1046 SpdyFramer framer(spdy_version_); | 943 SpdyFramer framer(spdy_version_); |
1047 framer.set_visitor(&visitor); | 944 framer.set_visitor(&visitor); |
1048 | 945 |
1049 // HEADERS frame with invalid padding length. | 946 // HEADERS frame with invalid padding length. |
1050 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses | 947 // |kH2FrameData| has to be |unsigned char|, because Chromium on Windows uses |
1051 // MSVC, where |char| is signed by default, which would not compile because of | 948 // MSVC, where |char| is signed by default, which would not compile because of |
1052 // the element exceeding 127. | 949 // the element exceeding 127. |
1053 unsigned char kH2FrameData[] = { | 950 unsigned char kH2FrameData[] = { |
1054 0x00, 0x00, 0x05, // Length: 5 | 951 0x00, 0x00, 0x05, // Length: 5 |
(...skipping 12 matching lines...) Expand all Loading... | |
1067 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 964 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1068 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 965 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1069 EXPECT_TRUE(framer.HasError()); | 966 EXPECT_TRUE(framer.HasError()); |
1070 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 967 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
1071 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 968 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1072 } | 969 } |
1073 | 970 |
1074 // Test that if we receive a HEADERS frame with padding length not larger | 971 // Test that if we receive a HEADERS frame with padding length not larger |
1075 // than the payload length, we do not set an error of SPDY_INVALID_PADDING | 972 // than the payload length, we do not set an error of SPDY_INVALID_PADDING |
1076 TEST_P(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { | 973 TEST_P(SpdyFramerTest, CorrectlySizedHeadersPaddingNoError) { |
1077 if (!IsHttp2()) { | |
1078 return; | |
1079 } | |
1080 | |
1081 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 974 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1082 SpdyFramer framer(spdy_version_); | 975 SpdyFramer framer(spdy_version_); |
1083 framer.set_visitor(&visitor); | 976 framer.set_visitor(&visitor); |
1084 | 977 |
1085 // HEADERS frame with invalid Padding length | 978 // HEADERS frame with invalid Padding length |
1086 char kH2FrameData[] = { | 979 char kH2FrameData[] = { |
1087 0x00, 0x00, 0x05, // Length: 5 | 980 0x00, 0x00, 0x05, // Length: 5 |
1088 0x01, // Type: HEADERS | 981 0x01, // Type: HEADERS |
1089 0x08, // Flags: PADDED | 982 0x08, // Flags: PADDED |
1090 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 983 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1091 0x04, // PadLen: 4 trailing bytes | 984 0x04, // PadLen: 4 trailing bytes |
1092 0x00, 0x00, 0x00, 0x00, // Padding | 985 0x00, 0x00, 0x00, 0x00, // Padding |
1093 }; | 986 }; |
1094 | 987 |
1095 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 988 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
1096 | 989 |
1097 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); | 990 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); |
1098 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | 991 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); |
1099 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 992 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1100 EXPECT_FALSE(framer.HasError()); | 993 EXPECT_FALSE(framer.HasError()); |
1101 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 994 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
1102 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 995 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1103 } | 996 } |
1104 | 997 |
1105 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error | |
1106 // (but don't crash). | |
1107 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { | |
1108 if (!IsSpdy3()) { | |
1109 return; | |
1110 } | |
1111 | |
1112 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
1113 SpdyFramer framer(spdy_version_); | |
1114 framer.set_visitor(&visitor); | |
1115 | |
1116 SpdySynReplyIR syn_reply(0); | |
1117 syn_reply.SetHeader("alpha", "beta"); | |
1118 SpdySerializedFrame frame(framer.SerializeSynReply(syn_reply)); | |
1119 | |
1120 // We shouldn't have to read the whole frame before we signal an error. | |
1121 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | |
1122 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | |
1123 EXPECT_TRUE(framer.HasError()); | |
1124 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | |
1125 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
1126 } | |
1127 | |
1128 // Test that if we receive a DATA with stream ID zero, we signal an error | 998 // Test that if we receive a DATA with stream ID zero, we signal an error |
1129 // (but don't crash). | 999 // (but don't crash). |
1130 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { | 1000 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { |
1131 if (!IsHttp2()) { | |
1132 return; | |
1133 } | |
1134 | |
1135 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1001 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1136 SpdyFramer framer(spdy_version_); | 1002 SpdyFramer framer(spdy_version_); |
1137 framer.set_visitor(&visitor); | 1003 framer.set_visitor(&visitor); |
1138 | 1004 |
1139 const char bytes[] = "hello"; | 1005 const char bytes[] = "hello"; |
1140 SpdyDataIR data_ir(0, bytes); | 1006 SpdyDataIR data_ir(0, bytes); |
1141 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1007 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
1142 | 1008 |
1143 // We shouldn't have to read the whole frame before we signal an error. | 1009 // We shouldn't have to read the whole frame before we signal an error. |
1144 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1010 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
(...skipping 11 matching lines...) Expand all Loading... | |
1156 framer.set_visitor(&visitor); | 1022 framer.set_visitor(&visitor); |
1157 | 1023 |
1158 SpdyHeadersIR headers(0); | 1024 SpdyHeadersIR headers(0); |
1159 headers.SetHeader("alpha", "beta"); | 1025 headers.SetHeader("alpha", "beta"); |
1160 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1026 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
1161 | 1027 |
1162 // We shouldn't have to read the whole frame before we signal an error. | 1028 // We shouldn't have to read the whole frame before we signal an error. |
1163 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1029 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1164 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1030 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1165 EXPECT_TRUE(framer.HasError()); | 1031 EXPECT_TRUE(framer.HasError()); |
1166 if (IsHttp2()) { | 1032 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1167 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1033 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1168 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
1169 } else { | |
1170 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | |
1171 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
1172 } | |
1173 } | 1034 } |
1174 | 1035 |
1175 // Test that if we receive a PRIORITY with stream ID zero, we signal an error | 1036 // Test that if we receive a PRIORITY with stream ID zero, we signal an error |
1176 // (but don't crash). | 1037 // (but don't crash). |
1177 TEST_P(SpdyFramerTest, PriorityWithStreamIdZero) { | 1038 TEST_P(SpdyFramerTest, PriorityWithStreamIdZero) { |
1178 if (!IsHttp2()) { | |
1179 return; | |
1180 } | |
1181 | |
1182 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1039 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1183 SpdyFramer framer(spdy_version_); | 1040 SpdyFramer framer(spdy_version_); |
1184 framer.set_visitor(&visitor); | 1041 framer.set_visitor(&visitor); |
1185 | 1042 |
1186 SpdyPriorityIR priority_ir(0, 1, 16, true); | 1043 SpdyPriorityIR priority_ir(0, 1, 16, true); |
1187 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 1044 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
1188 | 1045 |
1189 // We shouldn't have to read the whole frame before we signal an error. | 1046 // We shouldn't have to read the whole frame before we signal an error. |
1190 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1047 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1191 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1048 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1192 EXPECT_TRUE(framer.HasError()); | 1049 EXPECT_TRUE(framer.HasError()); |
1193 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1050 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1194 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1051 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1195 } | 1052 } |
1196 | 1053 |
1197 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error | 1054 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error |
1198 // (but don't crash). | 1055 // (but don't crash). |
1199 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { | 1056 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { |
1200 if (!IsHttp2()) { | |
1201 return; | |
1202 } | |
1203 | |
1204 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1057 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1205 SpdyFramer framer(spdy_version_); | 1058 SpdyFramer framer(spdy_version_); |
1206 framer.set_visitor(&visitor); | 1059 framer.set_visitor(&visitor); |
1207 | 1060 |
1208 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); | 1061 SpdyRstStreamIR rst_stream_ir(0, RST_STREAM_PROTOCOL_ERROR); |
1209 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); | 1062 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); |
1210 | 1063 |
1211 // We shouldn't have to read the whole frame before we signal an error. | 1064 // We shouldn't have to read the whole frame before we signal an error. |
1212 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1065 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1213 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1066 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1214 EXPECT_TRUE(framer.HasError()); | 1067 EXPECT_TRUE(framer.HasError()); |
1215 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1068 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1216 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1069 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1217 } | 1070 } |
1218 | 1071 |
1219 // Test that if we receive a SETTINGS with stream ID other than zero, | 1072 // Test that if we receive a SETTINGS with stream ID other than zero, |
1220 // we signal an error (but don't crash). | 1073 // we signal an error (but don't crash). |
1221 TEST_P(SpdyFramerTest, SettingsWithStreamIdNotZero) { | 1074 TEST_P(SpdyFramerTest, SettingsWithStreamIdNotZero) { |
1222 if (!IsHttp2()) { | |
1223 return; | |
1224 } | |
1225 | |
1226 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1075 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1227 SpdyFramer framer(spdy_version_); | 1076 SpdyFramer framer(spdy_version_); |
1228 framer.set_visitor(&visitor); | 1077 framer.set_visitor(&visitor); |
1229 | 1078 |
1230 // Settings frame with invalid StreamID of 0x01 | 1079 // Settings frame with invalid StreamID of 0x01 |
1231 char kH2FrameData[] = { | 1080 char kH2FrameData[] = { |
1232 0x00, 0x00, 0x06, // Length: 6 | 1081 0x00, 0x00, 0x06, // Length: 6 |
1233 0x04, // Type: SETTINGS | 1082 0x04, // Type: SETTINGS |
1234 0x00, // Flags: none | 1083 0x00, // Flags: none |
1235 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1084 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1236 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1085 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
1237 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 | 1086 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 |
1238 }; | 1087 }; |
1239 | 1088 |
1240 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1089 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
1241 | 1090 |
1242 // We shouldn't have to read the whole frame before we signal an error. | 1091 // We shouldn't have to read the whole frame before we signal an error. |
1243 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1092 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1244 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1093 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1245 EXPECT_TRUE(framer.HasError()); | 1094 EXPECT_TRUE(framer.HasError()); |
1246 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1095 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1247 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1096 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1248 } | 1097 } |
1249 | 1098 |
1250 // Test that if we receive a GOAWAY with stream ID other than zero, | 1099 // Test that if we receive a GOAWAY with stream ID other than zero, |
1251 // we signal an error (but don't crash). | 1100 // we signal an error (but don't crash). |
1252 TEST_P(SpdyFramerTest, GoawayWithStreamIdNotZero) { | 1101 TEST_P(SpdyFramerTest, GoawayWithStreamIdNotZero) { |
1253 if (!IsHttp2()) { | |
1254 return; | |
1255 } | |
1256 | |
1257 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1102 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1258 SpdyFramer framer(spdy_version_); | 1103 SpdyFramer framer(spdy_version_); |
1259 framer.set_visitor(&visitor); | 1104 framer.set_visitor(&visitor); |
1260 | 1105 |
1261 // GOAWAY frame with invalid StreamID of 0x01 | 1106 // GOAWAY frame with invalid StreamID of 0x01 |
1262 char kH2FrameData[] = { | 1107 char kH2FrameData[] = { |
1263 0x00, 0x00, 0x0a, // Length: 10 | 1108 0x00, 0x00, 0x0a, // Length: 10 |
1264 0x07, // Type: GOAWAY | 1109 0x07, // Type: GOAWAY |
1265 0x00, // Flags: none | 1110 0x00, // Flags: none |
1266 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1111 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1267 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1112 0x00, 0x00, 0x00, 0x00, // Last: 0 |
1268 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1113 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
1269 0x47, 0x41, // Description | 1114 0x47, 0x41, // Description |
1270 }; | 1115 }; |
1271 | 1116 |
1272 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1117 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
1273 | 1118 |
1274 // We shouldn't have to read the whole frame before we signal an error. | 1119 // We shouldn't have to read the whole frame before we signal an error. |
1275 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1120 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1276 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1121 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1277 EXPECT_TRUE(framer.HasError()); | 1122 EXPECT_TRUE(framer.HasError()); |
1278 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1123 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1279 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1124 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1280 } | 1125 } |
1281 | 1126 |
1282 // Test that if we receive a CONTINUATION with stream ID zero, we signal an | 1127 // Test that if we receive a CONTINUATION with stream ID zero, we signal an |
1283 // SPDY_INVALID_STREAM_ID. | 1128 // SPDY_INVALID_STREAM_ID. |
1284 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { | 1129 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { |
1285 if (!IsHttp2()) { | |
1286 return; | |
1287 } | |
1288 | |
1289 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1130 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1290 SpdyFramer framer(spdy_version_); | 1131 SpdyFramer framer(spdy_version_); |
1291 framer.set_visitor(&visitor); | 1132 framer.set_visitor(&visitor); |
1292 | 1133 |
1293 SpdyContinuationIR continuation(0); | 1134 SpdyContinuationIR continuation(0); |
1294 auto some_nonsense_encoding = | 1135 auto some_nonsense_encoding = |
1295 base::MakeUnique<string>("some nonsense encoding"); | 1136 base::MakeUnique<string>("some nonsense encoding"); |
1296 continuation.take_encoding(std::move(some_nonsense_encoding)); | 1137 continuation.take_encoding(std::move(some_nonsense_encoding)); |
1297 continuation.set_end_headers(true); | 1138 continuation.set_end_headers(true); |
1298 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 1139 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
1299 | 1140 |
1300 // We shouldn't have to read the whole frame before we signal an error. | 1141 // We shouldn't have to read the whole frame before we signal an error. |
1301 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1142 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1302 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1143 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1303 EXPECT_TRUE(framer.HasError()); | 1144 EXPECT_TRUE(framer.HasError()); |
1304 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1145 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1305 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1146 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1306 } | 1147 } |
1307 | 1148 |
1308 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 1149 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an |
1309 // SPDY_INVALID_STREAM_ID. | 1150 // SPDY_INVALID_STREAM_ID. |
1310 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 1151 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
1311 if (!IsHttp2()) { | |
1312 return; | |
1313 } | |
1314 | |
1315 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1152 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1316 SpdyFramer framer(spdy_version_); | 1153 SpdyFramer framer(spdy_version_); |
1317 framer.set_visitor(&visitor); | 1154 framer.set_visitor(&visitor); |
1318 | 1155 |
1319 SpdyPushPromiseIR push_promise(0, 4); | 1156 SpdyPushPromiseIR push_promise(0, 4); |
1320 push_promise.SetHeader("alpha", "beta"); | 1157 push_promise.SetHeader("alpha", "beta"); |
1321 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1158 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
1322 | 1159 |
1323 // We shouldn't have to read the whole frame before we signal an error. | 1160 // We shouldn't have to read the whole frame before we signal an error. |
1324 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1161 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1325 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1162 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1326 EXPECT_TRUE(framer.HasError()); | 1163 EXPECT_TRUE(framer.HasError()); |
1327 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) | 1164 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.error_code()) |
1328 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1165 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1329 } | 1166 } |
1330 | 1167 |
1331 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 1168 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
1332 // signal SPDY_INVALID_STREAM_ID. | 1169 // signal SPDY_INVALID_STREAM_ID. |
1333 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 1170 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
1334 if (!IsHttp2()) { | |
1335 return; | |
1336 } | |
1337 | |
1338 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1171 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
1339 SpdyFramer framer(spdy_version_); | 1172 SpdyFramer framer(spdy_version_); |
1340 framer.set_visitor(&visitor); | 1173 framer.set_visitor(&visitor); |
1341 | 1174 |
1342 SpdyPushPromiseIR push_promise(3, 0); | 1175 SpdyPushPromiseIR push_promise(3, 0); |
1343 push_promise.SetHeader("alpha", "beta"); | 1176 push_promise.SetHeader("alpha", "beta"); |
1344 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 1177 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
1345 | 1178 |
1346 // We shouldn't have to read the whole frame before we signal an error. | 1179 // We shouldn't have to read the whole frame before we signal an error. |
1347 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1180 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
1348 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1181 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
1349 EXPECT_TRUE(framer.HasError()); | 1182 EXPECT_TRUE(framer.HasError()); |
1350 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 1183 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
1351 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 1184 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
1352 } | 1185 } |
1353 | 1186 |
1354 TEST_P(SpdyFramerTest, DuplicateHeader) { | 1187 TEST_P(SpdyFramerTest, DuplicateHeader) { |
1355 if (!IsSpdy3()) { | |
1356 // TODO(jgraettinger): Punting on this because we haven't determined | |
1357 // whether duplicate HPACK headers other than Cookie are an error. | |
1358 // If they are, this will need to be updated to use HpackOutputStream. | |
1359 return; | |
1360 } | |
1361 SpdyFramer framer(spdy_version_); | 1188 SpdyFramer framer(spdy_version_); |
1362 // Frame builder with plentiful buffer size. | 1189 // Frame builder with plentiful buffer size. |
1363 SpdyFrameBuilder frame(1024, spdy_version_); | 1190 SpdyFrameBuilder frame(1024, spdy_version_); |
1364 if (spdy_version_ <= SPDY3) { | 1191 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); |
1365 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 1192 frame.WriteUInt32(framer.GetHighestPriority()); |
1366 frame.WriteUInt32(3); // stream_id | |
1367 frame.WriteUInt32(0); // associated stream id | |
1368 frame.WriteUInt16(0); // Priority. | |
1369 } else { | |
1370 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); | |
1371 frame.WriteUInt32(framer.GetHighestPriority()); | |
1372 } | |
1373 | 1193 |
1374 frame.WriteUInt32(2); // Number of headers. | 1194 frame.WriteUInt32(2); // Number of headers. |
1375 frame.WriteStringPiece32("name"); | 1195 frame.WriteStringPiece32("name"); |
1376 frame.WriteStringPiece32("value1"); | 1196 frame.WriteStringPiece32("value1"); |
1377 frame.WriteStringPiece32("name"); | 1197 frame.WriteStringPiece32("name"); |
1378 frame.WriteStringPiece32("value2"); | 1198 frame.WriteStringPiece32("value2"); |
1379 // write the length | 1199 // write the length |
1380 frame.RewriteLength(framer); | 1200 frame.RewriteLength(framer); |
1381 | 1201 |
1382 SpdyHeaderBlock new_headers; | 1202 SpdyHeaderBlock new_headers; |
1383 framer.set_enable_compression(false); | 1203 framer.set_enable_compression(false); |
1384 SpdySerializedFrame control_frame(frame.take()); | 1204 SpdySerializedFrame control_frame(frame.take()); |
1385 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); | 1205 StringPiece serialized_headers = GetSerializedHeaders(control_frame, framer); |
1386 // This should fail because duplicate headers are verboten by the spec. | 1206 // This should fail because duplicate headers are verboten by the spec. |
1387 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( | 1207 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
1388 serialized_headers.data(), serialized_headers.size(), &new_headers)); | 1208 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
1389 } | 1209 } |
1390 | 1210 |
1391 TEST_P(SpdyFramerTest, MultiValueHeader) { | 1211 TEST_P(SpdyFramerTest, MultiValueHeader) { |
1392 SpdyFramer framer(spdy_version_); | 1212 SpdyFramer framer(spdy_version_); |
1393 // Frame builder with plentiful buffer size. | 1213 // Frame builder with plentiful buffer size. |
1394 SpdyFrameBuilder frame(1024, spdy_version_); | 1214 SpdyFrameBuilder frame(1024, spdy_version_); |
1395 if (IsSpdy3()) { | 1215 frame.BeginNewFrame(framer, HEADERS, |
1396 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 1216 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); |
1397 frame.WriteUInt32(3); // stream_id | 1217 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. |
1398 frame.WriteUInt32(0); // associated stream id | 1218 frame.WriteUInt8(255); // Priority weight. |
1399 frame.WriteUInt16(0); // Priority. | |
1400 } else { | |
1401 frame.BeginNewFrame(framer, HEADERS, | |
1402 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); | |
1403 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. | |
1404 frame.WriteUInt8(255); // Priority weight. | |
1405 } | |
1406 | 1219 |
1407 string value("value1\0value2", 13); | 1220 string value("value1\0value2", 13); |
1408 if (IsSpdy3()) { | 1221 // TODO(jgraettinger): If this pattern appears again, move to test class. |
1409 frame.WriteUInt32(1); // Number of headers. | 1222 SpdyHeaderBlock header_set; |
1410 frame.WriteStringPiece32("name"); | 1223 header_set["name"] = value; |
1411 frame.WriteStringPiece32(value); | 1224 string buffer; |
1412 } else { | 1225 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
1413 // TODO(jgraettinger): If this pattern appears again, move to test class. | 1226 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); |
1414 SpdyHeaderBlock header_set; | 1227 frame.WriteBytes(&buffer[0], buffer.size()); |
1415 header_set["name"] = value; | |
1416 string buffer; | |
1417 HpackEncoder encoder(ObtainHpackHuffmanTable()); | |
1418 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); | |
1419 frame.WriteBytes(&buffer[0], buffer.size()); | |
1420 } | |
1421 // write the length | 1228 // write the length |
1422 frame.RewriteLength(framer); | 1229 frame.RewriteLength(framer); |
1423 | 1230 |
1424 framer.set_enable_compression(false); | 1231 framer.set_enable_compression(false); |
1425 SpdySerializedFrame control_frame(frame.take()); | 1232 SpdySerializedFrame control_frame(frame.take()); |
1426 | 1233 |
1427 TestSpdyVisitor visitor(spdy_version_); | 1234 TestSpdyVisitor visitor(spdy_version_); |
1428 visitor.use_compression_ = false; | 1235 visitor.use_compression_ = false; |
1429 visitor.SimulateInFramer( | 1236 visitor.SimulateInFramer( |
1430 reinterpret_cast<unsigned char*>(control_frame.data()), | 1237 reinterpret_cast<unsigned char*>(control_frame.data()), |
1431 control_frame.size()); | 1238 control_frame.size()); |
1432 | 1239 |
1433 EXPECT_THAT(visitor.headers_, | 1240 EXPECT_THAT(visitor.headers_, |
1434 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); | 1241 testing::ElementsAre(testing::Pair("name", StringPiece(value)))); |
1435 } | 1242 } |
1436 | 1243 |
1437 TEST_P(SpdyFramerTest, BasicCompression) { | |
1438 if (!IsSpdy3()) { | |
1439 // Deflate compression doesn't apply to HPACK. | |
1440 return; | |
1441 } | |
1442 | |
1443 std::unique_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); | |
1444 SpdyFramer framer(spdy_version_); | |
1445 framer.set_debug_visitor(visitor.get()); | |
1446 SpdySynStreamIR syn_stream(1); | |
1447 syn_stream.set_priority(1); | |
1448 syn_stream.SetHeader("server", "SpdyServer 1.0"); | |
1449 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | |
1450 syn_stream.SetHeader("status", "200"); | |
1451 syn_stream.SetHeader("version", "HTTP/1.1"); | |
1452 syn_stream.SetHeader("content-type", "text/html"); | |
1453 syn_stream.SetHeader("content-length", "12"); | |
1454 SpdySerializedFrame frame1(framer.SerializeSynStream(syn_stream)); | |
1455 size_t uncompressed_size1 = visitor->last_payload_len_; | |
1456 size_t compressed_size1 = | |
1457 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | |
1458 EXPECT_EQ(165u, uncompressed_size1); | |
1459 #if defined(USE_SYSTEM_ZLIB) | |
1460 EXPECT_EQ(181u, compressed_size1); | |
1461 #else // !defined(USE_SYSTEM_ZLIB) | |
1462 EXPECT_EQ(116u, compressed_size1); | |
1463 #endif // !defined(USE_SYSTEM_ZLIB) | |
1464 SpdySerializedFrame frame2(framer.SerializeSynStream(syn_stream)); | |
1465 size_t uncompressed_size2 = visitor->last_payload_len_; | |
1466 size_t compressed_size2 = | |
1467 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | |
1468 | |
1469 // Expect the second frame to be more compact than the first. | |
1470 EXPECT_LE(frame2.size(), frame1.size()); | |
1471 | |
1472 // Decompress the first frame | |
1473 SpdySerializedFrame frame3( | |
1474 SpdyFramerTestUtil::DecompressFrame(&framer, frame1)); | |
1475 | |
1476 // Decompress the second frame | |
1477 visitor.reset(new TestSpdyVisitor(spdy_version_)); | |
1478 framer.set_debug_visitor(visitor.get()); | |
1479 SpdySerializedFrame frame4( | |
1480 SpdyFramerTestUtil::DecompressFrame(&framer, frame2)); | |
1481 size_t uncompressed_size4 = frame4.size() - framer.GetSynStreamMinimumSize(); | |
1482 size_t compressed_size4 = | |
1483 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | |
1484 EXPECT_EQ(165u, uncompressed_size4); | |
1485 #if defined(USE_SYSTEM_ZLIB) | |
1486 EXPECT_EQ(175u, compressed_size4); | |
1487 #else // !defined(USE_SYSTEM_ZLIB) | |
1488 EXPECT_EQ(98u, compressed_size4); | |
1489 #endif // !defined(USE_SYSTEM_ZLIB) | |
1490 | |
1491 EXPECT_EQ(uncompressed_size1, uncompressed_size2); | |
1492 EXPECT_EQ(uncompressed_size1, uncompressed_size4); | |
1493 EXPECT_EQ(compressed_size2, compressed_size4); | |
1494 | |
1495 // Expect frames 3 & 4 to be the same. | |
1496 CompareFrames("Uncompressed SYN_STREAM", frame3, frame4); | |
1497 | |
1498 // Expect frames 3 to be the same as a uncompressed frame created | |
1499 // from scratch. | |
1500 framer.set_enable_compression(false); | |
1501 SpdySerializedFrame uncompressed_frame(framer.SerializeSynStream(syn_stream)); | |
1502 CompareFrames("Uncompressed SYN_STREAM", frame3, uncompressed_frame); | |
1503 } | |
1504 | |
1505 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { | 1244 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { |
1506 // See crbug.com/172383 | 1245 // See crbug.com/172383 |
1507 SpdyHeadersIR headers(1); | 1246 SpdyHeadersIR headers(1); |
1508 headers.SetHeader("server", "SpdyServer 1.0"); | 1247 headers.SetHeader("server", "SpdyServer 1.0"); |
1509 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 1248 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
1510 headers.SetHeader("status", "200"); | 1249 headers.SetHeader("status", "200"); |
1511 headers.SetHeader("version", "HTTP/1.1"); | 1250 headers.SetHeader("version", "HTTP/1.1"); |
1512 headers.SetHeader("content-type", "text/html"); | 1251 headers.SetHeader("content-type", "text/html"); |
1513 headers.SetHeader("content-length", "12"); | 1252 headers.SetHeader("content-length", "12"); |
1514 headers.SetHeader("x-empty-header", ""); | 1253 headers.SetHeader("x-empty-header", ""); |
1515 | 1254 |
1516 SpdyFramer framer(spdy_version_); | 1255 SpdyFramer framer(spdy_version_); |
1517 framer.set_enable_compression(true); | 1256 framer.set_enable_compression(true); |
1518 SpdySerializedFrame frame1( | 1257 SpdySerializedFrame frame1( |
1519 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1258 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
1520 } | 1259 } |
1521 | 1260 |
1522 TEST_P(SpdyFramerTest, Basic) { | 1261 TEST_P(SpdyFramerTest, Basic) { |
1523 // clang-format off | |
1524 const unsigned char kV3Input[] = { | |
1525 0x80, 0x03, 0x00, 0x01, // SYN Stream #1 | |
1526 0x00, 0x00, 0x00, 0x1a, | |
1527 0x00, 0x00, 0x00, 0x01, | |
1528 0x00, 0x00, 0x00, 0x00, | |
1529 0x00, 0x00, 0x00, 0x00, | |
1530 0x00, 0x01, 0x00, 0x00, | |
1531 0x00, 0x02, 'h', 'h', | |
1532 0x00, 0x00, 0x00, 0x02, | |
1533 'v', 'v', | |
1534 | |
1535 0x80, 0x03, 0x00, 0x08, // HEADERS on Stream #1 | |
1536 0x00, 0x00, 0x00, 0x20, | |
1537 0x00, 0x00, 0x00, 0x01, | |
1538 0x00, 0x00, 0x00, 0x02, | |
1539 0x00, 0x00, 0x00, 0x02, | |
1540 'h', '2', | |
1541 0x00, 0x00, 0x00, 0x02, | |
1542 'v', '2', 0x00, 0x00, | |
1543 0x00, 0x02, 'h', '3', | |
1544 0x00, 0x00, 0x00, 0x02, | |
1545 'v', '3', | |
1546 | |
1547 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
1548 0x00, 0x00, 0x00, 0x0c, | |
1549 0xde, 0xad, 0xbe, 0xef, | |
1550 0xde, 0xad, 0xbe, 0xef, | |
1551 0xde, 0xad, 0xbe, 0xef, | |
1552 | |
1553 0x80, 0x03, 0x00, 0x01, // SYN Stream #3 | |
1554 0x00, 0x00, 0x00, 0x0e, | |
1555 0x00, 0x00, 0x00, 0x03, | |
1556 0x00, 0x00, 0x00, 0x00, | |
1557 0x00, 0x00, 0x00, 0x00, | |
1558 0x00, 0x00, | |
1559 | |
1560 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | |
1561 0x00, 0x00, 0x00, 0x08, | |
1562 0xde, 0xad, 0xbe, 0xef, | |
1563 0xde, 0xad, 0xbe, 0xef, | |
1564 | |
1565 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
1566 0x00, 0x00, 0x00, 0x04, | |
1567 0xde, 0xad, 0xbe, 0xef, | |
1568 | |
1569 0x80, 0x03, 0x00, 0x03, // RST_STREAM on Stream #1 | |
1570 0x00, 0x00, 0x00, 0x08, | |
1571 0x00, 0x00, 0x00, 0x01, | |
1572 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
1573 | |
1574 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | |
1575 0x00, 0x00, 0x00, 0x00, | |
1576 | |
1577 0x80, 0x03, 0x00, 0x03, // RST_STREAM on Stream #3 | |
1578 0x00, 0x00, 0x00, 0x08, | |
1579 0x00, 0x00, 0x00, 0x03, | |
1580 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
1581 }; | |
1582 // clang-format on | |
1583 | |
1584 // SYN_STREAM doesn't exist in HTTP/2, so instead we send | 1262 // SYN_STREAM doesn't exist in HTTP/2, so instead we send |
1585 // HEADERS frames with PRIORITY and END_HEADERS set. | 1263 // HEADERS frames with PRIORITY and END_HEADERS set. |
1586 // frame-format off | 1264 // frame-format off |
1587 const unsigned char kH2Input[] = { | 1265 const unsigned char kH2Input[] = { |
1588 0x00, 0x00, 0x05, // Length: 5 | 1266 0x00, 0x00, 0x05, // Length: 5 |
1589 0x01, // Type: HEADERS | 1267 0x01, // Type: HEADERS |
1590 0x24, // Flags: END_HEADERS|PRIORITY | 1268 0x24, // Flags: END_HEADERS|PRIORITY |
1591 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1269 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1592 0x00, 0x00, 0x00, 0x00, // Parent: 0 | 1270 0x00, 0x00, 0x00, 0x00, // Parent: 0 |
1593 0x82, // Weight: 131 | 1271 0x82, // Weight: 131 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1639 | 1317 |
1640 0x00, 0x00, 0x04, // Length: 4 | 1318 0x00, 0x00, 0x04, // Length: 4 |
1641 0x03, // Type: RST_STREAM | 1319 0x03, // Type: RST_STREAM |
1642 0x00, // Flags: none | 1320 0x00, // Flags: none |
1643 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 1321 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
1644 0x00, 0x00, 0x00, 0x08, // Error: CANCEL | 1322 0x00, 0x00, 0x00, 0x08, // Error: CANCEL |
1645 }; | 1323 }; |
1646 // frame-format on | 1324 // frame-format on |
1647 | 1325 |
1648 TestSpdyVisitor visitor(spdy_version_); | 1326 TestSpdyVisitor visitor(spdy_version_); |
1649 if (IsSpdy3()) { | 1327 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
1650 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | |
1651 } else { | |
1652 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | |
1653 } | |
1654 | 1328 |
1655 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 1329 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1656 EXPECT_EQ(24, visitor.data_bytes_); | 1330 EXPECT_EQ(24, visitor.data_bytes_); |
1657 EXPECT_EQ(0, visitor.error_count_); | 1331 EXPECT_EQ(0, visitor.error_count_); |
1658 EXPECT_EQ(2, visitor.fin_frame_count_); | 1332 EXPECT_EQ(2, visitor.fin_frame_count_); |
1659 | 1333 |
1660 if (IsSpdy3()) { | 1334 EXPECT_EQ(3, visitor.headers_frame_count_); |
1661 EXPECT_EQ(1, visitor.headers_frame_count_); | 1335 EXPECT_EQ(0, visitor.syn_frame_count_); |
1662 EXPECT_EQ(2, visitor.syn_frame_count_); | 1336 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); |
1663 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); | |
1664 } else { | |
1665 EXPECT_EQ(3, visitor.headers_frame_count_); | |
1666 EXPECT_EQ(0, visitor.syn_frame_count_); | |
1667 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); | |
1668 } | |
1669 | 1337 |
1670 EXPECT_EQ(0, visitor.fin_flag_count_); | 1338 EXPECT_EQ(0, visitor.fin_flag_count_); |
1671 EXPECT_EQ(0, visitor.end_of_stream_count_); | 1339 EXPECT_EQ(0, visitor.end_of_stream_count_); |
1672 EXPECT_EQ(4, visitor.data_frame_count_); | 1340 EXPECT_EQ(4, visitor.data_frame_count_); |
1673 visitor.fin_opaque_data_.clear(); | 1341 visitor.fin_opaque_data_.clear(); |
1674 } | 1342 } |
1675 | 1343 |
1676 // Test that the FIN flag on a data frame signifies EOF. | 1344 // Test that the FIN flag on a data frame signifies EOF. |
1677 TEST_P(SpdyFramerTest, FinOnDataFrame) { | 1345 TEST_P(SpdyFramerTest, FinOnDataFrame) { |
1678 // clang-format off | |
1679 const unsigned char kV3Input[] = { | |
1680 0x80, 0x03, 0x00, 0x01, // SYN Stream #1 | |
1681 0x00, 0x00, 0x00, 0x1a, | |
1682 0x00, 0x00, 0x00, 0x01, | |
1683 0x00, 0x00, 0x00, 0x00, | |
1684 0x00, 0x00, 0x00, 0x00, | |
1685 0x00, 0x01, 0x00, 0x00, | |
1686 0x00, 0x02, 'h', 'h', | |
1687 0x00, 0x00, 0x00, 0x02, | |
1688 'v', 'v', | |
1689 | |
1690 0x80, 0x03, 0x00, 0x02, // SYN REPLY Stream #1 | |
1691 0x00, 0x00, 0x00, 0x14, | |
1692 0x00, 0x00, 0x00, 0x01, | |
1693 0x00, 0x00, 0x00, 0x01, | |
1694 0x00, 0x00, 0x00, 0x02, | |
1695 'a', 'a', 0x00, 0x00, | |
1696 0x00, 0x02, 'b', 'b', | |
1697 | |
1698 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
1699 0x00, 0x00, 0x00, 0x0c, | |
1700 0xde, 0xad, 0xbe, 0xef, | |
1701 0xde, 0xad, 0xbe, 0xef, | |
1702 0xde, 0xad, 0xbe, 0xef, | |
1703 | |
1704 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF | |
1705 0x01, 0x00, 0x00, 0x04, | |
1706 0xde, 0xad, 0xbe, 0xef, | |
1707 }; | |
1708 // clang-format on | |
1709 | |
1710 // SYN_STREAM and SYN_REPLY don't exist in HTTP2, so instead we send | 1346 // SYN_STREAM and SYN_REPLY don't exist in HTTP2, so instead we send |
1711 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. | 1347 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. |
1712 // frame-format off | 1348 // frame-format off |
1713 const unsigned char kH2Input[] = { | 1349 const unsigned char kH2Input[] = { |
1714 0x00, 0x00, 0x05, // Length: 5 | 1350 0x00, 0x00, 0x05, // Length: 5 |
1715 0x01, // Type: HEADERS | 1351 0x01, // Type: HEADERS |
1716 0x24, // Flags: END_HEADERS|PRIORITY | 1352 0x24, // Flags: END_HEADERS|PRIORITY |
1717 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1353 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1718 0x00, 0x00, 0x00, 0x00, // Parent: 0 | 1354 0x00, 0x00, 0x00, 0x00, // Parent: 0 |
1719 0x82, // Weight: 131 | 1355 0x82, // Weight: 131 |
(...skipping 14 matching lines...) Expand all Loading... | |
1734 | 1370 |
1735 0x00, 0x00, 0x04, // Length: 4 | 1371 0x00, 0x00, 0x04, // Length: 4 |
1736 0x00, // Type: DATA | 1372 0x00, // Type: DATA |
1737 0x01, // Flags: END_STREAM | 1373 0x01, // Flags: END_STREAM |
1738 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1374 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1739 0xde, 0xad, 0xbe, 0xef, // Payload | 1375 0xde, 0xad, 0xbe, 0xef, // Payload |
1740 }; | 1376 }; |
1741 // frame-format on | 1377 // frame-format on |
1742 | 1378 |
1743 TestSpdyVisitor visitor(spdy_version_); | 1379 TestSpdyVisitor visitor(spdy_version_); |
1744 if (IsSpdy3()) { | 1380 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
1745 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | |
1746 } else { | |
1747 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | |
1748 } | |
1749 | 1381 |
1750 EXPECT_EQ(0, visitor.error_count_); | 1382 EXPECT_EQ(0, visitor.error_count_); |
1751 if (IsSpdy3()) { | 1383 EXPECT_EQ(0, visitor.syn_frame_count_); |
1752 EXPECT_EQ(1, visitor.syn_frame_count_); | 1384 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1753 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | 1385 EXPECT_EQ(2, visitor.headers_frame_count_); |
1754 EXPECT_EQ(0, visitor.headers_frame_count_); | |
1755 } else { | |
1756 EXPECT_EQ(0, visitor.syn_frame_count_); | |
1757 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | |
1758 EXPECT_EQ(2, visitor.headers_frame_count_); | |
1759 } | |
1760 EXPECT_EQ(16, visitor.data_bytes_); | 1386 EXPECT_EQ(16, visitor.data_bytes_); |
1761 EXPECT_EQ(0, visitor.fin_frame_count_); | 1387 EXPECT_EQ(0, visitor.fin_frame_count_); |
1762 EXPECT_EQ(0, visitor.fin_flag_count_); | 1388 EXPECT_EQ(0, visitor.fin_flag_count_); |
1763 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1389 EXPECT_EQ(1, visitor.end_of_stream_count_); |
1764 EXPECT_EQ(2, visitor.data_frame_count_); | 1390 EXPECT_EQ(2, visitor.data_frame_count_); |
1765 } | 1391 } |
1766 | 1392 |
1767 // Test that the FIN flag on a SYN reply frame signifies EOF. | 1393 // Test that the FIN flag on a SYN reply frame signifies EOF. |
1768 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { | 1394 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { |
1769 // clang-format off | |
1770 const unsigned char kV3Input[] = { | |
1771 0x80, 0x03, 0x00, // SYN Stream #1 | |
1772 0x01, 0x00, 0x00, 0x00, | |
1773 0x1a, 0x00, 0x00, 0x00, | |
1774 0x01, 0x00, 0x00, 0x00, | |
1775 0x00, 0x00, 0x00, 0x00, | |
1776 0x00, 0x00, 0x01, 0x00, | |
1777 0x00, 0x00, 0x02, 'h', | |
1778 'h', 0x00, 0x00, 0x00, | |
1779 0x02, 'v', 'v', | |
1780 | |
1781 0x80, 0x03, 0x00, 0x02, // SYN REPLY Stream #1 | |
1782 0x01, 0x00, 0x00, 0x14, | |
1783 0x00, 0x00, 0x00, 0x01, | |
1784 0x00, 0x00, 0x00, 0x01, | |
1785 0x00, 0x00, 0x00, 0x02, | |
1786 'a', 'a', 0x00, 0x00, | |
1787 0x00, 0x02, 'b', 'b', | |
1788 }; | |
1789 // clang-format on | |
1790 | |
1791 // SYN_STREAM and SYN_REPLY don't exist in HTTP2, so instead we send | 1395 // SYN_STREAM and SYN_REPLY don't exist in HTTP2, so instead we send |
1792 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. | 1396 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. |
1793 // frame-format off | 1397 // frame-format off |
1794 const unsigned char kH2Input[] = { | 1398 const unsigned char kH2Input[] = { |
1795 0x00, 0x00, 0x05, // Length: 5 | 1399 0x00, 0x00, 0x05, // Length: 5 |
1796 0x01, // Type: HEADERS | 1400 0x01, // Type: HEADERS |
1797 0x24, // Flags: END_HEADERS|PRIORITY | 1401 0x24, // Flags: END_HEADERS|PRIORITY |
1798 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1402 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1799 0x00, 0x00, 0x00, 0x00, // Parent: 0 | 1403 0x00, 0x00, 0x00, 0x00, // Parent: 0 |
1800 0x82, // Weight: 131 | 1404 0x82, // Weight: 131 |
1801 | 1405 |
1802 0x00, 0x00, 0x01, // Length: 1 | 1406 0x00, 0x00, 0x01, // Length: 1 |
1803 0x01, // Type: HEADERS | 1407 0x01, // Type: HEADERS |
1804 0x05, // Flags: END_STREAM|END_HEADERS | 1408 0x05, // Flags: END_STREAM|END_HEADERS |
1805 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1409 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1806 0x8c, // :status: 200 | 1410 0x8c, // :status: 200 |
1807 }; | 1411 }; |
1808 // frame-format on | 1412 // frame-format on |
1809 | 1413 |
1810 TestSpdyVisitor visitor(spdy_version_); | 1414 TestSpdyVisitor visitor(spdy_version_); |
1811 if (IsSpdy3()) { | 1415 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); |
1812 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | |
1813 } else { | |
1814 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); | |
1815 } | |
1816 | 1416 |
1817 EXPECT_EQ(0, visitor.error_count_); | 1417 EXPECT_EQ(0, visitor.error_count_); |
1818 if (IsSpdy3()) { | 1418 EXPECT_EQ(0, visitor.syn_frame_count_); |
1819 EXPECT_EQ(1, visitor.syn_frame_count_); | 1419 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1820 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | 1420 EXPECT_EQ(2, visitor.headers_frame_count_); |
1821 EXPECT_EQ(0, visitor.headers_frame_count_); | |
1822 } else { | |
1823 EXPECT_EQ(0, visitor.syn_frame_count_); | |
1824 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | |
1825 EXPECT_EQ(2, visitor.headers_frame_count_); | |
1826 } | |
1827 EXPECT_EQ(0, visitor.data_bytes_); | 1421 EXPECT_EQ(0, visitor.data_bytes_); |
1828 EXPECT_EQ(0, visitor.fin_frame_count_); | 1422 EXPECT_EQ(0, visitor.fin_frame_count_); |
1829 EXPECT_EQ(1, visitor.fin_flag_count_); | 1423 EXPECT_EQ(1, visitor.fin_flag_count_); |
1830 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1424 EXPECT_EQ(1, visitor.end_of_stream_count_); |
1831 EXPECT_EQ(0, visitor.data_frame_count_); | 1425 EXPECT_EQ(0, visitor.data_frame_count_); |
1832 } | 1426 } |
1833 | 1427 |
1834 TEST_P(SpdyFramerTest, HeaderCompression) { | |
1835 if (!IsSpdy3()) { | |
1836 // Deflate compression doesn't apply to HPACK. | |
1837 return; | |
1838 } | |
1839 | |
1840 SpdyFramer send_framer(spdy_version_); | |
1841 SpdyFramer recv_framer(spdy_version_); | |
1842 | |
1843 send_framer.set_enable_compression(true); | |
1844 recv_framer.set_enable_compression(true); | |
1845 | |
1846 const char kHeader1[] = "header1"; | |
1847 const char kHeader2[] = "header2"; | |
1848 const char kHeader3[] = "header3"; | |
1849 const char kValue1[] = "value1"; | |
1850 const char kValue2[] = "value2"; | |
1851 const char kValue3[] = "value3"; | |
1852 | |
1853 // SYN_STREAM #1 | |
1854 SpdyHeaderBlock block; | |
1855 block[kHeader1] = kValue1; | |
1856 block[kHeader2] = kValue2; | |
1857 SpdySynStreamIR syn_ir_1(1, block.Clone()); | |
1858 SpdySerializedFrame syn_frame_1(send_framer.SerializeFrame(syn_ir_1)); | |
1859 | |
1860 // SYN_STREAM #2 | |
1861 block[kHeader3] = kValue3; | |
1862 SpdySynStreamIR syn_stream(3, std::move(block)); | |
1863 SpdySerializedFrame syn_frame_2(send_framer.SerializeSynStream(syn_stream)); | |
1864 | |
1865 // Decompress SYN_STREAM #1 | |
1866 SpdySerializedFrame decompressed( | |
1867 SpdyFramerTestUtil::DecompressFrame(&recv_framer, syn_frame_1)); | |
1868 StringPiece serialized_headers = | |
1869 GetSerializedHeaders(decompressed, send_framer); | |
1870 SpdyHeaderBlock decompressed_headers; | |
1871 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | |
1872 serialized_headers.size(), | |
1873 &decompressed_headers)); | |
1874 EXPECT_EQ(2u, decompressed_headers.size()); | |
1875 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); | |
1876 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); | |
1877 | |
1878 // Decompress SYN_STREAM #2 | |
1879 decompressed = SpdyFramerTestUtil::DecompressFrame(&recv_framer, syn_frame_2); | |
1880 serialized_headers = GetSerializedHeaders(decompressed, send_framer); | |
1881 decompressed_headers.clear(); | |
1882 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | |
1883 serialized_headers.size(), | |
1884 &decompressed_headers)); | |
1885 EXPECT_EQ(3u, decompressed_headers.size()); | |
1886 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); | |
1887 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); | |
1888 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); | |
1889 } | |
1890 | |
1891 // Verify we can decompress the stream even if handed over to the | 1428 // Verify we can decompress the stream even if handed over to the |
1892 // framer 1 byte at a time. | 1429 // framer 1 byte at a time. |
1893 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { | 1430 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { |
1894 SpdyFramer framer(spdy_version_); | 1431 SpdyFramer framer(spdy_version_); |
1895 | 1432 |
1896 framer.set_enable_compression(true); | 1433 framer.set_enable_compression(true); |
1897 | 1434 |
1898 const char kHeader1[] = "header1"; | 1435 const char kHeader1[] = "header1"; |
1899 const char kHeader2[] = "header2"; | 1436 const char kHeader2[] = "header2"; |
1900 const char kValue1[] = "value1"; | 1437 const char kValue1[] = "value1"; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1936 EXPECT_EQ(1, visitor.end_of_stream_count_); | 1473 EXPECT_EQ(1, visitor.end_of_stream_count_); |
1937 EXPECT_EQ(1, visitor.data_frame_count_); | 1474 EXPECT_EQ(1, visitor.data_frame_count_); |
1938 } | 1475 } |
1939 | 1476 |
1940 TEST_P(SpdyFramerTest, WindowUpdateFrame) { | 1477 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
1941 SpdyFramer framer(spdy_version_); | 1478 SpdyFramer framer(spdy_version_); |
1942 SpdySerializedFrame frame( | 1479 SpdySerializedFrame frame( |
1943 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); | 1480 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); |
1944 | 1481 |
1945 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; | 1482 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; |
1946 // clang-format off | |
1947 const unsigned char kV3FrameData[] = { | |
1948 0x80, 0x03, 0x00, 0x09, | |
1949 0x00, 0x00, 0x00, 0x08, | |
1950 0x00, 0x00, 0x00, 0x01, | |
1951 0x12, 0x34, 0x56, 0x78 | |
1952 }; | |
1953 // clang-format on | |
1954 const unsigned char kH2FrameData[] = { | 1483 const unsigned char kH2FrameData[] = { |
1955 0x00, 0x00, 0x04, // Length: 4 | 1484 0x00, 0x00, 0x04, // Length: 4 |
1956 0x08, // Type: WINDOW_UPDATE | 1485 0x08, // Type: WINDOW_UPDATE |
1957 0x00, // Flags: none | 1486 0x00, // Flags: none |
1958 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1487 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1959 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 | 1488 0x12, 0x34, 0x56, 0x78, // Increment: 305419896 |
1960 }; | 1489 }; |
1961 | 1490 |
1962 if (IsSpdy3()) { | 1491 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
1963 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
1964 } else { | |
1965 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
1966 } | |
1967 } | 1492 } |
1968 | 1493 |
1969 TEST_P(SpdyFramerTest, CreateDataFrame) { | 1494 TEST_P(SpdyFramerTest, CreateDataFrame) { |
1970 SpdyFramer framer(spdy_version_); | 1495 SpdyFramer framer(spdy_version_); |
1971 | 1496 |
1972 { | 1497 { |
1973 const char kDescription[] = "'hello' data frame, no FIN"; | 1498 const char kDescription[] = "'hello' data frame, no FIN"; |
1974 // clang-format off | |
1975 const unsigned char kV3FrameData[] = { | |
1976 0x00, 0x00, 0x00, 0x01, | |
1977 0x00, 0x00, 0x00, 0x05, | |
1978 'h', 'e', 'l', 'l', | |
1979 'o' | |
1980 }; | |
1981 // clang-format on | |
1982 // frame-format off | 1499 // frame-format off |
1983 const unsigned char kH2FrameData[] = { | 1500 const unsigned char kH2FrameData[] = { |
1984 0x00, 0x00, 0x05, // Length: 5 | 1501 0x00, 0x00, 0x05, // Length: 5 |
1985 0x00, // Type: DATA | 1502 0x00, // Type: DATA |
1986 0x00, // Flags: none | 1503 0x00, // Flags: none |
1987 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1504 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
1988 'h', 'e', 'l', 'l', // Payload | 1505 'h', 'e', 'l', 'l', // Payload |
1989 'o', // | 1506 'o', // |
1990 }; | 1507 }; |
1991 // frame-format on | 1508 // frame-format on |
1992 const char bytes[] = "hello"; | 1509 const char bytes[] = "hello"; |
1993 | 1510 |
1994 SpdyDataIR data_ir(1, bytes); | 1511 SpdyDataIR data_ir(1, bytes); |
1995 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1512 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
1996 if (IsSpdy3()) { | 1513 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
1997 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
1998 } else { | |
1999 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2000 } | |
2001 | 1514 |
2002 SpdyDataIR data_header_ir(1); | 1515 SpdyDataIR data_header_ir(1); |
2003 data_header_ir.SetDataShallow(bytes); | 1516 data_header_ir.SetDataShallow(bytes); |
2004 frame = | 1517 frame = |
2005 framer.SerializeDataFrameHeaderWithPaddingLengthField(data_header_ir); | 1518 framer.SerializeDataFrameHeaderWithPaddingLengthField(data_header_ir); |
2006 CompareCharArraysWithHexError( | 1519 CompareCharArraysWithHexError( |
2007 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), | 1520 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), |
2008 framer.GetDataFrameMinimumSize(), | 1521 framer.GetDataFrameMinimumSize(), kH2FrameData, |
2009 IsSpdy3() ? kV3FrameData : kH2FrameData, | |
2010 framer.GetDataFrameMinimumSize()); | 1522 framer.GetDataFrameMinimumSize()); |
2011 } | 1523 } |
2012 | 1524 |
2013 { | 1525 { |
2014 const char kDescription[] = "'hello' data frame with more padding, no FIN"; | 1526 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
2015 // clang-format off | |
2016 const unsigned char kV3FrameData[] = { | |
2017 0x00, 0x00, 0x00, 0x01, | |
2018 0x00, 0x00, 0x00, 0x05, | |
2019 'h', 'e', 'l', 'l', | |
2020 'o' | |
2021 }; | |
2022 // frame-format off | |
2023 const unsigned char kH2FrameData[] = { | 1527 const unsigned char kH2FrameData[] = { |
2024 0x00, 0x00, 0xfd, // Length: 253 | 1528 0x00, 0x00, 0xfd, // Length: 253 |
2025 0x00, // Type: DATA | 1529 0x00, // Type: DATA |
2026 0x08, // Flags: PADDED | 1530 0x08, // Flags: PADDED |
2027 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1531 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2028 0xf7, // PadLen: 247 trailing bytes | 1532 0xf7, // PadLen: 247 trailing bytes |
2029 'h', 'e', 'l', 'l', // Payload | 1533 'h', 'e', 'l', 'l', // Payload |
2030 'o', // | 1534 'o', // |
2031 // Padding of 247 0x00(s). | 1535 // Padding of 247 0x00(s). |
2032 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1536 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2033 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1537 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2034 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1538 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2035 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1539 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2036 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1540 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2037 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1541 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2038 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1542 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
2039 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 1543 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
(...skipping 13 matching lines...) Expand all Loading... | |
2053 }; | 1557 }; |
2054 // frame-format on | 1558 // frame-format on |
2055 // clang-format on | 1559 // clang-format on |
2056 const char bytes[] = "hello"; | 1560 const char bytes[] = "hello"; |
2057 | 1561 |
2058 SpdyDataIR data_ir(1, bytes); | 1562 SpdyDataIR data_ir(1, bytes); |
2059 // 247 zeros and the pad length field make the overall padding to be 248 | 1563 // 247 zeros and the pad length field make the overall padding to be 248 |
2060 // bytes. | 1564 // bytes. |
2061 data_ir.set_padding_len(248); | 1565 data_ir.set_padding_len(248); |
2062 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1566 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2063 if (IsSpdy3()) { | 1567 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2064 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2065 } else { | |
2066 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2067 } | |
2068 | 1568 |
2069 frame = framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir); | 1569 frame = framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir); |
2070 CompareCharArraysWithHexError( | 1570 CompareCharArraysWithHexError( |
2071 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), | 1571 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), |
2072 framer.GetDataFrameMinimumSize(), | 1572 framer.GetDataFrameMinimumSize(), kH2FrameData, |
2073 IsSpdy3() ? kV3FrameData : kH2FrameData, | |
2074 framer.GetDataFrameMinimumSize()); | 1573 framer.GetDataFrameMinimumSize()); |
2075 } | 1574 } |
2076 | 1575 |
2077 { | 1576 { |
2078 const char kDescription[] = "'hello' data frame with few padding, no FIN"; | 1577 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
2079 // clang-format off | |
2080 const unsigned char kV3FrameData[] = { | |
2081 0x00, 0x00, 0x00, 0x01, | |
2082 0x00, 0x00, 0x00, 0x05, | |
2083 'h', 'e', 'l', 'l', | |
2084 'o' | |
2085 }; | |
2086 // clang-format on | |
2087 // frame-format off | 1578 // frame-format off |
2088 const unsigned char kH2FrameData[] = { | 1579 const unsigned char kH2FrameData[] = { |
2089 0x00, 0x00, 0x0d, // Length: 13 | 1580 0x00, 0x00, 0x0d, // Length: 13 |
2090 0x00, // Type: DATA | 1581 0x00, // Type: DATA |
2091 0x08, // Flags: PADDED | 1582 0x08, // Flags: PADDED |
2092 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1583 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2093 0x07, // PadLen: 7 trailing bytes | 1584 0x07, // PadLen: 7 trailing bytes |
2094 'h', 'e', 'l', 'l', // Payload | 1585 'h', 'e', 'l', 'l', // Payload |
2095 'o', // | 1586 'o', // |
2096 0x00, 0x00, 0x00, 0x00, // Padding | 1587 0x00, 0x00, 0x00, 0x00, // Padding |
2097 0x00, 0x00, 0x00, // Padding | 1588 0x00, 0x00, 0x00, // Padding |
2098 }; | 1589 }; |
2099 // frame-format on | 1590 // frame-format on |
2100 const char bytes[] = "hello"; | 1591 const char bytes[] = "hello"; |
2101 | 1592 |
2102 SpdyDataIR data_ir(1, bytes); | 1593 SpdyDataIR data_ir(1, bytes); |
2103 // 7 zeros and the pad length field make the overall padding to be 8 bytes. | 1594 // 7 zeros and the pad length field make the overall padding to be 8 bytes. |
2104 data_ir.set_padding_len(8); | 1595 data_ir.set_padding_len(8); |
2105 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1596 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2106 if (IsSpdy3()) { | 1597 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2107 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2108 } else { | |
2109 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2110 } | |
2111 } | 1598 } |
2112 | 1599 |
2113 { | 1600 { |
2114 const char kDescription[] = | 1601 const char kDescription[] = |
2115 "'hello' data frame with 1 byte padding, no FIN"; | 1602 "'hello' data frame with 1 byte padding, no FIN"; |
2116 // clang-format off | |
2117 const unsigned char kV3FrameData[] = { | |
2118 0x00, 0x00, 0x00, 0x01, | |
2119 0x00, 0x00, 0x00, 0x05, | |
2120 'h', 'e', 'l', 'l', | |
2121 'o' | |
2122 }; | |
2123 // clang-format on | |
2124 | |
2125 // frame-format off | 1603 // frame-format off |
2126 const unsigned char kH2FrameData[] = { | 1604 const unsigned char kH2FrameData[] = { |
2127 0x00, 0x00, 0x06, // Length: 6 | 1605 0x00, 0x00, 0x06, // Length: 6 |
2128 0x00, // Type: DATA | 1606 0x00, // Type: DATA |
2129 0x08, // Flags: PADDED | 1607 0x08, // Flags: PADDED |
2130 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1608 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2131 0x00, // PadLen: 0 trailing bytes | 1609 0x00, // PadLen: 0 trailing bytes |
2132 'h', 'e', 'l', 'l', // Payload | 1610 'h', 'e', 'l', 'l', // Payload |
2133 'o', // | 1611 'o', // |
2134 }; | 1612 }; |
2135 // frame-format on | 1613 // frame-format on |
2136 const char bytes[] = "hello"; | 1614 const char bytes[] = "hello"; |
2137 | 1615 |
2138 SpdyDataIR data_ir(1, bytes); | 1616 SpdyDataIR data_ir(1, bytes); |
2139 // The pad length field itself is used for the 1-byte padding and no padding | 1617 // The pad length field itself is used for the 1-byte padding and no padding |
2140 // payload is needed. | 1618 // payload is needed. |
2141 data_ir.set_padding_len(1); | 1619 data_ir.set_padding_len(1); |
2142 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1620 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2143 if (IsSpdy3()) { | 1621 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2144 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2145 } else { | |
2146 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2147 } | |
2148 | 1622 |
2149 frame = framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir); | 1623 frame = framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir); |
2150 CompareCharArraysWithHexError( | 1624 CompareCharArraysWithHexError( |
2151 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), | 1625 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), |
2152 framer.GetDataFrameMinimumSize(), | 1626 framer.GetDataFrameMinimumSize(), kH2FrameData, |
2153 IsSpdy3() ? kV3FrameData : kH2FrameData, | |
2154 framer.GetDataFrameMinimumSize()); | 1627 framer.GetDataFrameMinimumSize()); |
2155 } | 1628 } |
2156 | 1629 |
2157 { | 1630 { |
2158 const char kDescription[] = "Data frame with negative data byte, no FIN"; | 1631 const char kDescription[] = "Data frame with negative data byte, no FIN"; |
2159 // clang-format off | |
2160 const unsigned char kV3FrameData[] = { | |
2161 0x00, 0x00, 0x00, 0x01, | |
2162 0x00, 0x00, 0x00, 0x01, | |
2163 0xff | |
2164 }; | |
2165 // clang-format on | |
2166 const unsigned char kH2FrameData[] = { | 1632 const unsigned char kH2FrameData[] = { |
2167 0x00, 0x00, 0x01, // Length: 1 | 1633 0x00, 0x00, 0x01, // Length: 1 |
2168 0x00, // Type: DATA | 1634 0x00, // Type: DATA |
2169 0x00, // Flags: none | 1635 0x00, // Flags: none |
2170 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1636 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2171 0xff, // Payload | 1637 0xff, // Payload |
2172 }; | 1638 }; |
2173 SpdyDataIR data_ir(1, "\xff"); | 1639 SpdyDataIR data_ir(1, "\xff"); |
2174 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1640 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2175 if (IsSpdy3()) { | 1641 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2176 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2177 } else { | |
2178 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2179 } | |
2180 } | 1642 } |
2181 | 1643 |
2182 { | 1644 { |
2183 const char kDescription[] = "'hello' data frame, with FIN"; | 1645 const char kDescription[] = "'hello' data frame, with FIN"; |
2184 // clang-format off | |
2185 const unsigned char kV3FrameData[] = { | |
2186 0x00, 0x00, 0x00, 0x01, | |
2187 0x01, 0x00, 0x00, 0x05, | |
2188 'h', 'e', 'l', 'l', | |
2189 'o' | |
2190 }; | |
2191 // clang-format on | |
2192 const unsigned char kH2FrameData[] = { | 1646 const unsigned char kH2FrameData[] = { |
2193 0x00, 0x00, 0x05, // Length: 5 | 1647 0x00, 0x00, 0x05, // Length: 5 |
2194 0x00, // Type: DATA | 1648 0x00, // Type: DATA |
2195 0x01, // Flags: END_STREAM | 1649 0x01, // Flags: END_STREAM |
2196 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1650 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2197 0x68, 0x65, 0x6c, 0x6c, // Payload | 1651 0x68, 0x65, 0x6c, 0x6c, // Payload |
2198 0x6f, // | 1652 0x6f, // |
2199 }; | 1653 }; |
2200 SpdyDataIR data_ir(1, "hello"); | 1654 SpdyDataIR data_ir(1, "hello"); |
2201 data_ir.set_fin(true); | 1655 data_ir.set_fin(true); |
2202 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1656 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2203 if (IsSpdy3()) { | 1657 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2204 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2205 } else { | |
2206 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2207 } | |
2208 } | 1658 } |
2209 | 1659 |
2210 { | 1660 { |
2211 const char kDescription[] = "Empty data frame"; | 1661 const char kDescription[] = "Empty data frame"; |
2212 // clang-format off | |
2213 const unsigned char kV3FrameData[] = { | |
2214 0x00, 0x00, 0x00, 0x01, | |
2215 0x00, 0x00, 0x00, 0x00, | |
2216 }; | |
2217 // clang-format on | |
2218 const unsigned char kH2FrameData[] = { | 1662 const unsigned char kH2FrameData[] = { |
2219 0x00, 0x00, 0x00, // Length: 0 | 1663 0x00, 0x00, 0x00, // Length: 0 |
2220 0x00, // Type: DATA | 1664 0x00, // Type: DATA |
2221 0x00, // Flags: none | 1665 0x00, // Flags: none |
2222 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1666 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2223 }; | 1667 }; |
2224 SpdyDataIR data_ir(1, ""); | 1668 SpdyDataIR data_ir(1, ""); |
2225 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1669 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2226 if (IsSpdy3()) { | 1670 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2227 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2228 } else { | |
2229 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2230 } | |
2231 | 1671 |
2232 frame = framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir); | 1672 frame = framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir); |
2233 CompareCharArraysWithHexError( | 1673 CompareCharArraysWithHexError( |
2234 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), | 1674 kDescription, reinterpret_cast<const unsigned char*>(frame.data()), |
2235 framer.GetDataFrameMinimumSize(), | 1675 framer.GetDataFrameMinimumSize(), kH2FrameData, |
2236 IsSpdy3() ? kV3FrameData : kH2FrameData, | |
2237 framer.GetDataFrameMinimumSize()); | 1676 framer.GetDataFrameMinimumSize()); |
2238 } | 1677 } |
2239 | 1678 |
2240 { | 1679 { |
2241 const char kDescription[] = "Data frame with max stream ID"; | 1680 const char kDescription[] = "Data frame with max stream ID"; |
2242 // clang-format off | |
2243 const unsigned char kV3FrameData[] = { | |
2244 0x7f, 0xff, 0xff, 0xff, | |
2245 0x01, 0x00, 0x00, 0x05, | |
2246 'h', 'e', 'l', 'l', | |
2247 'o' | |
2248 }; | |
2249 // clang-format on | |
2250 const unsigned char kH2FrameData[] = { | 1681 const unsigned char kH2FrameData[] = { |
2251 0x00, 0x00, 0x05, // Length: 5 | 1682 0x00, 0x00, 0x05, // Length: 5 |
2252 0x00, // Type: DATA | 1683 0x00, // Type: DATA |
2253 0x01, // Flags: END_STREAM | 1684 0x01, // Flags: END_STREAM |
2254 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1685 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
2255 0x68, 0x65, 0x6c, 0x6c, // Payload | 1686 0x68, 0x65, 0x6c, 0x6c, // Payload |
2256 0x6f, // | 1687 0x6f, // |
2257 }; | 1688 }; |
2258 SpdyDataIR data_ir(0x7fffffff, "hello"); | 1689 SpdyDataIR data_ir(0x7fffffff, "hello"); |
2259 data_ir.set_fin(true); | 1690 data_ir.set_fin(true); |
2260 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 1691 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
2261 if (IsSpdy3()) { | 1692 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2262 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2263 } else { | |
2264 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2265 } | |
2266 } | |
2267 | |
2268 if (!IsHttp2()) { | |
2269 // This test does not apply to HTTP/2 because the max frame size is smaller | |
2270 // than 4MB. | |
2271 const char kDescription[] = "Large data frame"; | |
2272 const int kDataSize = 4 * 1024 * 1024; // 4 MB | |
2273 const string kData(kDataSize, 'A'); | |
2274 // clang-format off | |
2275 const unsigned char kFrameHeader[] = { | |
2276 0x00, 0x00, 0x00, 0x01, | |
2277 0x01, 0x40, 0x00, 0x00, | |
2278 }; | |
2279 // clang-format on | |
2280 | |
2281 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; | |
2282 std::unique_ptr<unsigned char[]> expected_frame_data( | |
2283 new unsigned char[kFrameSize]); | |
2284 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); | |
2285 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | |
2286 | |
2287 SpdyDataIR data_ir(1, kData); | |
2288 data_ir.set_fin(true); | |
2289 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | |
2290 CompareFrame(kDescription, frame, expected_frame_data.get(), kFrameSize); | |
2291 } | 1693 } |
2292 } | 1694 } |
2293 | 1695 |
2294 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { | |
2295 if (!IsSpdy3()) { | |
2296 return; | |
2297 } | |
2298 | |
2299 SpdyFramer framer(spdy_version_); | |
2300 framer.set_enable_compression(false); | |
2301 | |
2302 { | |
2303 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; | |
2304 | |
2305 // clang-format off | |
2306 const unsigned char kV3FrameData[] = { | |
2307 0x80, 0x03, 0x00, 0x01, | |
2308 0x00, 0x00, 0x00, 0x2a, | |
2309 0x00, 0x00, 0x00, 0x01, | |
2310 0x00, 0x00, 0x00, 0x00, | |
2311 0xE0, 0x00, 0x00, 0x00, | |
2312 0x00, 0x02, 0x00, 0x00, | |
2313 0x00, 0x03, 'b', 'a', | |
2314 'r', 0x00, 0x00, 0x00, | |
2315 0x03, 'f', 'o', 'o', | |
2316 0x00, 0x00, 0x00, 0x03, | |
2317 'f', 'o', 'o', 0x00, | |
2318 0x00, 0x00, 0x03, 'b', | |
2319 'a', 'r' | |
2320 }; | |
2321 // clang-format on | |
2322 SpdySynStreamIR syn_stream(1); | |
2323 syn_stream.set_priority(framer.GetLowestPriority()); | |
2324 syn_stream.SetHeader("bar", "foo"); | |
2325 syn_stream.SetHeader("foo", "bar"); | |
2326 SpdySerializedFrame frame(framer.SerializeSynStream(syn_stream)); | |
2327 if (IsSpdy3()) { | |
2328 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2329 } else { | |
2330 LOG(FATAL) << "Unsupported version in test."; | |
2331 } | |
2332 } | |
2333 | |
2334 { | |
2335 const char kDescription[] = | |
2336 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " | |
2337 "max stream ID"; | |
2338 | |
2339 // clang-format off | |
2340 const unsigned char kV3FrameData[] = { | |
2341 0x80, 0x03, 0x00, 0x01, | |
2342 0x01, 0x00, 0x00, 0x27, | |
2343 0x7f, 0xff, 0xff, 0xff, | |
2344 0x7f, 0xff, 0xff, 0xff, | |
2345 0x00, 0x00, 0x00, 0x00, | |
2346 0x00, 0x02, 0x00, 0x00, | |
2347 0x00, 0x00, 0x00, 0x00, | |
2348 0x00, 0x03, 'f', 'o', | |
2349 'o', 0x00, 0x00, 0x00, | |
2350 0x03, 'f', 'o', 'o', | |
2351 0x00, 0x00, 0x00, 0x03, | |
2352 'b', 'a', 'r' | |
2353 }; | |
2354 // clang-format on | |
2355 SpdySynStreamIR syn_stream(0x7fffffff); | |
2356 syn_stream.set_associated_to_stream_id(0x7fffffff); | |
2357 syn_stream.set_priority(framer.GetHighestPriority()); | |
2358 syn_stream.set_fin(true); | |
2359 syn_stream.SetHeader("", "foo"); | |
2360 syn_stream.SetHeader("foo", "bar"); | |
2361 SpdySerializedFrame frame(framer.SerializeSynStream(syn_stream)); | |
2362 if (IsSpdy3()) { | |
2363 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2364 } else { | |
2365 LOG(FATAL) << "Unsupported version in test."; | |
2366 } | |
2367 } | |
2368 | |
2369 { | |
2370 const char kDescription[] = | |
2371 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " | |
2372 "max stream ID"; | |
2373 | |
2374 // clang-format off | |
2375 const unsigned char kV3FrameData[] = { | |
2376 0x80, 0x03, 0x00, 0x01, | |
2377 0x01, 0x00, 0x00, 0x27, | |
2378 0x7f, 0xff, 0xff, 0xff, | |
2379 0x7f, 0xff, 0xff, 0xff, | |
2380 0x20, 0x00, 0x00, 0x00, | |
2381 0x00, 0x02, 0x00, 0x00, | |
2382 0x00, 0x03, 'b', 'a', | |
2383 'r', 0x00, 0x00, 0x00, | |
2384 0x03, 'f', 'o', 'o', | |
2385 0x00, 0x00, 0x00, 0x03, | |
2386 'f', 'o', 'o', 0x00, | |
2387 0x00, 0x00, 0x00 | |
2388 }; | |
2389 // clang-format on | |
2390 SpdySynStreamIR syn_stream(0x7fffffff); | |
2391 syn_stream.set_associated_to_stream_id(0x7fffffff); | |
2392 syn_stream.set_priority(1); | |
2393 syn_stream.set_fin(true); | |
2394 syn_stream.SetHeader("bar", "foo"); | |
2395 syn_stream.SetHeader("foo", ""); | |
2396 SpdySerializedFrame frame(framer.SerializeSynStream(syn_stream)); | |
2397 if (IsSpdy3()) { | |
2398 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2399 } else { | |
2400 LOG(FATAL) << "Unsupported version in test."; | |
2401 } | |
2402 } | |
2403 } | |
2404 | |
2405 // TODO(phajdan.jr): Clean up after we no longer need | |
2406 // to workaround http://crbug.com/139744. | |
2407 #if !defined(USE_SYSTEM_ZLIB) | |
2408 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { | |
2409 if (!IsSpdy3()) { | |
2410 return; | |
2411 } | |
2412 | |
2413 SpdyFramer framer(spdy_version_); | |
2414 framer.set_enable_compression(true); | |
2415 | |
2416 { | |
2417 const char kDescription[] = "SYN_STREAM frame, low pri, no FIN"; | |
2418 | |
2419 // clang-format off | |
2420 const unsigned char kV3FrameData[] = { | |
2421 0x80, 0x03, 0x00, 0x01, | |
2422 0x00, 0x00, 0x00, 0x36, | |
2423 0x00, 0x00, 0x00, 0x01, | |
2424 0x00, 0x00, 0x00, 0x00, | |
2425 0x80, 0x00, 0x38, 0xEA, | |
2426 0xE3, 0xC6, 0xA7, 0xC2, | |
2427 0x02, 0xE5, 0x0E, 0x50, | |
2428 0xC2, 0x4B, 0x4A, 0x04, | |
2429 0xE5, 0x0B, 0x66, 0x80, | |
2430 0x00, 0x4A, 0xCB, 0xCF, | |
2431 0x07, 0x08, 0x20, 0x10, | |
2432 0x95, 0x96, 0x9F, 0x0F, | |
2433 0xA2, 0x00, 0x02, 0x28, | |
2434 0x29, 0xB1, 0x08, 0x20, | |
2435 0x00, 0x00, 0x00, 0x00, | |
2436 0xFF, 0xFF, | |
2437 }; | |
2438 const unsigned char kV3SIMDFrameData[] = { | |
2439 0x80, 0x03, 0x00, 0x01, | |
2440 0x00, 0x00, 0x00, 0x31, | |
2441 0x00, 0x00, 0x00, 0x01, | |
2442 0x00, 0x00, 0x00, 0x00, | |
2443 0x80, 0x00, 0x38, 0xea, | |
2444 0xe3, 0xc6, 0xa7, 0xc2, | |
2445 0x02, 0xe5, 0x0e, 0x50, | |
2446 0xc2, 0x4b, 0x4a, 0x04, | |
2447 0xe5, 0x0b, 0x66, 0x80, | |
2448 0x00, 0x4a, 0xcb, 0xcf, | |
2449 0x07, 0x08, 0x20, 0x24, | |
2450 0x0a, 0x20, 0x80, 0x92, | |
2451 0x12, 0x8b, 0x00, 0x02, | |
2452 0x00, 0x00, 0x00, 0xff, | |
2453 0xff, | |
2454 }; | |
2455 // clang-format on | |
2456 | |
2457 SpdySynStreamIR syn_stream(1); | |
2458 syn_stream.set_priority(4); | |
2459 syn_stream.SetHeader("bar", "foo"); | |
2460 syn_stream.SetHeader("foo", "bar"); | |
2461 SpdySerializedFrame frame(framer.SerializeSynStream(syn_stream)); | |
2462 const unsigned char* frame_data = | |
2463 reinterpret_cast<const unsigned char*>(frame.data()); | |
2464 if (IsSpdy3()) { | |
2465 if (memcmp(frame_data, kV3SIMDFrameData, | |
2466 std::min(arraysize(kV3SIMDFrameData), frame.size())) != 0) { | |
2467 CompareCharArraysWithHexError(kDescription, frame_data, frame.size(), | |
2468 kV3FrameData, arraysize(kV3FrameData)); | |
2469 } | |
2470 } else { | |
2471 LOG(FATAL) << "Unsupported version in test."; | |
2472 } | |
2473 } | |
2474 } | |
2475 #endif // !defined(USE_SYSTEM_ZLIB) | |
2476 | |
2477 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | |
2478 if (!IsSpdy3()) { | |
2479 return; | |
2480 } | |
2481 | |
2482 SpdyFramer framer(spdy_version_); | |
2483 framer.set_enable_compression(false); | |
2484 | |
2485 { | |
2486 const char kDescription[] = "SYN_REPLY frame, no FIN"; | |
2487 | |
2488 // clang-format off | |
2489 const unsigned char kV3FrameData[] = { | |
2490 0x80, 0x03, 0x00, 0x02, | |
2491 0x00, 0x00, 0x00, 0x24, | |
2492 0x00, 0x00, 0x00, 0x01, | |
2493 0x00, 0x00, 0x00, 0x02, | |
2494 0x00, 0x00, 0x00, 0x03, | |
2495 'b', 'a', 'r', 0x00, | |
2496 0x00, 0x00, 0x03, 'f', | |
2497 'o', 'o', 0x00, 0x00, | |
2498 0x00, 0x03, 'f', 'o', | |
2499 'o', 0x00, 0x00, 0x00, | |
2500 0x03, 'b', 'a', 'r' | |
2501 }; | |
2502 // clang-format on | |
2503 SpdySynReplyIR syn_reply(1); | |
2504 syn_reply.SetHeader("bar", "foo"); | |
2505 syn_reply.SetHeader("foo", "bar"); | |
2506 SpdySerializedFrame frame(framer.SerializeSynReply(syn_reply)); | |
2507 if (IsSpdy3()) { | |
2508 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2509 } else { | |
2510 LOG(FATAL) << "Unsupported version in test."; | |
2511 } | |
2512 } | |
2513 | |
2514 { | |
2515 const char kDescription[] = | |
2516 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; | |
2517 | |
2518 // clang-format off | |
2519 const unsigned char kV3FrameData[] = { | |
2520 0x80, 0x03, 0x00, 0x02, | |
2521 0x01, 0x00, 0x00, 0x21, | |
2522 0x7f, 0xff, 0xff, 0xff, | |
2523 0x00, 0x00, 0x00, 0x02, | |
2524 0x00, 0x00, 0x00, 0x00, | |
2525 0x00, 0x00, 0x00, 0x03, | |
2526 'f', 'o', 'o', 0x00, | |
2527 0x00, 0x00, 0x03, 'f', | |
2528 'o', 'o', 0x00, 0x00, | |
2529 0x00, 0x03, 'b', 'a', | |
2530 'r' | |
2531 }; | |
2532 // clang-format on | |
2533 SpdySynReplyIR syn_reply(0x7fffffff); | |
2534 syn_reply.set_fin(true); | |
2535 syn_reply.SetHeader("", "foo"); | |
2536 syn_reply.SetHeader("foo", "bar"); | |
2537 SpdySerializedFrame frame(framer.SerializeSynReply(syn_reply)); | |
2538 if (IsSpdy3()) { | |
2539 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2540 } else { | |
2541 LOG(FATAL) << "Unsupported version in test."; | |
2542 } | |
2543 } | |
2544 | |
2545 { | |
2546 const char kDescription[] = | |
2547 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; | |
2548 | |
2549 // clang-format off | |
2550 const unsigned char kV3FrameData[] = { | |
2551 0x80, 0x03, 0x00, 0x02, | |
2552 0x01, 0x00, 0x00, 0x21, | |
2553 0x7f, 0xff, 0xff, 0xff, | |
2554 0x00, 0x00, 0x00, 0x02, | |
2555 0x00, 0x00, 0x00, 0x03, | |
2556 'b', 'a', 'r', 0x00, | |
2557 0x00, 0x00, 0x03, 'f', | |
2558 'o', 'o', 0x00, 0x00, | |
2559 0x00, 0x03, 'f', 'o', | |
2560 'o', 0x00, 0x00, 0x00, | |
2561 0x00 | |
2562 }; | |
2563 // clang-format on | |
2564 SpdySynReplyIR syn_reply(0x7fffffff); | |
2565 syn_reply.set_fin(true); | |
2566 syn_reply.SetHeader("bar", "foo"); | |
2567 syn_reply.SetHeader("foo", ""); | |
2568 SpdySerializedFrame frame(framer.SerializeSynReply(syn_reply)); | |
2569 if (IsSpdy3()) { | |
2570 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2571 } else { | |
2572 LOG(FATAL) << "Unsupported version in test."; | |
2573 } | |
2574 } | |
2575 } | |
2576 | |
2577 // TODO(phajdan.jr): Clean up after we no longer need | |
2578 // to workaround http://crbug.com/139744. | |
2579 #if !defined(USE_SYSTEM_ZLIB) | |
2580 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { | |
2581 if (!IsSpdy3()) { | |
2582 return; | |
2583 } | |
2584 | |
2585 SpdyFramer framer(spdy_version_); | |
2586 framer.set_enable_compression(true); | |
2587 | |
2588 { | |
2589 const char kDescription[] = "SYN_REPLY frame, no FIN"; | |
2590 | |
2591 // clang-format off | |
2592 const unsigned char kV3FrameData[] = { | |
2593 0x80, 0x03, 0x00, 0x02, | |
2594 0x00, 0x00, 0x00, 0x30, | |
2595 0x00, 0x00, 0x00, 0x01, | |
2596 0x38, 0xea, 0xe3, 0xc6, | |
2597 0xa7, 0xc2, 0x02, 0xe5, | |
2598 0x0e, 0x50, 0xc2, 0x4b, | |
2599 0x4a, 0x04, 0xe5, 0x0b, | |
2600 0x66, 0x80, 0x00, 0x4a, | |
2601 0xcb, 0xcf, 0x07, 0x08, | |
2602 0x20, 0x10, 0x95, 0x96, | |
2603 0x9f, 0x0f, 0xa2, 0x00, | |
2604 0x02, 0x28, 0x29, 0xb1, | |
2605 0x08, 0x20, 0x00, 0x00, | |
2606 0x00, 0x00, 0xff, 0xff, | |
2607 }; | |
2608 | |
2609 const unsigned char kV3SIMDFrameData[] = { | |
2610 0x80, 0x03, 0x00, 0x02, | |
2611 0x00, 0x00, 0x00, 0x2b, | |
2612 0x00, 0x00, 0x00, 0x01, | |
2613 0x38, 0xea, 0xe3, 0xc6, | |
2614 0xa7, 0xc2, 0x02, 0xe5, | |
2615 0x0e, 0x50, 0xc2, 0x4b, | |
2616 0x4a, 0x04, 0xe5, 0x0b, | |
2617 0x66, 0x80, 0x00, 0x4a, | |
2618 0xcb, 0xcf, 0x07, 0x08, | |
2619 0x20, 0x24, 0x0a, 0x20, | |
2620 0x80, 0x92, 0x12, 0x8b, | |
2621 0x00, 0x02, 0x00, 0x00, | |
2622 0x00, 0xff, 0xff, | |
2623 }; | |
2624 // clang-format on | |
2625 | |
2626 SpdySynReplyIR syn_reply(1); | |
2627 syn_reply.SetHeader("bar", "foo"); | |
2628 syn_reply.SetHeader("foo", "bar"); | |
2629 SpdySerializedFrame frame(framer.SerializeSynReply(syn_reply)); | |
2630 const unsigned char* frame_data = | |
2631 reinterpret_cast<const unsigned char*>(frame.data()); | |
2632 if (IsSpdy3()) { | |
2633 if (memcmp(frame_data, kV3SIMDFrameData, | |
2634 std::min(arraysize(kV3SIMDFrameData), frame.size())) != 0) { | |
2635 CompareCharArraysWithHexError(kDescription, frame_data, frame.size(), | |
2636 kV3FrameData, arraysize(kV3FrameData)); | |
2637 } | |
2638 } else { | |
2639 LOG(FATAL) << "Unsupported version in test."; | |
2640 } | |
2641 } | |
2642 } | |
2643 #endif // !defined(USE_SYSTEM_ZLIB) | |
2644 | |
2645 TEST_P(SpdyFramerTest, CreateRstStream) { | 1696 TEST_P(SpdyFramerTest, CreateRstStream) { |
2646 SpdyFramer framer(spdy_version_); | 1697 SpdyFramer framer(spdy_version_); |
2647 | 1698 |
2648 { | 1699 { |
2649 const char kDescription[] = "RST_STREAM frame"; | 1700 const char kDescription[] = "RST_STREAM frame"; |
2650 // clang-format off | |
2651 const unsigned char kV3FrameData[] = { | |
2652 0x80, 0x03, 0x00, 0x03, | |
2653 0x00, 0x00, 0x00, 0x08, | |
2654 0x00, 0x00, 0x00, 0x01, | |
2655 0x00, 0x00, 0x00, 0x01, | |
2656 }; | |
2657 // clang-format on | |
2658 const unsigned char kH2FrameData[] = { | 1701 const unsigned char kH2FrameData[] = { |
2659 0x00, 0x00, 0x04, // Length: 4 | 1702 0x00, 0x00, 0x04, // Length: 4 |
2660 0x03, // Type: RST_STREAM | 1703 0x03, // Type: RST_STREAM |
2661 0x00, // Flags: none | 1704 0x00, // Flags: none |
2662 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1705 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2663 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR | 1706 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR |
2664 }; | 1707 }; |
2665 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR); | 1708 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR); |
2666 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1709 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
2667 if (IsSpdy3()) { | 1710 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2668 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2669 } else { | |
2670 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2671 } | |
2672 } | 1711 } |
2673 | 1712 |
2674 { | 1713 { |
2675 const char kDescription[] = "RST_STREAM frame with max stream ID"; | 1714 const char kDescription[] = "RST_STREAM frame with max stream ID"; |
2676 // clang-format off | |
2677 const unsigned char kV3FrameData[] = { | |
2678 0x80, 0x03, 0x00, 0x03, | |
2679 0x00, 0x00, 0x00, 0x08, | |
2680 0x7f, 0xff, 0xff, 0xff, | |
2681 0x00, 0x00, 0x00, 0x01, | |
2682 }; | |
2683 // clang-format on | |
2684 const unsigned char kH2FrameData[] = { | 1715 const unsigned char kH2FrameData[] = { |
2685 0x00, 0x00, 0x04, // Length: 4 | 1716 0x00, 0x00, 0x04, // Length: 4 |
2686 0x03, // Type: RST_STREAM | 1717 0x03, // Type: RST_STREAM |
2687 0x00, // Flags: none | 1718 0x00, // Flags: none |
2688 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1719 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
2689 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR | 1720 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR |
2690 }; | 1721 }; |
2691 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_PROTOCOL_ERROR); | 1722 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_PROTOCOL_ERROR); |
2692 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1723 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
2693 if (IsSpdy3()) { | 1724 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2694 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2695 } else { | |
2696 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2697 } | |
2698 } | 1725 } |
2699 | 1726 |
2700 { | 1727 { |
2701 const char kDescription[] = "RST_STREAM frame with max status code"; | 1728 const char kDescription[] = "RST_STREAM frame with max status code"; |
2702 // clang-format off | |
2703 const unsigned char kV3FrameData[] = { | |
2704 0x80, 0x03, 0x00, 0x03, | |
2705 0x00, 0x00, 0x00, 0x08, | |
2706 0x7f, 0xff, 0xff, 0xff, | |
2707 0x00, 0x00, 0x00, 0x06, | |
2708 }; | |
2709 // clang-format on | |
2710 const unsigned char kH2FrameData[] = { | 1729 const unsigned char kH2FrameData[] = { |
2711 0x00, 0x00, 0x04, // Length: 4 | 1730 0x00, 0x00, 0x04, // Length: 4 |
2712 0x03, // Type: RST_STREAM | 1731 0x03, // Type: RST_STREAM |
2713 0x00, // Flags: none | 1732 0x00, // Flags: none |
2714 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1733 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
2715 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1734 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
2716 }; | 1735 }; |
2717 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); | 1736 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); |
2718 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1737 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
2719 if (IsSpdy3()) { | 1738 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2720 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2721 } else { | |
2722 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2723 } | |
2724 } | 1739 } |
2725 } | 1740 } |
2726 | 1741 |
2727 TEST_P(SpdyFramerTest, CreateSettings) { | 1742 TEST_P(SpdyFramerTest, CreateSettings) { |
2728 SpdyFramer framer(spdy_version_); | 1743 SpdyFramer framer(spdy_version_); |
2729 | 1744 |
2730 { | 1745 { |
2731 const char kDescription[] = "Network byte order SETTINGS frame"; | 1746 const char kDescription[] = "Network byte order SETTINGS frame"; |
2732 | 1747 |
2733 // clang-format off | |
2734 const unsigned char kV3FrameData[] = { | |
2735 0x80, 0x03, 0x00, 0x04, | |
2736 0x00, 0x00, 0x00, 0x0c, | |
2737 0x00, 0x00, 0x00, 0x01, | |
2738 0x01, 0x00, 0x00, 0x07, | |
2739 0x0a, 0x0b, 0x0c, 0x0d, | |
2740 }; | |
2741 // clang-format on | |
2742 const unsigned char kH2FrameData[] = { | 1748 const unsigned char kH2FrameData[] = { |
2743 0x00, 0x00, 0x06, // Length: 6 | 1749 0x00, 0x00, 0x06, // Length: 6 |
2744 0x04, // Type: SETTINGS | 1750 0x04, // Type: SETTINGS |
2745 0x00, // Flags: none | 1751 0x00, // Flags: none |
2746 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1752 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2747 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1753 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
2748 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 | 1754 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 |
2749 }; | 1755 }; |
2750 | 1756 |
2751 uint32_t kValue = 0x0a0b0c0d; | 1757 uint32_t kValue = 0x0a0b0c0d; |
2752 SpdySettingsIR settings_ir; | 1758 SpdySettingsIR settings_ir; |
2753 | 1759 |
2754 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); | 1760 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); |
2755 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; | 1761 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; |
2756 settings_ir.AddSetting(kId, kFlags & SETTINGS_FLAG_PLEASE_PERSIST, | 1762 settings_ir.AddSetting(kId, kFlags & SETTINGS_FLAG_PLEASE_PERSIST, |
2757 kFlags & SETTINGS_FLAG_PERSISTED, kValue); | 1763 kFlags & SETTINGS_FLAG_PERSISTED, kValue); |
2758 | 1764 |
2759 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1765 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
2760 if (IsSpdy3()) { | 1766 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2761 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2762 } else { | |
2763 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2764 } | |
2765 } | 1767 } |
2766 | 1768 |
2767 { | 1769 { |
2768 const char kDescription[] = "Basic SETTINGS frame"; | 1770 const char kDescription[] = "Basic SETTINGS frame"; |
2769 | |
2770 // clang-format off | |
2771 const unsigned char kV3FrameData[] = { | |
2772 0x80, 0x03, 0x00, 0x04, | |
2773 0x00, 0x00, 0x00, 0x24, | |
2774 0x00, 0x00, 0x00, 0x04, | |
2775 0x00, 0x00, 0x00, 0x01, // 1st Setting | |
2776 0x00, 0x00, 0x00, 0x05, | |
2777 0x00, 0x00, 0x00, 0x02, // 2nd Setting | |
2778 0x00, 0x00, 0x00, 0x06, | |
2779 0x00, 0x00, 0x00, 0x03, // 3rd Setting | |
2780 0x00, 0x00, 0x00, 0x07, | |
2781 0x00, 0x00, 0x00, 0x04, // 4th Setting | |
2782 0x00, 0x00, 0x00, 0x08, | |
2783 }; | |
2784 // clang-format on | |
2785 // These end up seemingly out of order because of the way that our internal | 1771 // These end up seemingly out of order because of the way that our internal |
2786 // ordering for settings_ir works. HTTP2 has no requirement on ordering on | 1772 // ordering for settings_ir works. HTTP2 has no requirement on ordering on |
2787 // the wire. | 1773 // the wire. |
2788 const unsigned char kH2FrameData[] = { | 1774 const unsigned char kH2FrameData[] = { |
2789 0x00, 0x00, 0x18, // Length: 24 | 1775 0x00, 0x00, 0x18, // Length: 24 |
2790 0x04, // Type: SETTINGS | 1776 0x04, // Type: SETTINGS |
2791 0x00, // Flags: none | 1777 0x00, // Flags: none |
2792 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1778 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2793 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 1779 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
2794 0x00, 0x00, 0x00, 0x07, // Value: 7 | 1780 0x00, 0x00, 0x00, 0x07, // Value: 7 |
(...skipping 17 matching lines...) Expand all Loading... | |
2812 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), | 1798 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), |
2813 false, // persist | 1799 false, // persist |
2814 false, // persisted | 1800 false, // persisted |
2815 7); | 1801 7); |
2816 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4), | 1802 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4), |
2817 false, // persist | 1803 false, // persist |
2818 false, // persisted | 1804 false, // persisted |
2819 8); | 1805 8); |
2820 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1806 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
2821 | 1807 |
2822 if (IsSpdy3()) { | 1808 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2823 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2824 } else { | |
2825 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2826 } | |
2827 } | 1809 } |
2828 | 1810 |
2829 { | 1811 { |
2830 const char kDescription[] = "Empty SETTINGS frame"; | 1812 const char kDescription[] = "Empty SETTINGS frame"; |
2831 | 1813 |
2832 // clang-format off | |
2833 const unsigned char kV3FrameData[] = { | |
2834 0x80, 0x03, 0x00, 0x04, | |
2835 0x00, 0x00, 0x00, 0x04, | |
2836 0x00, 0x00, 0x00, 0x00, | |
2837 }; | |
2838 // clang-format on | |
2839 const unsigned char kH2FrameData[] = { | 1814 const unsigned char kH2FrameData[] = { |
2840 0x00, 0x00, 0x00, // Length: 0 | 1815 0x00, 0x00, 0x00, // Length: 0 |
2841 0x04, // Type: SETTINGS | 1816 0x04, // Type: SETTINGS |
2842 0x00, // Flags: none | 1817 0x00, // Flags: none |
2843 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1818 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2844 }; | 1819 }; |
2845 SpdySettingsIR settings_ir; | 1820 SpdySettingsIR settings_ir; |
2846 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1821 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
2847 if (IsSpdy3()) { | 1822 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2848 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2849 } else { | |
2850 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2851 } | |
2852 } | 1823 } |
2853 } | 1824 } |
2854 | 1825 |
2855 TEST_P(SpdyFramerTest, CreatePingFrame) { | 1826 TEST_P(SpdyFramerTest, CreatePingFrame) { |
2856 SpdyFramer framer(spdy_version_); | 1827 SpdyFramer framer(spdy_version_); |
2857 | 1828 |
2858 { | 1829 { |
2859 const char kDescription[] = "PING frame"; | 1830 const char kDescription[] = "PING frame"; |
2860 // clang-format off | |
2861 const unsigned char kV3FrameData[] = { | |
2862 0x80, 0x03, 0x00, 0x06, | |
2863 0x00, 0x00, 0x00, 0x04, | |
2864 0x12, 0x34, 0x56, 0x78, | |
2865 }; | |
2866 // clang-format on | |
2867 const unsigned char kH2FrameData[] = { | 1831 const unsigned char kH2FrameData[] = { |
2868 0x00, 0x00, 0x08, // Length: 8 | 1832 0x00, 0x00, 0x08, // Length: 8 |
2869 0x06, // Type: PING | 1833 0x06, // Type: PING |
2870 0x00, // Flags: none | 1834 0x00, // Flags: none |
2871 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1835 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2872 0x12, 0x34, 0x56, 0x78, // Opaque | 1836 0x12, 0x34, 0x56, 0x78, // Opaque |
2873 0x9a, 0xbc, 0xde, 0xff, // Data | 1837 0x9a, 0xbc, 0xde, 0xff, // Data |
2874 }; | 1838 }; |
2875 const unsigned char kH2FrameDataWithAck[] = { | 1839 const unsigned char kH2FrameDataWithAck[] = { |
2876 0x00, 0x00, 0x08, // Length: 8 | 1840 0x00, 0x00, 0x08, // Length: 8 |
2877 0x06, // Type: PING | 1841 0x06, // Type: PING |
2878 0x01, // Flags: ACK | 1842 0x01, // Flags: ACK |
2879 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1843 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2880 0x12, 0x34, 0x56, 0x78, // Opaque | 1844 0x12, 0x34, 0x56, 0x78, // Opaque |
2881 0x9a, 0xbc, 0xde, 0xff, // Data | 1845 0x9a, 0xbc, 0xde, 0xff, // Data |
2882 }; | 1846 }; |
2883 SpdySerializedFrame frame; | 1847 SpdySerializedFrame frame; |
2884 if (IsSpdy3()) { | 1848 const SpdyPingId kPingId = 0x123456789abcdeffULL; |
2885 frame = framer.SerializePing(SpdyPingIR(0x12345678ull)); | 1849 SpdyPingIR ping_ir(kPingId); |
2886 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | 1850 // Tests SpdyPingIR when the ping is not an ack. |
2887 } else { | 1851 ASSERT_FALSE(ping_ir.is_ack()); |
2888 const SpdyPingId kPingId = 0x123456789abcdeffULL; | 1852 frame = framer.SerializePing(ping_ir); |
2889 SpdyPingIR ping_ir(kPingId); | 1853 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2890 // Tests SpdyPingIR when the ping is not an ack. | |
2891 ASSERT_FALSE(ping_ir.is_ack()); | |
2892 frame = framer.SerializePing(ping_ir); | |
2893 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2894 | 1854 |
2895 // Tests SpdyPingIR when the ping is an ack. | 1855 // Tests SpdyPingIR when the ping is an ack. |
2896 ping_ir.set_is_ack(true); | 1856 ping_ir.set_is_ack(true); |
2897 frame = framer.SerializePing(ping_ir); | 1857 frame = framer.SerializePing(ping_ir); |
2898 CompareFrame(kDescription, frame, kH2FrameDataWithAck, | 1858 CompareFrame(kDescription, frame, kH2FrameDataWithAck, |
2899 arraysize(kH2FrameDataWithAck)); | 1859 arraysize(kH2FrameDataWithAck)); |
2900 } | |
2901 } | 1860 } |
2902 } | 1861 } |
2903 | 1862 |
2904 TEST_P(SpdyFramerTest, CreateGoAway) { | 1863 TEST_P(SpdyFramerTest, CreateGoAway) { |
2905 SpdyFramer framer(spdy_version_); | 1864 SpdyFramer framer(spdy_version_); |
2906 | 1865 |
2907 { | 1866 { |
2908 const char kDescription[] = "GOAWAY frame"; | 1867 const char kDescription[] = "GOAWAY frame"; |
2909 // clang-format off | |
2910 const unsigned char kV3FrameData[] = { | |
2911 0x80, 0x03, 0x00, 0x07, | |
2912 0x00, 0x00, 0x00, 0x08, | |
2913 0x00, 0x00, 0x00, 0x00, // Stream Id | |
2914 0x00, 0x00, 0x00, 0x00, // Status | |
2915 }; | |
2916 // clang-format on | |
2917 const unsigned char kH2FrameData[] = { | 1868 const unsigned char kH2FrameData[] = { |
2918 0x00, 0x00, 0x0a, // Length: 10 | 1869 0x00, 0x00, 0x0a, // Length: 10 |
2919 0x07, // Type: GOAWAY | 1870 0x07, // Type: GOAWAY |
2920 0x00, // Flags: none | 1871 0x00, // Flags: none |
2921 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1872 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2922 0x00, 0x00, 0x00, 0x00, // Last: 0 | 1873 0x00, 0x00, 0x00, 0x00, // Last: 0 |
2923 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 1874 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
2924 0x47, 0x41, // Description | 1875 0x47, 0x41, // Description |
2925 }; | 1876 }; |
2926 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); | 1877 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); |
2927 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 1878 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
2928 if (IsSpdy3()) { | 1879 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2929 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2930 } else { | |
2931 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2932 } | |
2933 } | 1880 } |
2934 | 1881 |
2935 { | 1882 { |
2936 const char kDescription[] = "GOAWAY frame with max stream ID, status"; | 1883 const char kDescription[] = "GOAWAY frame with max stream ID, status"; |
2937 // clang-format off | |
2938 const unsigned char kV3FrameData[] = { | |
2939 0x80, 0x03, 0x00, 0x07, | |
2940 0x00, 0x00, 0x00, 0x08, | |
2941 0x7f, 0xff, 0xff, 0xff, // Stream Id | |
2942 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR. | |
2943 }; | |
2944 // clang-format on | |
2945 const unsigned char kH2FrameData[] = { | 1884 const unsigned char kH2FrameData[] = { |
2946 0x00, 0x00, 0x0a, // Length: 10 | 1885 0x00, 0x00, 0x0a, // Length: 10 |
2947 0x07, // Type: GOAWAY | 1886 0x07, // Type: GOAWAY |
2948 0x00, // Flags: none | 1887 0x00, // Flags: none |
2949 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1888 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
2950 0x7f, 0xff, 0xff, 0xff, // Last: 0x7fffffff | 1889 0x7f, 0xff, 0xff, 0xff, // Last: 0x7fffffff |
2951 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR | 1890 0x00, 0x00, 0x00, 0x02, // Error: INTERNAL_ERROR |
2952 0x47, 0x41, // Description | 1891 0x47, 0x41, // Description |
2953 }; | 1892 }; |
2954 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); | 1893 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); |
2955 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); | 1894 SpdySerializedFrame frame(framer.SerializeGoAway(goaway_ir)); |
2956 if (IsSpdy3()) { | 1895 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
2957 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
2958 } else { | |
2959 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
2960 } | |
2961 } | 1896 } |
2962 } | 1897 } |
2963 | 1898 |
2964 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { | 1899 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { |
2965 SpdyFramer framer(spdy_version_); | 1900 SpdyFramer framer(spdy_version_); |
2966 framer.set_enable_compression(false); | 1901 framer.set_enable_compression(false); |
2967 | 1902 |
2968 { | 1903 { |
2969 const char kDescription[] = "HEADERS frame, no FIN"; | 1904 const char kDescription[] = "HEADERS frame, no FIN"; |
2970 | |
2971 // clang-format off | |
2972 const unsigned char kV3FrameData[] = { | |
2973 0x80, 0x03, 0x00, 0x08, | |
2974 0x00, 0x00, 0x00, 0x24, | |
2975 0x00, 0x00, 0x00, 0x01, | |
2976 0x00, 0x00, 0x00, 0x02, | |
2977 0x00, 0x00, 0x00, 0x03, | |
2978 'b', 'a', 'r', 0x00, | |
2979 0x00, 0x00, 0x03, 'f', | |
2980 'o', 'o', 0x00, 0x00, | |
2981 0x00, 0x03, 'f', 'o', | |
2982 'o', 0x00, 0x00, 0x00, | |
2983 0x03, 'b', 'a', 'r' | |
2984 }; | |
2985 // clang-format on | |
2986 // frame-format off | 1905 // frame-format off |
2987 const unsigned char kH2FrameData[] = { | 1906 const unsigned char kH2FrameData[] = { |
2988 0x00, 0x00, 0x12, // Length: 18 | 1907 0x00, 0x00, 0x12, // Length: 18 |
2989 0x01, // Type: HEADERS | 1908 0x01, // Type: HEADERS |
2990 0x04, // Flags: END_HEADERS | 1909 0x04, // Flags: END_HEADERS |
2991 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1910 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
2992 | 1911 |
2993 0x00, // Unindexed Entry | 1912 0x00, // Unindexed Entry |
2994 0x03, // Name Len: 3 | 1913 0x03, // Name Len: 3 |
2995 0x62, 0x61, 0x72, // bar | 1914 0x62, 0x61, 0x72, // bar |
2996 0x03, // Value Len: 3 | 1915 0x03, // Value Len: 3 |
2997 0x66, 0x6f, 0x6f, // foo | 1916 0x66, 0x6f, 0x6f, // foo |
2998 | 1917 |
2999 0x00, // Unindexed Entry | 1918 0x00, // Unindexed Entry |
3000 0x03, // Name Len: 3 | 1919 0x03, // Name Len: 3 |
3001 0x66, 0x6f, 0x6f, // foo | 1920 0x66, 0x6f, 0x6f, // foo |
3002 0x03, // Value Len: 3 | 1921 0x03, // Value Len: 3 |
3003 0x62, 0x61, 0x72, // bar | 1922 0x62, 0x61, 0x72, // bar |
3004 }; | 1923 }; |
3005 // frame-format on | 1924 // frame-format on |
3006 | 1925 |
3007 SpdyHeadersIR headers(1); | 1926 SpdyHeadersIR headers(1); |
3008 headers.SetHeader("bar", "foo"); | 1927 headers.SetHeader("bar", "foo"); |
3009 headers.SetHeader("foo", "bar"); | 1928 headers.SetHeader("foo", "bar"); |
3010 SpdySerializedFrame frame( | 1929 SpdySerializedFrame frame( |
3011 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1930 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
3012 if (IsSpdy3()) { | 1931 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3013 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
3014 } else { | |
3015 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3016 } | |
3017 } | 1932 } |
3018 | 1933 |
3019 { | 1934 { |
3020 const char kDescription[] = | 1935 const char kDescription[] = |
3021 "HEADERS frame with a 0-length header name, FIN, max stream ID"; | 1936 "HEADERS frame with a 0-length header name, FIN, max stream ID"; |
3022 | |
3023 // clang-format off | |
3024 const unsigned char kV3FrameData[] = { | |
3025 0x80, 0x03, 0x00, 0x08, | |
3026 0x01, 0x00, 0x00, 0x21, | |
3027 0x7f, 0xff, 0xff, 0xff, | |
3028 0x00, 0x00, 0x00, 0x02, | |
3029 0x00, 0x00, 0x00, 0x00, | |
3030 0x00, 0x00, 0x00, 0x03, | |
3031 'f', 'o', 'o', 0x00, | |
3032 0x00, 0x00, 0x03, 'f', | |
3033 'o', 'o', 0x00, 0x00, | |
3034 0x00, 0x03, 'b', 'a', | |
3035 'r' | |
3036 }; | |
3037 // clang-format on | |
3038 // frame-format off | 1937 // frame-format off |
3039 const unsigned char kH2FrameData[] = { | 1938 const unsigned char kH2FrameData[] = { |
3040 0x00, 0x00, 0x0f, // Length: 15 | 1939 0x00, 0x00, 0x0f, // Length: 15 |
3041 0x01, // Type: HEADERS | 1940 0x01, // Type: HEADERS |
3042 0x05, // Flags: END_STREAM|END_HEADERS | 1941 0x05, // Flags: END_STREAM|END_HEADERS |
3043 0x7f, 0xff, 0xff, 0xff, // Stream: 2147483647 | 1942 0x7f, 0xff, 0xff, 0xff, // Stream: 2147483647 |
3044 | 1943 |
3045 0x00, // Unindexed Entry | 1944 0x00, // Unindexed Entry |
3046 0x00, // Name Len: 0 | 1945 0x00, // Name Len: 0 |
3047 0x03, // Value Len: 3 | 1946 0x03, // Value Len: 3 |
3048 0x66, 0x6f, 0x6f, // foo | 1947 0x66, 0x6f, 0x6f, // foo |
3049 | 1948 |
3050 0x00, // Unindexed Entry | 1949 0x00, // Unindexed Entry |
3051 0x03, // Name Len: 3 | 1950 0x03, // Name Len: 3 |
3052 0x66, 0x6f, 0x6f, // foo | 1951 0x66, 0x6f, 0x6f, // foo |
3053 0x03, // Value Len: 3 | 1952 0x03, // Value Len: 3 |
3054 0x62, 0x61, 0x72, // bar | 1953 0x62, 0x61, 0x72, // bar |
3055 }; | 1954 }; |
3056 // frame-format on | 1955 // frame-format on |
3057 SpdyHeadersIR headers(0x7fffffff); | 1956 SpdyHeadersIR headers(0x7fffffff); |
3058 headers.set_fin(true); | 1957 headers.set_fin(true); |
3059 headers.SetHeader("", "foo"); | 1958 headers.SetHeader("", "foo"); |
3060 headers.SetHeader("foo", "bar"); | 1959 headers.SetHeader("foo", "bar"); |
3061 SpdySerializedFrame frame( | 1960 SpdySerializedFrame frame( |
3062 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 1961 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
3063 if (IsSpdy3()) { | 1962 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3064 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
3065 } else { | |
3066 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3067 } | |
3068 } | 1963 } |
3069 | 1964 |
3070 { | 1965 { |
3071 const char kDescription[] = | 1966 const char kDescription[] = |
3072 "HEADERS frame with a 0-length header val, FIN, max stream ID"; | 1967 "HEADERS frame with a 0-length header val, FIN, max stream ID"; |
3073 | |
3074 // clang-format off | |
3075 const unsigned char kV3FrameData[] = { | |
3076 0x80, 0x03, 0x00, 0x08, | |
3077 0x01, 0x00, 0x00, 0x21, | |
3078 0x7f, 0xff, 0xff, 0xff, | |
3079 0x00, 0x00, 0x00, 0x02, | |
3080 0x00, 0x00, 0x00, 0x03, | |
3081 'b', 'a', 'r', 0x00, | |
3082 0x00, 0x00, 0x03, 'f', | |
3083 'o', 'o', 0x00, 0x00, | |
3084 0x00, 0x03, 'f', 'o', | |
3085 'o', 0x00, 0x00, 0x00, | |
3086 0x00 | |
3087 }; | |
3088 // clang-format on | |
3089 // frame-format off | 1968 // frame-format off |
3090 const unsigned char kH2FrameData[] = { | 1969 const unsigned char kH2FrameData[] = { |
3091 0x00, 0x00, 0x0f, // Length: 15 | 1970 0x00, 0x00, 0x0f, // Length: 15 |
3092 0x01, // Type: HEADERS | 1971 0x01, // Type: HEADERS |
3093 0x05, // Flags: END_STREAM|END_HEADERS | 1972 0x05, // Flags: END_STREAM|END_HEADERS |
3094 0x7f, 0xff, 0xff, 0xff, // Stream: 2147483647 | 1973 0x7f, 0xff, 0xff, 0xff, // Stream: 2147483647 |
3095 | 1974 |
3096 0x00, // Unindexed Entry | 1975 0x00, // Unindexed Entry |
3097 0x03, // Name Len: 3 | 1976 0x03, // Name Len: 3 |
3098 0x62, 0x61, 0x72, // bar | 1977 0x62, 0x61, 0x72, // bar |
3099 0x03, // Value Len: 3 | 1978 0x03, // Value Len: 3 |
3100 0x66, 0x6f, 0x6f, // foo | 1979 0x66, 0x6f, 0x6f, // foo |
3101 | 1980 |
3102 0x00, // Unindexed Entry | 1981 0x00, // Unindexed Entry |
3103 0x03, // Name Len: 3 | 1982 0x03, // Name Len: 3 |
3104 0x66, 0x6f, 0x6f, // foo | 1983 0x66, 0x6f, 0x6f, // foo |
3105 0x00, // Value Len: 0 | 1984 0x00, // Value Len: 0 |
3106 }; | 1985 }; |
3107 // frame-format on | 1986 // frame-format on |
3108 SpdyHeadersIR headers_ir(0x7fffffff); | 1987 SpdyHeadersIR headers_ir(0x7fffffff); |
3109 headers_ir.set_fin(true); | 1988 headers_ir.set_fin(true); |
3110 headers_ir.SetHeader("bar", "foo"); | 1989 headers_ir.SetHeader("bar", "foo"); |
3111 headers_ir.SetHeader("foo", ""); | 1990 headers_ir.SetHeader("foo", ""); |
3112 SpdySerializedFrame frame( | 1991 SpdySerializedFrame frame( |
3113 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 1992 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3114 if (IsSpdy3()) { | 1993 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3115 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
3116 } else { | |
3117 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3118 } | |
3119 } | 1994 } |
3120 | 1995 |
3121 { | 1996 { |
3122 const char kDescription[] = | 1997 const char kDescription[] = |
3123 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; | 1998 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; |
3124 | 1999 |
3125 // frame-format off | 2000 // frame-format off |
3126 const unsigned char kH2FrameData[] = { | 2001 const unsigned char kH2FrameData[] = { |
3127 0x00, 0x00, 0x14, // Length: 20 | 2002 0x00, 0x00, 0x14, // Length: 20 |
3128 0x01, // Type: HEADERS | 2003 0x01, // Type: HEADERS |
(...skipping 15 matching lines...) Expand all Loading... | |
3144 }; | 2019 }; |
3145 // frame-format on | 2020 // frame-format on |
3146 SpdyHeadersIR headers_ir(0x7fffffff); | 2021 SpdyHeadersIR headers_ir(0x7fffffff); |
3147 headers_ir.set_fin(true); | 2022 headers_ir.set_fin(true); |
3148 headers_ir.set_has_priority(true); | 2023 headers_ir.set_has_priority(true); |
3149 headers_ir.set_weight(220); | 2024 headers_ir.set_weight(220); |
3150 headers_ir.SetHeader("bar", "foo"); | 2025 headers_ir.SetHeader("bar", "foo"); |
3151 headers_ir.SetHeader("foo", ""); | 2026 headers_ir.SetHeader("foo", ""); |
3152 SpdySerializedFrame frame( | 2027 SpdySerializedFrame frame( |
3153 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2028 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3154 if (IsSpdy3()) { | 2029 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3155 // HEADERS with priority not supported. | |
3156 } else { | |
3157 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3158 } | |
3159 } | 2030 } |
3160 | 2031 |
3161 { | 2032 { |
3162 const char kDescription[] = | 2033 const char kDescription[] = |
3163 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, " | 2034 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, " |
3164 "exclusive=true, parent_stream=0"; | 2035 "exclusive=true, parent_stream=0"; |
3165 | 2036 |
3166 // frame-format off | 2037 // frame-format off |
3167 const unsigned char kV4FrameData[] = { | 2038 const unsigned char kV4FrameData[] = { |
3168 0x00, 0x00, 0x14, // Length: 20 | 2039 0x00, 0x00, 0x14, // Length: 20 |
(...skipping 18 matching lines...) Expand all Loading... | |
3187 SpdyHeadersIR headers_ir(0x7fffffff); | 2058 SpdyHeadersIR headers_ir(0x7fffffff); |
3188 headers_ir.set_fin(true); | 2059 headers_ir.set_fin(true); |
3189 headers_ir.set_has_priority(true); | 2060 headers_ir.set_has_priority(true); |
3190 headers_ir.set_weight(220); | 2061 headers_ir.set_weight(220); |
3191 headers_ir.set_exclusive(true); | 2062 headers_ir.set_exclusive(true); |
3192 headers_ir.set_parent_stream_id(0); | 2063 headers_ir.set_parent_stream_id(0); |
3193 headers_ir.SetHeader("bar", "foo"); | 2064 headers_ir.SetHeader("bar", "foo"); |
3194 headers_ir.SetHeader("foo", ""); | 2065 headers_ir.SetHeader("foo", ""); |
3195 SpdySerializedFrame frame( | 2066 SpdySerializedFrame frame( |
3196 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2067 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3197 if (IsSpdy3()) { | 2068 CompareFrame(kDescription, frame, kV4FrameData, arraysize(kV4FrameData)); |
3198 // HEADERS with priority not supported. | |
3199 } else { | |
3200 CompareFrame(kDescription, frame, kV4FrameData, arraysize(kV4FrameData)); | |
3201 } | |
3202 } | 2069 } |
3203 | 2070 |
3204 { | 2071 { |
3205 const char kDescription[] = | 2072 const char kDescription[] = |
3206 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, " | 2073 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, " |
3207 "exclusive=false, parent_stream=max stream ID"; | 2074 "exclusive=false, parent_stream=max stream ID"; |
3208 | 2075 |
3209 // frame-format off | 2076 // frame-format off |
3210 const unsigned char kV4FrameData[] = { | 2077 const unsigned char kV4FrameData[] = { |
3211 0x00, 0x00, 0x14, // Length: 20 | 2078 0x00, 0x00, 0x14, // Length: 20 |
(...skipping 18 matching lines...) Expand all Loading... | |
3230 SpdyHeadersIR headers_ir(0x7fffffff); | 2097 SpdyHeadersIR headers_ir(0x7fffffff); |
3231 headers_ir.set_fin(true); | 2098 headers_ir.set_fin(true); |
3232 headers_ir.set_has_priority(true); | 2099 headers_ir.set_has_priority(true); |
3233 headers_ir.set_weight(220); | 2100 headers_ir.set_weight(220); |
3234 headers_ir.set_exclusive(false); | 2101 headers_ir.set_exclusive(false); |
3235 headers_ir.set_parent_stream_id(0x7fffffff); | 2102 headers_ir.set_parent_stream_id(0x7fffffff); |
3236 headers_ir.SetHeader("bar", "foo"); | 2103 headers_ir.SetHeader("bar", "foo"); |
3237 headers_ir.SetHeader("foo", ""); | 2104 headers_ir.SetHeader("foo", ""); |
3238 SpdySerializedFrame frame( | 2105 SpdySerializedFrame frame( |
3239 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2106 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3240 if (IsSpdy3()) { | 2107 CompareFrame(kDescription, frame, kV4FrameData, arraysize(kV4FrameData)); |
3241 // HEADERS with priority not supported. | |
3242 } else { | |
3243 CompareFrame(kDescription, frame, kV4FrameData, arraysize(kV4FrameData)); | |
3244 } | |
3245 } | 2108 } |
3246 | 2109 |
3247 { | 2110 { |
3248 const char kDescription[] = | 2111 const char kDescription[] = |
3249 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded"; | 2112 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded"; |
3250 | 2113 |
3251 // frame-format off | 2114 // frame-format off |
3252 const unsigned char kH2FrameData[] = { | 2115 const unsigned char kH2FrameData[] = { |
3253 0x00, 0x00, 0x15, // Length: 21 | 2116 0x00, 0x00, 0x15, // Length: 21 |
3254 0x01, // Type: HEADERS | 2117 0x01, // Type: HEADERS |
(...skipping 16 matching lines...) Expand all Loading... | |
3271 0x00, // Padding | 2134 0x00, // Padding |
3272 }; | 2135 }; |
3273 // frame-format on | 2136 // frame-format on |
3274 SpdyHeadersIR headers_ir(0x7fffffff); | 2137 SpdyHeadersIR headers_ir(0x7fffffff); |
3275 headers_ir.set_fin(true); | 2138 headers_ir.set_fin(true); |
3276 headers_ir.SetHeader("", "foo"); | 2139 headers_ir.SetHeader("", "foo"); |
3277 headers_ir.SetHeader("foo", "bar"); | 2140 headers_ir.SetHeader("foo", "bar"); |
3278 headers_ir.set_padding_len(6); | 2141 headers_ir.set_padding_len(6); |
3279 SpdySerializedFrame frame( | 2142 SpdySerializedFrame frame( |
3280 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2143 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3281 if (IsSpdy3()) { | 2144 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3282 // Padding is not supported. | |
3283 } else { | |
3284 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3285 } | |
3286 } | 2145 } |
3287 } | 2146 } |
3288 | 2147 |
3289 // TODO(phajdan.jr): Clean up after we no longer need | 2148 // TODO(phajdan.jr): Clean up after we no longer need |
3290 // to workaround http://crbug.com/139744. | 2149 // to workaround http://crbug.com/139744. |
3291 #if !defined(USE_SYSTEM_ZLIB) | 2150 #if !defined(USE_SYSTEM_ZLIB) |
Bence
2016/11/21 17:50:45
Please remove this commend and #if, because zlib w
| |
3292 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { | 2151 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
3293 SpdyFramer framer(spdy_version_); | 2152 SpdyFramer framer(spdy_version_); |
3294 framer.set_enable_compression(true); | 2153 framer.set_enable_compression(true); |
3295 | 2154 |
3296 { | 2155 { |
3297 const char kDescription[] = "HEADERS frame, no FIN"; | |
3298 | |
3299 // clang-format off | |
3300 const unsigned char kV3FrameData[] = { | |
3301 0x80, 0x03, 0x00, 0x08, | |
3302 0x00, 0x00, 0x00, 0x30, | |
3303 0x00, 0x00, 0x00, 0x01, | |
3304 0x38, 0xea, 0xe3, 0xc6, | |
3305 0xa7, 0xc2, 0x02, 0xe5, | |
3306 0x0e, 0x50, 0xc2, 0x4b, | |
3307 0x4a, 0x04, 0xe5, 0x0b, | |
3308 0x66, 0x80, 0x00, 0x4a, | |
3309 0xcb, 0xcf, 0x07, 0x08, | |
3310 0x20, 0x10, 0x95, 0x96, | |
3311 0x9f, 0x0f, 0xa2, 0x00, | |
3312 0x02, 0x28, 0x29, 0xb1, | |
3313 0x08, 0x20, 0x00, 0x00, | |
3314 0x00, 0x00, 0xff, 0xff, | |
3315 }; | |
3316 const unsigned char kV3SIMDFrameData[] = { | |
3317 0x80, 0x03, 0x00, 0x08, | |
3318 0x00, 0x00, 0x00, 0x2b, | |
3319 0x00, 0x00, 0x00, 0x01, | |
3320 0x38, 0xea, 0xe3, 0xc6, | |
3321 0xa7, 0xc2, 0x02, 0xe5, | |
3322 0x0e, 0x50, 0xc2, 0x4b, | |
3323 0x4a, 0x04, 0xe5, 0x0b, | |
3324 0x66, 0x80, 0x00, 0x4a, | |
3325 0xcb, 0xcf, 0x07, 0x08, | |
3326 0x20, 0x24, 0x0a, 0x20, | |
3327 0x80, 0x92, 0x12, 0x8b, | |
3328 0x00, 0x02, 0x00, 0x00, | |
3329 0x00, 0xff, 0xff, | |
3330 }; | |
3331 // clang-format on | |
3332 | |
3333 SpdyHeadersIR headers_ir(1); | 2156 SpdyHeadersIR headers_ir(1); |
3334 headers_ir.SetHeader("bar", "foo"); | 2157 headers_ir.SetHeader("bar", "foo"); |
3335 headers_ir.SetHeader("foo", "bar"); | 2158 headers_ir.SetHeader("foo", "bar"); |
3336 SpdySerializedFrame frame( | 2159 SpdySerializedFrame frame( |
3337 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2160 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3338 const unsigned char* frame_data = | 2161 // Deflate compression doesn't apply to HPACK. |
3339 reinterpret_cast<const unsigned char*>(frame.data()); | |
3340 if (IsSpdy3()) { | |
3341 if (memcmp(frame_data, kV3SIMDFrameData, | |
3342 std::min(arraysize(kV3SIMDFrameData), frame.size())) != 0) { | |
3343 CompareCharArraysWithHexError(kDescription, frame_data, frame.size(), | |
3344 kV3FrameData, arraysize(kV3FrameData)); | |
3345 } | |
3346 } else { | |
3347 // Deflate compression doesn't apply to HPACK. | |
3348 } | |
3349 } | 2162 } |
3350 } | 2163 } |
3351 #endif // !defined(USE_SYSTEM_ZLIB) | 2164 #endif // !defined(USE_SYSTEM_ZLIB) |
3352 | 2165 |
3353 TEST_P(SpdyFramerTest, CreateWindowUpdate) { | 2166 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
3354 SpdyFramer framer(spdy_version_); | 2167 SpdyFramer framer(spdy_version_); |
3355 | 2168 |
3356 { | 2169 { |
3357 const char kDescription[] = "WINDOW_UPDATE frame"; | 2170 const char kDescription[] = "WINDOW_UPDATE frame"; |
3358 // clang-format off | |
3359 const unsigned char kV3FrameData[] = { | |
3360 0x80, 0x03, 0x00, 0x09, | |
3361 0x00, 0x00, 0x00, 0x08, | |
3362 0x00, 0x00, 0x00, 0x01, | |
3363 0x00, 0x00, 0x00, 0x01, | |
3364 }; | |
3365 // clang-format on | |
3366 const unsigned char kH2FrameData[] = { | 2171 const unsigned char kH2FrameData[] = { |
3367 0x00, 0x00, 0x04, // Length: 4 | 2172 0x00, 0x00, 0x04, // Length: 4 |
3368 0x08, // Type: WINDOW_UPDATE | 2173 0x08, // Type: WINDOW_UPDATE |
3369 0x00, // Flags: none | 2174 0x00, // Flags: none |
3370 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2175 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
3371 0x00, 0x00, 0x00, 0x01, // Increment: 1 | 2176 0x00, 0x00, 0x00, 0x01, // Increment: 1 |
3372 }; | 2177 }; |
3373 SpdySerializedFrame frame( | 2178 SpdySerializedFrame frame( |
3374 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); | 2179 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); |
3375 if (IsSpdy3()) { | 2180 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3376 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
3377 } else { | |
3378 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3379 } | |
3380 } | 2181 } |
3381 | 2182 |
3382 { | 2183 { |
3383 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; | 2184 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; |
3384 // clang-format off | |
3385 const unsigned char kV3FrameData[] = { | |
3386 0x80, 0x03, 0x00, 0x09, | |
3387 0x00, 0x00, 0x00, 0x08, | |
3388 0x7f, 0xff, 0xff, 0xff, | |
3389 0x00, 0x00, 0x00, 0x01, | |
3390 }; | |
3391 // clang-format on | |
3392 const unsigned char kH2FrameData[] = { | 2185 const unsigned char kH2FrameData[] = { |
3393 0x00, 0x00, 0x04, // Length: 4 | 2186 0x00, 0x00, 0x04, // Length: 4 |
3394 0x08, // Type: WINDOW_UPDATE | 2187 0x08, // Type: WINDOW_UPDATE |
3395 0x00, // Flags: none | 2188 0x00, // Flags: none |
3396 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 2189 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
3397 0x00, 0x00, 0x00, 0x01, // Increment: 1 | 2190 0x00, 0x00, 0x00, 0x01, // Increment: 1 |
3398 }; | 2191 }; |
3399 SpdySerializedFrame frame( | 2192 SpdySerializedFrame frame( |
3400 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(0x7FFFFFFF, 1))); | 2193 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(0x7FFFFFFF, 1))); |
3401 if (IsSpdy3()) { | 2194 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3402 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
3403 } else { | |
3404 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3405 } | |
3406 } | 2195 } |
3407 | 2196 |
3408 { | 2197 { |
3409 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; | 2198 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; |
3410 // clang-format off | |
3411 const unsigned char kV3FrameData[] = { | |
3412 0x80, 0x03, 0x00, 0x09, | |
3413 0x00, 0x00, 0x00, 0x08, | |
3414 0x00, 0x00, 0x00, 0x01, | |
3415 0x7f, 0xff, 0xff, 0xff, | |
3416 }; | |
3417 // clang-format on | |
3418 const unsigned char kH2FrameData[] = { | 2199 const unsigned char kH2FrameData[] = { |
3419 0x00, 0x00, 0x04, // Length: 4 | 2200 0x00, 0x00, 0x04, // Length: 4 |
3420 0x08, // Type: WINDOW_UPDATE | 2201 0x08, // Type: WINDOW_UPDATE |
3421 0x00, // Flags: none | 2202 0x00, // Flags: none |
3422 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 2203 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
3423 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff | 2204 0x7f, 0xff, 0xff, 0xff, // Increment: 0x7fffffff |
3424 }; | 2205 }; |
3425 SpdySerializedFrame frame( | 2206 SpdySerializedFrame frame( |
3426 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2207 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
3427 if (IsSpdy3()) { | 2208 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
3428 CompareFrame(kDescription, frame, kV3FrameData, arraysize(kV3FrameData)); | |
3429 } else { | |
3430 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | |
3431 } | |
3432 } | 2209 } |
3433 } | 2210 } |
3434 | 2211 |
3435 TEST_P(SpdyFramerTest, SerializeBlocked) { | 2212 TEST_P(SpdyFramerTest, SerializeBlocked) { |
3436 if (!IsHttp2()) { | |
3437 return; | |
3438 } | |
3439 | |
3440 SpdyFramer framer(spdy_version_); | 2213 SpdyFramer framer(spdy_version_); |
3441 | 2214 |
3442 const char kDescription[] = "BLOCKED frame"; | 2215 const char kDescription[] = "BLOCKED frame"; |
3443 const unsigned char kType = static_cast<unsigned char>( | 2216 const unsigned char kType = static_cast<unsigned char>( |
3444 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); | 2217 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); |
3445 const unsigned char kFrameData[] = { | 2218 const unsigned char kFrameData[] = { |
3446 0x00, 0x00, 0x00, // Length: 0 | 2219 0x00, 0x00, 0x00, // Length: 0 |
3447 kType, // Type: BLOCKED | 2220 kType, // Type: BLOCKED |
3448 0x00, // Flags: none | 2221 0x00, // Flags: none |
3449 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2222 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
3450 }; | 2223 }; |
3451 SpdyBlockedIR blocked_ir(0); | 2224 SpdyBlockedIR blocked_ir(0); |
3452 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 2225 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
3453 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2226 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
3454 } | 2227 } |
3455 | 2228 |
3456 TEST_P(SpdyFramerTest, CreateBlocked) { | 2229 TEST_P(SpdyFramerTest, CreateBlocked) { |
3457 if (!IsHttp2()) { | |
3458 return; | |
3459 } | |
3460 | |
3461 SpdyFramer framer(spdy_version_); | 2230 SpdyFramer framer(spdy_version_); |
3462 | 2231 |
3463 const char kDescription[] = "BLOCKED frame"; | 2232 const char kDescription[] = "BLOCKED frame"; |
3464 const SpdyStreamId kStreamId = 3; | 2233 const SpdyStreamId kStreamId = 3; |
3465 | 2234 |
3466 SpdySerializedFrame frame_serialized( | 2235 SpdySerializedFrame frame_serialized( |
3467 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2236 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
3468 SpdyBlockedIR blocked_ir(kStreamId); | 2237 SpdyBlockedIR blocked_ir(kStreamId); |
3469 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); | 2238 SpdySerializedFrame frame_created(framer.SerializeFrame(blocked_ir)); |
3470 | 2239 |
3471 CompareFrames(kDescription, frame_serialized, frame_created); | 2240 CompareFrames(kDescription, frame_serialized, frame_created); |
3472 } | 2241 } |
3473 | 2242 |
3474 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2243 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
3475 if (!IsHttp2()) { | |
3476 return; | |
3477 } | |
3478 | |
3479 { | 2244 { |
3480 // Test framing PUSH_PROMISE without padding. | 2245 // Test framing PUSH_PROMISE without padding. |
3481 SpdyFramer framer(spdy_version_); | 2246 SpdyFramer framer(spdy_version_); |
3482 framer.set_enable_compression(false); | 2247 framer.set_enable_compression(false); |
3483 const char kDescription[] = "PUSH_PROMISE frame without padding"; | 2248 const char kDescription[] = "PUSH_PROMISE frame without padding"; |
3484 | 2249 |
3485 // frame-format off | 2250 // frame-format off |
3486 const unsigned char kFrameData[] = { | 2251 const unsigned char kFrameData[] = { |
3487 0x00, 0x00, 0x16, // Length: 22 | 2252 0x00, 0x00, 0x16, // Length: 22 |
3488 0x05, // Type: PUSH_PROMISE | 2253 0x05, // Type: PUSH_PROMISE |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3601 push_promise.set_padding_len(177); | 2366 push_promise.set_padding_len(177); |
3602 push_promise.SetHeader("bar", "foo"); | 2367 push_promise.SetHeader("bar", "foo"); |
3603 push_promise.SetHeader("foo", "bar"); | 2368 push_promise.SetHeader("foo", "bar"); |
3604 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 2369 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
3605 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2370 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
3606 } | 2371 } |
3607 } | 2372 } |
3608 | 2373 |
3609 // Regression test for https://crbug.com/464748. | 2374 // Regression test for https://crbug.com/464748. |
3610 TEST_P(SpdyFramerTest, GetNumberRequiredContinuationFrames) { | 2375 TEST_P(SpdyFramerTest, GetNumberRequiredContinuationFrames) { |
3611 if (!IsHttp2()) { | |
3612 return; | |
3613 } | |
3614 | |
3615 SpdyFramer framer(spdy_version_); | 2376 SpdyFramer framer(spdy_version_); |
3616 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2377 EXPECT_EQ(1u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
3617 &framer, 16383 + 16374)); | 2378 &framer, 16383 + 16374)); |
3618 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2379 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
3619 &framer, 16383 + 16374 + 1)); | 2380 &framer, 16383 + 16374 + 1)); |
3620 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2381 EXPECT_EQ(2u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
3621 &framer, 16383 + 2 * 16374)); | 2382 &framer, 16383 + 2 * 16374)); |
3622 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( | 2383 EXPECT_EQ(3u, SpdyFramerPeer::GetNumberRequiredContinuationFrames( |
3623 &framer, 16383 + 2 * 16374 + 1)); | 2384 &framer, 16383 + 2 * 16374 + 1)); |
3624 } | 2385 } |
3625 | 2386 |
3626 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { | 2387 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
3627 if (!IsHttp2()) { | |
3628 return; | |
3629 } | |
3630 | |
3631 SpdyFramer framer(spdy_version_); | 2388 SpdyFramer framer(spdy_version_); |
3632 framer.set_enable_compression(false); | 2389 framer.set_enable_compression(false); |
3633 const char kDescription[] = "CONTINUATION frame"; | 2390 const char kDescription[] = "CONTINUATION frame"; |
3634 | 2391 |
3635 // frame-format off | 2392 // frame-format off |
3636 const unsigned char kFrameData[] = { | 2393 const unsigned char kFrameData[] = { |
3637 0x00, 0x00, 0x12, // Length: 18 | 2394 0x00, 0x00, 0x12, // Length: 18 |
3638 0x09, // Type: CONTINUATION | 2395 0x09, // Type: CONTINUATION |
3639 0x04, // Flags: END_HEADERS | 2396 0x04, // Flags: END_HEADERS |
3640 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2397 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
(...skipping 23 matching lines...) Expand all Loading... | |
3664 continuation.take_encoding(std::move(buffer)); | 2421 continuation.take_encoding(std::move(buffer)); |
3665 continuation.set_end_headers(true); | 2422 continuation.set_end_headers(true); |
3666 | 2423 |
3667 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 2424 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
3668 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2425 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
3669 } | 2426 } |
3670 | 2427 |
3671 // Test that if we send an unexpected CONTINUATION | 2428 // Test that if we send an unexpected CONTINUATION |
3672 // we signal an error (but don't crash). | 2429 // we signal an error (but don't crash). |
3673 TEST_P(SpdyFramerTest, SendUnexpectedContinuation) { | 2430 TEST_P(SpdyFramerTest, SendUnexpectedContinuation) { |
3674 if (!IsHttp2()) { | |
3675 return; | |
3676 } | |
3677 | |
3678 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 2431 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
3679 SpdyFramer framer(spdy_version_); | 2432 SpdyFramer framer(spdy_version_); |
3680 framer.set_visitor(&visitor); | 2433 framer.set_visitor(&visitor); |
3681 | 2434 |
3682 // frame-format off | 2435 // frame-format off |
3683 char kH2FrameData[] = { | 2436 char kH2FrameData[] = { |
3684 0x00, 0x00, 0x12, // Length: 18 | 2437 0x00, 0x00, 0x12, // Length: 18 |
3685 0x09, // Type: CONTINUATION | 2438 0x09, // Type: CONTINUATION |
3686 0x04, // Flags: END_HEADERS | 2439 0x04, // Flags: END_HEADERS |
3687 0x00, 0x00, 0x00, 0x2a, // Stream: 42 | 2440 0x00, 0x00, 0x00, 0x2a, // Stream: 42 |
(...skipping 16 matching lines...) Expand all Loading... | |
3704 | 2457 |
3705 // We shouldn't have to read the whole frame before we signal an error. | 2458 // We shouldn't have to read the whole frame before we signal an error. |
3706 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 2459 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
3707 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 2460 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
3708 EXPECT_TRUE(framer.HasError()); | 2461 EXPECT_TRUE(framer.HasError()); |
3709 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) | 2462 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, framer.error_code()) |
3710 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2463 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
3711 } | 2464 } |
3712 | 2465 |
3713 TEST_P(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { | 2466 TEST_P(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) { |
3714 if (!IsHttp2()) { | |
3715 return; | |
3716 } | |
3717 | |
3718 { | 2467 { |
3719 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of | 2468 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of |
3720 // padding, cannot hold all the data payload, which is overflowed to the | 2469 // padding, cannot hold all the data payload, which is overflowed to the |
3721 // consecutive CONTINUATION frame. | 2470 // consecutive CONTINUATION frame. |
3722 SpdyFramer framer(spdy_version_); | 2471 SpdyFramer framer(spdy_version_); |
3723 framer.set_enable_compression(false); | 2472 framer.set_enable_compression(false); |
3724 const char kDescription[] = | 2473 const char kDescription[] = |
3725 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; | 2474 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; |
3726 | 2475 |
3727 // frame-format off | 2476 // frame-format off |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3809 | 2558 |
3810 // Compare the CONTINUATION frame against the template. | 2559 // Compare the CONTINUATION frame against the template. |
3811 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); | 2560 frame_data += TestSpdyVisitor::sent_control_frame_max_size(); |
3812 CompareCharArraysWithHexError( | 2561 CompareCharArraysWithHexError( |
3813 kDescription, frame_data, arraysize(kContinuationFrameData), | 2562 kDescription, frame_data, arraysize(kContinuationFrameData), |
3814 kContinuationFrameData, arraysize(kContinuationFrameData)); | 2563 kContinuationFrameData, arraysize(kContinuationFrameData)); |
3815 } | 2564 } |
3816 } | 2565 } |
3817 | 2566 |
3818 TEST_P(SpdyFramerTest, CreateAltSvc) { | 2567 TEST_P(SpdyFramerTest, CreateAltSvc) { |
3819 if (!IsHttp2()) { | |
3820 return; | |
3821 } | |
3822 | |
3823 SpdyFramer framer(spdy_version_); | 2568 SpdyFramer framer(spdy_version_); |
3824 | 2569 |
3825 const char kDescription[] = "ALTSVC frame"; | 2570 const char kDescription[] = "ALTSVC frame"; |
3826 const char kType = static_cast<unsigned char>( | 2571 const char kType = static_cast<unsigned char>( |
3827 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | 2572 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
3828 const unsigned char kFrameData[] = { | 2573 const unsigned char kFrameData[] = { |
3829 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', | 2574 0x00, 0x00, 0x49, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', |
3830 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', | 2575 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', |
3831 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', | 2576 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', |
3832 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', | 2577 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', |
3833 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', | 2578 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', |
3834 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', | 2579 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', |
3835 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; | 2580 '4', '2', ';', ' ', 'v', '=', '"', '2', '4', '"'}; |
3836 SpdyAltSvcIR altsvc_ir(3); | 2581 SpdyAltSvcIR altsvc_ir(3); |
3837 altsvc_ir.set_origin("origin"); | 2582 altsvc_ir.set_origin("origin"); |
3838 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2583 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
3839 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 2584 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
3840 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2585 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
3841 "p\"=i:d", "h_\\o\"st", 123, 42, | 2586 "p\"=i:d", "h_\\o\"st", 123, 42, |
3842 SpdyAltSvcWireFormat::VersionVector{24})); | 2587 SpdyAltSvcWireFormat::VersionVector{24})); |
3843 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 2588 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
3844 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2589 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
3845 } | 2590 } |
3846 | 2591 |
3847 TEST_P(SpdyFramerTest, CreatePriority) { | 2592 TEST_P(SpdyFramerTest, CreatePriority) { |
3848 if (!IsHttp2()) { | |
3849 return; | |
3850 } | |
3851 | |
3852 SpdyFramer framer(spdy_version_); | 2593 SpdyFramer framer(spdy_version_); |
3853 | 2594 |
3854 const char kDescription[] = "PRIORITY frame"; | 2595 const char kDescription[] = "PRIORITY frame"; |
3855 const unsigned char kFrameData[] = { | 2596 const unsigned char kFrameData[] = { |
3856 0x00, 0x00, 0x05, // Length: 5 | 2597 0x00, 0x00, 0x05, // Length: 5 |
3857 0x02, // Type: PRIORITY | 2598 0x02, // Type: PRIORITY |
3858 0x00, // Flags: none | 2599 0x00, // Flags: none |
3859 0x00, 0x00, 0x00, 0x02, // Stream: 2 | 2600 0x00, 0x00, 0x00, 0x02, // Stream: 2 |
3860 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) | 2601 0x80, 0x00, 0x00, 0x01, // Parent: 1 (Exclusive) |
3861 0x10, // Weight: 17 | 2602 0x10, // Weight: 17 |
3862 }; | 2603 }; |
3863 SpdyPriorityIR priority_ir(2, 1, 17, true); | 2604 SpdyPriorityIR priority_ir(2, 1, 17, true); |
3864 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); | 2605 SpdySerializedFrame frame(framer.SerializeFrame(priority_ir)); |
3865 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2606 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
3866 SpdyPriorityIR priority2(2); | 2607 SpdyPriorityIR priority2(2); |
3867 priority2.set_parent_stream_id(1); | 2608 priority2.set_parent_stream_id(1); |
3868 priority2.set_weight(17); | 2609 priority2.set_weight(17); |
3869 priority2.set_exclusive(true); | 2610 priority2.set_exclusive(true); |
3870 frame = framer.SerializeFrame(priority2); | 2611 frame = framer.SerializeFrame(priority2); |
3871 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); | 2612 CompareFrame(kDescription, frame, kFrameData, arraysize(kFrameData)); |
3872 } | 2613 } |
3873 | 2614 |
3874 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { | |
3875 if (!IsSpdy3()) { | |
3876 return; | |
3877 } | |
3878 | |
3879 SpdyFramer framer(spdy_version_); | |
3880 SpdySynStreamIR syn_stream(1); | |
3881 syn_stream.set_priority(1); | |
3882 syn_stream.SetHeader("aa", "vv"); | |
3883 syn_stream.SetHeader("bb", "ww"); | |
3884 SpdySerializedFrame control_frame(framer.SerializeSynStream(syn_stream)); | |
3885 TestSpdyVisitor visitor(spdy_version_); | |
3886 visitor.use_compression_ = true; | |
3887 visitor.SimulateInFramer( | |
3888 reinterpret_cast<unsigned char*>(control_frame.data()), | |
3889 control_frame.size()); | |
3890 EXPECT_EQ(1, visitor.syn_frame_count_); | |
3891 EXPECT_EQ(syn_stream.header_block(), visitor.headers_); | |
3892 } | |
3893 | |
3894 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { | |
3895 if (!IsSpdy3()) { | |
3896 return; | |
3897 } | |
3898 | |
3899 SpdyFramer framer(spdy_version_); | |
3900 SpdySynReplyIR syn_reply(1); | |
3901 syn_reply.SetHeader("alpha", "beta"); | |
3902 syn_reply.SetHeader("gamma", "delta"); | |
3903 SpdySerializedFrame control_frame(framer.SerializeSynReply(syn_reply)); | |
3904 TestSpdyVisitor visitor(spdy_version_); | |
3905 visitor.use_compression_ = true; | |
3906 visitor.SimulateInFramer( | |
3907 reinterpret_cast<unsigned char*>(control_frame.data()), | |
3908 control_frame.size()); | |
3909 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | |
3910 EXPECT_EQ(0, visitor.headers_frame_count_); | |
3911 EXPECT_EQ(syn_reply.header_block(), visitor.headers_); | |
3912 } | |
3913 | |
3914 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { | 2615 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { |
3915 SpdyFramer framer(spdy_version_); | 2616 SpdyFramer framer(spdy_version_); |
3916 SpdyHeadersIR headers_ir(1); | 2617 SpdyHeadersIR headers_ir(1); |
3917 headers_ir.SetHeader("alpha", "beta"); | 2618 headers_ir.SetHeader("alpha", "beta"); |
3918 headers_ir.SetHeader("gamma", "delta"); | 2619 headers_ir.SetHeader("gamma", "delta"); |
3919 SpdySerializedFrame control_frame( | 2620 SpdySerializedFrame control_frame( |
3920 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 2621 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
3921 TestSpdyVisitor visitor(spdy_version_); | 2622 TestSpdyVisitor visitor(spdy_version_); |
3922 visitor.use_compression_ = true; | 2623 visitor.use_compression_ = true; |
3923 visitor.SimulateInFramer( | 2624 visitor.SimulateInFramer( |
(...skipping 19 matching lines...) Expand all Loading... | |
3943 visitor.SimulateInFramer( | 2644 visitor.SimulateInFramer( |
3944 reinterpret_cast<unsigned char*>(control_frame.data()), | 2645 reinterpret_cast<unsigned char*>(control_frame.data()), |
3945 control_frame.size()); | 2646 control_frame.size()); |
3946 EXPECT_EQ(1, visitor.headers_frame_count_); | 2647 EXPECT_EQ(1, visitor.headers_frame_count_); |
3947 EXPECT_EQ(0, visitor.control_frame_header_data_count_); | 2648 EXPECT_EQ(0, visitor.control_frame_header_data_count_); |
3948 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2649 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
3949 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2650 EXPECT_EQ(1, visitor.end_of_stream_count_); |
3950 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); | 2651 EXPECT_EQ(headers_ir.header_block(), visitor.headers_); |
3951 } | 2652 } |
3952 | 2653 |
3953 TEST_P(SpdyFramerTest, ControlFrameAtMaxSizeLimit) { | |
3954 if (!IsSpdy3()) { | |
3955 // TODO(jgraettinger): This test setup doesn't work with HPACK. | |
3956 return; | |
3957 } | |
3958 | |
3959 // First find the size of the header value in order to just reach the control | |
3960 // frame max size. | |
3961 SpdyFramer framer(spdy_version_); | |
3962 framer.set_enable_compression(false); | |
3963 SpdySynStreamIR syn_stream(1); | |
3964 syn_stream.set_priority(1); | |
3965 syn_stream.SetHeader("aa", ""); | |
3966 SpdySerializedFrame control_frame(framer.SerializeSynStream(syn_stream)); | |
3967 const size_t kBigValueSize = | |
3968 TestSpdyVisitor::sent_control_frame_max_size() - control_frame.size(); | |
3969 | |
3970 // Create a frame at exactly that size. | |
3971 string big_value(kBigValueSize, 'x'); | |
3972 syn_stream.SetHeader("aa", big_value); | |
3973 control_frame = framer.SerializeSynStream(syn_stream); | |
3974 EXPECT_EQ(TestSpdyVisitor::sent_control_frame_max_size(), | |
3975 control_frame.size()); | |
3976 | |
3977 TestSpdyVisitor visitor(spdy_version_); | |
3978 visitor.SimulateInFramer( | |
3979 reinterpret_cast<unsigned char*>(control_frame.data()), | |
3980 control_frame.size()); | |
3981 EXPECT_TRUE(visitor.header_buffer_valid_); | |
3982 EXPECT_EQ(0, visitor.error_count_); | |
3983 EXPECT_EQ(1, visitor.syn_frame_count_); | |
3984 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | |
3985 EXPECT_EQ(0, visitor.end_of_stream_count_); | |
3986 } | |
3987 | |
3988 TEST_P(SpdyFramerTest, ControlFrameTooLarge) { | |
3989 if (!IsSpdy3()) { | |
3990 // TODO(jgraettinger): This test setup doesn't work with HPACK. | |
3991 return; | |
3992 } | |
3993 | |
3994 // First find the size of the header value in order to just reach the control | |
3995 // frame max size. | |
3996 SpdyFramer framer(spdy_version_); | |
3997 framer.set_enable_compression(false); | |
3998 SpdySynStreamIR syn_stream(1); | |
3999 syn_stream.SetHeader("aa", ""); | |
4000 syn_stream.set_priority(1); | |
4001 SpdySerializedFrame control_frame(framer.SerializeSynStream(syn_stream)); | |
4002 const size_t kBigValueSize = | |
4003 TestSpdyVisitor::received_control_frame_max_size() + | |
4004 SpdyConstants::GetFrameHeaderSize(spdy_version_) - control_frame.size() + | |
4005 1; | |
4006 | |
4007 // Create a frame at exatly that size. | |
4008 string big_value(kBigValueSize, 'x'); | |
4009 syn_stream.SetHeader("aa", big_value); | |
4010 if (IsSpdy3()) { | |
4011 control_frame = framer.SerializeSynStream(syn_stream); | |
4012 } else { | |
4013 EXPECT_SPDY_BUG({ control_frame = framer.SerializeSynStream(syn_stream); }, | |
4014 "Serializing frame over-capacity."); | |
4015 } | |
4016 EXPECT_EQ(TestSpdyVisitor::received_control_frame_max_size() + | |
4017 SpdyConstants::GetFrameHeaderSize(spdy_version_) + 1, | |
4018 control_frame.size()); | |
4019 | |
4020 TestSpdyVisitor visitor(spdy_version_); | |
4021 visitor.SimulateInFramer( | |
4022 reinterpret_cast<unsigned char*>(control_frame.data()), | |
4023 control_frame.size()); | |
4024 EXPECT_FALSE(visitor.header_buffer_valid_); | |
4025 EXPECT_EQ(1, visitor.error_count_); | |
4026 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, | |
4027 visitor.framer_.error_code()) | |
4028 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | |
4029 EXPECT_EQ(0, visitor.syn_frame_count_); | |
4030 EXPECT_EQ(0u, visitor.header_buffer_length_); | |
4031 } | |
4032 | |
4033 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { | 2654 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
4034 if (!IsHttp2()) { | |
4035 return; | |
4036 } | |
4037 | |
4038 SpdyFramer framer(spdy_version_); | 2655 SpdyFramer framer(spdy_version_); |
4039 framer.set_enable_compression(false); | 2656 framer.set_enable_compression(false); |
4040 SpdyHeadersIR headers(1); | 2657 SpdyHeadersIR headers(1); |
4041 headers.set_padding_len(256); | 2658 headers.set_padding_len(256); |
4042 | 2659 |
4043 // Exact payload length will change with HPACK, but this should be long | 2660 // Exact payload length will change with HPACK, but this should be long |
4044 // enough to cause an overflow. | 2661 // enough to cause an overflow. |
4045 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2662 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
4046 string big_value(kBigValueSize, 'x'); | 2663 string big_value(kBigValueSize, 'x'); |
4047 headers.SetHeader("aa", big_value); | 2664 headers.SetHeader("aa", big_value); |
4048 SpdySerializedFrame control_frame( | 2665 SpdySerializedFrame control_frame( |
4049 SpdyFramerPeer::SerializeHeaders(&framer, headers)); | 2666 SpdyFramerPeer::SerializeHeaders(&framer, headers)); |
4050 EXPECT_GT(control_frame.size(), | 2667 EXPECT_GT(control_frame.size(), |
4051 TestSpdyVisitor::sent_control_frame_max_size()); | 2668 TestSpdyVisitor::sent_control_frame_max_size()); |
4052 | 2669 |
4053 TestSpdyVisitor visitor(spdy_version_); | 2670 TestSpdyVisitor visitor(spdy_version_); |
4054 visitor.SimulateInFramer( | 2671 visitor.SimulateInFramer( |
4055 reinterpret_cast<unsigned char*>(control_frame.data()), | 2672 reinterpret_cast<unsigned char*>(control_frame.data()), |
4056 control_frame.size()); | 2673 control_frame.size()); |
4057 EXPECT_TRUE(visitor.header_buffer_valid_); | 2674 EXPECT_TRUE(visitor.header_buffer_valid_); |
4058 EXPECT_EQ(0, visitor.error_count_); | 2675 EXPECT_EQ(0, visitor.error_count_); |
4059 EXPECT_EQ(1, visitor.headers_frame_count_); | 2676 EXPECT_EQ(1, visitor.headers_frame_count_); |
4060 EXPECT_EQ(1, visitor.continuation_count_); | 2677 EXPECT_EQ(1, visitor.continuation_count_); |
4061 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2678 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
4062 } | 2679 } |
4063 | 2680 |
4064 TEST_P(SpdyFramerTest, MultipleContinuationFramesWithIterator) { | 2681 TEST_P(SpdyFramerTest, MultipleContinuationFramesWithIterator) { |
4065 if (!IsHttp2()) { | |
4066 return; | |
4067 } | |
4068 | |
4069 SpdyFramer framer(spdy_version_); | 2682 SpdyFramer framer(spdy_version_); |
4070 framer.set_enable_compression(false); | 2683 framer.set_enable_compression(false); |
4071 auto headers = base::MakeUnique<SpdyHeadersIR>(1); | 2684 auto headers = base::MakeUnique<SpdyHeadersIR>(1); |
4072 headers->set_padding_len(256); | 2685 headers->set_padding_len(256); |
4073 | 2686 |
4074 // Exact payload length will change with HPACK, but this should be long | 2687 // Exact payload length will change with HPACK, but this should be long |
4075 // enough to cause an overflow. | 2688 // enough to cause an overflow. |
4076 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2689 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
4077 string big_valuex(kBigValueSize, 'x'); | 2690 string big_valuex(kBigValueSize, 'x'); |
4078 headers->SetHeader("aa", big_valuex); | 2691 headers->SetHeader("aa", big_valuex); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4121 EXPECT_TRUE(visitor.header_buffer_valid_); | 2734 EXPECT_TRUE(visitor.header_buffer_valid_); |
4122 EXPECT_EQ(0, visitor.error_count_); | 2735 EXPECT_EQ(0, visitor.error_count_); |
4123 EXPECT_EQ(1, visitor.headers_frame_count_); | 2736 EXPECT_EQ(1, visitor.headers_frame_count_); |
4124 EXPECT_EQ(2, visitor.continuation_count_); | 2737 EXPECT_EQ(2, visitor.continuation_count_); |
4125 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 2738 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
4126 | 2739 |
4127 EXPECT_FALSE(frame_it.HasNextFrame()); | 2740 EXPECT_FALSE(frame_it.HasNextFrame()); |
4128 } | 2741 } |
4129 | 2742 |
4130 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 2743 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
4131 if (!IsHttp2()) { | |
4132 return; | |
4133 } | |
4134 | |
4135 SpdyFramer framer(spdy_version_); | 2744 SpdyFramer framer(spdy_version_); |
4136 framer.set_enable_compression(false); | 2745 framer.set_enable_compression(false); |
4137 SpdyPushPromiseIR push_promise(1, 2); | 2746 SpdyPushPromiseIR push_promise(1, 2); |
4138 push_promise.set_padding_len(256); | 2747 push_promise.set_padding_len(256); |
4139 | 2748 |
4140 // Exact payload length will change with HPACK, but this should be long | 2749 // Exact payload length will change with HPACK, but this should be long |
4141 // enough to cause an overflow. | 2750 // enough to cause an overflow. |
4142 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); | 2751 const size_t kBigValueSize = TestSpdyVisitor::sent_control_frame_max_size(); |
4143 string big_value(kBigValueSize, 'x'); | 2752 string big_value(kBigValueSize, 'x'); |
4144 push_promise.SetHeader("aa", big_value); | 2753 push_promise.SetHeader("aa", big_value); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4177 visitor.use_compression_ = true; | 2786 visitor.use_compression_ = true; |
4178 visitor.SimulateInFramer( | 2787 visitor.SimulateInFramer( |
4179 reinterpret_cast<unsigned char*>(control_frame.data()), | 2788 reinterpret_cast<unsigned char*>(control_frame.data()), |
4180 control_frame.size()); | 2789 control_frame.size()); |
4181 // It's up to the visitor to ignore extraneous header data; the framer | 2790 // It's up to the visitor to ignore extraneous header data; the framer |
4182 // won't throw an error. | 2791 // won't throw an error. |
4183 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); | 2792 EXPECT_GT(visitor.header_bytes_received_, visitor.header_buffer_size_); |
4184 EXPECT_EQ(1, visitor.end_of_stream_count_); | 2793 EXPECT_EQ(1, visitor.end_of_stream_count_); |
4185 } | 2794 } |
4186 | 2795 |
4187 TEST_P(SpdyFramerTest, DecompressCorruptHeaderBlock) { | |
4188 if (!IsSpdy3()) { | |
4189 // Deflate compression doesn't apply to HPACK. | |
4190 return; | |
4191 } | |
4192 | |
4193 SpdyFramer framer(spdy_version_); | |
4194 framer.set_enable_compression(false); | |
4195 // Construct a SYN_STREAM control frame without compressing the header block, | |
4196 // and have the framer try to decompress it. This will cause the framer to | |
4197 // deal with a decompression error. | |
4198 SpdySynStreamIR syn_stream(1); | |
4199 syn_stream.set_priority(1); | |
4200 syn_stream.SetHeader("aa", "alpha beta gamma delta"); | |
4201 SpdySerializedFrame control_frame(framer.SerializeSynStream(syn_stream)); | |
4202 TestSpdyVisitor visitor(spdy_version_); | |
4203 visitor.use_compression_ = true; | |
4204 visitor.SimulateInFramer( | |
4205 reinterpret_cast<unsigned char*>(control_frame.data()), | |
4206 control_frame.size()); | |
4207 EXPECT_EQ(1, visitor.error_count_); | |
4208 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()) | |
4209 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | |
4210 EXPECT_EQ(0u, visitor.header_buffer_length_); | |
4211 } | |
4212 | |
4213 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { | 2796 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
4214 SpdyFramer framer(spdy_version_); | 2797 SpdyFramer framer(spdy_version_); |
4215 // Create a GoAway frame that has a few extra bytes at the end. | 2798 // Create a GoAway frame that has a few extra bytes at the end. |
4216 // We create enough overhead to overflow the framer's control frame buffer. | 2799 // We create enough overhead to overflow the framer's control frame buffer. |
4217 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); | 2800 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); |
4218 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; | 2801 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; |
4219 const unsigned char kV3FrameData[] = { | |
4220 0x80, 0x03, 0x00, 0x07, | |
4221 0x00, 0x00, 0x00, static_cast<unsigned char>(length), | |
4222 0x00, 0x00, 0x00, 0x00, // Stream ID | |
4223 0x00, 0x00, 0x00, 0x00, // Status | |
4224 }; | |
4225 | 2802 |
4226 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may | 2803 // HTTP/2 GOAWAY frames are only bound by a minimal length, since they may |
4227 // carry opaque data. Verify that minimal length is tested. | 2804 // carry opaque data. Verify that minimal length is tested. |
4228 ASSERT_GT(framer.GetGoAwayMinimumSize(), framer.GetFrameHeaderSize()); | 2805 ASSERT_GT(framer.GetGoAwayMinimumSize(), framer.GetFrameHeaderSize()); |
4229 const size_t less_than_min_length = | 2806 const size_t less_than_min_length = |
4230 framer.GetGoAwayMinimumSize() - framer.GetFrameHeaderSize() - 1; | 2807 framer.GetGoAwayMinimumSize() - framer.GetFrameHeaderSize() - 1; |
4231 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); | 2808 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); |
4232 const unsigned char kH2Len = static_cast<unsigned char>(less_than_min_length); | 2809 const unsigned char kH2Len = static_cast<unsigned char>(less_than_min_length); |
4233 const unsigned char kH2FrameData[] = { | 2810 const unsigned char kH2FrameData[] = { |
4234 0x00, 0x00, kH2Len, // Length: min length - 1 | 2811 0x00, 0x00, kH2Len, // Length: min length - 1 |
4235 0x07, // Type: GOAWAY | 2812 0x07, // Type: GOAWAY |
4236 0x00, // Flags: none | 2813 0x00, // Flags: none |
4237 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2814 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
4238 0x00, 0x00, 0x00, 0x00, // Last: 0 | 2815 0x00, 0x00, 0x00, 0x00, // Last: 0 |
4239 0x00, 0x00, 0x00, // Truncated Status Field | 2816 0x00, 0x00, 0x00, // Truncated Status Field |
4240 }; | 2817 }; |
4241 const size_t pad_length = | 2818 const size_t pad_length = |
4242 length + framer.GetFrameHeaderSize() - | 2819 length + framer.GetFrameHeaderSize() - sizeof(kH2FrameData); |
4243 (IsSpdy3() ? sizeof(kV3FrameData) : sizeof(kH2FrameData)); | |
4244 string pad(pad_length, 'A'); | 2820 string pad(pad_length, 'A'); |
4245 TestSpdyVisitor visitor(spdy_version_); | 2821 TestSpdyVisitor visitor(spdy_version_); |
4246 | 2822 |
4247 if (IsSpdy3()) { | 2823 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
4248 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | |
4249 } else { | |
4250 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | |
4251 } | |
4252 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), | 2824 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), |
4253 pad.length()); | 2825 pad.length()); |
4254 | 2826 |
4255 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2827 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
4256 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 2828 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
4257 visitor.framer_.error_code()) | 2829 visitor.framer_.error_code()) |
4258 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2830 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
4259 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. | 2831 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. |
4260 } | 2832 } |
4261 | 2833 |
4262 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 2834 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
4263 SpdyFramer framer(spdy_version_); | 2835 SpdyFramer framer(spdy_version_); |
4264 SpdySettingsIR settings_ir; | 2836 SpdySettingsIR settings_ir; |
4265 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2837 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
4266 SetFrameLength(&control_frame, 0, spdy_version_); | 2838 SetFrameLength(&control_frame, 0, spdy_version_); |
4267 TestSpdyVisitor visitor(spdy_version_); | 2839 TestSpdyVisitor visitor(spdy_version_); |
4268 visitor.use_compression_ = false; | 2840 visitor.use_compression_ = false; |
4269 visitor.SimulateInFramer( | 2841 visitor.SimulateInFramer( |
4270 reinterpret_cast<unsigned char*>(control_frame.data()), | 2842 reinterpret_cast<unsigned char*>(control_frame.data()), |
4271 framer.GetFrameHeaderSize()); | 2843 framer.GetFrameHeaderSize()); |
4272 if (IsSpdy3()) { | 2844 // Zero-len settings frames are permitted as of HTTP/2. |
4273 // Should generate an error, since zero-len settings frames are unsupported. | 2845 EXPECT_EQ(0, visitor.error_count_); |
4274 EXPECT_EQ(1, visitor.error_count_); | |
4275 } else { | |
4276 // Zero-len settings frames are permitted as of HTTP/2. | |
4277 EXPECT_EQ(0, visitor.error_count_); | |
4278 } | |
4279 } | 2846 } |
4280 | 2847 |
4281 // Tests handling of SETTINGS frames with invalid length. | 2848 // Tests handling of SETTINGS frames with invalid length. |
4282 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 2849 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
4283 SpdyFramer framer(spdy_version_); | 2850 SpdyFramer framer(spdy_version_); |
4284 SpdySettingsIR settings_ir; | 2851 SpdySettingsIR settings_ir; |
4285 | 2852 |
4286 // Add a setting to pad the frame so that we don't get a buffer overflow when | 2853 // Add a setting to pad the frame so that we don't get a buffer overflow when |
4287 // calling SimulateInFramer() below. | 2854 // calling SimulateInFramer() below. |
4288 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, | 2855 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4324 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); | 2891 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); |
4325 TestSpdyVisitor visitor(spdy_version_); | 2892 TestSpdyVisitor visitor(spdy_version_); |
4326 visitor.use_compression_ = false; | 2893 visitor.use_compression_ = false; |
4327 | 2894 |
4328 // Read all at once. | 2895 // Read all at once. |
4329 visitor.SimulateInFramer( | 2896 visitor.SimulateInFramer( |
4330 reinterpret_cast<unsigned char*>(control_frame.data()), | 2897 reinterpret_cast<unsigned char*>(control_frame.data()), |
4331 control_frame.size()); | 2898 control_frame.size()); |
4332 EXPECT_EQ(0, visitor.error_count_); | 2899 EXPECT_EQ(0, visitor.error_count_); |
4333 EXPECT_EQ(3, visitor.setting_count_); | 2900 EXPECT_EQ(3, visitor.setting_count_); |
4334 if (IsHttp2()) { | 2901 EXPECT_EQ(1, visitor.settings_ack_sent_); |
4335 EXPECT_EQ(1, visitor.settings_ack_sent_); | |
4336 } | |
4337 | 2902 |
4338 // Read data in small chunks. | 2903 // Read data in small chunks. |
4339 size_t framed_data = 0; | 2904 size_t framed_data = 0; |
4340 size_t unframed_data = control_frame.size(); | 2905 size_t unframed_data = control_frame.size(); |
4341 size_t kReadChunkSize = 5; // Read five bytes at a time. | 2906 size_t kReadChunkSize = 5; // Read five bytes at a time. |
4342 while (unframed_data > 0) { | 2907 while (unframed_data > 0) { |
4343 size_t to_read = std::min(kReadChunkSize, unframed_data); | 2908 size_t to_read = std::min(kReadChunkSize, unframed_data); |
4344 visitor.SimulateInFramer( | 2909 visitor.SimulateInFramer( |
4345 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), | 2910 reinterpret_cast<unsigned char*>(control_frame.data() + framed_data), |
4346 to_read); | 2911 to_read); |
4347 unframed_data -= to_read; | 2912 unframed_data -= to_read; |
4348 framed_data += to_read; | 2913 framed_data += to_read; |
4349 } | 2914 } |
4350 EXPECT_EQ(0, visitor.error_count_); | 2915 EXPECT_EQ(0, visitor.error_count_); |
4351 EXPECT_EQ(3 * 2, visitor.setting_count_); | 2916 EXPECT_EQ(3 * 2, visitor.setting_count_); |
4352 if (IsHttp2()) { | 2917 EXPECT_EQ(2, visitor.settings_ack_sent_); |
4353 EXPECT_EQ(2, visitor.settings_ack_sent_); | |
4354 } | |
4355 } | 2918 } |
4356 | 2919 |
4357 // Tests handling of SETTINGS frame with duplicate entries. | 2920 // Tests handling of SETTINGS frame with duplicate entries. |
4358 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { | 2921 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
4359 SpdyFramer framer(spdy_version_); | 2922 SpdyFramer framer(spdy_version_); |
4360 | 2923 |
4361 // clang-format off | |
4362 const unsigned char kV3FrameData[] = { | |
4363 0x80, 0x03, 0x00, 0x04, | |
4364 0x00, 0x00, 0x00, 0x1C, | |
4365 0x00, 0x00, 0x00, 0x03, | |
4366 0x00, 0x00, 0x00, 0x01, // 1st Setting | |
4367 0x00, 0x00, 0x00, 0x02, | |
4368 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting | |
4369 0x00, 0x00, 0x00, 0x03, | |
4370 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting | |
4371 0x00, 0x00, 0x00, 0x03, | |
4372 }; | |
4373 // clang-format on | |
4374 const unsigned char kH2FrameData[] = { | 2924 const unsigned char kH2FrameData[] = { |
4375 0x00, 0x00, 0x12, // Length: 18 | 2925 0x00, 0x00, 0x12, // Length: 18 |
4376 0x04, // Type: SETTINGS | 2926 0x04, // Type: SETTINGS |
4377 0x00, // Flags: none | 2927 0x00, // Flags: none |
4378 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2928 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
4379 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2929 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
4380 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2930 0x00, 0x00, 0x00, 0x02, // Value: 2 |
4381 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2931 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
4382 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2932 0x00, 0x00, 0x00, 0x03, // Value: 3 |
4383 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2933 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
4384 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2934 0x00, 0x00, 0x00, 0x03, // Value: 3 |
4385 }; | 2935 }; |
4386 | 2936 |
4387 TestSpdyVisitor visitor(spdy_version_); | 2937 TestSpdyVisitor visitor(spdy_version_); |
4388 visitor.use_compression_ = false; | 2938 visitor.use_compression_ = false; |
4389 if (IsSpdy3()) { | 2939 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
4390 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | |
4391 } else { | |
4392 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | |
4393 } | |
4394 | 2940 |
4395 if (IsSpdy3()) { | 2941 // In HTTP/2, duplicate settings are allowed; |
4396 EXPECT_EQ(1, visitor.setting_count_); | 2942 // each setting replaces the previous value for that setting. |
4397 EXPECT_EQ(1, visitor.error_count_); | 2943 EXPECT_EQ(3, visitor.setting_count_); |
4398 } else { | 2944 EXPECT_EQ(0, visitor.error_count_); |
4399 // In HTTP/2, duplicate settings are allowed; | 2945 EXPECT_EQ(1, visitor.settings_ack_sent_); |
4400 // each setting replaces the previous value for that setting. | |
4401 EXPECT_EQ(3, visitor.setting_count_); | |
4402 EXPECT_EQ(0, visitor.error_count_); | |
4403 EXPECT_EQ(1, visitor.settings_ack_sent_); | |
4404 } | |
4405 } | 2946 } |
4406 | 2947 |
4407 // Tests handling of SETTINGS frame with a setting we don't recognize. | 2948 // Tests handling of SETTINGS frame with a setting we don't recognize. |
4408 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { | 2949 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { |
4409 SpdyFramer framer(spdy_version_); | 2950 SpdyFramer framer(spdy_version_); |
4410 | |
4411 // clang-format off | |
4412 const unsigned char kV3FrameData[] = { | |
4413 0x80, 0x03, 0x00, 0x04, | |
4414 0x00, 0x00, 0x00, 0x1C, | |
4415 0x00, 0x00, 0x00, 0x01, | |
4416 0x00, 0x00, 0x00, 0x10, // 1st Setting | |
4417 0x00, 0x00, 0x00, 0x02, | |
4418 }; | |
4419 // clang-format on | |
4420 const unsigned char kH2FrameData[] = { | 2951 const unsigned char kH2FrameData[] = { |
4421 0x00, 0x00, 0x06, // Length: 6 | 2952 0x00, 0x00, 0x06, // Length: 6 |
4422 0x04, // Type: SETTINGS | 2953 0x04, // Type: SETTINGS |
4423 0x00, // Flags: none | 2954 0x00, // Flags: none |
4424 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2955 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
4425 0x00, 0x10, // Param: 16 | 2956 0x00, 0x10, // Param: 16 |
4426 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2957 0x00, 0x00, 0x00, 0x02, // Value: 2 |
4427 }; | 2958 }; |
4428 | 2959 |
4429 TestSpdyVisitor visitor(spdy_version_); | 2960 TestSpdyVisitor visitor(spdy_version_); |
4430 visitor.use_compression_ = false; | 2961 visitor.use_compression_ = false; |
4431 if (IsSpdy3()) { | 2962 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
4432 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | |
4433 } else { | |
4434 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | |
4435 } | |
4436 | 2963 |
4437 if (IsSpdy3()) { | 2964 // In HTTP/2, we ignore unknown settings because of extensions. |
4438 EXPECT_EQ(0, visitor.setting_count_); | 2965 EXPECT_EQ(0, visitor.setting_count_); |
4439 EXPECT_EQ(1, visitor.error_count_); | 2966 EXPECT_EQ(0, visitor.error_count_); |
4440 } else { | |
4441 // In HTTP/2, we ignore unknown settings because of extensions. | |
4442 EXPECT_EQ(0, visitor.setting_count_); | |
4443 EXPECT_EQ(0, visitor.error_count_); | |
4444 } | |
4445 } | 2967 } |
4446 | 2968 |
4447 // Tests handling of SETTINGS frame with entries out of order. | 2969 // Tests handling of SETTINGS frame with entries out of order. |
4448 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 2970 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
4449 SpdyFramer framer(spdy_version_); | 2971 SpdyFramer framer(spdy_version_); |
4450 | |
4451 // clang-format off | |
4452 const unsigned char kV3FrameData[] = { | |
4453 0x80, 0x03, 0x00, 0x04, | |
4454 0x00, 0x00, 0x00, 0x1C, | |
4455 0x00, 0x00, 0x00, 0x03, | |
4456 0x00, 0x00, 0x00, 0x02, // 1st Setting | |
4457 0x00, 0x00, 0x00, 0x02, | |
4458 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting | |
4459 0x00, 0x00, 0x00, 0x03, | |
4460 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting | |
4461 0x00, 0x00, 0x00, 0x03, | |
4462 }; | |
4463 // clang-format on | |
4464 const unsigned char kH2FrameData[] = { | 2972 const unsigned char kH2FrameData[] = { |
4465 0x00, 0x00, 0x12, // Length: 18 | 2973 0x00, 0x00, 0x12, // Length: 18 |
4466 0x04, // Type: SETTINGS | 2974 0x04, // Type: SETTINGS |
4467 0x00, // Flags: none | 2975 0x00, // Flags: none |
4468 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 2976 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
4469 0x00, 0x02, // Param: ENABLE_PUSH | 2977 0x00, 0x02, // Param: ENABLE_PUSH |
4470 0x00, 0x00, 0x00, 0x02, // Value: 2 | 2978 0x00, 0x00, 0x00, 0x02, // Value: 2 |
4471 0x00, 0x01, // Param: HEADER_TABLE_SIZE | 2979 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
4472 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2980 0x00, 0x00, 0x00, 0x03, // Value: 3 |
4473 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 2981 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
4474 0x00, 0x00, 0x00, 0x03, // Value: 3 | 2982 0x00, 0x00, 0x00, 0x03, // Value: 3 |
4475 }; | 2983 }; |
4476 | 2984 |
4477 TestSpdyVisitor visitor(spdy_version_); | 2985 TestSpdyVisitor visitor(spdy_version_); |
4478 visitor.use_compression_ = false; | 2986 visitor.use_compression_ = false; |
4479 if (IsSpdy3()) { | 2987 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); |
4480 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | |
4481 } else { | |
4482 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); | |
4483 } | |
4484 | 2988 |
4485 if (IsSpdy3()) { | 2989 // In HTTP/2, settings are allowed in any order. |
4486 EXPECT_EQ(1, visitor.setting_count_); | 2990 EXPECT_EQ(3, visitor.setting_count_); |
4487 EXPECT_EQ(1, visitor.error_count_); | 2991 EXPECT_EQ(0, visitor.error_count_); |
4488 } else { | |
4489 // In HTTP/2, settings are allowed in any order. | |
4490 EXPECT_EQ(3, visitor.setting_count_); | |
4491 EXPECT_EQ(0, visitor.error_count_); | |
4492 } | |
4493 } | 2992 } |
4494 | 2993 |
4495 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { | 2994 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
4496 if (!IsHttp2()) { | |
4497 return; | |
4498 } | |
4499 | |
4500 SpdyFramer framer(spdy_version_); | 2995 SpdyFramer framer(spdy_version_); |
4501 | 2996 |
4502 const unsigned char kFrameData[] = { | 2997 const unsigned char kFrameData[] = { |
4503 0x00, 0x00, 0x00, // Length: 0 | 2998 0x00, 0x00, 0x00, // Length: 0 |
4504 0x04, // Type: SETTINGS | 2999 0x04, // Type: SETTINGS |
4505 0x01, // Flags: ACK | 3000 0x01, // Flags: ACK |
4506 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 3001 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
4507 }; | 3002 }; |
4508 | 3003 |
4509 TestSpdyVisitor visitor(spdy_version_); | 3004 TestSpdyVisitor visitor(spdy_version_); |
4510 visitor.use_compression_ = false; | 3005 visitor.use_compression_ = false; |
4511 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 3006 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
4512 | 3007 |
4513 EXPECT_EQ(0, visitor.error_count_); | 3008 EXPECT_EQ(0, visitor.error_count_); |
4514 EXPECT_EQ(0, visitor.setting_count_); | 3009 EXPECT_EQ(0, visitor.setting_count_); |
4515 EXPECT_EQ(1, visitor.settings_ack_received_); | 3010 EXPECT_EQ(1, visitor.settings_ack_received_); |
4516 } | 3011 } |
4517 | 3012 |
4518 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 3013 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
4519 if (!IsHttp2()) { | |
4520 return; | |
4521 } | |
4522 | |
4523 const int kPaddingLen = 119; | 3014 const int kPaddingLen = 119; |
4524 const char data_payload[] = "hello"; | 3015 const char data_payload[] = "hello"; |
4525 | 3016 |
4526 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3017 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4527 SpdyFramer framer(spdy_version_); | 3018 SpdyFramer framer(spdy_version_); |
4528 framer.set_visitor(&visitor); | 3019 framer.set_visitor(&visitor); |
4529 | 3020 |
4530 SpdyDataIR data_ir(1, data_payload); | 3021 SpdyDataIR data_ir(1, data_payload); |
4531 data_ir.set_padding_len(kPaddingLen); | 3022 data_ir.set_padding_len(kPaddingLen); |
4532 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | 3023 SpdySerializedFrame frame(framer.SerializeData(data_ir)); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4583 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 3074 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
4584 TestSpdyVisitor visitor(spdy_version_); | 3075 TestSpdyVisitor visitor(spdy_version_); |
4585 visitor.SimulateInFramer( | 3076 visitor.SimulateInFramer( |
4586 reinterpret_cast<unsigned char*>(control_frame.data()), | 3077 reinterpret_cast<unsigned char*>(control_frame.data()), |
4587 control_frame.size()); | 3078 control_frame.size()); |
4588 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3079 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
4589 EXPECT_EQ(2, visitor.last_window_update_delta_); | 3080 EXPECT_EQ(2, visitor.last_window_update_delta_); |
4590 } | 3081 } |
4591 | 3082 |
4592 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { | 3083 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
4593 if (!IsHttp2()) { | |
4594 return; | |
4595 } | |
4596 | |
4597 SpdyFramer framer(spdy_version_); | 3084 SpdyFramer framer(spdy_version_); |
4598 SpdyPushPromiseIR push_promise(42, 57); | 3085 SpdyPushPromiseIR push_promise(42, 57); |
4599 push_promise.SetHeader("foo", "bar"); | 3086 push_promise.SetHeader("foo", "bar"); |
4600 push_promise.SetHeader("bar", "foofoo"); | 3087 push_promise.SetHeader("bar", "foofoo"); |
4601 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); | 3088 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); |
4602 TestSpdyVisitor visitor(spdy_version_); | 3089 TestSpdyVisitor visitor(spdy_version_); |
4603 visitor.use_compression_ = true; | 3090 visitor.use_compression_ = true; |
4604 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 3091 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
4605 frame.size()); | 3092 frame.size()); |
4606 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3093 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
4607 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3094 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
4608 EXPECT_EQ(push_promise.header_block(), visitor.headers_); | 3095 EXPECT_EQ(push_promise.header_block(), visitor.headers_); |
4609 } | 3096 } |
4610 | 3097 |
4611 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3098 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
4612 if (!IsHttp2()) { | |
4613 return; | |
4614 } | |
4615 | |
4616 // frame-format off | 3099 // frame-format off |
4617 const unsigned char kInput[] = { | 3100 const unsigned char kInput[] = { |
4618 0x00, 0x00, 0x14, // Length: 20 | 3101 0x00, 0x00, 0x14, // Length: 20 |
4619 0x01, // Type: HEADERS | 3102 0x01, // Type: HEADERS |
4620 0x08, // Flags: PADDED | 3103 0x08, // Flags: PADDED |
4621 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3104 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4622 0x03, // PadLen: 3 trailing bytes | 3105 0x03, // PadLen: 3 trailing bytes |
4623 0x00, // Unindexed Entry | 3106 0x00, // Unindexed Entry |
4624 0x06, // Name Len: 6 | 3107 0x06, // Name Len: 6 |
4625 'c', 'o', 'o', 'k', 'i', 'e', // Name | 3108 'c', 'o', 'o', 'k', 'i', 'e', // Name |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4664 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3147 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
4665 EXPECT_EQ(0, visitor.end_of_stream_count_); | 3148 EXPECT_EQ(0, visitor.end_of_stream_count_); |
4666 | 3149 |
4667 EXPECT_THAT( | 3150 EXPECT_THAT( |
4668 visitor.headers_, | 3151 visitor.headers_, |
4669 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3152 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
4670 testing::Pair("name", "value"))); | 3153 testing::Pair("name", "value"))); |
4671 } | 3154 } |
4672 | 3155 |
4673 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { | 3156 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { |
4674 if (!IsHttp2()) { | |
4675 return; | |
4676 } | |
4677 // frame-format off | 3157 // frame-format off |
4678 const unsigned char kInput[] = { | 3158 const unsigned char kInput[] = { |
4679 0x00, 0x00, 0x10, // Length: 20 | 3159 0x00, 0x00, 0x10, // Length: 20 |
4680 0x01, // Type: HEADERS | 3160 0x01, // Type: HEADERS |
4681 0x01, // Flags: END_STREAM | 3161 0x01, // Flags: END_STREAM |
4682 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3162 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4683 0x00, // Unindexed Entry | 3163 0x00, // Unindexed Entry |
4684 0x06, // Name Len: 6 | 3164 0x06, // Name Len: 6 |
4685 'c', 'o', 'o', 'k', 'i', 'e', // Name | 3165 'c', 'o', 'o', 'k', 'i', 'e', // Name |
4686 0x07, // Value Len: 7 | 3166 0x07, // Value Len: 7 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4724 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3204 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
4725 EXPECT_EQ(1, visitor.end_of_stream_count_); | 3205 EXPECT_EQ(1, visitor.end_of_stream_count_); |
4726 | 3206 |
4727 EXPECT_THAT( | 3207 EXPECT_THAT( |
4728 visitor.headers_, | 3208 visitor.headers_, |
4729 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3209 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
4730 testing::Pair("name", "value"))); | 3210 testing::Pair("name", "value"))); |
4731 } | 3211 } |
4732 | 3212 |
4733 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3213 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
4734 if (!IsHttp2()) { | |
4735 return; | |
4736 } | |
4737 | |
4738 // frame-format off | 3214 // frame-format off |
4739 const unsigned char kInput[] = { | 3215 const unsigned char kInput[] = { |
4740 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE | 3216 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE |
4741 0x08, 0x00, 0x00, 0x00, // PADDED | 3217 0x08, 0x00, 0x00, 0x00, // PADDED |
4742 0x01, 0x02, 0x00, 0x00, // Stream 1, Pad length field | 3218 0x01, 0x02, 0x00, 0x00, // Stream 1, Pad length field |
4743 0x00, 0x2A, 0x00, 0x06, // Promised stream 42 | 3219 0x00, 0x2A, 0x00, 0x06, // Promised stream 42 |
4744 'c', 'o', 'o', 'k', | 3220 'c', 'o', 'o', 'k', |
4745 'i', 'e', 0x07, 'f', | 3221 'i', 'e', 0x07, 'f', |
4746 'o', 'o', '=', 'b', | 3222 'o', 'o', '=', 'b', |
4747 'a', 'r', 0x00, 0x00, | 3223 'a', 'r', 0x00, 0x00, |
(...skipping 30 matching lines...) Expand all Loading... | |
4778 | 3254 |
4779 EXPECT_THAT( | 3255 EXPECT_THAT( |
4780 visitor.headers_, | 3256 visitor.headers_, |
4781 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3257 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
4782 testing::Pair("name", "value"))); | 3258 testing::Pair("name", "value"))); |
4783 } | 3259 } |
4784 | 3260 |
4785 // Receiving an unknown frame when a continuation is expected should | 3261 // Receiving an unknown frame when a continuation is expected should |
4786 // result in a SPDY_UNEXPECTED_FRAME error | 3262 // result in a SPDY_UNEXPECTED_FRAME error |
4787 TEST_P(SpdyFramerTest, ReceiveUnknownMidContinuation) { | 3263 TEST_P(SpdyFramerTest, ReceiveUnknownMidContinuation) { |
4788 if (!IsHttp2()) { | |
4789 return; | |
4790 } | |
4791 | |
4792 const unsigned char kInput[] = { | 3264 const unsigned char kInput[] = { |
4793 0x00, 0x00, 0x10, // Length: 16 | 3265 0x00, 0x00, 0x10, // Length: 16 |
4794 0x01, // Type: HEADERS | 3266 0x01, // Type: HEADERS |
4795 0x00, // Flags: none | 3267 0x00, // Flags: none |
4796 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3268 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4797 0x00, 0x06, 0x63, 0x6f, // HPACK | 3269 0x00, 0x06, 0x63, 0x6f, // HPACK |
4798 0x6f, 0x6b, 0x69, 0x65, // | 3270 0x6f, 0x6b, 0x69, 0x65, // |
4799 0x07, 0x66, 0x6f, 0x6f, // | 3271 0x07, 0x66, 0x6f, 0x6f, // |
4800 0x3d, 0x62, 0x61, 0x72, // | 3272 0x3d, 0x62, 0x61, 0x72, // |
4801 | 3273 |
(...skipping 17 matching lines...) Expand all Loading... | |
4819 | 3291 |
4820 EXPECT_EQ(1, visitor.error_count_); | 3292 EXPECT_EQ(1, visitor.error_count_); |
4821 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3293 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
4822 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3294 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
4823 EXPECT_EQ(1, visitor.headers_frame_count_); | 3295 EXPECT_EQ(1, visitor.headers_frame_count_); |
4824 EXPECT_EQ(0, visitor.continuation_count_); | 3296 EXPECT_EQ(0, visitor.continuation_count_); |
4825 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3297 EXPECT_EQ(0u, visitor.header_buffer_length_); |
4826 } | 3298 } |
4827 | 3299 |
4828 TEST_P(SpdyFramerTest, ReceiveContinuationOnWrongStream) { | 3300 TEST_P(SpdyFramerTest, ReceiveContinuationOnWrongStream) { |
4829 if (!IsHttp2()) { | |
4830 return; | |
4831 } | |
4832 | |
4833 const unsigned char kInput[] = { | 3301 const unsigned char kInput[] = { |
4834 0x00, 0x00, 0x10, // Length: 16 | 3302 0x00, 0x00, 0x10, // Length: 16 |
4835 0x01, // Type: HEADERS | 3303 0x01, // Type: HEADERS |
4836 0x00, // Flags: none | 3304 0x00, // Flags: none |
4837 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3305 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4838 0x00, 0x06, 0x63, 0x6f, // HPACK | 3306 0x00, 0x06, 0x63, 0x6f, // HPACK |
4839 0x6f, 0x6b, 0x69, 0x65, // | 3307 0x6f, 0x6b, 0x69, 0x65, // |
4840 0x07, 0x66, 0x6f, 0x6f, // | 3308 0x07, 0x66, 0x6f, 0x6f, // |
4841 0x3d, 0x62, 0x61, 0x72, // | 3309 0x3d, 0x62, 0x61, 0x72, // |
4842 | 3310 |
(...skipping 15 matching lines...) Expand all Loading... | |
4858 | 3326 |
4859 EXPECT_EQ(1, visitor.error_count_); | 3327 EXPECT_EQ(1, visitor.error_count_); |
4860 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3328 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
4861 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3329 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
4862 EXPECT_EQ(1, visitor.headers_frame_count_); | 3330 EXPECT_EQ(1, visitor.headers_frame_count_); |
4863 EXPECT_EQ(0, visitor.continuation_count_); | 3331 EXPECT_EQ(0, visitor.continuation_count_); |
4864 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3332 EXPECT_EQ(0u, visitor.header_buffer_length_); |
4865 } | 3333 } |
4866 | 3334 |
4867 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3335 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { |
4868 if (!IsHttp2()) { | |
4869 return; | |
4870 } | |
4871 | |
4872 const unsigned char kInput[] = { | 3336 const unsigned char kInput[] = { |
4873 0x00, 0x00, 0x18, // Length: 24 | 3337 0x00, 0x00, 0x18, // Length: 24 |
4874 0x09, // Type: CONTINUATION | 3338 0x09, // Type: CONTINUATION |
4875 0x00, // Flags: none | 3339 0x00, // Flags: none |
4876 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3340 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4877 0x00, 0x06, 0x63, 0x6f, // HPACK | 3341 0x00, 0x06, 0x63, 0x6f, // HPACK |
4878 0x6f, 0x6b, 0x69, 0x65, // | 3342 0x6f, 0x6b, 0x69, 0x65, // |
4879 0x07, 0x66, 0x6f, 0x6f, // | 3343 0x07, 0x66, 0x6f, 0x6f, // |
4880 0x3d, 0x62, 0x61, 0x72, // | 3344 0x3d, 0x62, 0x61, 0x72, // |
4881 }; | 3345 }; |
4882 | 3346 |
4883 SpdyFramer framer(spdy_version_); | 3347 SpdyFramer framer(spdy_version_); |
4884 TestSpdyVisitor visitor(spdy_version_); | 3348 TestSpdyVisitor visitor(spdy_version_); |
4885 framer.set_visitor(&visitor); | 3349 framer.set_visitor(&visitor); |
4886 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3350 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
4887 | 3351 |
4888 EXPECT_EQ(1, visitor.error_count_); | 3352 EXPECT_EQ(1, visitor.error_count_); |
4889 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3353 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
4890 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3354 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
4891 EXPECT_EQ(0, visitor.continuation_count_); | 3355 EXPECT_EQ(0, visitor.continuation_count_); |
4892 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3356 EXPECT_EQ(0u, visitor.header_buffer_length_); |
4893 } | 3357 } |
4894 | 3358 |
4895 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { | 3359 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { |
4896 if (!IsHttp2()) { | |
4897 return; | |
4898 } | |
4899 | |
4900 const unsigned char kInput[] = { | 3360 const unsigned char kInput[] = { |
4901 0x00, 0x00, 0x10, // Length: 16 | 3361 0x00, 0x00, 0x10, // Length: 16 |
4902 0x01, // Type: HEADERS | 3362 0x01, // Type: HEADERS |
4903 0x00, // Flags: none | 3363 0x00, // Flags: none |
4904 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3364 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4905 0x00, 0x06, 0x63, 0x6f, // HPACK | 3365 0x00, 0x06, 0x63, 0x6f, // HPACK |
4906 0x6f, 0x6b, 0x69, 0x65, // | 3366 0x6f, 0x6b, 0x69, 0x65, // |
4907 0x07, 0x66, 0x6f, 0x6f, // | 3367 0x07, 0x66, 0x6f, 0x6f, // |
4908 0x3d, 0x62, 0x61, 0x72, // | 3368 0x3d, 0x62, 0x61, 0x72, // |
4909 | 3369 |
(...skipping 13 matching lines...) Expand all Loading... | |
4923 EXPECT_EQ(1, visitor.error_count_); | 3383 EXPECT_EQ(1, visitor.error_count_); |
4924 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) | 3384 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
4925 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 3385 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
4926 EXPECT_EQ(1, visitor.headers_frame_count_); | 3386 EXPECT_EQ(1, visitor.headers_frame_count_); |
4927 EXPECT_EQ(0, visitor.continuation_count_); | 3387 EXPECT_EQ(0, visitor.continuation_count_); |
4928 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3388 EXPECT_EQ(0u, visitor.header_buffer_length_); |
4929 EXPECT_EQ(0, visitor.data_frame_count_); | 3389 EXPECT_EQ(0, visitor.data_frame_count_); |
4930 } | 3390 } |
4931 | 3391 |
4932 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { | 3392 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { |
4933 if (!IsHttp2()) { | |
4934 return; | |
4935 } | |
4936 | |
4937 const unsigned char kInput[] = { | 3393 const unsigned char kInput[] = { |
4938 0x00, 0x00, 0x10, // Length: 16 | 3394 0x00, 0x00, 0x10, // Length: 16 |
4939 0x01, // Type: HEADERS | 3395 0x01, // Type: HEADERS |
4940 0x00, // Flags: none | 3396 0x00, // Flags: none |
4941 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3397 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
4942 0x00, 0x06, 0x63, 0x6f, // HPACK | 3398 0x00, 0x06, 0x63, 0x6f, // HPACK |
4943 0x6f, 0x6b, 0x69, 0x65, // | 3399 0x6f, 0x6b, 0x69, 0x65, // |
4944 0x07, 0x66, 0x6f, 0x6f, // | 3400 0x07, 0x66, 0x6f, 0x6f, // |
4945 0x3d, 0x62, 0x61, 0x72, // | 3401 0x3d, 0x62, 0x61, 0x72, // |
4946 | 3402 |
(...skipping 25 matching lines...) Expand all Loading... | |
4972 SpdyFramer framer(spdy_version_); | 3428 SpdyFramer framer(spdy_version_); |
4973 unsigned char garbage_frame[256]; | 3429 unsigned char garbage_frame[256]; |
4974 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 3430 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
4975 TestSpdyVisitor visitor(spdy_version_); | 3431 TestSpdyVisitor visitor(spdy_version_); |
4976 visitor.use_compression_ = false; | 3432 visitor.use_compression_ = false; |
4977 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 3433 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
4978 EXPECT_EQ(1, visitor.error_count_); | 3434 EXPECT_EQ(1, visitor.error_count_); |
4979 } | 3435 } |
4980 | 3436 |
4981 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) { | 3437 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) { |
4982 if (!IsHttp2()) { | |
4983 return; | |
4984 } | |
4985 | |
4986 SpdyFramer framer(spdy_version_); | 3438 SpdyFramer framer(spdy_version_); |
4987 | 3439 |
4988 // The unrecognized frame type should still have a valid length. | 3440 // The unrecognized frame type should still have a valid length. |
4989 const unsigned char unknown_frame[] = { | 3441 const unsigned char unknown_frame[] = { |
4990 0x00, 0x00, 0x08, // Length: 8 | 3442 0x00, 0x00, 0x08, // Length: 8 |
4991 0xff, // Type: UnknownFrameType(255) | 3443 0xff, // Type: UnknownFrameType(255) |
4992 0xff, // Flags: 0xff | 3444 0xff, // Flags: 0xff |
4993 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3445 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
4994 0xff, 0xff, 0xff, 0xff, // Payload | 3446 0xff, 0xff, 0xff, 0xff, // Payload |
4995 0xff, 0xff, 0xff, 0xff, // | 3447 0xff, 0xff, 0xff, 0xff, // |
(...skipping 16 matching lines...) Expand all Loading... | |
5012 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3464 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
5013 visitor.SimulateInFramer( | 3465 visitor.SimulateInFramer( |
5014 reinterpret_cast<unsigned char*>(control_frame.data()), | 3466 reinterpret_cast<unsigned char*>(control_frame.data()), |
5015 control_frame.size()); | 3467 control_frame.size()); |
5016 EXPECT_EQ(0, visitor.error_count_); | 3468 EXPECT_EQ(0, visitor.error_count_); |
5017 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3469 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); |
5018 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3470 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); |
5019 } | 3471 } |
5020 | 3472 |
5021 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { | 3473 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { |
5022 if (!IsHttp2()) { | |
5023 return; | |
5024 } | |
5025 | |
5026 SpdyFramer framer(spdy_version_); | 3474 SpdyFramer framer(spdy_version_); |
5027 const unsigned char kFrameData[] = { | 3475 const unsigned char kFrameData[] = { |
5028 0x00, 0x00, 0x08, // Length: 8 | 3476 0x00, 0x00, 0x08, // Length: 8 |
5029 0xff, // Type: UnknownFrameType(255) | 3477 0xff, // Type: UnknownFrameType(255) |
5030 0xff, // Flags: 0xff | 3478 0xff, // Flags: 0xff |
5031 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3479 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
5032 0xff, 0xff, 0xff, 0xff, // Payload | 3480 0xff, 0xff, 0xff, 0xff, // Payload |
5033 0xff, 0xff, 0xff, 0xff, // | 3481 0xff, 0xff, 0xff, 0xff, // |
5034 }; | 3482 }; |
5035 TestSpdyVisitor visitor(spdy_version_); | 3483 TestSpdyVisitor visitor(spdy_version_); |
5036 visitor.use_compression_ = false; | 3484 visitor.use_compression_ = false; |
5037 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 3485 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
5038 EXPECT_EQ(1, visitor.error_count_); | 3486 EXPECT_EQ(1, visitor.error_count_); |
5039 } | 3487 } |
5040 | 3488 |
5041 TEST_P(SpdyFramerTest, ReadGarbageWithValidVersion) { | |
5042 if (!IsSpdy3()) { | |
5043 return; | |
5044 } | |
5045 | |
5046 SpdyFramer framer(spdy_version_); | |
5047 // clang-format off | |
5048 const unsigned char kFrameData[] = { | |
5049 0x80, 0x03, 0xff, 0xff, | |
5050 0xff, 0xff, 0xff, 0xff, | |
5051 }; | |
5052 // clang-format on | |
5053 TestSpdyVisitor visitor(spdy_version_); | |
5054 visitor.use_compression_ = false; | |
5055 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | |
5056 EXPECT_EQ(1, visitor.error_count_); | |
5057 } | |
5058 | |
5059 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { | 3489 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { |
5060 if (!IsHttp2()) { | |
5061 return; | |
5062 } | |
5063 | |
5064 const unsigned char kInput[] = { | 3490 const unsigned char kInput[] = { |
5065 0x00, 0x12, 0x01, // Length: 4609 | 3491 0x00, 0x12, 0x01, // Length: 4609 |
5066 0x04, // Type: SETTINGS | 3492 0x04, // Type: SETTINGS |
5067 0x00, // Flags: none | 3493 0x00, // Flags: none |
5068 0x00, 0x00, 0x01, 0xef, // Stream: 495 | 3494 0x00, 0x00, 0x01, 0xef, // Stream: 495 |
5069 0xef, 0xff, // Param: 61439 | 3495 0xef, 0xff, // Param: 61439 |
5070 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3496 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
5071 0xff, 0xff, // Param: 0xffff | 3497 0xff, 0xff, // Param: 0xffff |
5072 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 | 3498 0xff, 0xff, 0xff, 0xff, // Value: 4294967295 |
5073 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) | 3499 0xff, 0xff, 0xff, 0xff, // Settings (Truncated) |
5074 0xff, // | 3500 0xff, // |
5075 }; | 3501 }; |
5076 | 3502 |
5077 TestSpdyVisitor visitor(spdy_version_); | 3503 TestSpdyVisitor visitor(spdy_version_); |
5078 visitor.SimulateInFramer(kInput, arraysize(kInput)); | 3504 visitor.SimulateInFramer(kInput, arraysize(kInput)); |
5079 EXPECT_EQ(1, visitor.error_count_); | 3505 EXPECT_EQ(1, visitor.error_count_); |
5080 } | 3506 } |
5081 | 3507 |
5082 TEST_P(SpdyFramerTest, SizesTest) { | 3508 TEST_P(SpdyFramerTest, SizesTest) { |
5083 SpdyFramer framer(spdy_version_); | 3509 SpdyFramer framer(spdy_version_); |
5084 if (IsSpdy3()) { | 3510 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); |
5085 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); | 3511 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); |
5086 EXPECT_EQ(8u, framer.GetFrameHeaderSize()); | 3512 EXPECT_EQ(14u, framer.GetSynStreamMinimumSize()); |
5087 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); | 3513 EXPECT_EQ(9u, framer.GetSynReplyMinimumSize()); |
5088 EXPECT_EQ(12u, framer.GetSynReplyMinimumSize()); | 3514 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); |
5089 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); | 3515 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); |
5090 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); | 3516 EXPECT_EQ(17u, framer.GetPingSize()); |
5091 EXPECT_EQ(12u, framer.GetPingSize()); | 3517 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); |
5092 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); | 3518 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); |
5093 EXPECT_EQ(12u, framer.GetHeadersMinimumSize()); | 3519 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); |
5094 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); | 3520 EXPECT_EQ(9u, framer.GetBlockedSize()); |
5095 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); | 3521 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); |
5096 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize()); | 3522 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize()); |
5097 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload()); | 3523 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); |
5098 } else { | 3524 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); |
5099 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize()); | 3525 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); |
5100 EXPECT_EQ(9u, framer.GetFrameHeaderSize()); | |
5101 EXPECT_EQ(14u, framer.GetSynStreamMinimumSize()); | |
5102 EXPECT_EQ(9u, framer.GetSynReplyMinimumSize()); | |
5103 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); | |
5104 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); | |
5105 EXPECT_EQ(17u, framer.GetPingSize()); | |
5106 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); | |
5107 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); | |
5108 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); | |
5109 EXPECT_EQ(9u, framer.GetBlockedSize()); | |
5110 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); | |
5111 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize()); | |
5112 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); | |
5113 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); | |
5114 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); | |
5115 } | |
5116 } | 3526 } |
5117 | 3527 |
5118 TEST_P(SpdyFramerTest, StateToStringTest) { | 3528 TEST_P(SpdyFramerTest, StateToStringTest) { |
5119 EXPECT_STREQ("ERROR", SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); | 3529 EXPECT_STREQ("ERROR", SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); |
5120 EXPECT_STREQ("FRAME_COMPLETE", | 3530 EXPECT_STREQ("FRAME_COMPLETE", |
5121 SpdyFramer::StateToString(SpdyFramer::SPDY_FRAME_COMPLETE)); | 3531 SpdyFramer::StateToString(SpdyFramer::SPDY_FRAME_COMPLETE)); |
5122 EXPECT_STREQ("READY_FOR_FRAME", | 3532 EXPECT_STREQ("READY_FOR_FRAME", |
5123 SpdyFramer::StateToString(SpdyFramer::SPDY_READY_FOR_FRAME)); | 3533 SpdyFramer::StateToString(SpdyFramer::SPDY_READY_FOR_FRAME)); |
5124 EXPECT_STREQ( | 3534 EXPECT_STREQ( |
5125 "READING_COMMON_HEADER", | 3535 "READING_COMMON_HEADER", |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5209 EXPECT_STREQ("RST_STREAM", SpdyFramer::FrameTypeToString(RST_STREAM)); | 3619 EXPECT_STREQ("RST_STREAM", SpdyFramer::FrameTypeToString(RST_STREAM)); |
5210 EXPECT_STREQ("SETTINGS", SpdyFramer::FrameTypeToString(SETTINGS)); | 3620 EXPECT_STREQ("SETTINGS", SpdyFramer::FrameTypeToString(SETTINGS)); |
5211 EXPECT_STREQ("PING", SpdyFramer::FrameTypeToString(PING)); | 3621 EXPECT_STREQ("PING", SpdyFramer::FrameTypeToString(PING)); |
5212 EXPECT_STREQ("GOAWAY", SpdyFramer::FrameTypeToString(GOAWAY)); | 3622 EXPECT_STREQ("GOAWAY", SpdyFramer::FrameTypeToString(GOAWAY)); |
5213 EXPECT_STREQ("HEADERS", SpdyFramer::FrameTypeToString(HEADERS)); | 3623 EXPECT_STREQ("HEADERS", SpdyFramer::FrameTypeToString(HEADERS)); |
5214 EXPECT_STREQ("WINDOW_UPDATE", SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); | 3624 EXPECT_STREQ("WINDOW_UPDATE", SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); |
5215 EXPECT_STREQ("PUSH_PROMISE", SpdyFramer::FrameTypeToString(PUSH_PROMISE)); | 3625 EXPECT_STREQ("PUSH_PROMISE", SpdyFramer::FrameTypeToString(PUSH_PROMISE)); |
5216 EXPECT_STREQ("CONTINUATION", SpdyFramer::FrameTypeToString(CONTINUATION)); | 3626 EXPECT_STREQ("CONTINUATION", SpdyFramer::FrameTypeToString(CONTINUATION)); |
5217 } | 3627 } |
5218 | 3628 |
5219 TEST_P(SpdyFramerTest, CatchProbableHttpResponse) { | |
5220 if (!IsSpdy3()) { | |
5221 // TODO(hkhalil): catch probable HTTP response in HTTP/2? | |
5222 return; | |
5223 } | |
5224 | |
5225 { | |
5226 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5227 SpdyFramer framer(spdy_version_); | |
5228 framer.set_visitor(&visitor); | |
5229 | |
5230 EXPECT_CALL(visitor, OnError(_)); | |
5231 framer.ProcessInput("HTTP/1.1", 8); | |
5232 EXPECT_TRUE(framer.probable_http_response()); | |
5233 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
5234 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) | |
5235 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5236 } | |
5237 { | |
5238 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5239 SpdyFramer framer(spdy_version_); | |
5240 framer.set_visitor(&visitor); | |
5241 | |
5242 EXPECT_CALL(visitor, OnError(_)); | |
5243 framer.ProcessInput("HTTP/1.0", 8); | |
5244 EXPECT_TRUE(framer.probable_http_response()); | |
5245 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
5246 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) | |
5247 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5248 } | |
5249 } | |
5250 | |
5251 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { | |
5252 if (!IsSpdy3()) { | |
5253 return; | |
5254 } | |
5255 | |
5256 uint8_t flags = 0; | |
5257 do { | |
5258 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | |
5259 << static_cast<int>(flags)); | |
5260 | |
5261 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5262 SpdyFramer framer(spdy_version_); | |
5263 framer.set_visitor(&visitor); | |
5264 | |
5265 SpdyDataIR data_ir(1, "hello"); | |
5266 SpdySerializedFrame frame(framer.SerializeData(data_ir)); | |
5267 SetFrameFlags(&frame, flags, spdy_version_); | |
5268 | |
5269 if (flags & ~DATA_FLAG_FIN) { | |
5270 EXPECT_CALL(visitor, OnError(_)); | |
5271 } else { | |
5272 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | |
5273 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5)); | |
5274 if (flags & DATA_FLAG_FIN) { | |
5275 EXPECT_CALL(visitor, OnStreamEnd(_)); | |
5276 } | |
5277 } | |
5278 | |
5279 framer.ProcessInput(frame.data(), frame.size()); | |
5280 if (flags & ~DATA_FLAG_FIN) { | |
5281 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
5282 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) | |
5283 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5284 } else { | |
5285 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | |
5286 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
5287 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5288 } | |
5289 } while (++flags != 0); | |
5290 } | |
5291 | |
5292 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 3629 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
5293 if (!IsHttp2()) { | |
5294 return; | |
5295 } | |
5296 | |
5297 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; | 3630 uint8_t valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_PADDED; |
5298 | 3631 |
5299 uint8_t flags = 0; | 3632 uint8_t flags = 0; |
5300 do { | 3633 do { |
5301 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3634 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5302 << static_cast<int>(flags)); | 3635 << static_cast<int>(flags)); |
5303 | 3636 |
5304 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3637 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5305 SpdyFramer framer(spdy_version_); | 3638 SpdyFramer framer(spdy_version_); |
5306 framer.set_visitor(&visitor); | 3639 framer.set_visitor(&visitor); |
(...skipping 30 matching lines...) Expand all Loading... | |
5337 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) | 3670 EXPECT_EQ(SpdyFramer::SPDY_INVALID_PADDING, framer.error_code()) |
5338 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3671 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5339 } else { | 3672 } else { |
5340 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3673 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5341 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3674 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5342 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3675 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5343 } | 3676 } |
5344 } while (++flags != 0); | 3677 } while (++flags != 0); |
5345 } | 3678 } |
5346 | 3679 |
5347 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { | |
5348 if (!IsSpdy3()) { | |
5349 return; | |
5350 } | |
5351 | |
5352 uint8_t flags = 0; | |
5353 do { | |
5354 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | |
5355 << static_cast<int>(flags)); | |
5356 | |
5357 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5358 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | |
5359 SpdyFramer framer(spdy_version_); | |
5360 framer.set_visitor(&visitor); | |
5361 framer.set_debug_visitor(&debug_visitor); | |
5362 | |
5363 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _)); | |
5364 | |
5365 SpdySynStreamIR syn_stream(8); | |
5366 syn_stream.set_associated_to_stream_id(3); | |
5367 syn_stream.set_priority(1); | |
5368 syn_stream.SetHeader("foo", "bar"); | |
5369 SpdySerializedFrame frame(framer.SerializeSynStream(syn_stream)); | |
5370 SetFrameFlags(&frame, flags, spdy_version_); | |
5371 | |
5372 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | |
5373 EXPECT_CALL(visitor, OnError(_)); | |
5374 } else { | |
5375 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); | |
5376 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, | |
5377 flags & CONTROL_FLAG_UNIDIRECTIONAL)); | |
5378 EXPECT_CALL(visitor, OnHeaderFrameStart(8)).Times(1); | |
5379 EXPECT_CALL(visitor, OnHeaderFrameEnd(8, _)).Times(1); | |
5380 if (flags & DATA_FLAG_FIN) { | |
5381 EXPECT_CALL(visitor, OnStreamEnd(_)); | |
5382 } else { | |
5383 // Do not close the stream if we are expecting a CONTINUATION frame. | |
5384 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); | |
5385 } | |
5386 } | |
5387 | |
5388 framer.ProcessInput(frame.data(), frame.size()); | |
5389 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | |
5390 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
5391 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | |
5392 framer.error_code()) | |
5393 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5394 } else { | |
5395 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | |
5396 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
5397 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5398 } | |
5399 } while (++flags != 0); | |
5400 } | |
5401 | |
5402 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { | |
5403 if (!IsSpdy3()) { | |
5404 return; | |
5405 } | |
5406 | |
5407 uint8_t flags = 0; | |
5408 do { | |
5409 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | |
5410 << static_cast<int>(flags)); | |
5411 | |
5412 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5413 SpdyFramer framer(spdy_version_); | |
5414 framer.set_visitor(&visitor); | |
5415 | |
5416 SpdySynReplyIR syn_reply(37); | |
5417 syn_reply.SetHeader("foo", "bar"); | |
5418 SpdySerializedFrame frame(framer.SerializeSynReply(syn_reply)); | |
5419 SetFrameFlags(&frame, flags, spdy_version_); | |
5420 | |
5421 if (flags & ~CONTROL_FLAG_FIN) { | |
5422 EXPECT_CALL(visitor, OnError(_)); | |
5423 } else { | |
5424 EXPECT_CALL(visitor, OnSynReply(37, flags & CONTROL_FLAG_FIN)); | |
5425 EXPECT_CALL(visitor, OnHeaderFrameStart(37)).Times(1); | |
5426 EXPECT_CALL(visitor, OnHeaderFrameEnd(37, _)).Times(1); | |
5427 if (flags & DATA_FLAG_FIN) { | |
5428 EXPECT_CALL(visitor, OnStreamEnd(_)); | |
5429 } | |
5430 } | |
5431 | |
5432 framer.ProcessInput(frame.data(), frame.size()); | |
5433 if (flags & ~CONTROL_FLAG_FIN) { | |
5434 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
5435 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | |
5436 framer.error_code()) | |
5437 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5438 } else { | |
5439 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | |
5440 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
5441 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5442 } | |
5443 } while (++flags != 0); | |
5444 } | |
5445 | |
5446 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { | 3680 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { |
5447 uint8_t flags = 0; | 3681 uint8_t flags = 0; |
5448 do { | 3682 do { |
5449 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3683 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5450 << static_cast<int>(flags)); | 3684 << static_cast<int>(flags)); |
5451 | 3685 |
5452 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3686 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5453 SpdyFramer framer(spdy_version_); | 3687 SpdyFramer framer(spdy_version_); |
5454 framer.set_visitor(&visitor); | 3688 framer.set_visitor(&visitor); |
5455 | 3689 |
5456 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); | 3690 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL); |
5457 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 3691 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
5458 SetFrameFlags(&frame, flags, spdy_version_); | 3692 SetFrameFlags(&frame, flags, spdy_version_); |
5459 | 3693 |
5460 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); | 3694 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); |
5461 | 3695 |
5462 framer.ProcessInput(frame.data(), frame.size()); | 3696 framer.ProcessInput(frame.data(), frame.size()); |
5463 | 3697 |
5464 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3698 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5465 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3699 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5466 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3700 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5467 } while (++flags != 0); | 3701 } while (++flags != 0); |
5468 } | 3702 } |
5469 | 3703 |
5470 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { | |
5471 if (!IsSpdy3()) { | |
5472 return; | |
5473 } | |
5474 | |
5475 uint8_t flags = 0; | |
5476 do { | |
5477 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | |
5478 << static_cast<int>(flags)); | |
5479 | |
5480 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5481 SpdyFramer framer(spdy_version_); | |
5482 framer.set_visitor(&visitor); | |
5483 | |
5484 SpdySettingsIR settings_ir; | |
5485 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, false, false, 54321); | |
5486 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | |
5487 SetFrameFlags(&frame, flags, spdy_version_); | |
5488 | |
5489 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { | |
5490 EXPECT_CALL(visitor, OnError(_)); | |
5491 } else { | |
5492 EXPECT_CALL( | |
5493 visitor, | |
5494 OnSettings(flags & | |
5495 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS)); | |
5496 EXPECT_CALL(visitor, OnSetting(SETTINGS_UPLOAD_BANDWIDTH, | |
5497 SETTINGS_FLAG_NONE, 54321)); | |
5498 EXPECT_CALL(visitor, OnSettingsEnd()); | |
5499 } | |
5500 | |
5501 framer.ProcessInput(frame.data(), frame.size()); | |
5502 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { | |
5503 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
5504 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | |
5505 framer.error_code()) | |
5506 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5507 } else { | |
5508 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | |
5509 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
5510 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5511 } | |
5512 } while (++flags != 0); | |
5513 } | |
5514 | |
5515 TEST_P(SpdyFramerTest, SettingsFrameFlags) { | 3704 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
5516 if (!IsHttp2()) { | |
5517 return; | |
5518 } | |
5519 | |
5520 uint8_t flags = 0; | 3705 uint8_t flags = 0; |
5521 do { | 3706 do { |
5522 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3707 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5523 << static_cast<int>(flags)); | 3708 << static_cast<int>(flags)); |
5524 | 3709 |
5525 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3710 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5526 SpdyFramer framer(spdy_version_); | 3711 SpdyFramer framer(spdy_version_); |
5527 framer.set_visitor(&visitor); | 3712 framer.set_visitor(&visitor); |
5528 | 3713 |
5529 SpdySettingsIR settings_ir; | 3714 SpdySettingsIR settings_ir; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5581 uint8_t flags = 0; | 3766 uint8_t flags = 0; |
5582 do { | 3767 do { |
5583 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3768 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5584 << static_cast<int>(flags)); | 3769 << static_cast<int>(flags)); |
5585 | 3770 |
5586 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3771 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5587 SpdyFramer framer(spdy_version_); | 3772 SpdyFramer framer(spdy_version_); |
5588 framer.set_visitor(&visitor); | 3773 framer.set_visitor(&visitor); |
5589 | 3774 |
5590 SpdyHeadersIR headers_ir(57); | 3775 SpdyHeadersIR headers_ir(57); |
5591 if (IsHttp2() && (flags & HEADERS_FLAG_PRIORITY)) { | 3776 if (flags & HEADERS_FLAG_PRIORITY) { |
5592 headers_ir.set_weight(3); | 3777 headers_ir.set_weight(3); |
5593 headers_ir.set_has_priority(true); | 3778 headers_ir.set_has_priority(true); |
5594 headers_ir.set_parent_stream_id(5); | 3779 headers_ir.set_parent_stream_id(5); |
5595 headers_ir.set_exclusive(true); | 3780 headers_ir.set_exclusive(true); |
5596 } | 3781 } |
5597 headers_ir.SetHeader("foo", "bar"); | 3782 headers_ir.SetHeader("foo", "bar"); |
5598 SpdySerializedFrame frame( | 3783 SpdySerializedFrame frame( |
5599 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); | 3784 SpdyFramerPeer::SerializeHeaders(&framer, headers_ir)); |
5600 uint8_t set_flags = flags; | 3785 uint8_t set_flags = flags & ~HEADERS_FLAG_PADDED; |
5601 if (IsHttp2()) { | |
5602 // TODO(jgraettinger): Add padding to SpdyHeadersIR, | |
5603 // and implement framing. | |
5604 set_flags &= ~HEADERS_FLAG_PADDED; | |
5605 } | |
5606 SetFrameFlags(&frame, set_flags, spdy_version_); | 3786 SetFrameFlags(&frame, set_flags, spdy_version_); |
5607 | 3787 |
5608 // Expected callback values | 3788 // Expected callback values |
5609 SpdyStreamId stream_id = 57; | 3789 SpdyStreamId stream_id = 57; |
5610 bool has_priority = false; | 3790 bool has_priority = false; |
5611 SpdyPriority priority = 0; | 3791 SpdyPriority priority = 0; |
5612 SpdyStreamId parent_stream_id = 0; | 3792 SpdyStreamId parent_stream_id = 0; |
5613 bool exclusive = false; | 3793 bool exclusive = false; |
5614 bool fin = flags & CONTROL_FLAG_FIN; | 3794 bool fin = flags & CONTROL_FLAG_FIN; |
5615 bool end = IsSpdy3() || (flags & HEADERS_FLAG_END_HEADERS); | 3795 bool end = flags & HEADERS_FLAG_END_HEADERS; |
5616 if (IsHttp2() && flags & HEADERS_FLAG_PRIORITY) { | 3796 if (flags & HEADERS_FLAG_PRIORITY) { |
5617 has_priority = true; | 3797 has_priority = true; |
5618 priority = 3; | 3798 priority = 3; |
5619 parent_stream_id = 5; | 3799 parent_stream_id = 5; |
5620 exclusive = true; | 3800 exclusive = true; |
5621 } | 3801 } |
5622 EXPECT_CALL(visitor, OnHeaders(stream_id, has_priority, priority, | 3802 EXPECT_CALL(visitor, OnHeaders(stream_id, has_priority, priority, |
5623 parent_stream_id, exclusive, fin, end)); | 3803 parent_stream_id, exclusive, fin, end)); |
5624 EXPECT_CALL(visitor, OnHeaderFrameStart(57)).Times(1); | 3804 EXPECT_CALL(visitor, OnHeaderFrameStart(57)).Times(1); |
5625 if (end) { | 3805 if (end) { |
5626 EXPECT_CALL(visitor, OnHeaderFrameEnd(57, _)).Times(1); | 3806 EXPECT_CALL(visitor, OnHeaderFrameEnd(57, _)).Times(1); |
5627 } | 3807 } |
5628 if (flags & DATA_FLAG_FIN && | 3808 if (flags & DATA_FLAG_FIN && end) { |
5629 (IsSpdy3() || flags & HEADERS_FLAG_END_HEADERS)) { | |
5630 EXPECT_CALL(visitor, OnStreamEnd(_)); | 3809 EXPECT_CALL(visitor, OnStreamEnd(_)); |
5631 } else { | 3810 } else { |
5632 // Do not close the stream if we are expecting a CONTINUATION frame. | 3811 // Do not close the stream if we are expecting a CONTINUATION frame. |
5633 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); | 3812 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); |
5634 } | 3813 } |
5635 | 3814 |
5636 framer.ProcessInput(frame.data(), frame.size()); | 3815 framer.ProcessInput(frame.data(), frame.size()); |
5637 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3816 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5638 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3817 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5639 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3818 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5640 } while (++flags != 0); | 3819 } while (++flags != 0); |
5641 } | 3820 } |
5642 | 3821 |
5643 TEST_P(SpdyFramerTest, PingFrameFlags) { | 3822 TEST_P(SpdyFramerTest, PingFrameFlags) { |
5644 uint8_t flags = 0; | 3823 uint8_t flags = 0; |
5645 do { | 3824 do { |
5646 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3825 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5647 << static_cast<int>(flags)); | 3826 << static_cast<int>(flags)); |
5648 | 3827 |
5649 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3828 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5650 SpdyFramer framer(spdy_version_); | 3829 SpdyFramer framer(spdy_version_); |
5651 framer.set_visitor(&visitor); | 3830 framer.set_visitor(&visitor); |
5652 | 3831 |
5653 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); | 3832 SpdySerializedFrame frame(framer.SerializePing(SpdyPingIR(42))); |
5654 SetFrameFlags(&frame, flags, spdy_version_); | 3833 SetFrameFlags(&frame, flags, spdy_version_); |
5655 | 3834 |
5656 if (IsHttp2() && (flags & PING_FLAG_ACK)) { | 3835 if (flags & PING_FLAG_ACK) { |
5657 EXPECT_CALL(visitor, OnPing(42, true)); | 3836 EXPECT_CALL(visitor, OnPing(42, true)); |
5658 } else { | 3837 } else { |
5659 EXPECT_CALL(visitor, OnPing(42, false)); | 3838 EXPECT_CALL(visitor, OnPing(42, false)); |
5660 } | 3839 } |
5661 | 3840 |
5662 framer.ProcessInput(frame.data(), frame.size()); | 3841 framer.ProcessInput(frame.data(), frame.size()); |
5663 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3842 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5664 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3843 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5665 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3844 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5666 } while (++flags != 0); | 3845 } while (++flags != 0); |
(...skipping 16 matching lines...) Expand all Loading... | |
5683 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 3862 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
5684 | 3863 |
5685 framer.ProcessInput(frame.data(), frame.size()); | 3864 framer.ProcessInput(frame.data(), frame.size()); |
5686 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3865 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5687 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3866 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5688 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3867 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5689 } while (++flags != 0); | 3868 } while (++flags != 0); |
5690 } | 3869 } |
5691 | 3870 |
5692 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { | 3871 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { |
5693 if (!IsHttp2()) { | |
5694 return; | |
5695 } | |
5696 | |
5697 const SpdyStreamId client_id = 123; // Must be odd. | 3872 const SpdyStreamId client_id = 123; // Must be odd. |
5698 const SpdyStreamId promised_id = 22; // Must be even. | 3873 const SpdyStreamId promised_id = 22; // Must be even. |
5699 uint8_t flags = 0; | 3874 uint8_t flags = 0; |
5700 do { | 3875 do { |
5701 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3876 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5702 << static_cast<int>(flags)); | 3877 << static_cast<int>(flags)); |
5703 | 3878 |
5704 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3879 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5705 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3880 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
5706 SpdyFramer framer(spdy_version_); | 3881 SpdyFramer framer(spdy_version_); |
(...skipping 20 matching lines...) Expand all Loading... | |
5727 } | 3902 } |
5728 | 3903 |
5729 framer.ProcessInput(frame.data(), frame.size()); | 3904 framer.ProcessInput(frame.data(), frame.size()); |
5730 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3905 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5731 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3906 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5732 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3907 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5733 } while (++flags != 0); | 3908 } while (++flags != 0); |
5734 } | 3909 } |
5735 | 3910 |
5736 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { | 3911 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { |
5737 if (!IsHttp2()) { | |
5738 return; | |
5739 } | |
5740 | |
5741 uint8_t flags = 0; | 3912 uint8_t flags = 0; |
5742 do { | 3913 do { |
5743 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex | 3914 SCOPED_TRACE(testing::Message() << "Flags " << flags << std::hex |
5744 << static_cast<int>(flags)); | 3915 << static_cast<int>(flags)); |
5745 | 3916 |
5746 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3917 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5747 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 3918 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
5748 SpdyFramer framer(spdy_version_); | 3919 SpdyFramer framer(spdy_version_); |
5749 framer.set_visitor(&visitor); | 3920 framer.set_visitor(&visitor); |
5750 framer.set_debug_visitor(&debug_visitor); | 3921 framer.set_debug_visitor(&debug_visitor); |
(...skipping 25 matching lines...) Expand all Loading... | |
5776 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3947 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5777 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3948 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5778 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3949 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5779 } while (++flags != 0); | 3950 } while (++flags != 0); |
5780 } | 3951 } |
5781 | 3952 |
5782 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) | 3953 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
5783 | 3954 |
5784 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) | 3955 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) |
5785 | 3956 |
5786 TEST_P(SpdyFramerTest, EmptySynStream) { | |
5787 if (!IsSpdy3()) { | |
5788 return; | |
5789 } | |
5790 | |
5791 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | |
5792 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | |
5793 SpdyFramer framer(spdy_version_); | |
5794 framer.set_visitor(&visitor); | |
5795 framer.set_debug_visitor(&debug_visitor); | |
5796 | |
5797 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); | |
5798 | |
5799 SpdySynStreamIR syn_stream(1); | |
5800 syn_stream.set_priority(1); | |
5801 SpdySerializedFrame frame(framer.SerializeSynStream(syn_stream)); | |
5802 // Adjust size to remove the header block. | |
5803 SetFrameLength(&frame, | |
5804 framer.GetSynStreamMinimumSize() - framer.GetFrameHeaderSize(), | |
5805 spdy_version_); | |
5806 | |
5807 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(1, SYN_STREAM, _)); | |
5808 EXPECT_CALL(visitor, OnSynStream(1, 0, 1, false, false)); | |
5809 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | |
5810 EXPECT_CALL(visitor, OnHeaderFrameEnd(1, _)).Times(1); | |
5811 | |
5812 framer.ProcessInput(frame.data(), framer.GetSynStreamMinimumSize()); | |
5813 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | |
5814 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
5815 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
5816 } | |
5817 | |
5818 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { | 3957 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { |
5819 const uint32_t kId = 0x020304; | 3958 const uint32_t kId = 0x020304; |
5820 const uint32_t kFlags = 0x01; | 3959 const uint32_t kFlags = 0x01; |
5821 const uint32_t kWireFormat = base::HostToNet32(0x01020304); | 3960 const uint32_t kWireFormat = base::HostToNet32(0x01020304); |
5822 | 3961 |
5823 SettingsFlagsAndId id_and_flags = | 3962 SettingsFlagsAndId id_and_flags = |
5824 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 3963 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
5825 EXPECT_EQ(kId, id_and_flags.id()); | 3964 EXPECT_EQ(kId, id_and_flags.id()); |
5826 EXPECT_EQ(kFlags, id_and_flags.flags()); | 3965 EXPECT_EQ(kFlags, id_and_flags.flags()); |
5827 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 3966 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
5828 } | 3967 } |
5829 | 3968 |
5830 // Test handling of a RST_STREAM with out-of-bounds status codes. | 3969 // Test handling of a RST_STREAM with out-of-bounds status codes. |
5831 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { | 3970 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
5832 const unsigned char kRstStreamStatusTooLow = 0x00; | |
5833 const unsigned char kRstStreamStatusTooHigh = 0xff; | |
5834 // clang-format off | |
5835 const unsigned char kV3RstStreamInvalid[] = { | |
5836 0x80, 0x03, 0x00, 0x03, | |
5837 0x00, 0x00, 0x00, 0x08, | |
5838 0x00, 0x00, 0x00, 0x01, | |
5839 0x00, 0x00, 0x00, kRstStreamStatusTooLow | |
5840 }; | |
5841 // clang-format on | |
5842 const unsigned char kH2RstStreamInvalid[] = { | 3971 const unsigned char kH2RstStreamInvalid[] = { |
5843 0x00, 0x00, 0x04, // Length: 4 | 3972 0x00, 0x00, 0x04, // Length: 4 |
5844 0x03, // Type: RST_STREAM | 3973 0x03, // Type: RST_STREAM |
5845 0x00, // Flags: none | 3974 0x00, // Flags: none |
5846 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3975 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
5847 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 3976 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
5848 }; | 3977 }; |
5849 | |
5850 // clang-format off | |
5851 const unsigned char kV3RstStreamNumStatusCodes[] = { | |
5852 0x80, 0x03, 0x00, 0x03, | |
5853 0x00, 0x00, 0x00, 0x08, | |
5854 0x00, 0x00, 0x00, 0x01, | |
5855 0x00, 0x00, 0x00, kRstStreamStatusTooHigh | |
5856 }; | |
5857 // clang-format on | |
5858 const unsigned char kH2RstStreamNumStatusCodes[] = { | 3978 const unsigned char kH2RstStreamNumStatusCodes[] = { |
5859 0x00, 0x00, 0x04, // Length: 4 | 3979 0x00, 0x00, 0x04, // Length: 4 |
5860 0x03, // Type: RST_STREAM | 3980 0x03, // Type: RST_STREAM |
5861 0x00, // Flags: none | 3981 0x00, // Flags: none |
5862 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 3982 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
5863 0x00, 0x00, 0x00, 0xff, // Error: 255 | 3983 0x00, 0x00, 0x00, 0xff, // Error: 255 |
5864 }; | 3984 }; |
5865 | 3985 |
5866 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3986 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5867 SpdyFramer framer(spdy_version_); | 3987 SpdyFramer framer(spdy_version_); |
5868 framer.set_visitor(&visitor); | 3988 framer.set_visitor(&visitor); |
5869 | 3989 |
5870 if (IsSpdy3()) { | 3990 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); |
5871 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); | 3991 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamInvalid), |
5872 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), | 3992 arraysize(kH2RstStreamInvalid)); |
5873 arraysize(kV3RstStreamInvalid)); | |
5874 } else { | |
5875 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); | |
5876 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamInvalid), | |
5877 arraysize(kH2RstStreamInvalid)); | |
5878 } | |
5879 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 3993 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5880 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3994 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5881 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3995 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5882 | 3996 |
5883 framer.Reset(); | 3997 framer.Reset(); |
5884 | 3998 |
5885 if (IsSpdy3()) { | 3999 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); |
5886 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_NO_ERROR)); | 4000 framer.ProcessInput(reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), |
5887 framer.ProcessInput( | 4001 arraysize(kH2RstStreamNumStatusCodes)); |
5888 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), | |
5889 arraysize(kV3RstStreamNumStatusCodes)); | |
5890 } else { | |
5891 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR)); | |
5892 framer.ProcessInput( | |
5893 reinterpret_cast<const char*>(kH2RstStreamNumStatusCodes), | |
5894 arraysize(kH2RstStreamNumStatusCodes)); | |
5895 } | |
5896 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4002 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5897 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4003 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5898 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4004 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5899 } | 4005 } |
5900 | 4006 |
5901 // Test handling of GOAWAY frames with out-of-bounds status code. | 4007 // Test handling of GOAWAY frames with out-of-bounds status code. |
5902 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { | 4008 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { |
5903 SpdyFramer framer(spdy_version_); | 4009 SpdyFramer framer(spdy_version_); |
5904 | |
5905 // clang-format off | |
5906 const unsigned char kV3FrameData[] = { | |
5907 0x80, 0x03, 0x00, 0x07, | |
5908 0x00, 0x00, 0x00, 0x08, | |
5909 0x00, 0x00, 0x00, 0x01, // Stream Id | |
5910 0xff, 0xff, 0xff, 0xff, // Status | |
5911 }; | |
5912 // clang-format on | |
5913 const unsigned char kH2FrameData[] = { | 4010 const unsigned char kH2FrameData[] = { |
5914 0x00, 0x00, 0x0a, // Length: 10 | 4011 0x00, 0x00, 0x0a, // Length: 10 |
5915 0x07, // Type: GOAWAY | 4012 0x07, // Type: GOAWAY |
5916 0x00, // Flags: none | 4013 0x00, // Flags: none |
5917 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 4014 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
5918 0x00, 0x00, 0x00, 0x01, // Last: 1 | 4015 0x00, 0x00, 0x00, 0x01, // Last: 1 |
5919 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff | 4016 0xff, 0xff, 0xff, 0xff, // Error: 0xffffffff |
5920 0x47, 0x41, // Description | 4017 0x47, 0x41, // Description |
5921 }; | 4018 }; |
5922 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4019 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5923 framer.set_visitor(&visitor); | 4020 framer.set_visitor(&visitor); |
5924 | 4021 |
5925 if (IsSpdy3()) { | 4022 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_INTERNAL_ERROR)); |
5926 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_OK)); | 4023 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), |
5927 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), | 4024 arraysize(kH2FrameData)); |
5928 arraysize(kV3FrameData)); | |
5929 } else { | |
5930 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_INTERNAL_ERROR)); | |
5931 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), | |
5932 arraysize(kH2FrameData)); | |
5933 } | |
5934 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4025 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5935 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4026 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5936 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4027 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5937 } | 4028 } |
5938 | 4029 |
5939 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 4030 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
5940 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { | 4031 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
5941 // clang-format off | |
5942 const unsigned char kV3FrameData[] = { | |
5943 0x80, 0x03, 0x00, 0x07, | |
5944 0x00, 0x00, 0x00, 0x08, | |
5945 0xff, 0xff, 0xff, 0xff, | |
5946 0x00, 0x00, 0x00, 0x00, | |
5947 }; | |
5948 // clang-format on | |
5949 const unsigned char kH2FrameData[] = { | 4032 const unsigned char kH2FrameData[] = { |
5950 0x00, 0x00, 0x08, // Length: 8 | 4033 0x00, 0x00, 0x08, // Length: 8 |
5951 0x07, // Type: GOAWAY | 4034 0x07, // Type: GOAWAY |
5952 0x00, // Flags: none | 4035 0x00, // Flags: none |
5953 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 4036 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
5954 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) | 4037 0xff, 0xff, 0xff, 0xff, // Last: 0x7fffffff (R-bit set) |
5955 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 4038 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
5956 }; | 4039 }; |
5957 | 4040 |
5958 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4041 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5959 SpdyFramer framer(spdy_version_); | 4042 SpdyFramer framer(spdy_version_); |
5960 framer.set_visitor(&visitor); | 4043 framer.set_visitor(&visitor); |
5961 | 4044 |
5962 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); | 4045 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); |
5963 if (IsSpdy3()) { | 4046 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), |
5964 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), | 4047 arraysize(kH2FrameData)); |
5965 arraysize(kV3FrameData)); | |
5966 } else { | |
5967 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), | |
5968 arraysize(kH2FrameData)); | |
5969 } | |
5970 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4048 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5971 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4049 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5972 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4050 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5973 } | 4051 } |
5974 | 4052 |
5975 TEST_P(SpdyFramerTest, OnBlocked) { | 4053 TEST_P(SpdyFramerTest, OnBlocked) { |
5976 if (!IsHttp2()) { | |
5977 return; | |
5978 } | |
5979 | |
5980 const SpdyStreamId kStreamId = 0; | 4054 const SpdyStreamId kStreamId = 0; |
5981 | 4055 |
5982 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4056 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5983 SpdyFramer framer(spdy_version_); | 4057 SpdyFramer framer(spdy_version_); |
5984 framer.set_visitor(&visitor); | 4058 framer.set_visitor(&visitor); |
5985 | 4059 |
5986 EXPECT_CALL(visitor, OnBlocked(kStreamId)); | 4060 EXPECT_CALL(visitor, OnBlocked(kStreamId)); |
5987 | 4061 |
5988 SpdyBlockedIR blocked_ir(0); | 4062 SpdyBlockedIR blocked_ir(0); |
5989 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); | 4063 SpdySerializedFrame frame(framer.SerializeFrame(blocked_ir)); |
5990 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); | 4064 framer.ProcessInput(frame.data(), framer.GetBlockedSize()); |
5991 | 4065 |
5992 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4066 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5993 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4067 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5994 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4068 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5995 } | 4069 } |
5996 | 4070 |
5997 TEST_P(SpdyFramerTest, OnAltSvc) { | 4071 TEST_P(SpdyFramerTest, OnAltSvc) { |
5998 if (!IsHttp2()) { | |
5999 return; | |
6000 } | |
6001 | |
6002 const SpdyStreamId kStreamId = 1; | 4072 const SpdyStreamId kStreamId = 1; |
6003 | 4073 |
6004 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4074 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
6005 SpdyFramer framer(spdy_version_); | 4075 SpdyFramer framer(spdy_version_); |
6006 framer.set_visitor(&visitor); | 4076 framer.set_visitor(&visitor); |
6007 | 4077 |
6008 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4078 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
6009 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4079 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
6010 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4080 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
6011 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4081 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
6012 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4082 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
6013 altsvc_vector.push_back(altsvc1); | 4083 altsvc_vector.push_back(altsvc1); |
6014 altsvc_vector.push_back(altsvc2); | 4084 altsvc_vector.push_back(altsvc2); |
6015 EXPECT_CALL(visitor, | 4085 EXPECT_CALL(visitor, |
6016 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); | 4086 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); |
6017 | 4087 |
6018 SpdyAltSvcIR altsvc_ir(1); | 4088 SpdyAltSvcIR altsvc_ir(1); |
6019 altsvc_ir.set_origin("o_r|g!n"); | 4089 altsvc_ir.set_origin("o_r|g!n"); |
6020 altsvc_ir.add_altsvc(altsvc1); | 4090 altsvc_ir.add_altsvc(altsvc1); |
6021 altsvc_ir.add_altsvc(altsvc2); | 4091 altsvc_ir.add_altsvc(altsvc2); |
6022 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4092 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
6023 framer.ProcessInput(frame.data(), frame.size()); | 4093 framer.ProcessInput(frame.data(), frame.size()); |
6024 | 4094 |
6025 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4095 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
6026 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4096 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
6027 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4097 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
6028 } | 4098 } |
6029 | 4099 |
6030 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { | 4100 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
6031 if (!IsHttp2()) { | |
6032 return; | |
6033 } | |
6034 | |
6035 const SpdyStreamId kStreamId = 1; | 4101 const SpdyStreamId kStreamId = 1; |
6036 | 4102 |
6037 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4103 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
6038 SpdyFramer framer(spdy_version_); | 4104 SpdyFramer framer(spdy_version_); |
6039 framer.set_visitor(&visitor); | 4105 framer.set_visitor(&visitor); |
6040 | 4106 |
6041 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4107 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
6042 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4108 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
6043 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4109 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
6044 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4110 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
6045 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4111 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
6046 altsvc_vector.push_back(altsvc1); | 4112 altsvc_vector.push_back(altsvc1); |
6047 altsvc_vector.push_back(altsvc2); | 4113 altsvc_vector.push_back(altsvc2); |
6048 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); | 4114 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); |
6049 | 4115 |
6050 SpdyAltSvcIR altsvc_ir(1); | 4116 SpdyAltSvcIR altsvc_ir(1); |
6051 altsvc_ir.add_altsvc(altsvc1); | 4117 altsvc_ir.add_altsvc(altsvc1); |
6052 altsvc_ir.add_altsvc(altsvc2); | 4118 altsvc_ir.add_altsvc(altsvc2); |
6053 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4119 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
6054 framer.ProcessInput(frame.data(), frame.size()); | 4120 framer.ProcessInput(frame.data(), frame.size()); |
6055 | 4121 |
6056 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4122 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
6057 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4123 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
6058 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4124 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
6059 } | 4125 } |
6060 | 4126 |
6061 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { | 4127 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { |
6062 if (!IsHttp2()) { | |
6063 return; | |
6064 } | |
6065 | |
6066 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4128 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
6067 SpdyFramer framer(spdy_version_); | 4129 SpdyFramer framer(spdy_version_); |
6068 framer.set_visitor(&visitor); | 4130 framer.set_visitor(&visitor); |
6069 | 4131 |
6070 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 4132 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
6071 | 4133 |
6072 SpdyAltSvcIR altsvc_ir(1); | 4134 SpdyAltSvcIR altsvc_ir(1); |
6073 altsvc_ir.set_origin("o1"); | 4135 altsvc_ir.set_origin("o1"); |
6074 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4136 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
6075 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 4137 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
6076 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 4138 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
6077 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); | 4139 "", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector())); |
6078 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4140 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
6079 framer.ProcessInput(frame.data(), frame.size()); | 4141 framer.ProcessInput(frame.data(), frame.size()); |
6080 | 4142 |
6081 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4143 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
6082 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 4144 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
6083 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4145 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
6084 } | 4146 } |
6085 | 4147 |
6086 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { | 4148 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
6087 if (!IsHttp2()) { | |
6088 return; | |
6089 } | |
6090 | |
6091 const SpdyStreamId kStreamId = 1; | 4149 const SpdyStreamId kStreamId = 1; |
6092 | 4150 |
6093 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4151 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
6094 SpdyFramer framer(spdy_version_); | 4152 SpdyFramer framer(spdy_version_); |
6095 framer.set_visitor(&visitor); | 4153 framer.set_visitor(&visitor); |
6096 | 4154 |
6097 SpdyAltSvcWireFormat::AlternativeService altsvc( | 4155 SpdyAltSvcWireFormat::AlternativeService altsvc( |
6098 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); | 4156 "pid", "h1", 443, 10, SpdyAltSvcWireFormat::VersionVector()); |
6099 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 4157 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
6100 altsvc_vector.push_back(altsvc); | 4158 altsvc_vector.push_back(altsvc); |
6101 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); | 4159 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); |
6102 | 4160 |
6103 SpdyAltSvcIR altsvc_ir(1); | 4161 SpdyAltSvcIR altsvc_ir(1); |
6104 altsvc_ir.set_origin("o1"); | 4162 altsvc_ir.set_origin("o1"); |
6105 altsvc_ir.add_altsvc(altsvc); | 4163 altsvc_ir.add_altsvc(altsvc); |
6106 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); | 4164 SpdySerializedFrame frame(framer.SerializeFrame(altsvc_ir)); |
6107 framer.ProcessInput(frame.data(), frame.size()); | 4165 framer.ProcessInput(frame.data(), frame.size()); |
6108 | 4166 |
6109 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4167 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
6110 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4168 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
6111 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4169 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
6112 } | 4170 } |
6113 | 4171 |
6114 // Tests handling of ALTSVC frames delivered in small chunks. | 4172 // Tests handling of ALTSVC frames delivered in small chunks. |
6115 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 4173 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
6116 if (!IsHttp2()) { | |
6117 return; | |
6118 } | |
6119 | |
6120 SpdyFramer framer(spdy_version_); | 4174 SpdyFramer framer(spdy_version_); |
6121 SpdyAltSvcIR altsvc_ir(1); | 4175 SpdyAltSvcIR altsvc_ir(1); |
6122 SpdyAltSvcWireFormat::AlternativeService altsvc1( | 4176 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
6123 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); | 4177 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector()); |
6124 SpdyAltSvcWireFormat::AlternativeService altsvc2( | 4178 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
6125 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); | 4179 "p\"=i:d", "h_\\o\"st", 123, 42, SpdyAltSvcWireFormat::VersionVector{24}); |
6126 altsvc_ir.add_altsvc(altsvc1); | 4180 altsvc_ir.add_altsvc(altsvc1); |
6127 altsvc_ir.add_altsvc(altsvc2); | 4181 altsvc_ir.add_altsvc(altsvc2); |
6128 | 4182 |
6129 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); | 4183 SpdySerializedFrame control_frame(framer.SerializeAltSvc(altsvc_ir)); |
(...skipping 14 matching lines...) Expand all Loading... | |
6144 } | 4198 } |
6145 EXPECT_EQ(0, visitor.error_count_); | 4199 EXPECT_EQ(0, visitor.error_count_); |
6146 EXPECT_EQ(1, visitor.altsvc_count_); | 4200 EXPECT_EQ(1, visitor.altsvc_count_); |
6147 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); | 4201 ASSERT_EQ(2u, visitor.test_altsvc_ir_.altsvc_vector().size()); |
6148 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); | 4202 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[0] == altsvc1); |
6149 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); | 4203 EXPECT_TRUE(visitor.test_altsvc_ir_.altsvc_vector()[1] == altsvc2); |
6150 } | 4204 } |
6151 | 4205 |
6152 // Tests handling of PRIORITY frames. | 4206 // Tests handling of PRIORITY frames. |
6153 TEST_P(SpdyFramerTest, ReadPriority) { | 4207 TEST_P(SpdyFramerTest, ReadPriority) { |
6154 if (!IsHttp2()) { | |
6155 return; | |
6156 } | |
6157 | |
6158 SpdyFramer framer(spdy_version_); | 4208 SpdyFramer framer(spdy_version_); |
6159 SpdyPriorityIR priority(3, 1, 256, false); | 4209 SpdyPriorityIR priority(3, 1, 256, false); |
6160 SpdySerializedFrame frame(framer.SerializePriority(priority)); | 4210 SpdySerializedFrame frame(framer.SerializePriority(priority)); |
6161 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4211 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
6162 framer.set_visitor(&visitor); | 4212 framer.set_visitor(&visitor); |
6163 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); | 4213 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); |
6164 framer.ProcessInput(frame.data(), frame.size()); | 4214 framer.ProcessInput(frame.data(), frame.size()); |
6165 | 4215 |
6166 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4216 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
6167 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4217 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
6168 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4218 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
6169 // TODO(mlavan): once we actually maintain a priority tree, | 4219 // TODO(mlavan): once we actually maintain a priority tree, |
6170 // check that state is adjusted correctly. | 4220 // check that state is adjusted correctly. |
6171 } | 4221 } |
6172 | 4222 |
6173 // Tests handling of PRIORITY frame with incorrect size. | 4223 // Tests handling of PRIORITY frame with incorrect size. |
6174 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { | 4224 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
6175 if (!IsHttp2()) { | |
6176 return; | |
6177 } | |
6178 | |
6179 // PRIORITY frame of size 4, which isn't correct. | 4225 // PRIORITY frame of size 4, which isn't correct. |
6180 const unsigned char kFrameData[] = { | 4226 const unsigned char kFrameData[] = { |
6181 0x00, 0x00, 0x04, // Length: 4 | 4227 0x00, 0x00, 0x04, // Length: 4 |
6182 0x02, // Type: PRIORITY | 4228 0x02, // Type: PRIORITY |
6183 0x00, // Flags: none | 4229 0x00, // Flags: none |
6184 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4230 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
6185 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) | 4231 0x00, 0x00, 0x00, 0x01, // Priority (Truncated) |
6186 }; | 4232 }; |
6187 | 4233 |
6188 TestSpdyVisitor visitor(spdy_version_); | 4234 TestSpdyVisitor visitor(spdy_version_); |
6189 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4235 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
6190 | 4236 |
6191 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4237 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
6192 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4238 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
6193 visitor.framer_.error_code()) | 4239 visitor.framer_.error_code()) |
6194 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4240 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
6195 } | 4241 } |
6196 | 4242 |
6197 // Tests handling of PING frame with incorrect size. | 4243 // Tests handling of PING frame with incorrect size. |
6198 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPing) { | 4244 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPing) { |
6199 if (!IsHttp2()) { | |
6200 return; | |
6201 } | |
6202 | |
6203 // PING frame of size 4, which isn't correct. | 4245 // PING frame of size 4, which isn't correct. |
6204 const unsigned char kFrameData[] = { | 4246 const unsigned char kFrameData[] = { |
6205 0x00, 0x00, 0x04, // Length: 4 | 4247 0x00, 0x00, 0x04, // Length: 4 |
6206 0x06, // Type: PING | 4248 0x06, // Type: PING |
6207 0x00, // Flags: none | 4249 0x00, // Flags: none |
6208 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 4250 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
6209 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) | 4251 0x00, 0x00, 0x00, 0x01, // Ping (Truncated) |
6210 }; | 4252 }; |
6211 | 4253 |
6212 TestSpdyVisitor visitor(spdy_version_); | 4254 TestSpdyVisitor visitor(spdy_version_); |
6213 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4255 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
6214 | 4256 |
6215 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4257 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
6216 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4258 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
6217 visitor.framer_.error_code()) | 4259 visitor.framer_.error_code()) |
6218 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4260 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
6219 } | 4261 } |
6220 | 4262 |
6221 // Tests handling of WINDOW_UPDATE frame with incorrect size. | 4263 // Tests handling of WINDOW_UPDATE frame with incorrect size. |
6222 TEST_P(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { | 4264 TEST_P(SpdyFramerTest, ReadIncorrectlySizedWindowUpdate) { |
6223 if (!IsHttp2()) { | |
6224 return; | |
6225 } | |
6226 | |
6227 // WINDOW_UPDATE frame of size 3, which isn't correct. | 4265 // WINDOW_UPDATE frame of size 3, which isn't correct. |
6228 const unsigned char kFrameData[] = { | 4266 const unsigned char kFrameData[] = { |
6229 0x00, 0x00, 0x03, // Length: 3 | 4267 0x00, 0x00, 0x03, // Length: 3 |
6230 0x08, // Type: WINDOW_UPDATE | 4268 0x08, // Type: WINDOW_UPDATE |
6231 0x00, // Flags: none | 4269 0x00, // Flags: none |
6232 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4270 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
6233 0x00, 0x00, 0x01, // WindowUpdate (Truncated) | 4271 0x00, 0x00, 0x01, // WindowUpdate (Truncated) |
6234 }; | 4272 }; |
6235 | 4273 |
6236 TestSpdyVisitor visitor(spdy_version_); | 4274 TestSpdyVisitor visitor(spdy_version_); |
6237 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 4275 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
6238 | 4276 |
6239 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 4277 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
6240 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 4278 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
6241 visitor.framer_.error_code()) | 4279 visitor.framer_.error_code()) |
6242 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 4280 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
6243 } | 4281 } |
6244 | 4282 |
6245 // Tests handling of RST_STREAM frame with incorrect size. | 4283 // Tests handling of RST_STREAM frame with incorrect size. |
6246 TEST_P(SpdyFramerTest, ReadIncorrectlySizedRstStream) { | 4284 TEST_P(SpdyFramerTest, ReadIncorrectlySizedRstStream) { |
6247 if (!IsHttp2()) { | |
6248 return; | |
6249 } | |
6250 | |
6251 // RST_STREAM frame of size 3, which isn't correct. | 4285 // RST_STREAM frame of size 3, which isn't correct. |
6252 const unsigned char kFrameData[] = { | 4286 const unsigned char kFrameData[] = { |
6253 0x00, 0x00, 0x03, // Length: 3 | 4287 0x00, 0x00, 0x03, // Length: 3 |
6254 0x03, // Type: RST_STREAM | 4288 0x03, // Type: RST_STREAM |
6255 0x00, // Flags: none | 4289 0x00, // Flags: none |
6256 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4290 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
6257 0x00, 0x00, 0x01, // RstStream (Truncated) | 4291 0x00, 0x00, 0x01, // RstStream (Truncated) |
6258 }; | 4292 }; |
6259 | 4293 |
6260 TestSpdyVisitor visitor(spdy_version_); | 4294 TestSpdyVisitor visitor(spdy_version_); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6392 | 4426 |
6393 EXPECT_EQ(1, visitor->data_frame_count_); | 4427 EXPECT_EQ(1, visitor->data_frame_count_); |
6394 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4428 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
6395 EXPECT_EQ(0, visitor->headers_frame_count_); | 4429 EXPECT_EQ(0, visitor->headers_frame_count_); |
6396 } | 4430 } |
6397 } | 4431 } |
6398 | 4432 |
6399 } // namespace test | 4433 } // namespace test |
6400 | 4434 |
6401 } // namespace net | 4435 } // namespace net |
OLD | NEW |