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 <algorithm> | 5 #include <algorithm> |
6 #include <iostream> | 6 #include <iostream> |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 LOG(ERROR) << "Expected header named '" << it->first | 657 LOG(ERROR) << "Expected header named '" << it->first |
658 << "' to have a value of '" << it->second | 658 << "' to have a value of '" << it->second |
659 << "'. The actual value received was '" << it2->second | 659 << "'. The actual value received was '" << it2->second |
660 << "'."; | 660 << "'."; |
661 return false; | 661 return false; |
662 } | 662 } |
663 } | 663 } |
664 return true; | 664 return true; |
665 } | 665 } |
666 | 666 |
667 bool IsSpdy2() { return spdy_version_ == SPDY2; } | |
668 bool IsSpdy3() { return spdy_version_ == SPDY3; } | 667 bool IsSpdy3() { return spdy_version_ == SPDY3; } |
669 bool IsSpdy4() { return spdy_version_ == SPDY4; } | 668 bool IsSpdy4() { return spdy_version_ == SPDY4; } |
670 bool IsSpdy5() { return spdy_version_ == SPDY5; } | 669 bool IsSpdy5() { return spdy_version_ == SPDY5; } |
671 | 670 |
672 // Version of SPDY protocol to be used. | 671 // Version of SPDY protocol to be used. |
673 SpdyMajorVersion spdy_version_; | 672 SpdyMajorVersion spdy_version_; |
674 unsigned char spdy_version_ch_; | 673 unsigned char spdy_version_ch_; |
675 }; | 674 }; |
676 | 675 |
677 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. | |
678 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | 676 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, |
679 SpdyFramerTest, | 677 SpdyFramerTest, |
680 ::testing::Values(SPDY2, SPDY3, SPDY4)); | 678 ::testing::Values(SPDY3, SPDY4)); |
681 | 679 |
682 // Test that we ignore cookie where both name and value are empty. | 680 // Test that we ignore cookie where both name and value are empty. |
683 TEST_P(SpdyFramerTest, HeaderBlockWithEmptyCookie) { | 681 TEST_P(SpdyFramerTest, HeaderBlockWithEmptyCookie) { |
684 if (spdy_version_ > SPDY3) { | 682 if (spdy_version_ > SPDY3) { |
685 // Not implemented for hpack. | 683 // Not implemented for hpack. |
686 return; | 684 return; |
687 } | 685 } |
688 | 686 |
689 SpdyFramer framer(spdy_version_); | 687 SpdyFramer framer(spdy_version_); |
690 framer.set_enable_compression(true); | 688 framer.set_enable_compression(true); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 if (spdy_version_ <= SPDY3) { | 860 if (spdy_version_ <= SPDY3) { |
863 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 861 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); |
864 frame.WriteUInt32(3); // stream_id | 862 frame.WriteUInt32(3); // stream_id |
865 frame.WriteUInt32(0); // associated stream id | 863 frame.WriteUInt32(0); // associated stream id |
866 frame.WriteUInt16(0); // Priority. | 864 frame.WriteUInt16(0); // Priority. |
867 } else { | 865 } else { |
868 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); | 866 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); |
869 frame.WriteUInt32(framer.GetHighestPriority()); | 867 frame.WriteUInt32(framer.GetHighestPriority()); |
870 } | 868 } |
871 | 869 |
872 if (IsSpdy2()) { | 870 frame.WriteUInt32(2); // Number of headers. |
873 frame.WriteUInt16(2); // Number of headers. | 871 frame.WriteStringPiece32("name"); |
874 frame.WriteString("name"); | 872 frame.WriteStringPiece32("value1"); |
875 frame.WriteString("value1"); | 873 frame.WriteStringPiece32("name"); |
876 frame.WriteString("name"); | 874 frame.WriteStringPiece32("value2"); |
877 frame.WriteString("value2"); | |
878 } else { | |
879 frame.WriteUInt32(2); // Number of headers. | |
880 frame.WriteStringPiece32("name"); | |
881 frame.WriteStringPiece32("value1"); | |
882 frame.WriteStringPiece32("name"); | |
883 frame.WriteStringPiece32("value2"); | |
884 } | |
885 // write the length | 875 // write the length |
886 frame.RewriteLength(framer); | 876 frame.RewriteLength(framer); |
887 | 877 |
888 SpdyHeaderBlock new_headers; | 878 SpdyHeaderBlock new_headers; |
889 framer.set_enable_compression(false); | 879 framer.set_enable_compression(false); |
890 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 880 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
891 base::StringPiece serialized_headers = | 881 base::StringPiece serialized_headers = |
892 GetSerializedHeaders(control_frame.get(), framer); | 882 GetSerializedHeaders(control_frame.get(), framer); |
893 // This should fail because duplicate headers are verboten by the spec. | 883 // This should fail because duplicate headers are verboten by the spec. |
894 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 884 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
(...skipping 13 matching lines...) Expand all Loading... | |
908 } else { | 898 } else { |
909 frame.BeginNewFrame(framer, | 899 frame.BeginNewFrame(framer, |
910 HEADERS, | 900 HEADERS, |
911 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, | 901 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, |
912 3); | 902 3); |
913 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. | 903 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. |
914 frame.WriteUInt8(255); // Priority weight. | 904 frame.WriteUInt8(255); // Priority weight. |
915 } | 905 } |
916 | 906 |
917 string value("value1\0value2", 13); | 907 string value("value1\0value2", 13); |
918 if (IsSpdy2()) { | 908 if (spdy_version_ > SPDY3) { |
919 frame.WriteUInt16(1); // Number of headers. | |
920 frame.WriteString("name"); | |
921 frame.WriteString(value); | |
922 } else if (spdy_version_ > SPDY3) { | |
923 // TODO(jgraettinger): If this pattern appears again, move to test class. | 909 // TODO(jgraettinger): If this pattern appears again, move to test class. |
924 std::map<string, string> header_set; | 910 std::map<string, string> header_set; |
925 header_set["name"] = value; | 911 header_set["name"] = value; |
926 string buffer; | 912 string buffer; |
927 HpackEncoder encoder(ObtainHpackHuffmanTable()); | 913 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
928 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); | 914 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); |
929 frame.WriteBytes(&buffer[0], buffer.size()); | 915 frame.WriteBytes(&buffer[0], buffer.size()); |
930 } else { | 916 } else { |
931 frame.WriteUInt32(1); // Number of headers. | 917 frame.WriteUInt32(1); // Number of headers. |
932 frame.WriteStringPiece32("name"); | 918 frame.WriteStringPiece32("name"); |
(...skipping 28 matching lines...) Expand all Loading... | |
961 syn_stream.SetHeader("server", "SpdyServer 1.0"); | 947 syn_stream.SetHeader("server", "SpdyServer 1.0"); |
962 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 948 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
963 syn_stream.SetHeader("status", "200"); | 949 syn_stream.SetHeader("status", "200"); |
964 syn_stream.SetHeader("version", "HTTP/1.1"); | 950 syn_stream.SetHeader("version", "HTTP/1.1"); |
965 syn_stream.SetHeader("content-type", "text/html"); | 951 syn_stream.SetHeader("content-type", "text/html"); |
966 syn_stream.SetHeader("content-length", "12"); | 952 syn_stream.SetHeader("content-length", "12"); |
967 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); | 953 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); |
968 size_t uncompressed_size1 = visitor->last_payload_len_; | 954 size_t uncompressed_size1 = visitor->last_payload_len_; |
969 size_t compressed_size1 = | 955 size_t compressed_size1 = |
970 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 956 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
971 if (IsSpdy2()) { | 957 EXPECT_EQ(165u, uncompressed_size1); |
972 EXPECT_EQ(139u, uncompressed_size1); | |
973 #if defined(USE_SYSTEM_ZLIB) | 958 #if defined(USE_SYSTEM_ZLIB) |
974 EXPECT_EQ(155u, compressed_size1); | 959 EXPECT_EQ(181u, compressed_size1); |
975 #else // !defined(USE_SYSTEM_ZLIB) | 960 #else // !defined(USE_SYSTEM_ZLIB) |
976 EXPECT_EQ(135u, compressed_size1); | 961 EXPECT_EQ(117u, compressed_size1); |
977 #endif // !defined(USE_SYSTEM_ZLIB) | 962 #endif // !defined(USE_SYSTEM_ZLIB) |
978 } else { | |
979 EXPECT_EQ(165u, uncompressed_size1); | |
980 #if defined(USE_SYSTEM_ZLIB) | |
981 EXPECT_EQ(181u, compressed_size1); | |
982 #else // !defined(USE_SYSTEM_ZLIB) | |
983 EXPECT_EQ(117u, compressed_size1); | |
984 #endif // !defined(USE_SYSTEM_ZLIB) | |
985 } | |
986 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); | 963 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); |
987 size_t uncompressed_size2 = visitor->last_payload_len_; | 964 size_t uncompressed_size2 = visitor->last_payload_len_; |
988 size_t compressed_size2 = | 965 size_t compressed_size2 = |
989 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 966 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
990 | 967 |
991 // Expect the second frame to be more compact than the first. | 968 // Expect the second frame to be more compact than the first. |
992 EXPECT_LE(frame2->size(), frame1->size()); | 969 EXPECT_LE(frame2->size(), frame1->size()); |
993 | 970 |
994 // Decompress the first frame | 971 // Decompress the first frame |
995 scoped_ptr<SpdyFrame> frame3( | 972 scoped_ptr<SpdyFrame> frame3( |
996 SpdyFramerTestUtil::DecompressFrame(&framer, *frame1)); | 973 SpdyFramerTestUtil::DecompressFrame(&framer, *frame1)); |
997 | 974 |
998 // Decompress the second frame | 975 // Decompress the second frame |
999 visitor.reset(new TestSpdyVisitor(spdy_version_)); | 976 visitor.reset(new TestSpdyVisitor(spdy_version_)); |
1000 framer.set_debug_visitor(visitor.get()); | 977 framer.set_debug_visitor(visitor.get()); |
1001 scoped_ptr<SpdyFrame> frame4( | 978 scoped_ptr<SpdyFrame> frame4( |
1002 SpdyFramerTestUtil::DecompressFrame(&framer, *frame2)); | 979 SpdyFramerTestUtil::DecompressFrame(&framer, *frame2)); |
1003 size_t uncompressed_size4 = | 980 size_t uncompressed_size4 = |
1004 frame4->size() - framer.GetSynStreamMinimumSize(); | 981 frame4->size() - framer.GetSynStreamMinimumSize(); |
1005 size_t compressed_size4 = | 982 size_t compressed_size4 = |
1006 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 983 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
1007 if (IsSpdy2()) { | 984 EXPECT_EQ(165u, uncompressed_size4); |
1008 EXPECT_EQ(139u, uncompressed_size4); | |
1009 #if defined(USE_SYSTEM_ZLIB) | 985 #if defined(USE_SYSTEM_ZLIB) |
1010 EXPECT_EQ(149u, compressed_size4); | 986 EXPECT_EQ(175u, compressed_size4); |
1011 #else // !defined(USE_SYSTEM_ZLIB) | 987 #else // !defined(USE_SYSTEM_ZLIB) |
1012 EXPECT_EQ(101u, compressed_size4); | 988 EXPECT_EQ(102u, compressed_size4); |
1013 #endif // !defined(USE_SYSTEM_ZLIB) | 989 #endif // !defined(USE_SYSTEM_ZLIB) |
1014 } else { | |
1015 EXPECT_EQ(165u, uncompressed_size4); | |
1016 #if defined(USE_SYSTEM_ZLIB) | |
1017 EXPECT_EQ(175u, compressed_size4); | |
1018 #else // !defined(USE_SYSTEM_ZLIB) | |
1019 EXPECT_EQ(102u, compressed_size4); | |
1020 #endif // !defined(USE_SYSTEM_ZLIB) | |
1021 } | |
1022 | 990 |
1023 EXPECT_EQ(uncompressed_size1, uncompressed_size2); | 991 EXPECT_EQ(uncompressed_size1, uncompressed_size2); |
1024 EXPECT_EQ(uncompressed_size1, uncompressed_size4); | 992 EXPECT_EQ(uncompressed_size1, uncompressed_size4); |
1025 EXPECT_EQ(compressed_size2, compressed_size4); | 993 EXPECT_EQ(compressed_size2, compressed_size4); |
1026 | 994 |
1027 // Expect frames 3 & 4 to be the same. | 995 // Expect frames 3 & 4 to be the same. |
1028 CompareFrames("Uncompressed SYN_STREAM", *frame3, *frame4); | 996 CompareFrames("Uncompressed SYN_STREAM", *frame3, *frame4); |
1029 | 997 |
1030 // Expect frames 3 to be the same as a uncompressed frame created | 998 // Expect frames 3 to be the same as a uncompressed frame created |
1031 // from scratch. | 999 // from scratch. |
(...skipping 13 matching lines...) Expand all Loading... | |
1045 headers.SetHeader("content-type", "text/html"); | 1013 headers.SetHeader("content-type", "text/html"); |
1046 headers.SetHeader("content-length", "12"); | 1014 headers.SetHeader("content-length", "12"); |
1047 headers.SetHeader("x-empty-header", ""); | 1015 headers.SetHeader("x-empty-header", ""); |
1048 | 1016 |
1049 SpdyFramer framer(spdy_version_); | 1017 SpdyFramer framer(spdy_version_); |
1050 framer.set_enable_compression(true); | 1018 framer.set_enable_compression(true); |
1051 scoped_ptr<SpdyFrame> frame1(framer.SerializeHeaders(headers)); | 1019 scoped_ptr<SpdyFrame> frame1(framer.SerializeHeaders(headers)); |
1052 } | 1020 } |
1053 | 1021 |
1054 TEST_P(SpdyFramerTest, Basic) { | 1022 TEST_P(SpdyFramerTest, Basic) { |
1055 const unsigned char kV2Input[] = { | |
1056 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | |
1057 0x00, 0x00, 0x00, 0x14, | |
1058 0x00, 0x00, 0x00, 0x01, | |
1059 0x00, 0x00, 0x00, 0x00, | |
1060 0x00, 0x00, 0x00, 0x01, | |
1061 0x00, 0x02, 'h', 'h', | |
1062 0x00, 0x02, 'v', 'v', | |
1063 | |
1064 0x80, spdy_version_ch_, 0x00, 0x08, // HEADERS on Stream #1 | |
1065 0x00, 0x00, 0x00, 0x18, | |
1066 0x00, 0x00, 0x00, 0x01, | |
1067 0x00, 0x00, 0x00, 0x02, | |
1068 0x00, 0x02, 'h', '2', | |
1069 0x00, 0x02, 'v', '2', | |
1070 0x00, 0x02, 'h', '3', | |
1071 0x00, 0x02, 'v', '3', | |
1072 | |
1073 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
1074 0x00, 0x00, 0x00, 0x0c, | |
1075 0xde, 0xad, 0xbe, 0xef, | |
1076 0xde, 0xad, 0xbe, 0xef, | |
1077 0xde, 0xad, 0xbe, 0xef, | |
1078 | |
1079 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #3 | |
1080 0x00, 0x00, 0x00, 0x0c, | |
1081 0x00, 0x00, 0x00, 0x03, | |
1082 0x00, 0x00, 0x00, 0x00, | |
1083 0x00, 0x00, 0x00, 0x00, | |
1084 | |
1085 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | |
1086 0x00, 0x00, 0x00, 0x08, | |
1087 0xde, 0xad, 0xbe, 0xef, | |
1088 0xde, 0xad, 0xbe, 0xef, | |
1089 | |
1090 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
1091 0x00, 0x00, 0x00, 0x04, | |
1092 0xde, 0xad, 0xbe, 0xef, | |
1093 | |
1094 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | |
1095 0x00, 0x00, 0x00, 0x08, | |
1096 0x00, 0x00, 0x00, 0x01, | |
1097 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
1098 | |
1099 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | |
1100 0x00, 0x00, 0x00, 0x00, | |
1101 | |
1102 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | |
1103 0x00, 0x00, 0x00, 0x08, | |
1104 0x00, 0x00, 0x00, 0x03, | |
1105 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
1106 }; | |
1107 | |
1108 const unsigned char kV3Input[] = { | 1023 const unsigned char kV3Input[] = { |
1109 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1024 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
1110 0x00, 0x00, 0x00, 0x1a, | 1025 0x00, 0x00, 0x00, 0x1a, |
1111 0x00, 0x00, 0x00, 0x01, | 1026 0x00, 0x00, 0x00, 0x01, |
1112 0x00, 0x00, 0x00, 0x00, | 1027 0x00, 0x00, 0x00, 0x00, |
1113 0x00, 0x00, 0x00, 0x00, | 1028 0x00, 0x00, 0x00, 0x00, |
1114 0x00, 0x01, 0x00, 0x00, | 1029 0x00, 0x01, 0x00, 0x00, |
1115 0x00, 0x02, 'h', 'h', | 1030 0x00, 0x02, 'h', 'h', |
1116 0x00, 0x00, 0x00, 0x02, | 1031 0x00, 0x00, 0x00, 0x02, |
1117 'v', 'v', | 1032 'v', 'v', |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1210 | 1125 |
1211 0x00, 0x00, 0x0f, 0x03, // RST_STREAM on Stream #3 | 1126 0x00, 0x00, 0x0f, 0x03, // RST_STREAM on Stream #3 |
1212 0x00, 0x00, 0x00, 0x00, | 1127 0x00, 0x00, 0x00, 0x00, |
1213 0x03, 0x00, 0x00, 0x00, // RST_STREAM_CANCEL | 1128 0x03, 0x00, 0x00, 0x00, // RST_STREAM_CANCEL |
1214 0x08, 0x52, 0x45, 0x53, // opaque data | 1129 0x08, 0x52, 0x45, 0x53, // opaque data |
1215 0x45, 0x54, 0x53, 0x54, | 1130 0x45, 0x54, 0x53, 0x54, |
1216 0x52, 0x45, 0x41, 0x4d, | 1131 0x52, 0x45, 0x41, 0x4d, |
1217 }; | 1132 }; |
1218 | 1133 |
1219 TestSpdyVisitor visitor(spdy_version_); | 1134 TestSpdyVisitor visitor(spdy_version_); |
1220 if (IsSpdy2()) { | 1135 if (IsSpdy3()) { |
1221 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | |
1222 } else if (IsSpdy3()) { | |
1223 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1136 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
1224 } else { | 1137 } else { |
1225 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); | 1138 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); |
1226 } | 1139 } |
1227 | 1140 |
1228 EXPECT_EQ(2, visitor.syn_frame_count_); | 1141 EXPECT_EQ(2, visitor.syn_frame_count_); |
1229 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 1142 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1230 EXPECT_EQ(1, visitor.headers_frame_count_); | 1143 EXPECT_EQ(1, visitor.headers_frame_count_); |
1231 EXPECT_EQ(24, visitor.data_bytes_); | 1144 EXPECT_EQ(24, visitor.data_bytes_); |
1232 | 1145 |
1233 EXPECT_EQ(0, visitor.error_count_); | 1146 EXPECT_EQ(0, visitor.error_count_); |
1234 EXPECT_EQ(2, visitor.fin_frame_count_); | 1147 EXPECT_EQ(2, visitor.fin_frame_count_); |
1235 | 1148 |
1236 if (IsSpdy4()) { | 1149 if (IsSpdy4()) { |
1237 base::StringPiece reset_stream = "RESETSTREAM"; | 1150 base::StringPiece reset_stream = "RESETSTREAM"; |
1238 EXPECT_EQ(reset_stream, visitor.fin_opaque_data_); | 1151 EXPECT_EQ(reset_stream, visitor.fin_opaque_data_); |
1239 } else { | 1152 } else { |
1240 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); | 1153 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); |
1241 } | 1154 } |
1242 | 1155 |
1243 EXPECT_EQ(0, visitor.fin_flag_count_); | 1156 EXPECT_EQ(0, visitor.fin_flag_count_); |
1244 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 1157 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
1245 EXPECT_EQ(4, visitor.data_frame_count_); | 1158 EXPECT_EQ(4, visitor.data_frame_count_); |
1246 visitor.fin_opaque_data_.clear(); | 1159 visitor.fin_opaque_data_.clear(); |
1247 } | 1160 } |
1248 | 1161 |
1249 // Test that the FIN flag on a data frame signifies EOF. | 1162 // Test that the FIN flag on a data frame signifies EOF. |
1250 TEST_P(SpdyFramerTest, FinOnDataFrame) { | 1163 TEST_P(SpdyFramerTest, FinOnDataFrame) { |
1251 const unsigned char kV2Input[] = { | |
1252 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | |
1253 0x00, 0x00, 0x00, 0x14, | |
1254 0x00, 0x00, 0x00, 0x01, | |
1255 0x00, 0x00, 0x00, 0x00, | |
1256 0x00, 0x00, 0x00, 0x01, | |
1257 0x00, 0x02, 'h', 'h', | |
1258 0x00, 0x02, 'v', 'v', | |
1259 | |
1260 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 | |
1261 0x00, 0x00, 0x00, 0x10, | |
1262 0x00, 0x00, 0x00, 0x01, | |
1263 0x00, 0x00, 0x00, 0x01, | |
1264 0x00, 0x02, 'a', 'a', | |
1265 0x00, 0x02, 'b', 'b', | |
1266 | |
1267 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
1268 0x00, 0x00, 0x00, 0x0c, | |
1269 0xde, 0xad, 0xbe, 0xef, | |
1270 0xde, 0xad, 0xbe, 0xef, | |
1271 0xde, 0xad, 0xbe, 0xef, | |
1272 | |
1273 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF | |
1274 0x01, 0x00, 0x00, 0x04, | |
1275 0xde, 0xad, 0xbe, 0xef, | |
1276 }; | |
1277 const unsigned char kV3Input[] = { | 1164 const unsigned char kV3Input[] = { |
1278 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1165 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
1279 0x00, 0x00, 0x00, 0x1a, | 1166 0x00, 0x00, 0x00, 0x1a, |
1280 0x00, 0x00, 0x00, 0x01, | 1167 0x00, 0x00, 0x00, 0x01, |
1281 0x00, 0x00, 0x00, 0x00, | 1168 0x00, 0x00, 0x00, 0x00, |
1282 0x00, 0x00, 0x00, 0x00, | 1169 0x00, 0x00, 0x00, 0x00, |
1283 0x00, 0x01, 0x00, 0x00, | 1170 0x00, 0x01, 0x00, 0x00, |
1284 0x00, 0x02, 'h', 'h', | 1171 0x00, 0x02, 'h', 'h', |
1285 0x00, 0x00, 0x00, 0x02, | 1172 0x00, 0x00, 0x00, 0x02, |
1286 'v', 'v', | 1173 'v', 'v', |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1323 0xef, 0xde, 0xad, 0xbe, | 1210 0xef, 0xde, 0xad, 0xbe, |
1324 0xef, | 1211 0xef, |
1325 | 1212 |
1326 0x00, 0x00, 0x04, 0x00, // DATA on Stream #1, with FIN | 1213 0x00, 0x00, 0x04, 0x00, // DATA on Stream #1, with FIN |
1327 0x01, 0x00, 0x00, 0x00, | 1214 0x01, 0x00, 0x00, 0x00, |
1328 0x01, 0xde, 0xad, 0xbe, | 1215 0x01, 0xde, 0xad, 0xbe, |
1329 0xef, | 1216 0xef, |
1330 }; | 1217 }; |
1331 | 1218 |
1332 TestSpdyVisitor visitor(spdy_version_); | 1219 TestSpdyVisitor visitor(spdy_version_); |
1333 if (IsSpdy2()) { | 1220 if (IsSpdy3()) { |
1334 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | |
1335 } else if (IsSpdy3()) { | |
1336 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1221 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
1337 } else { | 1222 } else { |
1338 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); | 1223 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); |
1339 } | 1224 } |
1340 | 1225 |
1341 EXPECT_EQ(0, visitor.error_count_); | 1226 EXPECT_EQ(0, visitor.error_count_); |
1342 EXPECT_EQ(1, visitor.syn_frame_count_); | 1227 EXPECT_EQ(1, visitor.syn_frame_count_); |
1343 if (IsSpdy4()) { | 1228 if (IsSpdy4()) { |
1344 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 1229 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1345 EXPECT_EQ(1, visitor.headers_frame_count_); | 1230 EXPECT_EQ(1, visitor.headers_frame_count_); |
1346 } else { | 1231 } else { |
1347 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | 1232 EXPECT_EQ(1, visitor.syn_reply_frame_count_); |
1348 EXPECT_EQ(0, visitor.headers_frame_count_); | 1233 EXPECT_EQ(0, visitor.headers_frame_count_); |
1349 } | 1234 } |
1350 EXPECT_EQ(16, visitor.data_bytes_); | 1235 EXPECT_EQ(16, visitor.data_bytes_); |
1351 EXPECT_EQ(0, visitor.fin_frame_count_); | 1236 EXPECT_EQ(0, visitor.fin_frame_count_); |
1352 EXPECT_EQ(0, visitor.fin_flag_count_); | 1237 EXPECT_EQ(0, visitor.fin_flag_count_); |
1353 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1238 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
1354 EXPECT_EQ(2, visitor.data_frame_count_); | 1239 EXPECT_EQ(2, visitor.data_frame_count_); |
1355 } | 1240 } |
1356 | 1241 |
1357 // Test that the FIN flag on a SYN reply frame signifies EOF. | 1242 // Test that the FIN flag on a SYN reply frame signifies EOF. |
1358 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { | 1243 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { |
1359 const unsigned char kV2Input[] = { | |
1360 0x80, spdy_version_ch_, 0x00, // SYN Stream #1 | |
1361 0x01, 0x00, 0x00, 0x00, | |
1362 0x14, 0x00, 0x00, 0x00, | |
1363 0x01, 0x00, 0x00, 0x00, | |
1364 0x00, 0x00, 0x00, 0x00, | |
1365 0x01, 0x00, 0x02, 'h', | |
1366 'h', 0x00, 0x02, 'v', | |
1367 'v', | |
1368 | |
1369 0x80, spdy_version_ch_, 0x00, // SYN REPLY Stream #1 | |
1370 0x02, 0x01, 0x00, 0x00, | |
1371 0x10, 0x00, 0x00, 0x00, | |
1372 0x01, 0x00, 0x00, 0x00, | |
1373 0x01, 0x00, 0x02, 'a', | |
1374 'a', 0x00, 0x02, 'b', | |
1375 'b', | |
1376 }; | |
1377 const unsigned char kV3Input[] = { | 1244 const unsigned char kV3Input[] = { |
1378 0x80, spdy_version_ch_, 0x00, // SYN Stream #1 | 1245 0x80, spdy_version_ch_, 0x00, // SYN Stream #1 |
1379 0x01, 0x00, 0x00, 0x00, | 1246 0x01, 0x00, 0x00, 0x00, |
1380 0x1a, 0x00, 0x00, 0x00, | 1247 0x1a, 0x00, 0x00, 0x00, |
1381 0x01, 0x00, 0x00, 0x00, | 1248 0x01, 0x00, 0x00, 0x00, |
1382 0x00, 0x00, 0x00, 0x00, | 1249 0x00, 0x00, 0x00, 0x00, |
1383 0x00, 0x00, 0x01, 0x00, | 1250 0x00, 0x00, 0x01, 0x00, |
1384 0x00, 0x00, 0x02, 'h', | 1251 0x00, 0x00, 0x02, 'h', |
1385 'h', 0x00, 0x00, 0x00, | 1252 'h', 0x00, 0x00, 0x00, |
1386 0x02, 'v', 'v', | 1253 0x02, 'v', 'v', |
(...skipping 15 matching lines...) Expand all Loading... | |
1402 0x24, 0x00, 0x00, 0x00, | 1269 0x24, 0x00, 0x00, 0x00, |
1403 0x01, 0x00, 0x00, 0x00, // Stream 1, Priority 0 | 1270 0x01, 0x00, 0x00, 0x00, // Stream 1, Priority 0 |
1404 0x00, 0x82, // :method: GET | 1271 0x00, 0x82, // :method: GET |
1405 | 1272 |
1406 0x00, 0x00, 0x01, 0x01, // HEADERS: FIN | END_HEADERS | 1273 0x00, 0x00, 0x01, 0x01, // HEADERS: FIN | END_HEADERS |
1407 0x05, 0x00, 0x00, 0x00, | 1274 0x05, 0x00, 0x00, 0x00, |
1408 0x01, 0x8c, // Stream 1, :status: 200 | 1275 0x01, 0x8c, // Stream 1, :status: 200 |
1409 }; | 1276 }; |
1410 | 1277 |
1411 TestSpdyVisitor visitor(spdy_version_); | 1278 TestSpdyVisitor visitor(spdy_version_); |
1412 if (IsSpdy2()) { | 1279 if (IsSpdy3()) { |
1413 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | |
1414 } else if (IsSpdy3()) { | |
1415 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1280 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
1416 } else { | 1281 } else { |
1417 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); | 1282 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); |
1418 } | 1283 } |
1419 | 1284 |
1420 EXPECT_EQ(0, visitor.error_count_); | 1285 EXPECT_EQ(0, visitor.error_count_); |
1421 EXPECT_EQ(1, visitor.syn_frame_count_); | 1286 EXPECT_EQ(1, visitor.syn_frame_count_); |
1422 if (IsSpdy4()) { | 1287 if (IsSpdy4()) { |
1423 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 1288 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1424 EXPECT_EQ(1, visitor.headers_frame_count_); | 1289 EXPECT_EQ(1, visitor.headers_frame_count_); |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1876 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | 1741 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); |
1877 | 1742 |
1878 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); | 1743 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); |
1879 data_ir.set_fin(true); | 1744 data_ir.set_fin(true); |
1880 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1745 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1881 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); | 1746 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); |
1882 } | 1747 } |
1883 } | 1748 } |
1884 | 1749 |
1885 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { | 1750 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { |
1886 if (!IsSpdy2() && !IsSpdy3()) { | 1751 if (!IsSpdy3()) { |
1887 // SYN_STREAM unsupported in SPDY>3 | 1752 // SYN_STREAM unsupported in SPDY>3 |
1888 return; | 1753 return; |
1889 } | 1754 } |
1890 SpdyFramer framer(spdy_version_); | 1755 SpdyFramer framer(spdy_version_); |
1891 framer.set_enable_compression(false); | 1756 framer.set_enable_compression(false); |
1892 | 1757 |
1893 { | 1758 { |
1894 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; | 1759 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; |
1895 | 1760 const unsigned char kPri = 0xE0; |
1896 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; | |
1897 const unsigned char kV2FrameData[] = { | |
1898 0x80, spdy_version_ch_, 0x00, 0x01, | |
1899 0x00, 0x00, 0x00, 0x20, | |
1900 0x00, 0x00, 0x00, 0x01, | |
1901 0x00, 0x00, 0x00, 0x00, | |
1902 kPri, 0x00, 0x00, 0x02, | |
1903 0x00, 0x03, 'b', 'a', | |
1904 'r', 0x00, 0x03, 'f', | |
1905 'o', 'o', 0x00, 0x03, | |
1906 'f', 'o', 'o', 0x00, | |
1907 0x03, 'b', 'a', 'r' | |
1908 }; | |
1909 const unsigned char kV3FrameData[] = { | 1761 const unsigned char kV3FrameData[] = { |
1910 0x80, spdy_version_ch_, 0x00, 0x01, | 1762 0x80, spdy_version_ch_, 0x00, 0x01, |
1911 0x00, 0x00, 0x00, 0x2a, | 1763 0x00, 0x00, 0x00, 0x2a, |
1912 0x00, 0x00, 0x00, 0x01, | 1764 0x00, 0x00, 0x00, 0x01, |
1913 0x00, 0x00, 0x00, 0x00, | 1765 0x00, 0x00, 0x00, 0x00, |
1914 kPri, 0x00, 0x00, 0x00, | 1766 kPri, 0x00, 0x00, 0x00, |
1915 0x00, 0x02, 0x00, 0x00, | 1767 0x00, 0x02, 0x00, 0x00, |
1916 0x00, 0x03, 'b', 'a', | 1768 0x00, 0x03, 'b', 'a', |
1917 'r', 0x00, 0x00, 0x00, | 1769 'r', 0x00, 0x00, 0x00, |
1918 0x03, 'f', 'o', 'o', | 1770 0x03, 'f', 'o', 'o', |
1919 0x00, 0x00, 0x00, 0x03, | 1771 0x00, 0x00, 0x00, 0x03, |
1920 'f', 'o', 'o', 0x00, | 1772 'f', 'o', 'o', 0x00, |
1921 0x00, 0x00, 0x03, 'b', | 1773 0x00, 0x00, 0x03, 'b', |
1922 'a', 'r' | 1774 'a', 'r' |
1923 }; | 1775 }; |
1924 SpdySynStreamIR syn_stream(1); | 1776 SpdySynStreamIR syn_stream(1); |
1925 syn_stream.set_priority(framer.GetLowestPriority()); | 1777 syn_stream.set_priority(framer.GetLowestPriority()); |
1926 syn_stream.SetHeader("bar", "foo"); | 1778 syn_stream.SetHeader("bar", "foo"); |
1927 syn_stream.SetHeader("foo", "bar"); | 1779 syn_stream.SetHeader("foo", "bar"); |
1928 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1780 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
1929 if (IsSpdy2()) { | 1781 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1930 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
1931 } else if (IsSpdy3()) { | |
1932 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
1933 } else { | |
1934 LOG(FATAL) << "Unsupported version in test."; | |
1935 } | |
1936 } | 1782 } |
1937 | 1783 |
1938 { | 1784 { |
1939 const char kDescription[] = | 1785 const char kDescription[] = |
1940 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " | 1786 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " |
1941 "max stream ID"; | 1787 "max stream ID"; |
1942 | |
1943 const unsigned char kV2FrameData[] = { | |
1944 0x80, spdy_version_ch_, 0x00, 0x01, | |
1945 0x01, 0x00, 0x00, 0x1D, | |
1946 0x7f, 0xff, 0xff, 0xff, | |
1947 0x7f, 0xff, 0xff, 0xff, | |
1948 0x00, 0x00, 0x00, 0x02, | |
1949 0x00, 0x00, 0x00, 0x03, | |
1950 'f', 'o', 'o', 0x00, | |
1951 0x03, 'f', 'o', 'o', | |
1952 0x00, 0x03, 'b', 'a', | |
1953 'r' | |
1954 }; | |
1955 const unsigned char kV3FrameData[] = { | 1788 const unsigned char kV3FrameData[] = { |
1956 0x80, spdy_version_ch_, 0x00, 0x01, | 1789 0x80, spdy_version_ch_, 0x00, 0x01, |
1957 0x01, 0x00, 0x00, 0x27, | 1790 0x01, 0x00, 0x00, 0x27, |
1958 0x7f, 0xff, 0xff, 0xff, | 1791 0x7f, 0xff, 0xff, 0xff, |
1959 0x7f, 0xff, 0xff, 0xff, | 1792 0x7f, 0xff, 0xff, 0xff, |
1960 0x00, 0x00, 0x00, 0x00, | 1793 0x00, 0x00, 0x00, 0x00, |
1961 0x00, 0x02, 0x00, 0x00, | 1794 0x00, 0x02, 0x00, 0x00, |
1962 0x00, 0x00, 0x00, 0x00, | 1795 0x00, 0x00, 0x00, 0x00, |
1963 0x00, 0x03, 'f', 'o', | 1796 0x00, 0x03, 'f', 'o', |
1964 'o', 0x00, 0x00, 0x00, | 1797 'o', 0x00, 0x00, 0x00, |
1965 0x03, 'f', 'o', 'o', | 1798 0x03, 'f', 'o', 'o', |
1966 0x00, 0x00, 0x00, 0x03, | 1799 0x00, 0x00, 0x00, 0x03, |
1967 'b', 'a', 'r' | 1800 'b', 'a', 'r' |
1968 }; | 1801 }; |
1969 SpdySynStreamIR syn_stream(0x7fffffff); | 1802 SpdySynStreamIR syn_stream(0x7fffffff); |
1970 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1803 syn_stream.set_associated_to_stream_id(0x7fffffff); |
1971 syn_stream.set_priority(framer.GetHighestPriority()); | 1804 syn_stream.set_priority(framer.GetHighestPriority()); |
1972 syn_stream.set_fin(true); | 1805 syn_stream.set_fin(true); |
1973 syn_stream.SetHeader("", "foo"); | 1806 syn_stream.SetHeader("", "foo"); |
1974 syn_stream.SetHeader("foo", "bar"); | 1807 syn_stream.SetHeader("foo", "bar"); |
1975 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1808 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
1976 if (IsSpdy2()) { | 1809 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1977 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
1978 } else if (IsSpdy3()) { | |
1979 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
1980 } else { | |
1981 LOG(FATAL) << "Unsupported version in test."; | |
1982 } | |
1983 } | 1810 } |
1984 | 1811 |
1985 { | 1812 { |
1986 const char kDescription[] = | 1813 const char kDescription[] = |
1987 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " | 1814 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " |
1988 "max stream ID"; | 1815 "max stream ID"; |
1989 | 1816 const unsigned char kPri = 0x20; |
1990 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20; | |
1991 const unsigned char kV2FrameData[] = { | |
1992 0x80, spdy_version_ch_, 0x00, 0x01, | |
1993 0x01, 0x00, 0x00, 0x1D, | |
1994 0x7f, 0xff, 0xff, 0xff, | |
1995 0x7f, 0xff, 0xff, 0xff, | |
1996 kPri, 0x00, 0x00, 0x02, | |
1997 0x00, 0x03, 'b', 'a', | |
1998 'r', 0x00, 0x03, 'f', | |
1999 'o', 'o', 0x00, 0x03, | |
2000 'f', 'o', 'o', 0x00, | |
2001 0x00 | |
2002 }; | |
2003 const unsigned char kV3FrameData[] = { | 1817 const unsigned char kV3FrameData[] = { |
2004 0x80, spdy_version_ch_, 0x00, 0x01, | 1818 0x80, spdy_version_ch_, 0x00, 0x01, |
2005 0x01, 0x00, 0x00, 0x27, | 1819 0x01, 0x00, 0x00, 0x27, |
2006 0x7f, 0xff, 0xff, 0xff, | 1820 0x7f, 0xff, 0xff, 0xff, |
2007 0x7f, 0xff, 0xff, 0xff, | 1821 0x7f, 0xff, 0xff, 0xff, |
2008 kPri, 0x00, 0x00, 0x00, | 1822 kPri, 0x00, 0x00, 0x00, |
2009 0x00, 0x02, 0x00, 0x00, | 1823 0x00, 0x02, 0x00, 0x00, |
2010 0x00, 0x03, 'b', 'a', | 1824 0x00, 0x03, 'b', 'a', |
2011 'r', 0x00, 0x00, 0x00, | 1825 'r', 0x00, 0x00, 0x00, |
2012 0x03, 'f', 'o', 'o', | 1826 0x03, 'f', 'o', 'o', |
2013 0x00, 0x00, 0x00, 0x03, | 1827 0x00, 0x00, 0x00, 0x03, |
2014 'f', 'o', 'o', 0x00, | 1828 'f', 'o', 'o', 0x00, |
2015 0x00, 0x00, 0x00 | 1829 0x00, 0x00, 0x00 |
2016 }; | 1830 }; |
2017 SpdySynStreamIR syn_stream(0x7fffffff); | 1831 SpdySynStreamIR syn_stream(0x7fffffff); |
2018 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1832 syn_stream.set_associated_to_stream_id(0x7fffffff); |
2019 syn_stream.set_priority(1); | 1833 syn_stream.set_priority(1); |
2020 syn_stream.set_fin(true); | 1834 syn_stream.set_fin(true); |
2021 syn_stream.SetHeader("bar", "foo"); | 1835 syn_stream.SetHeader("bar", "foo"); |
2022 syn_stream.SetHeader("foo", ""); | 1836 syn_stream.SetHeader("foo", ""); |
2023 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1837 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
2024 if (IsSpdy2()) { | 1838 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2025 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2026 } else if (IsSpdy3()) { | |
2027 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
2028 } else { | |
2029 LOG(FATAL) << "Unsupported version in test."; | |
2030 } | |
2031 } | 1839 } |
2032 } | 1840 } |
2033 | 1841 |
2034 // TODO(phajdan.jr): Clean up after we no longer need | 1842 // TODO(phajdan.jr): Clean up after we no longer need |
2035 // to workaround http://crbug.com/139744. | 1843 // to workaround http://crbug.com/139744. |
2036 #if !defined(USE_SYSTEM_ZLIB) | 1844 #if !defined(USE_SYSTEM_ZLIB) |
2037 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { | 1845 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { |
2038 if (!IsSpdy2() && !IsSpdy3()) { | 1846 if (!IsSpdy3()) { |
2039 // SYN_STREAM not supported for SPDY>3 | 1847 // SYN_STREAM not supported for SPDY>3 |
2040 return; | 1848 return; |
2041 } | 1849 } |
2042 SpdyFramer framer(spdy_version_); | 1850 SpdyFramer framer(spdy_version_); |
2043 framer.set_enable_compression(true); | 1851 framer.set_enable_compression(true); |
2044 | 1852 |
2045 { | 1853 { |
2046 const char kDescription[] = | 1854 const char kDescription[] = |
2047 "SYN_STREAM frame, low pri, no FIN"; | 1855 "SYN_STREAM frame, low pri, no FIN"; |
2048 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | 1856 const SpdyPriority priority = 4; |
2049 | 1857 |
2050 const unsigned char kV2FrameData[] = { | |
2051 0x80, spdy_version_ch_, 0x00, 0x01, | |
2052 0x00, 0x00, 0x00, 0x36, | |
2053 0x00, 0x00, 0x00, 0x01, | |
2054 0x00, 0x00, 0x00, 0x00, | |
2055 0x80, 0x00, 0x38, 0xea, | |
2056 0xdf, 0xa2, 0x51, 0xb2, | |
2057 0x62, 0x60, 0x62, 0x60, | |
2058 0x4e, 0x4a, 0x2c, 0x62, | |
2059 0x60, 0x06, 0x08, 0xa0, | |
2060 0xb4, 0xfc, 0x7c, 0x80, | |
2061 0x00, 0x62, 0x60, 0x4e, | |
2062 0xcb, 0xcf, 0x67, 0x60, | |
2063 0x06, 0x08, 0xa0, 0xa4, | |
2064 0xc4, 0x22, 0x80, 0x00, | |
2065 0x02, 0x00, 0x00, 0x00, | |
2066 0xff, 0xff, | |
2067 }; | |
2068 const unsigned char kV3FrameData[] = { | 1858 const unsigned char kV3FrameData[] = { |
2069 0x80, spdy_version_ch_, 0x00, 0x01, | 1859 0x80, spdy_version_ch_, 0x00, 0x01, |
2070 0x00, 0x00, 0x00, 0x37, | 1860 0x00, 0x00, 0x00, 0x37, |
2071 0x00, 0x00, 0x00, 0x01, | 1861 0x00, 0x00, 0x00, 0x01, |
2072 0x00, 0x00, 0x00, 0x00, | 1862 0x00, 0x00, 0x00, 0x00, |
2073 0x80, 0x00, 0x38, 0xEA, | 1863 0x80, 0x00, 0x38, 0xEA, |
2074 0xE3, 0xC6, 0xA7, 0xC2, | 1864 0xE3, 0xC6, 0xA7, 0xC2, |
2075 0x02, 0xE5, 0x0E, 0x50, | 1865 0x02, 0xE5, 0x0E, 0x50, |
2076 0xC2, 0x4B, 0x4A, 0x04, | 1866 0xC2, 0x4B, 0x4A, 0x04, |
2077 0xE5, 0x0B, 0x66, 0x80, | 1867 0xE5, 0x0B, 0x66, 0x80, |
2078 0x00, 0x4A, 0xCB, 0xCF, | 1868 0x00, 0x4A, 0xCB, 0xCF, |
2079 0x07, 0x08, 0x20, 0x10, | 1869 0x07, 0x08, 0x20, 0x10, |
2080 0x95, 0x96, 0x9F, 0x0F, | 1870 0x95, 0x96, 0x9F, 0x0F, |
2081 0xA2, 0x00, 0x02, 0x28, | 1871 0xA2, 0x00, 0x02, 0x28, |
2082 0x29, 0xB1, 0x08, 0x20, | 1872 0x29, 0xB1, 0x08, 0x20, |
2083 0x80, 0x00, 0x00, 0x00, | 1873 0x80, 0x00, 0x00, 0x00, |
2084 0x00, 0xFF, 0xFF, | 1874 0x00, 0xFF, 0xFF, |
2085 }; | 1875 }; |
2086 const unsigned char kV2SIMDFrameData[] = { | |
2087 0x80, spdy_version_ch_, 0x00, 0x01, | |
2088 0x00, 0x00, 0x00, 0x33, | |
2089 0x00, 0x00, 0x00, 0x01, | |
2090 0x00, 0x00, 0x00, 0x00, | |
2091 0x80, 0x00, 0x38, 0xea, | |
2092 0xdf, 0xa2, 0x51, 0xb2, | |
2093 0x62, 0x60, 0x62, 0x60, | |
2094 0x4e, 0x4a, 0x2c, 0x62, | |
2095 0x60, 0x06, 0x08, 0xa0, | |
2096 0xb4, 0xfc, 0x7c, 0x80, | |
2097 0x00, 0x62, 0x60, 0x06, | |
2098 0x13, 0x00, 0x01, 0x94, | |
2099 0x94, 0x58, 0x04, 0x10, | |
2100 0x40, 0x00, 0x00, 0x00, | |
2101 0x00, 0xff, 0xff, | |
2102 }; | |
2103 const unsigned char kV3SIMDFrameData[] = { | 1876 const unsigned char kV3SIMDFrameData[] = { |
2104 0x80, spdy_version_ch_, 0x00, 0x01, | 1877 0x80, spdy_version_ch_, 0x00, 0x01, |
2105 0x00, 0x00, 0x00, 0x32, | 1878 0x00, 0x00, 0x00, 0x32, |
2106 0x00, 0x00, 0x00, 0x01, | 1879 0x00, 0x00, 0x00, 0x01, |
2107 0x00, 0x00, 0x00, 0x00, | 1880 0x00, 0x00, 0x00, 0x00, |
2108 0x80, 0x00, 0x38, 0xea, | 1881 0x80, 0x00, 0x38, 0xea, |
2109 0xe3, 0xc6, 0xa7, 0xc2, | 1882 0xe3, 0xc6, 0xa7, 0xc2, |
2110 0x02, 0xe5, 0x0e, 0x50, | 1883 0x02, 0xe5, 0x0e, 0x50, |
2111 0xc2, 0x4b, 0x4a, 0x04, | 1884 0xc2, 0x4b, 0x4a, 0x04, |
2112 0xe5, 0x0b, 0x66, 0x80, | 1885 0xe5, 0x0b, 0x66, 0x80, |
2113 0x00, 0x4a, 0xcb, 0xcf, | 1886 0x00, 0x4a, 0xcb, 0xcf, |
2114 0x07, 0x08, 0x20, 0x24, | 1887 0x07, 0x08, 0x20, 0x24, |
2115 0x0a, 0x20, 0x80, 0x92, | 1888 0x0a, 0x20, 0x80, 0x92, |
2116 0x12, 0x8b, 0x00, 0x02, | 1889 0x12, 0x8b, 0x00, 0x02, |
2117 0x08, 0x00, 0x00, 0x00, | 1890 0x08, 0x00, 0x00, 0x00, |
2118 0xff, 0xff, | 1891 0xff, 0xff, |
2119 }; | 1892 }; |
2120 | 1893 |
2121 SpdySynStreamIR syn_stream(1); | 1894 SpdySynStreamIR syn_stream(1); |
2122 syn_stream.set_priority(priority); | 1895 syn_stream.set_priority(priority); |
2123 syn_stream.SetHeader("bar", "foo"); | 1896 syn_stream.SetHeader("bar", "foo"); |
2124 syn_stream.SetHeader("foo", "bar"); | 1897 syn_stream.SetHeader("foo", "bar"); |
2125 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1898 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
2126 const unsigned char* frame_data = | 1899 const unsigned char* frame_data = |
2127 reinterpret_cast<const unsigned char*>(frame->data()); | 1900 reinterpret_cast<const unsigned char*>(frame->data()); |
2128 if (IsSpdy2()) { | 1901 if (memcmp(frame_data, |
2129 // Try comparing with SIMD version, if that fails, do a failing check | 1902 kV3SIMDFrameData, |
2130 // with pretty printing against non-SIMD version | 1903 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { |
2131 if (memcmp(frame_data, | 1904 CompareCharArraysWithHexError(kDescription, |
2132 kV2SIMDFrameData, | 1905 frame_data, |
2133 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { | 1906 frame->size(), |
2134 CompareCharArraysWithHexError(kDescription, | 1907 kV3FrameData, |
2135 frame_data, | 1908 arraysize(kV3FrameData)); |
2136 frame->size(), | |
2137 kV2FrameData, | |
2138 arraysize(kV2FrameData)); | |
2139 } | |
2140 } else if (IsSpdy3()) { | |
2141 if (memcmp(frame_data, | |
2142 kV3SIMDFrameData, | |
2143 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { | |
2144 CompareCharArraysWithHexError(kDescription, | |
2145 frame_data, | |
2146 frame->size(), | |
2147 kV3FrameData, | |
2148 arraysize(kV3FrameData)); | |
2149 } | |
2150 } else { | |
2151 LOG(FATAL) << "Unsupported version in test."; | |
2152 } | 1909 } |
2153 } | 1910 } |
2154 } | 1911 } |
2155 #endif // !defined(USE_SYSTEM_ZLIB) | 1912 #endif // !defined(USE_SYSTEM_ZLIB) |
2156 | 1913 |
2157 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | 1914 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
2158 if (spdy_version_ > SPDY3) { | 1915 if (!IsSpdy3()) { |
asanka
2014/11/10 19:18:37
Nit: IMHO assuming the numerical value of the Spdy
Bence
2014/11/10 22:52:09
Done.
| |
2159 // SYN_REPLY unsupported in SPDY>3 | 1916 // SYN_REPLY unsupported in SPDY>3 |
2160 return; | 1917 return; |
2161 } | 1918 } |
2162 SpdyFramer framer(spdy_version_); | 1919 SpdyFramer framer(spdy_version_); |
2163 framer.set_enable_compression(false); | 1920 framer.set_enable_compression(false); |
2164 | 1921 |
2165 { | 1922 { |
2166 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 1923 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2167 | |
2168 const unsigned char kV2FrameData[] = { | |
2169 0x80, spdy_version_ch_, 0x00, 0x02, | |
2170 0x00, 0x00, 0x00, 0x1C, | |
2171 0x00, 0x00, 0x00, 0x01, | |
2172 0x00, 0x00, 0x00, 0x02, | |
2173 0x00, 0x03, 'b', 'a', | |
2174 'r', 0x00, 0x03, 'f', | |
2175 'o', 'o', 0x00, 0x03, | |
2176 'f', 'o', 'o', 0x00, | |
2177 0x03, 'b', 'a', 'r' | |
2178 }; | |
2179 const unsigned char kV3FrameData[] = { | 1924 const unsigned char kV3FrameData[] = { |
2180 0x80, spdy_version_ch_, 0x00, 0x02, | 1925 0x80, spdy_version_ch_, 0x00, 0x02, |
2181 0x00, 0x00, 0x00, 0x24, | 1926 0x00, 0x00, 0x00, 0x24, |
2182 0x00, 0x00, 0x00, 0x01, | 1927 0x00, 0x00, 0x00, 0x01, |
2183 0x00, 0x00, 0x00, 0x02, | 1928 0x00, 0x00, 0x00, 0x02, |
2184 0x00, 0x00, 0x00, 0x03, | 1929 0x00, 0x00, 0x00, 0x03, |
2185 'b', 'a', 'r', 0x00, | 1930 'b', 'a', 'r', 0x00, |
2186 0x00, 0x00, 0x03, 'f', | 1931 0x00, 0x00, 0x03, 'f', |
2187 'o', 'o', 0x00, 0x00, | 1932 'o', 'o', 0x00, 0x00, |
2188 0x00, 0x03, 'f', 'o', | 1933 0x00, 0x03, 'f', 'o', |
2189 'o', 0x00, 0x00, 0x00, | 1934 'o', 0x00, 0x00, 0x00, |
2190 0x03, 'b', 'a', 'r' | 1935 0x03, 'b', 'a', 'r' |
2191 }; | 1936 }; |
2192 SpdySynReplyIR syn_reply(1); | 1937 SpdySynReplyIR syn_reply(1); |
2193 syn_reply.SetHeader("bar", "foo"); | 1938 syn_reply.SetHeader("bar", "foo"); |
2194 syn_reply.SetHeader("foo", "bar"); | 1939 syn_reply.SetHeader("foo", "bar"); |
2195 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1940 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2196 if (IsSpdy2()) { | 1941 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2197 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2198 } else if (IsSpdy3()) { | |
2199 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
2200 } else { | |
2201 LOG(FATAL) << "Unsupported version in test."; | |
2202 } | |
2203 } | 1942 } |
2204 | 1943 |
2205 { | 1944 { |
2206 const char kDescription[] = | 1945 const char kDescription[] = |
2207 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; | 1946 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; |
2208 | |
2209 const unsigned char kV2FrameData[] = { | |
2210 0x80, spdy_version_ch_, 0x00, 0x02, | |
2211 0x01, 0x00, 0x00, 0x19, | |
2212 0x7f, 0xff, 0xff, 0xff, | |
2213 0x00, 0x00, 0x00, 0x02, | |
2214 0x00, 0x00, 0x00, 0x03, | |
2215 'f', 'o', 'o', 0x00, | |
2216 0x03, 'f', 'o', 'o', | |
2217 0x00, 0x03, 'b', 'a', | |
2218 'r' | |
2219 }; | |
2220 const unsigned char kV3FrameData[] = { | 1947 const unsigned char kV3FrameData[] = { |
2221 0x80, spdy_version_ch_, 0x00, 0x02, | 1948 0x80, spdy_version_ch_, 0x00, 0x02, |
2222 0x01, 0x00, 0x00, 0x21, | 1949 0x01, 0x00, 0x00, 0x21, |
2223 0x7f, 0xff, 0xff, 0xff, | 1950 0x7f, 0xff, 0xff, 0xff, |
2224 0x00, 0x00, 0x00, 0x02, | 1951 0x00, 0x00, 0x00, 0x02, |
2225 0x00, 0x00, 0x00, 0x00, | 1952 0x00, 0x00, 0x00, 0x00, |
2226 0x00, 0x00, 0x00, 0x03, | 1953 0x00, 0x00, 0x00, 0x03, |
2227 'f', 'o', 'o', 0x00, | 1954 'f', 'o', 'o', 0x00, |
2228 0x00, 0x00, 0x03, 'f', | 1955 0x00, 0x00, 0x03, 'f', |
2229 'o', 'o', 0x00, 0x00, | 1956 'o', 'o', 0x00, 0x00, |
2230 0x00, 0x03, 'b', 'a', | 1957 0x00, 0x03, 'b', 'a', |
2231 'r' | 1958 'r' |
2232 }; | 1959 }; |
2233 SpdySynReplyIR syn_reply(0x7fffffff); | 1960 SpdySynReplyIR syn_reply(0x7fffffff); |
2234 syn_reply.set_fin(true); | 1961 syn_reply.set_fin(true); |
2235 syn_reply.SetHeader("", "foo"); | 1962 syn_reply.SetHeader("", "foo"); |
2236 syn_reply.SetHeader("foo", "bar"); | 1963 syn_reply.SetHeader("foo", "bar"); |
2237 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1964 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2238 if (IsSpdy2()) { | 1965 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2239 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2240 } else if (IsSpdy3()) { | |
2241 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
2242 } else { | |
2243 LOG(FATAL) << "Unsupported version in test."; | |
2244 } | |
2245 } | 1966 } |
2246 | 1967 |
2247 { | 1968 { |
2248 const char kDescription[] = | 1969 const char kDescription[] = |
2249 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; | 1970 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; |
2250 | |
2251 const unsigned char kV2FrameData[] = { | |
2252 0x80, spdy_version_ch_, 0x00, 0x02, | |
2253 0x01, 0x00, 0x00, 0x19, | |
2254 0x7f, 0xff, 0xff, 0xff, | |
2255 0x00, 0x00, 0x00, 0x02, | |
2256 0x00, 0x03, 'b', 'a', | |
2257 'r', 0x00, 0x03, 'f', | |
2258 'o', 'o', 0x00, 0x03, | |
2259 'f', 'o', 'o', 0x00, | |
2260 0x00 | |
2261 }; | |
2262 const unsigned char kV3FrameData[] = { | 1971 const unsigned char kV3FrameData[] = { |
2263 0x80, spdy_version_ch_, 0x00, 0x02, | 1972 0x80, spdy_version_ch_, 0x00, 0x02, |
2264 0x01, 0x00, 0x00, 0x21, | 1973 0x01, 0x00, 0x00, 0x21, |
2265 0x7f, 0xff, 0xff, 0xff, | 1974 0x7f, 0xff, 0xff, 0xff, |
2266 0x00, 0x00, 0x00, 0x02, | 1975 0x00, 0x00, 0x00, 0x02, |
2267 0x00, 0x00, 0x00, 0x03, | 1976 0x00, 0x00, 0x00, 0x03, |
2268 'b', 'a', 'r', 0x00, | 1977 'b', 'a', 'r', 0x00, |
2269 0x00, 0x00, 0x03, 'f', | 1978 0x00, 0x00, 0x03, 'f', |
2270 'o', 'o', 0x00, 0x00, | 1979 'o', 'o', 0x00, 0x00, |
2271 0x00, 0x03, 'f', 'o', | 1980 0x00, 0x03, 'f', 'o', |
2272 'o', 0x00, 0x00, 0x00, | 1981 'o', 0x00, 0x00, 0x00, |
2273 0x00 | 1982 0x00 |
2274 }; | 1983 }; |
2275 SpdySynReplyIR syn_reply(0x7fffffff); | 1984 SpdySynReplyIR syn_reply(0x7fffffff); |
2276 syn_reply.set_fin(true); | 1985 syn_reply.set_fin(true); |
2277 syn_reply.SetHeader("bar", "foo"); | 1986 syn_reply.SetHeader("bar", "foo"); |
2278 syn_reply.SetHeader("foo", ""); | 1987 syn_reply.SetHeader("foo", ""); |
2279 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1988 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2280 if (IsSpdy2()) { | 1989 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2281 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2282 } else if (IsSpdy3()) { | |
2283 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
2284 } else { | |
2285 LOG(FATAL) << "Unsupported version in test."; | |
2286 } | |
2287 } | 1990 } |
2288 } | 1991 } |
2289 | 1992 |
2290 // TODO(phajdan.jr): Clean up after we no longer need | 1993 // TODO(phajdan.jr): Clean up after we no longer need |
2291 // to workaround http://crbug.com/139744. | 1994 // to workaround http://crbug.com/139744. |
2292 #if !defined(USE_SYSTEM_ZLIB) | 1995 #if !defined(USE_SYSTEM_ZLIB) |
2293 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { | 1996 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { |
2294 if (spdy_version_ > SPDY3) { | 1997 if (!IsSpdy3()) { |
2295 // SYN_REPLY unsupported in SPDY>3 | 1998 // SYN_REPLY unsupported in SPDY>3 |
2296 return; | 1999 return; |
2297 } | 2000 } |
2298 SpdyFramer framer(spdy_version_); | 2001 SpdyFramer framer(spdy_version_); |
2299 framer.set_enable_compression(true); | 2002 framer.set_enable_compression(true); |
2300 | 2003 |
2301 { | 2004 { |
2302 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 2005 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2303 | |
2304 const unsigned char kV2FrameData[] = { | |
2305 0x80, spdy_version_ch_, 0x00, 0x02, | |
2306 0x00, 0x00, 0x00, 0x32, | |
2307 0x00, 0x00, 0x00, 0x01, | |
2308 0x00, 0x00, 0x38, 0xea, | |
2309 0xdf, 0xa2, 0x51, 0xb2, | |
2310 0x62, 0x60, 0x62, 0x60, | |
2311 0x4e, 0x4a, 0x2c, 0x62, | |
2312 0x60, 0x06, 0x08, 0xa0, | |
2313 0xb4, 0xfc, 0x7c, 0x80, | |
2314 0x00, 0x62, 0x60, 0x4e, | |
2315 0xcb, 0xcf, 0x67, 0x60, | |
2316 0x06, 0x08, 0xa0, 0xa4, | |
2317 0xc4, 0x22, 0x80, 0x00, | |
2318 0x02, 0x00, 0x00, 0x00, | |
2319 0xff, 0xff, | |
2320 }; | |
2321 const unsigned char kV3FrameData[] = { | 2006 const unsigned char kV3FrameData[] = { |
2322 0x80, spdy_version_ch_, 0x00, 0x02, | 2007 0x80, spdy_version_ch_, 0x00, 0x02, |
2323 0x00, 0x00, 0x00, 0x31, | 2008 0x00, 0x00, 0x00, 0x31, |
2324 0x00, 0x00, 0x00, 0x01, | 2009 0x00, 0x00, 0x00, 0x01, |
2325 0x38, 0xea, 0xe3, 0xc6, | 2010 0x38, 0xea, 0xe3, 0xc6, |
2326 0xa7, 0xc2, 0x02, 0xe5, | 2011 0xa7, 0xc2, 0x02, 0xe5, |
2327 0x0e, 0x50, 0xc2, 0x4b, | 2012 0x0e, 0x50, 0xc2, 0x4b, |
2328 0x4a, 0x04, 0xe5, 0x0b, | 2013 0x4a, 0x04, 0xe5, 0x0b, |
2329 0x66, 0x80, 0x00, 0x4a, | 2014 0x66, 0x80, 0x00, 0x4a, |
2330 0xcb, 0xcf, 0x07, 0x08, | 2015 0xcb, 0xcf, 0x07, 0x08, |
2331 0x20, 0x10, 0x95, 0x96, | 2016 0x20, 0x10, 0x95, 0x96, |
2332 0x9f, 0x0f, 0xa2, 0x00, | 2017 0x9f, 0x0f, 0xa2, 0x00, |
2333 0x02, 0x28, 0x29, 0xb1, | 2018 0x02, 0x28, 0x29, 0xb1, |
2334 0x08, 0x20, 0x80, 0x00, | 2019 0x08, 0x20, 0x80, 0x00, |
2335 0x00, 0x00, 0x00, 0xff, | 2020 0x00, 0x00, 0x00, 0xff, |
2336 0xff, | 2021 0xff, |
2337 }; | 2022 }; |
2338 const unsigned char kV2SIMDFrameData[] = { | |
2339 0x80, spdy_version_ch_, 0x00, 0x02, | |
2340 0x00, 0x00, 0x00, 0x2f, | |
2341 0x00, 0x00, 0x00, 0x01, | |
2342 0x00, 0x00, 0x38, 0xea, | |
2343 0xdf, 0xa2, 0x51, 0xb2, | |
2344 0x62, 0x60, 0x62, 0x60, | |
2345 0x4e, 0x4a, 0x2c, 0x62, | |
2346 0x60, 0x06, 0x08, 0xa0, | |
2347 0xb4, 0xfc, 0x7c, 0x80, | |
2348 0x00, 0x62, 0x60, 0x06, | |
2349 0x13, 0x00, 0x01, 0x94, | |
2350 0x94, 0x58, 0x04, 0x10, | |
2351 0x40, 0x00, 0x00, 0x00, | |
2352 0x00, 0xff, 0xff, | |
2353 }; | |
2354 const unsigned char kV3SIMDFrameData[] = { | 2023 const unsigned char kV3SIMDFrameData[] = { |
2355 0x80, spdy_version_ch_, 0x00, 0x02, | 2024 0x80, spdy_version_ch_, 0x00, 0x02, |
2356 0x00, 0x00, 0x00, 0x2c, | 2025 0x00, 0x00, 0x00, 0x2c, |
2357 0x00, 0x00, 0x00, 0x01, | 2026 0x00, 0x00, 0x00, 0x01, |
2358 0x38, 0xea, 0xe3, 0xc6, | 2027 0x38, 0xea, 0xe3, 0xc6, |
2359 0xa7, 0xc2, 0x02, 0xe5, | 2028 0xa7, 0xc2, 0x02, 0xe5, |
2360 0x0e, 0x50, 0xc2, 0x4b, | 2029 0x0e, 0x50, 0xc2, 0x4b, |
2361 0x4a, 0x04, 0xe5, 0x0b, | 2030 0x4a, 0x04, 0xe5, 0x0b, |
2362 0x66, 0x80, 0x00, 0x4a, | 2031 0x66, 0x80, 0x00, 0x4a, |
2363 0xcb, 0xcf, 0x07, 0x08, | 2032 0xcb, 0xcf, 0x07, 0x08, |
2364 0x20, 0x24, 0x0a, 0x20, | 2033 0x20, 0x24, 0x0a, 0x20, |
2365 0x80, 0x92, 0x12, 0x8b, | 2034 0x80, 0x92, 0x12, 0x8b, |
2366 0x00, 0x02, 0x08, 0x00, | 2035 0x00, 0x02, 0x08, 0x00, |
2367 0x00, 0x00, 0xff, 0xff, | 2036 0x00, 0x00, 0xff, 0xff, |
2368 }; | 2037 }; |
2369 | 2038 |
2370 SpdySynReplyIR syn_reply(1); | 2039 SpdySynReplyIR syn_reply(1); |
2371 syn_reply.SetHeader("bar", "foo"); | 2040 syn_reply.SetHeader("bar", "foo"); |
2372 syn_reply.SetHeader("foo", "bar"); | 2041 syn_reply.SetHeader("foo", "bar"); |
2373 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2042 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2374 const unsigned char* frame_data = | 2043 const unsigned char* frame_data = |
2375 reinterpret_cast<const unsigned char*>(frame->data()); | 2044 reinterpret_cast<const unsigned char*>(frame->data()); |
2376 if (IsSpdy2()) { | 2045 if (memcmp(frame_data, |
2377 // Try comparing with SIMD version, if that fails, do a failing check | 2046 kV3SIMDFrameData, |
2378 // with pretty printing against non-SIMD version | 2047 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { |
2379 if (memcmp(frame_data, | 2048 CompareCharArraysWithHexError(kDescription, |
2380 kV2SIMDFrameData, | 2049 frame_data, |
2381 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { | 2050 frame->size(), |
2382 CompareCharArraysWithHexError(kDescription, | 2051 kV3FrameData, |
2383 frame_data, | 2052 arraysize(kV3FrameData)); |
2384 frame->size(), | |
2385 kV2FrameData, | |
2386 arraysize(kV2FrameData)); | |
2387 } | |
2388 } else if (IsSpdy3()) { | |
2389 if (memcmp(frame_data, | |
2390 kV3SIMDFrameData, | |
2391 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { | |
2392 CompareCharArraysWithHexError(kDescription, | |
2393 frame_data, | |
2394 frame->size(), | |
2395 kV3FrameData, | |
2396 arraysize(kV3FrameData)); | |
2397 } | |
2398 } else { | |
2399 LOG(FATAL) << "Unsupported version in test."; | |
2400 } | 2053 } |
2401 } | 2054 } |
2402 } | 2055 } |
2403 #endif // !defined(USE_SYSTEM_ZLIB) | 2056 #endif // !defined(USE_SYSTEM_ZLIB) |
2404 | 2057 |
2405 TEST_P(SpdyFramerTest, CreateRstStream) { | 2058 TEST_P(SpdyFramerTest, CreateRstStream) { |
2406 SpdyFramer framer(spdy_version_); | 2059 SpdyFramer framer(spdy_version_); |
2407 | 2060 |
2408 { | 2061 { |
2409 const char kDescription[] = "RST_STREAM frame"; | 2062 const char kDescription[] = "RST_STREAM frame"; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2477 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2130 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2478 } | 2131 } |
2479 } | 2132 } |
2480 } | 2133 } |
2481 | 2134 |
2482 TEST_P(SpdyFramerTest, CreateSettings) { | 2135 TEST_P(SpdyFramerTest, CreateSettings) { |
2483 SpdyFramer framer(spdy_version_); | 2136 SpdyFramer framer(spdy_version_); |
2484 | 2137 |
2485 { | 2138 { |
2486 const char kDescription[] = "Network byte order SETTINGS frame"; | 2139 const char kDescription[] = "Network byte order SETTINGS frame"; |
2487 | |
2488 const unsigned char kV2FrameData[] = { | |
2489 0x80, spdy_version_ch_, 0x00, 0x04, | |
2490 0x00, 0x00, 0x00, 0x0c, | |
2491 0x00, 0x00, 0x00, 0x01, | |
2492 0x07, 0x00, 0x00, 0x01, | |
2493 0x0a, 0x0b, 0x0c, 0x0d, | |
2494 }; | |
2495 const unsigned char kV3FrameData[] = { | 2140 const unsigned char kV3FrameData[] = { |
2496 0x80, spdy_version_ch_, 0x00, 0x04, | 2141 0x80, spdy_version_ch_, 0x00, 0x04, |
2497 0x00, 0x00, 0x00, 0x0c, | 2142 0x00, 0x00, 0x00, 0x0c, |
2498 0x00, 0x00, 0x00, 0x01, | 2143 0x00, 0x00, 0x00, 0x01, |
2499 0x01, 0x00, 0x00, 0x07, | 2144 0x01, 0x00, 0x00, 0x07, |
2500 0x0a, 0x0b, 0x0c, 0x0d, | 2145 0x0a, 0x0b, 0x0c, 0x0d, |
2501 }; | 2146 }; |
2502 const unsigned char kV4FrameData[] = { | 2147 const unsigned char kV4FrameData[] = { |
2503 0x00, 0x00, 0x06, 0x04, | 2148 0x00, 0x00, 0x06, 0x04, |
2504 0x00, 0x00, 0x00, 0x00, | 2149 0x00, 0x00, 0x00, 0x00, |
2505 0x00, 0x00, 0x04, 0x0a, | 2150 0x00, 0x00, 0x04, 0x0a, |
2506 0x0b, 0x0c, 0x0d, | 2151 0x0b, 0x0c, 0x0d, |
2507 }; | 2152 }; |
2508 | 2153 |
2509 uint32 kValue = 0x0a0b0c0d; | 2154 uint32 kValue = 0x0a0b0c0d; |
2510 SpdySettingsIR settings_ir; | 2155 SpdySettingsIR settings_ir; |
2511 | 2156 |
2512 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); | 2157 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); |
2513 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; | 2158 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; |
2514 SettingsMap settings; | 2159 SettingsMap settings; |
2515 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); | 2160 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); |
2516 EXPECT_EQ(kFlags, settings[kId].first); | 2161 EXPECT_EQ(kFlags, settings[kId].first); |
2517 EXPECT_EQ(kValue, settings[kId].second); | 2162 EXPECT_EQ(kValue, settings[kId].second); |
2518 settings_ir.AddSetting(kId, | 2163 settings_ir.AddSetting(kId, |
2519 kFlags & SETTINGS_FLAG_PLEASE_PERSIST, | 2164 kFlags & SETTINGS_FLAG_PLEASE_PERSIST, |
2520 kFlags & SETTINGS_FLAG_PERSISTED, | 2165 kFlags & SETTINGS_FLAG_PERSISTED, |
2521 kValue); | 2166 kValue); |
2522 | 2167 |
2523 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 2168 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
2524 if (IsSpdy2()) { | 2169 if (IsSpdy3()) { |
2525 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2526 } else if (IsSpdy3()) { | |
2527 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2170 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2528 } else { | 2171 } else { |
2529 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2172 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2530 } | 2173 } |
2531 } | 2174 } |
2532 | 2175 |
2533 { | 2176 { |
2534 const char kDescription[] = "Basic SETTINGS frame"; | 2177 const char kDescription[] = "Basic SETTINGS frame"; |
2535 | |
2536 const unsigned char kV2FrameData[] = { | |
2537 0x80, spdy_version_ch_, 0x00, 0x04, | |
2538 0x00, 0x00, 0x00, 0x24, | |
2539 0x00, 0x00, 0x00, 0x04, | |
2540 0x01, 0x00, 0x00, 0x00, // 1st Setting | |
2541 0x00, 0x00, 0x00, 0x05, | |
2542 0x02, 0x00, 0x00, 0x00, // 2nd Setting | |
2543 0x00, 0x00, 0x00, 0x06, | |
2544 0x03, 0x00, 0x00, 0x00, // 3rd Setting | |
2545 0x00, 0x00, 0x00, 0x07, | |
2546 0x04, 0x00, 0x00, 0x00, // 4th Setting | |
2547 0x00, 0x00, 0x00, 0x08, | |
2548 }; | |
2549 const unsigned char kV3FrameData[] = { | 2178 const unsigned char kV3FrameData[] = { |
2550 0x80, spdy_version_ch_, 0x00, 0x04, | 2179 0x80, spdy_version_ch_, 0x00, 0x04, |
2551 0x00, 0x00, 0x00, 0x24, | 2180 0x00, 0x00, 0x00, 0x24, |
2552 0x00, 0x00, 0x00, 0x04, | 2181 0x00, 0x00, 0x00, 0x04, |
2553 0x00, 0x00, 0x00, 0x01, // 1st Setting | 2182 0x00, 0x00, 0x00, 0x01, // 1st Setting |
2554 0x00, 0x00, 0x00, 0x05, | 2183 0x00, 0x00, 0x00, 0x05, |
2555 0x00, 0x00, 0x00, 0x02, // 2nd Setting | 2184 0x00, 0x00, 0x00, 0x02, // 2nd Setting |
2556 0x00, 0x00, 0x00, 0x06, | 2185 0x00, 0x00, 0x00, 0x06, |
2557 0x00, 0x00, 0x00, 0x03, // 3rd Setting | 2186 0x00, 0x00, 0x00, 0x03, // 3rd Setting |
2558 0x00, 0x00, 0x00, 0x07, | 2187 0x00, 0x00, 0x00, 0x07, |
(...skipping 28 matching lines...) Expand all Loading... | |
2587 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), | 2216 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), |
2588 false, // persist | 2217 false, // persist |
2589 false, // persisted | 2218 false, // persisted |
2590 7); | 2219 7); |
2591 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4), | 2220 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4), |
2592 false, // persist | 2221 false, // persist |
2593 false, // persisted | 2222 false, // persisted |
2594 8); | 2223 8); |
2595 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 2224 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
2596 | 2225 |
2597 if (IsSpdy2()) { | 2226 if (IsSpdy3()) { |
2598 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2599 } else if (IsSpdy3()) { | |
2600 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2227 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2601 } else { | 2228 } else { |
2602 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2229 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2603 } | 2230 } |
2604 } | 2231 } |
2605 | 2232 |
2606 { | 2233 { |
2607 const char kDescription[] = "Empty SETTINGS frame"; | 2234 const char kDescription[] = "Empty SETTINGS frame"; |
2608 | |
2609 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2235 const unsigned char kV3FrameData[] = { // Also applies for V2. |
2610 0x80, spdy_version_ch_, 0x00, 0x04, | 2236 0x80, spdy_version_ch_, 0x00, 0x04, |
2611 0x00, 0x00, 0x00, 0x04, | 2237 0x00, 0x00, 0x00, 0x04, |
2612 0x00, 0x00, 0x00, 0x00, | 2238 0x00, 0x00, 0x00, 0x00, |
2613 }; | 2239 }; |
2614 const unsigned char kV4FrameData[] = { | 2240 const unsigned char kV4FrameData[] = { |
2615 0x00, 0x00, 0x00, 0x04, | 2241 0x00, 0x00, 0x00, 0x04, |
2616 0x00, 0x00, 0x00, 0x00, | 2242 0x00, 0x00, 0x00, 0x00, |
2617 0x00, | 2243 0x00, |
2618 }; | 2244 }; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2670 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2296 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2671 } | 2297 } |
2672 } | 2298 } |
2673 } | 2299 } |
2674 | 2300 |
2675 TEST_P(SpdyFramerTest, CreateGoAway) { | 2301 TEST_P(SpdyFramerTest, CreateGoAway) { |
2676 SpdyFramer framer(spdy_version_); | 2302 SpdyFramer framer(spdy_version_); |
2677 | 2303 |
2678 { | 2304 { |
2679 const char kDescription[] = "GOAWAY frame"; | 2305 const char kDescription[] = "GOAWAY frame"; |
2680 const unsigned char kV2FrameData[] = { | |
2681 0x80, spdy_version_ch_, 0x00, 0x07, | |
2682 0x00, 0x00, 0x00, 0x04, | |
2683 0x00, 0x00, 0x00, 0x00, // Stream Id | |
2684 }; | |
2685 const unsigned char kV3FrameData[] = { | 2306 const unsigned char kV3FrameData[] = { |
2686 0x80, spdy_version_ch_, 0x00, 0x07, | 2307 0x80, spdy_version_ch_, 0x00, 0x07, |
2687 0x00, 0x00, 0x00, 0x08, | 2308 0x00, 0x00, 0x00, 0x08, |
2688 0x00, 0x00, 0x00, 0x00, // Stream Id | 2309 0x00, 0x00, 0x00, 0x00, // Stream Id |
2689 0x00, 0x00, 0x00, 0x00, // Status | 2310 0x00, 0x00, 0x00, 0x00, // Status |
2690 }; | 2311 }; |
2691 const unsigned char kV4FrameData[] = { | 2312 const unsigned char kV4FrameData[] = { |
2692 0x00, 0x00, 0x0a, 0x07, | 2313 0x00, 0x00, 0x0a, 0x07, |
2693 0x00, 0x00, 0x00, 0x00, | 2314 0x00, 0x00, 0x00, 0x00, |
2694 0x00, 0x00, 0x00, 0x00, // Stream id | 2315 0x00, 0x00, 0x00, 0x00, // Stream id |
2695 0x00, 0x00, 0x00, 0x00, // Status | 2316 0x00, 0x00, 0x00, 0x00, // Status |
2696 0x00, 0x47, 0x41, // Opaque Description | 2317 0x00, 0x47, 0x41, // Opaque Description |
2697 }; | 2318 }; |
2698 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); | 2319 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); |
2699 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); | 2320 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); |
2700 if (IsSpdy2()) { | 2321 if (IsSpdy3()) { |
2701 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2702 } else if (IsSpdy3()) { | |
2703 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2322 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2704 } else { | 2323 } else { |
2705 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2324 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2706 } | 2325 } |
2707 } | 2326 } |
2708 | 2327 |
2709 { | 2328 { |
2710 const char kDescription[] = "GOAWAY frame with max stream ID, status"; | 2329 const char kDescription[] = "GOAWAY frame with max stream ID, status"; |
2711 const unsigned char kV2FrameData[] = { | |
2712 0x80, spdy_version_ch_, 0x00, 0x07, | |
2713 0x00, 0x00, 0x00, 0x04, | |
2714 0x7f, 0xff, 0xff, 0xff, // Stream Id | |
2715 }; | |
2716 const unsigned char kV3FrameData[] = { | 2330 const unsigned char kV3FrameData[] = { |
2717 0x80, spdy_version_ch_, 0x00, 0x07, | 2331 0x80, spdy_version_ch_, 0x00, 0x07, |
2718 0x00, 0x00, 0x00, 0x08, | 2332 0x00, 0x00, 0x00, 0x08, |
2719 0x7f, 0xff, 0xff, 0xff, // Stream Id | 2333 0x7f, 0xff, 0xff, 0xff, // Stream Id |
2720 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR. | 2334 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR. |
2721 }; | 2335 }; |
2722 const unsigned char kV4FrameData[] = { | 2336 const unsigned char kV4FrameData[] = { |
2723 0x00, 0x00, 0x0a, 0x07, | 2337 0x00, 0x00, 0x0a, 0x07, |
2724 0x00, 0x00, 0x00, 0x00, | 2338 0x00, 0x00, 0x00, 0x00, |
2725 0x00, 0x7f, 0xff, 0xff, // Stream Id | 2339 0x00, 0x7f, 0xff, 0xff, // Stream Id |
2726 0xff, 0x00, 0x00, 0x00, // Status: INTERNAL_ERROR. | 2340 0xff, 0x00, 0x00, 0x00, // Status: INTERNAL_ERROR. |
2727 0x02, 0x47, 0x41, // Opaque Description | 2341 0x02, 0x47, 0x41, // Opaque Description |
2728 }; | 2342 }; |
2729 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); | 2343 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); |
2730 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); | 2344 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); |
2731 if (IsSpdy2()) { | 2345 if (IsSpdy3()) { |
2732 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2733 } else if (IsSpdy3()) { | |
2734 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2346 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2735 } else { | 2347 } else { |
2736 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2348 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2737 } | 2349 } |
2738 } | 2350 } |
2739 } | 2351 } |
2740 | 2352 |
2741 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { | 2353 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { |
2742 SpdyFramer framer(spdy_version_); | 2354 SpdyFramer framer(spdy_version_); |
2743 framer.set_enable_compression(false); | 2355 framer.set_enable_compression(false); |
2744 | 2356 |
2745 { | 2357 { |
2746 const char kDescription[] = "HEADERS frame, no FIN"; | 2358 const char kDescription[] = "HEADERS frame, no FIN"; |
2747 | |
2748 const unsigned char kV2FrameData[] = { | |
2749 0x80, spdy_version_ch_, 0x00, 0x08, | |
2750 0x00, 0x00, 0x00, 0x1C, | |
2751 0x00, 0x00, 0x00, 0x01, | |
2752 0x00, 0x00, 0x00, 0x02, | |
2753 0x00, 0x03, 'b', 'a', | |
2754 'r', 0x00, 0x03, 'f', | |
2755 'o', 'o', 0x00, 0x03, | |
2756 'f', 'o', 'o', 0x00, | |
2757 0x03, 'b', 'a', 'r' | |
2758 }; | |
2759 const unsigned char kV3FrameData[] = { | 2359 const unsigned char kV3FrameData[] = { |
2760 0x80, spdy_version_ch_, 0x00, 0x08, | 2360 0x80, spdy_version_ch_, 0x00, 0x08, |
2761 0x00, 0x00, 0x00, 0x24, | 2361 0x00, 0x00, 0x00, 0x24, |
2762 0x00, 0x00, 0x00, 0x01, | 2362 0x00, 0x00, 0x00, 0x01, |
2763 0x00, 0x00, 0x00, 0x02, | 2363 0x00, 0x00, 0x00, 0x02, |
2764 0x00, 0x00, 0x00, 0x03, | 2364 0x00, 0x00, 0x00, 0x03, |
2765 'b', 'a', 'r', 0x00, | 2365 'b', 'a', 'r', 0x00, |
2766 0x00, 0x00, 0x03, 'f', | 2366 0x00, 0x00, 0x03, 'f', |
2767 'o', 'o', 0x00, 0x00, | 2367 'o', 'o', 0x00, 0x00, |
2768 0x00, 0x03, 'f', 'o', | 2368 0x00, 0x03, 'f', 'o', |
2769 'o', 0x00, 0x00, 0x00, | 2369 'o', 0x00, 0x00, 0x00, |
2770 0x03, 'b', 'a', 'r' | 2370 0x03, 'b', 'a', 'r' |
2771 }; | 2371 }; |
2772 const unsigned char kV4FrameData[] = { | 2372 const unsigned char kV4FrameData[] = { |
2773 0x00, 0x00, 0x12, 0x01, // Headers: END_HEADERS | 2373 0x00, 0x00, 0x12, 0x01, // Headers: END_HEADERS |
2774 0x04, 0x00, 0x00, 0x00, // Stream 1 | 2374 0x04, 0x00, 0x00, 0x00, // Stream 1 |
2775 0x01, 0x00, 0x03, 0x62, // @.ba | 2375 0x01, 0x00, 0x03, 0x62, // @.ba |
2776 0x61, 0x72, 0x03, 0x66, // r.fo | 2376 0x61, 0x72, 0x03, 0x66, // r.fo |
2777 0x6f, 0x6f, 0x00, 0x03, // o@.f | 2377 0x6f, 0x6f, 0x00, 0x03, // o@.f |
2778 0x66, 0x6f, 0x6f, 0x03, // oo.b | 2378 0x66, 0x6f, 0x6f, 0x03, // oo.b |
2779 0x62, 0x61, 0x72, // ar | 2379 0x62, 0x61, 0x72, // ar |
2780 }; | 2380 }; |
2781 SpdyHeadersIR headers_ir(1); | 2381 SpdyHeadersIR headers_ir(1); |
2782 headers_ir.SetHeader("bar", "foo"); | 2382 headers_ir.SetHeader("bar", "foo"); |
2783 headers_ir.SetHeader("foo", "bar"); | 2383 headers_ir.SetHeader("foo", "bar"); |
2784 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2384 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2785 if (IsSpdy2()) { | 2385 if (IsSpdy3()) { |
2786 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2787 } else if (IsSpdy3()) { | |
2788 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2386 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2789 } else { | 2387 } else { |
2790 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2388 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2791 } | 2389 } |
2792 } | 2390 } |
2793 | 2391 |
2794 { | 2392 { |
2795 const char kDescription[] = | 2393 const char kDescription[] = |
2796 "HEADERS frame with a 0-length header name, FIN, max stream ID"; | 2394 "HEADERS frame with a 0-length header name, FIN, max stream ID"; |
2797 | |
2798 const unsigned char kV2FrameData[] = { | |
2799 0x80, spdy_version_ch_, 0x00, 0x08, | |
2800 0x01, 0x00, 0x00, 0x19, | |
2801 0x7f, 0xff, 0xff, 0xff, | |
2802 0x00, 0x00, 0x00, 0x02, | |
2803 0x00, 0x00, 0x00, 0x03, | |
2804 'f', 'o', 'o', 0x00, | |
2805 0x03, 'f', 'o', 'o', | |
2806 0x00, 0x03, 'b', 'a', | |
2807 'r' | |
2808 }; | |
2809 const unsigned char kV3FrameData[] = { | 2395 const unsigned char kV3FrameData[] = { |
2810 0x80, spdy_version_ch_, 0x00, 0x08, | 2396 0x80, spdy_version_ch_, 0x00, 0x08, |
2811 0x01, 0x00, 0x00, 0x21, | 2397 0x01, 0x00, 0x00, 0x21, |
2812 0x7f, 0xff, 0xff, 0xff, | 2398 0x7f, 0xff, 0xff, 0xff, |
2813 0x00, 0x00, 0x00, 0x02, | 2399 0x00, 0x00, 0x00, 0x02, |
2814 0x00, 0x00, 0x00, 0x00, | 2400 0x00, 0x00, 0x00, 0x00, |
2815 0x00, 0x00, 0x00, 0x03, | 2401 0x00, 0x00, 0x00, 0x03, |
2816 'f', 'o', 'o', 0x00, | 2402 'f', 'o', 'o', 0x00, |
2817 0x00, 0x00, 0x03, 'f', | 2403 0x00, 0x00, 0x03, 'f', |
2818 'o', 'o', 0x00, 0x00, | 2404 'o', 'o', 0x00, 0x00, |
2819 0x00, 0x03, 'b', 'a', | 2405 0x00, 0x03, 'b', 'a', |
2820 'r' | 2406 'r' |
2821 }; | 2407 }; |
2822 const unsigned char kV4FrameData[] = { | 2408 const unsigned char kV4FrameData[] = { |
2823 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS | 2409 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS |
2824 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff | 2410 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff |
2825 0xff, 0x00, 0x00, 0x03, // @.. | 2411 0xff, 0x00, 0x00, 0x03, // @.. |
2826 0x66, 0x6f, 0x6f, 0x00, // foo@ | 2412 0x66, 0x6f, 0x6f, 0x00, // foo@ |
2827 0x03, 0x66, 0x6f, 0x6f, // .foo | 2413 0x03, 0x66, 0x6f, 0x6f, // .foo |
2828 0x03, 0x62, 0x61, 0x72, // .bar | 2414 0x03, 0x62, 0x61, 0x72, // .bar |
2829 }; | 2415 }; |
2830 SpdyHeadersIR headers_ir(0x7fffffff); | 2416 SpdyHeadersIR headers_ir(0x7fffffff); |
2831 headers_ir.set_fin(true); | 2417 headers_ir.set_fin(true); |
2832 headers_ir.SetHeader("", "foo"); | 2418 headers_ir.SetHeader("", "foo"); |
2833 headers_ir.SetHeader("foo", "bar"); | 2419 headers_ir.SetHeader("foo", "bar"); |
2834 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2420 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2835 if (IsSpdy2()) { | 2421 if (IsSpdy3()) { |
2836 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2837 } else if (IsSpdy3()) { | |
2838 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2422 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2839 } else { | 2423 } else { |
2840 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2424 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2841 } | 2425 } |
2842 } | 2426 } |
2843 | 2427 |
2844 { | 2428 { |
2845 const char kDescription[] = | 2429 const char kDescription[] = |
2846 "HEADERS frame with a 0-length header val, FIN, max stream ID"; | 2430 "HEADERS frame with a 0-length header val, FIN, max stream ID"; |
2847 | |
2848 const unsigned char kV2FrameData[] = { | |
2849 0x80, spdy_version_ch_, 0x00, 0x08, | |
2850 0x01, 0x00, 0x00, 0x19, | |
2851 0x7f, 0xff, 0xff, 0xff, | |
2852 0x00, 0x00, 0x00, 0x02, | |
2853 0x00, 0x03, 'b', 'a', | |
2854 'r', 0x00, 0x03, 'f', | |
2855 'o', 'o', 0x00, 0x03, | |
2856 'f', 'o', 'o', 0x00, | |
2857 0x00 | |
2858 }; | |
2859 const unsigned char kV3FrameData[] = { | 2431 const unsigned char kV3FrameData[] = { |
2860 0x80, spdy_version_ch_, 0x00, 0x08, | 2432 0x80, spdy_version_ch_, 0x00, 0x08, |
2861 0x01, 0x00, 0x00, 0x21, | 2433 0x01, 0x00, 0x00, 0x21, |
2862 0x7f, 0xff, 0xff, 0xff, | 2434 0x7f, 0xff, 0xff, 0xff, |
2863 0x00, 0x00, 0x00, 0x02, | 2435 0x00, 0x00, 0x00, 0x02, |
2864 0x00, 0x00, 0x00, 0x03, | 2436 0x00, 0x00, 0x00, 0x03, |
2865 'b', 'a', 'r', 0x00, | 2437 'b', 'a', 'r', 0x00, |
2866 0x00, 0x00, 0x03, 'f', | 2438 0x00, 0x00, 0x03, 'f', |
2867 'o', 'o', 0x00, 0x00, | 2439 'o', 'o', 0x00, 0x00, |
2868 0x00, 0x03, 'f', 'o', | 2440 0x00, 0x03, 'f', 'o', |
2869 'o', 0x00, 0x00, 0x00, | 2441 'o', 0x00, 0x00, 0x00, |
2870 0x00 | 2442 0x00 |
2871 }; | 2443 }; |
2872 const unsigned char kV4FrameData[] = { | 2444 const unsigned char kV4FrameData[] = { |
2873 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS | 2445 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS |
2874 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff | 2446 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff |
2875 0xff, 0x00, 0x03, 0x62, // @.b | 2447 0xff, 0x00, 0x03, 0x62, // @.b |
2876 0x61, 0x72, 0x03, 0x66, // ar.f | 2448 0x61, 0x72, 0x03, 0x66, // ar.f |
2877 0x6f, 0x6f, 0x00, 0x03, // oo@. | 2449 0x6f, 0x6f, 0x00, 0x03, // oo@. |
2878 0x66, 0x6f, 0x6f, 0x00, // foo. | 2450 0x66, 0x6f, 0x6f, 0x00, // foo. |
2879 }; | 2451 }; |
2880 SpdyHeadersIR headers_ir(0x7fffffff); | 2452 SpdyHeadersIR headers_ir(0x7fffffff); |
2881 headers_ir.set_fin(true); | 2453 headers_ir.set_fin(true); |
2882 headers_ir.SetHeader("bar", "foo"); | 2454 headers_ir.SetHeader("bar", "foo"); |
2883 headers_ir.SetHeader("foo", ""); | 2455 headers_ir.SetHeader("foo", ""); |
2884 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2456 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2885 if (IsSpdy2()) { | 2457 if (IsSpdy3()) { |
2886 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | |
2887 } else if (IsSpdy3()) { | |
2888 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2458 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2889 } else { | 2459 } else { |
2890 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2460 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2891 } | 2461 } |
2892 } | 2462 } |
2893 | 2463 |
2894 { | 2464 { |
2895 const char kDescription[] = | 2465 const char kDescription[] = |
2896 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; | 2466 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; |
2897 | |
2898 const unsigned char kV4FrameData[] = { | 2467 const unsigned char kV4FrameData[] = { |
2899 0x00, 0x00, 0x14, 0x01, // Headers: FIN | END_HEADERS | PRIORITY | 2468 0x00, 0x00, 0x14, 0x01, // Headers: FIN | END_HEADERS | PRIORITY |
2900 0x25, 0x7f, 0xff, 0xff, // Stream 0x7fffffff | 2469 0x25, 0x7f, 0xff, 0xff, // Stream 0x7fffffff |
2901 0xff, 0x00, 0x00, 0x00, // parent stream | 2470 0xff, 0x00, 0x00, 0x00, // parent stream |
2902 0x00, 0xdb, // weight | 2471 0x00, 0xdb, // weight |
2903 0x00, 0x03, 0x62, 0x61, // @.ba | 2472 0x00, 0x03, 0x62, 0x61, // @.ba |
2904 0x72, 0x03, 0x66, 0x6f, // r.fo | 2473 0x72, 0x03, 0x66, 0x6f, // r.fo |
2905 0x6f, 0x00, 0x03, 0x66, // o@.f | 2474 0x6f, 0x00, 0x03, 0x66, // o@.f |
2906 0x6f, 0x6f, 0x00, // oo. | 2475 0x6f, 0x6f, 0x00, // oo. |
2907 }; | 2476 }; |
2908 SpdyHeadersIR headers_ir(0x7fffffff); | 2477 SpdyHeadersIR headers_ir(0x7fffffff); |
2909 headers_ir.set_fin(true); | 2478 headers_ir.set_fin(true); |
2910 headers_ir.set_priority(1); | 2479 headers_ir.set_priority(1); |
2911 headers_ir.set_has_priority(true); | 2480 headers_ir.set_has_priority(true); |
2912 headers_ir.SetHeader("bar", "foo"); | 2481 headers_ir.SetHeader("bar", "foo"); |
2913 headers_ir.SetHeader("foo", ""); | 2482 headers_ir.SetHeader("foo", ""); |
2914 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2483 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2915 if (IsSpdy2() || IsSpdy3()) { | 2484 if (IsSpdy3()) { |
2916 // HEADERS with priority not supported. | 2485 // HEADERS with priority not supported. |
2917 } else { | 2486 } else { |
2918 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2487 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2919 } | 2488 } |
2920 } | 2489 } |
2921 | 2490 |
2922 { | 2491 { |
2923 const char kDescription[] = | 2492 const char kDescription[] = |
2924 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded"; | 2493 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded"; |
2925 | |
2926 const unsigned char kV4FrameData[] = { | 2494 const unsigned char kV4FrameData[] = { |
2927 0x00, 0x00, 0x15, 0x01, // Headers | 2495 0x00, 0x00, 0x15, 0x01, // Headers |
2928 0x0d, 0x7f, 0xff, 0xff, // FIN | END_HEADERS | PADDED, Stream | 2496 0x0d, 0x7f, 0xff, 0xff, // FIN | END_HEADERS | PADDED, Stream |
2929 // 0x7fffffff | 2497 // 0x7fffffff |
2930 0xff, 0x05, 0x00, 0x00, // Pad length field | 2498 0xff, 0x05, 0x00, 0x00, // Pad length field |
2931 0x03, 0x66, 0x6f, 0x6f, // .foo | 2499 0x03, 0x66, 0x6f, 0x6f, // .foo |
2932 0x00, 0x03, 0x66, 0x6f, // @.fo | 2500 0x00, 0x03, 0x66, 0x6f, // @.fo |
2933 0x6f, 0x03, 0x62, 0x61, // o.ba | 2501 0x6f, 0x03, 0x62, 0x61, // o.ba |
2934 0x72, // r | 2502 0x72, // r |
2935 // Padding payload | 2503 // Padding payload |
2936 0x00, 0x00, 0x00, 0x00, 0x00, | 2504 0x00, 0x00, 0x00, 0x00, 0x00, |
2937 }; | 2505 }; |
2938 SpdyHeadersIR headers_ir(0x7fffffff); | 2506 SpdyHeadersIR headers_ir(0x7fffffff); |
2939 headers_ir.set_fin(true); | 2507 headers_ir.set_fin(true); |
2940 headers_ir.SetHeader("", "foo"); | 2508 headers_ir.SetHeader("", "foo"); |
2941 headers_ir.SetHeader("foo", "bar"); | 2509 headers_ir.SetHeader("foo", "bar"); |
2942 headers_ir.set_padding_len(6); | 2510 headers_ir.set_padding_len(6); |
2943 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2511 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2944 if (IsSpdy2() || IsSpdy3()) { | 2512 if (IsSpdy3()) { |
2945 // Padding is not supported. | 2513 // Padding is not supported. |
2946 } else { | 2514 } else { |
2947 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2515 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2948 } | 2516 } |
2949 } | 2517 } |
2950 } | 2518 } |
2951 | 2519 |
2952 // TODO(phajdan.jr): Clean up after we no longer need | 2520 // TODO(phajdan.jr): Clean up after we no longer need |
2953 // to workaround http://crbug.com/139744. | 2521 // to workaround http://crbug.com/139744. |
2954 #if !defined(USE_SYSTEM_ZLIB) | 2522 #if !defined(USE_SYSTEM_ZLIB) |
2955 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { | 2523 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
2524 if (!IsSpdy3()) { | |
2525 // Deflate compression doesn't apply to HPACK. | |
2526 return; | |
2527 } | |
2956 SpdyFramer framer(spdy_version_); | 2528 SpdyFramer framer(spdy_version_); |
2957 framer.set_enable_compression(true); | 2529 framer.set_enable_compression(true); |
2958 | 2530 |
2959 { | 2531 { |
2960 const char kDescription[] = "HEADERS frame, no FIN"; | 2532 const char kDescription[] = "HEADERS frame, no FIN"; |
2961 | |
2962 const unsigned char kV2FrameData[] = { | |
2963 0x80, spdy_version_ch_, 0x00, 0x08, | |
2964 0x00, 0x00, 0x00, 0x32, | |
2965 0x00, 0x00, 0x00, 0x01, | |
2966 0x00, 0x00, 0x38, 0xea, | |
2967 0xdf, 0xa2, 0x51, 0xb2, | |
2968 0x62, 0x60, 0x62, 0x60, | |
2969 0x4e, 0x4a, 0x2c, 0x62, | |
2970 0x60, 0x06, 0x08, 0xa0, | |
2971 0xb4, 0xfc, 0x7c, 0x80, | |
2972 0x00, 0x62, 0x60, 0x4e, | |
2973 0xcb, 0xcf, 0x67, 0x60, | |
2974 0x06, 0x08, 0xa0, 0xa4, | |
2975 0xc4, 0x22, 0x80, 0x00, | |
2976 0x02, 0x00, 0x00, 0x00, | |
2977 0xff, 0xff, | |
2978 }; | |
2979 const unsigned char kV3FrameData[] = { | 2533 const unsigned char kV3FrameData[] = { |
2980 0x80, spdy_version_ch_, 0x00, 0x08, | 2534 0x80, spdy_version_ch_, 0x00, 0x08, |
2981 0x00, 0x00, 0x00, 0x31, | 2535 0x00, 0x00, 0x00, 0x31, |
2982 0x00, 0x00, 0x00, 0x01, | 2536 0x00, 0x00, 0x00, 0x01, |
2983 0x38, 0xea, 0xe3, 0xc6, | 2537 0x38, 0xea, 0xe3, 0xc6, |
2984 0xa7, 0xc2, 0x02, 0xe5, | 2538 0xa7, 0xc2, 0x02, 0xe5, |
2985 0x0e, 0x50, 0xc2, 0x4b, | 2539 0x0e, 0x50, 0xc2, 0x4b, |
2986 0x4a, 0x04, 0xe5, 0x0b, | 2540 0x4a, 0x04, 0xe5, 0x0b, |
2987 0x66, 0x80, 0x00, 0x4a, | 2541 0x66, 0x80, 0x00, 0x4a, |
2988 0xcb, 0xcf, 0x07, 0x08, | 2542 0xcb, 0xcf, 0x07, 0x08, |
2989 0x20, 0x10, 0x95, 0x96, | 2543 0x20, 0x10, 0x95, 0x96, |
2990 0x9f, 0x0f, 0xa2, 0x00, | 2544 0x9f, 0x0f, 0xa2, 0x00, |
2991 0x02, 0x28, 0x29, 0xb1, | 2545 0x02, 0x28, 0x29, 0xb1, |
2992 0x08, 0x20, 0x80, 0x00, | 2546 0x08, 0x20, 0x80, 0x00, |
2993 0x00, 0x00, 0x00, 0xff, | 2547 0x00, 0x00, 0x00, 0xff, |
2994 0xff, | 2548 0xff, |
2995 }; | 2549 }; |
2996 const unsigned char kV2SIMDFrameData[] = { | |
2997 0x80, spdy_version_ch_, 0x00, 0x08, | |
2998 0x00, 0x00, 0x00, 0x2f, | |
2999 0x00, 0x00, 0x00, 0x01, | |
3000 0x00, 0x00, 0x38, 0xea, | |
3001 0xdf, 0xa2, 0x51, 0xb2, | |
3002 0x62, 0x60, 0x62, 0x60, | |
3003 0x4e, 0x4a, 0x2c, 0x62, | |
3004 0x60, 0x06, 0x08, 0xa0, | |
3005 0xb4, 0xfc, 0x7c, 0x80, | |
3006 0x00, 0x62, 0x60, 0x06, | |
3007 0x13, 0x00, 0x01, 0x94, | |
3008 0x94, 0x58, 0x04, 0x10, | |
3009 0x40, 0x00, 0x00, 0x00, | |
3010 0x00, 0xff, 0xff, | |
3011 }; | |
3012 const unsigned char kV3SIMDFrameData[] = { | 2550 const unsigned char kV3SIMDFrameData[] = { |
3013 0x80, spdy_version_ch_, 0x00, 0x08, | 2551 0x80, spdy_version_ch_, 0x00, 0x08, |
3014 0x00, 0x00, 0x00, 0x2c, | 2552 0x00, 0x00, 0x00, 0x2c, |
3015 0x00, 0x00, 0x00, 0x01, | 2553 0x00, 0x00, 0x00, 0x01, |
3016 0x38, 0xea, 0xe3, 0xc6, | 2554 0x38, 0xea, 0xe3, 0xc6, |
3017 0xa7, 0xc2, 0x02, 0xe5, | 2555 0xa7, 0xc2, 0x02, 0xe5, |
3018 0x0e, 0x50, 0xc2, 0x4b, | 2556 0x0e, 0x50, 0xc2, 0x4b, |
3019 0x4a, 0x04, 0xe5, 0x0b, | 2557 0x4a, 0x04, 0xe5, 0x0b, |
3020 0x66, 0x80, 0x00, 0x4a, | 2558 0x66, 0x80, 0x00, 0x4a, |
3021 0xcb, 0xcf, 0x07, 0x08, | 2559 0xcb, 0xcf, 0x07, 0x08, |
3022 0x20, 0x24, 0x0a, 0x20, | 2560 0x20, 0x24, 0x0a, 0x20, |
3023 0x80, 0x92, 0x12, 0x8b, | 2561 0x80, 0x92, 0x12, 0x8b, |
3024 0x00, 0x02, 0x08, 0x00, | 2562 0x00, 0x02, 0x08, 0x00, |
3025 0x00, 0x00, 0xff, 0xff, | 2563 0x00, 0x00, 0xff, 0xff, |
3026 }; | 2564 }; |
3027 | 2565 |
3028 SpdyHeadersIR headers_ir(1); | 2566 SpdyHeadersIR headers_ir(1); |
3029 headers_ir.SetHeader("bar", "foo"); | 2567 headers_ir.SetHeader("bar", "foo"); |
3030 headers_ir.SetHeader("foo", "bar"); | 2568 headers_ir.SetHeader("foo", "bar"); |
3031 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2569 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
3032 const unsigned char* frame_data = | 2570 const unsigned char* frame_data = |
3033 reinterpret_cast<const unsigned char*>(frame->data()); | 2571 reinterpret_cast<const unsigned char*>(frame->data()); |
3034 if (IsSpdy2()) { | 2572 if (memcmp(frame_data, |
3035 // Try comparing with SIMD version, if that fails, do a failing check | 2573 kV3SIMDFrameData, |
3036 // with pretty printing against non-SIMD version | 2574 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { |
3037 if (memcmp(frame_data, | 2575 CompareCharArraysWithHexError(kDescription, |
3038 kV2SIMDFrameData, | 2576 frame_data, |
3039 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { | 2577 frame->size(), |
3040 CompareCharArraysWithHexError(kDescription, | 2578 kV3FrameData, |
3041 frame_data, | 2579 arraysize(kV3FrameData)); |
3042 frame->size(), | |
3043 kV2FrameData, | |
3044 arraysize(kV2FrameData)); | |
3045 } | |
3046 } else if (IsSpdy3()) { | |
3047 if (memcmp(frame_data, | |
3048 kV3SIMDFrameData, | |
3049 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { | |
3050 CompareCharArraysWithHexError(kDescription, | |
3051 frame_data, | |
3052 frame->size(), | |
3053 kV3FrameData, | |
3054 arraysize(kV3FrameData)); | |
3055 } | |
3056 } else { | |
3057 // Deflate compression doesn't apply to HPACK. | |
3058 } | 2580 } |
3059 } | 2581 } |
3060 } | 2582 } |
3061 #endif // !defined(USE_SYSTEM_ZLIB) | 2583 #endif // !defined(USE_SYSTEM_ZLIB) |
3062 | 2584 |
3063 TEST_P(SpdyFramerTest, CreateWindowUpdate) { | 2585 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
3064 SpdyFramer framer(spdy_version_); | 2586 SpdyFramer framer(spdy_version_); |
3065 | 2587 |
3066 { | 2588 { |
3067 const char kDescription[] = "WINDOW_UPDATE frame"; | 2589 const char kDescription[] = "WINDOW_UPDATE frame"; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3174 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2696 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
3175 if (spdy_version_ <= SPDY3) { | 2697 if (spdy_version_ <= SPDY3) { |
3176 return; | 2698 return; |
3177 } | 2699 } |
3178 | 2700 |
3179 { | 2701 { |
3180 // Test framing PUSH_PROMISE without padding. | 2702 // Test framing PUSH_PROMISE without padding. |
3181 SpdyFramer framer(spdy_version_); | 2703 SpdyFramer framer(spdy_version_); |
3182 framer.set_enable_compression(false); | 2704 framer.set_enable_compression(false); |
3183 const char kDescription[] = "PUSH_PROMISE frame without padding"; | 2705 const char kDescription[] = "PUSH_PROMISE frame without padding"; |
3184 | |
3185 const unsigned char kFrameData[] = { | 2706 const unsigned char kFrameData[] = { |
3186 0x00, 0x00, 0x16, 0x05, // PUSH_PROMISE | 2707 0x00, 0x00, 0x16, 0x05, // PUSH_PROMISE |
3187 0x04, 0x00, 0x00, 0x00, // END_HEADERS | 2708 0x04, 0x00, 0x00, 0x00, // END_HEADERS |
3188 0x2a, 0x00, 0x00, 0x00, // Stream 42 | 2709 0x2a, 0x00, 0x00, 0x00, // Stream 42 |
3189 0x39, 0x00, 0x03, 0x62, // Promised stream 57, @.b | 2710 0x39, 0x00, 0x03, 0x62, // Promised stream 57, @.b |
3190 0x61, 0x72, 0x03, 0x66, // ar.f | 2711 0x61, 0x72, 0x03, 0x66, // ar.f |
3191 0x6f, 0x6f, 0x00, 0x03, // oo@. | 2712 0x6f, 0x6f, 0x00, 0x03, // oo@. |
3192 0x66, 0x6f, 0x6f, 0x03, // foo. | 2713 0x66, 0x6f, 0x6f, 0x03, // foo. |
3193 0x62, 0x61, 0x72, // bar | 2714 0x62, 0x61, 0x72, // bar |
3194 }; | 2715 }; |
3195 | 2716 |
3196 SpdyPushPromiseIR push_promise(42, 57); | 2717 SpdyPushPromiseIR push_promise(42, 57); |
3197 push_promise.SetHeader("bar", "foo"); | 2718 push_promise.SetHeader("bar", "foo"); |
3198 push_promise.SetHeader("foo", "bar"); | 2719 push_promise.SetHeader("foo", "bar"); |
3199 scoped_ptr<SpdySerializedFrame> frame( | 2720 scoped_ptr<SpdySerializedFrame> frame( |
3200 framer.SerializePushPromise(push_promise)); | 2721 framer.SerializePushPromise(push_promise)); |
3201 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2722 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
3202 } | 2723 } |
3203 | 2724 |
3204 { | 2725 { |
3205 // Test framing PUSH_PROMISE with one byte of padding. | 2726 // Test framing PUSH_PROMISE with one byte of padding. |
3206 SpdyFramer framer(spdy_version_); | 2727 SpdyFramer framer(spdy_version_); |
3207 framer.set_enable_compression(false); | 2728 framer.set_enable_compression(false); |
3208 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding"; | 2729 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding"; |
3209 | |
3210 const unsigned char kFrameData[] = { | 2730 const unsigned char kFrameData[] = { |
3211 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE | 2731 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE |
3212 0x0c, 0x00, 0x00, 0x00, // END_HEADERS | PADDED | 2732 0x0c, 0x00, 0x00, 0x00, // END_HEADERS | PADDED |
3213 0x2a, 0x00, 0x00, 0x00, // Stream 42, Pad length field | 2733 0x2a, 0x00, 0x00, 0x00, // Stream 42, Pad length field |
3214 0x00, 0x39, 0x00, 0x03, // Promised stream 57 | 2734 0x00, 0x39, 0x00, 0x03, // Promised stream 57 |
3215 0x62, 0x61, 0x72, 0x03, // bar. | 2735 0x62, 0x61, 0x72, 0x03, // bar. |
3216 0x66, 0x6f, 0x6f, 0x00, // foo@ | 2736 0x66, 0x6f, 0x6f, 0x00, // foo@ |
3217 0x03, 0x66, 0x6f, 0x6f, // .foo | 2737 0x03, 0x66, 0x6f, 0x6f, // .foo |
3218 0x03, 0x62, 0x61, 0x72, // .bar | 2738 0x03, 0x62, 0x61, 0x72, // .bar |
3219 }; | 2739 }; |
3220 | 2740 |
3221 SpdyPushPromiseIR push_promise(42, 57); | 2741 SpdyPushPromiseIR push_promise(42, 57); |
3222 push_promise.set_padding_len(1); | 2742 push_promise.set_padding_len(1); |
3223 push_promise.SetHeader("bar", "foo"); | 2743 push_promise.SetHeader("bar", "foo"); |
3224 push_promise.SetHeader("foo", "bar"); | 2744 push_promise.SetHeader("foo", "bar"); |
3225 scoped_ptr<SpdySerializedFrame> frame( | 2745 scoped_ptr<SpdySerializedFrame> frame( |
3226 framer.SerializePushPromise(push_promise)); | 2746 framer.SerializePushPromise(push_promise)); |
3227 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2747 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
3228 } | 2748 } |
3229 | 2749 |
3230 { | 2750 { |
3231 // Test framing PUSH_PROMISE with 177 bytes of padding. | 2751 // Test framing PUSH_PROMISE with 177 bytes of padding. |
3232 SpdyFramer framer(spdy_version_); | 2752 SpdyFramer framer(spdy_version_); |
3233 framer.set_enable_compression(false); | 2753 framer.set_enable_compression(false); |
3234 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding"; | 2754 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding"; |
3235 | |
3236 const unsigned char kFrameData[] = { | 2755 const unsigned char kFrameData[] = { |
3237 0x00, 0x00, 0xc7, 0x05, // PUSH_PROMISE | 2756 0x00, 0x00, 0xc7, 0x05, // PUSH_PROMISE |
3238 0x0c, 0x00, 0x00, 0x00, // END_HEADERS | PADDED | 2757 0x0c, 0x00, 0x00, 0x00, // END_HEADERS | PADDED |
3239 0x2a, 0xb0, 0x00, 0x00, // Stream 42, Pad length field | 2758 0x2a, 0xb0, 0x00, 0x00, // Stream 42, Pad length field |
3240 0x00, 0x39, 0x00, 0x03, // Promised stream 57 | 2759 0x00, 0x39, 0x00, 0x03, // Promised stream 57 |
3241 0x62, 0x61, 0x72, 0x03, // bar. | 2760 0x62, 0x61, 0x72, 0x03, // bar. |
3242 0x66, 0x6f, 0x6f, 0x00, // foo@ | 2761 0x66, 0x6f, 0x6f, 0x00, // foo@ |
3243 0x03, 0x66, 0x6f, 0x6f, // .foo | 2762 0x03, 0x66, 0x6f, 0x6f, // .foo |
3244 0x03, 0x62, 0x61, 0x72, // .bar | 2763 0x03, 0x62, 0x61, 0x72, // .bar |
3245 // Padding of 176 0x00(s). | 2764 // Padding of 176 0x00(s). |
(...skipping 25 matching lines...) Expand all Loading... | |
3271 } | 2790 } |
3272 | 2791 |
3273 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { | 2792 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
3274 if (spdy_version_ <= SPDY3) { | 2793 if (spdy_version_ <= SPDY3) { |
3275 return; | 2794 return; |
3276 } | 2795 } |
3277 | 2796 |
3278 SpdyFramer framer(spdy_version_); | 2797 SpdyFramer framer(spdy_version_); |
3279 framer.set_enable_compression(false); | 2798 framer.set_enable_compression(false); |
3280 const char kDescription[] = "CONTINUATION frame"; | 2799 const char kDescription[] = "CONTINUATION frame"; |
3281 | |
3282 const unsigned char kFrameData[] = { | 2800 const unsigned char kFrameData[] = { |
3283 0x00, 0x00, 0x12, 0x09, 0x00, // CONTINUATION | 2801 0x00, 0x00, 0x12, 0x09, 0x00, // CONTINUATION |
3284 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 2802 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
3285 0x00, 0x03, 0x62, 0x61, // @.ba | 2803 0x00, 0x03, 0x62, 0x61, // @.ba |
3286 0x72, 0x03, 0x66, 0x6f, // r.fo | 2804 0x72, 0x03, 0x66, 0x6f, // r.fo |
3287 0x6f, 0x00, 0x03, 0x66, // o@.f | 2805 0x6f, 0x00, 0x03, 0x66, // o@.f |
3288 0x6f, 0x6f, 0x03, 0x62, // oo.b | 2806 0x6f, 0x6f, 0x03, 0x62, // oo.b |
3289 0x61, 0x72, // ar | 2807 0x61, 0x72, // ar |
3290 }; | 2808 }; |
3291 | 2809 |
(...skipping 11 matching lines...) Expand all Loading... | |
3303 } | 2821 } |
3304 | 2822 |
3305 { | 2823 { |
3306 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of | 2824 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of |
3307 // padding, cannot hold all the data payload, which is overflowed to the | 2825 // padding, cannot hold all the data payload, which is overflowed to the |
3308 // consecutive CONTINUATION frame. | 2826 // consecutive CONTINUATION frame. |
3309 SpdyFramer framer(spdy_version_); | 2827 SpdyFramer framer(spdy_version_); |
3310 framer.set_enable_compression(false); | 2828 framer.set_enable_compression(false); |
3311 const char kDescription[] = | 2829 const char kDescription[] = |
3312 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; | 2830 "PUSH_PROMISE and CONTINUATION frames with one byte of padding"; |
3313 | |
3314 const unsigned char kPartialPushPromiseFrameData[] = { | 2831 const unsigned char kPartialPushPromiseFrameData[] = { |
3315 0x00, 0x03, 0xf7, 0x05, // PUSH_PROMISE | 2832 0x00, 0x03, 0xf7, 0x05, // PUSH_PROMISE |
3316 0x08, 0x00, 0x00, 0x00, // PADDED | 2833 0x08, 0x00, 0x00, 0x00, // PADDED |
3317 0x2a, 0x00, 0x00, 0x00, // Stream 42 | 2834 0x2a, 0x00, 0x00, 0x00, // Stream 42 |
3318 0x00, 0x39, 0x00, 0x03, // Promised stream 57 | 2835 0x00, 0x39, 0x00, 0x03, // Promised stream 57 |
3319 0x78, 0x78, 0x78, 0x7f, // xxx. | 2836 0x78, 0x78, 0x78, 0x7f, // xxx. |
3320 0x81, 0x07, 0x78, 0x78, // ..xx | 2837 0x81, 0x07, 0x78, 0x78, // ..xx |
3321 0x78, 0x78, 0x78, 0x78, // xxxx | 2838 0x78, 0x78, 0x78, 0x78, // xxxx |
3322 0x78, 0x78, 0x78, 0x78, // xxxx | 2839 0x78, 0x78, 0x78, 0x78, // xxxx |
3323 0x78, 0x78, 0x78, 0x78, // xxxx | 2840 0x78, 0x78, 0x78, 0x78, // xxxx |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3895 EXPECT_EQ(3 * 2, visitor.setting_count_); | 3412 EXPECT_EQ(3 * 2, visitor.setting_count_); |
3896 if (spdy_version_ > SPDY3) { | 3413 if (spdy_version_ > SPDY3) { |
3897 EXPECT_EQ(2, visitor.settings_ack_sent_); | 3414 EXPECT_EQ(2, visitor.settings_ack_sent_); |
3898 } | 3415 } |
3899 } | 3416 } |
3900 | 3417 |
3901 // Tests handling of SETTINGS frame with duplicate entries. | 3418 // Tests handling of SETTINGS frame with duplicate entries. |
3902 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { | 3419 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
3903 SpdyFramer framer(spdy_version_); | 3420 SpdyFramer framer(spdy_version_); |
3904 | 3421 |
3905 const unsigned char kV2FrameData[] = { | |
3906 0x80, spdy_version_ch_, 0x00, 0x04, | |
3907 0x00, 0x00, 0x00, 0x1C, | |
3908 0x00, 0x00, 0x00, 0x03, | |
3909 0x01, 0x00, 0x00, 0x00, // 1st Setting | |
3910 0x00, 0x00, 0x00, 0x02, | |
3911 0x01, 0x00, 0x00, 0x00, // 2nd (duplicate) Setting | |
3912 0x00, 0x00, 0x00, 0x03, | |
3913 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting | |
3914 0x00, 0x00, 0x00, 0x03, | |
3915 }; | |
3916 const unsigned char kV3FrameData[] = { | 3422 const unsigned char kV3FrameData[] = { |
3917 0x80, spdy_version_ch_, 0x00, 0x04, | 3423 0x80, spdy_version_ch_, 0x00, 0x04, |
3918 0x00, 0x00, 0x00, 0x1C, | 3424 0x00, 0x00, 0x00, 0x1C, |
3919 0x00, 0x00, 0x00, 0x03, | 3425 0x00, 0x00, 0x00, 0x03, |
3920 0x00, 0x00, 0x00, 0x01, // 1st Setting | 3426 0x00, 0x00, 0x00, 0x01, // 1st Setting |
3921 0x00, 0x00, 0x00, 0x02, | 3427 0x00, 0x00, 0x00, 0x02, |
3922 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting | 3428 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting |
3923 0x00, 0x00, 0x00, 0x03, | 3429 0x00, 0x00, 0x00, 0x03, |
3924 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting | 3430 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting |
3925 0x00, 0x00, 0x00, 0x03, | 3431 0x00, 0x00, 0x00, 0x03, |
3926 }; | 3432 }; |
3927 const unsigned char kV4FrameData[] = { | 3433 const unsigned char kV4FrameData[] = { |
3928 0x00, 0x00, 0x12, 0x04, | 3434 0x00, 0x00, 0x12, 0x04, |
3929 0x00, 0x00, 0x00, 0x00, | 3435 0x00, 0x00, 0x00, 0x00, |
3930 0x00, 0x00, 0x01, // 1st Setting | 3436 0x00, 0x00, 0x01, // 1st Setting |
3931 0x00, 0x00, 0x00, 0x02, | 3437 0x00, 0x00, 0x00, 0x02, |
3932 0x00, 0x01, // 2nd (duplicate) Setting | 3438 0x00, 0x01, // 2nd (duplicate) Setting |
3933 0x00, 0x00, 0x00, 0x03, | 3439 0x00, 0x00, 0x00, 0x03, |
3934 0x00, 0x03, // 3rd (unprocessed) Setting | 3440 0x00, 0x03, // 3rd (unprocessed) Setting |
3935 0x00, 0x00, 0x00, 0x03, | 3441 0x00, 0x00, 0x00, 0x03, |
3936 }; | 3442 }; |
3937 | 3443 |
3938 TestSpdyVisitor visitor(spdy_version_); | 3444 TestSpdyVisitor visitor(spdy_version_); |
3939 visitor.use_compression_ = false; | 3445 visitor.use_compression_ = false; |
3940 if (IsSpdy2()) { | 3446 if (IsSpdy3()) { |
3941 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | |
3942 } else if (IsSpdy3()) { | |
3943 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3447 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
3944 } else { | 3448 } else { |
3945 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3449 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
3946 } | 3450 } |
3947 | 3451 |
3948 if (!IsSpdy4()) { | 3452 if (!IsSpdy4()) { |
3949 EXPECT_EQ(1, visitor.setting_count_); | 3453 EXPECT_EQ(1, visitor.setting_count_); |
3950 EXPECT_EQ(1, visitor.error_count_); | 3454 EXPECT_EQ(1, visitor.error_count_); |
3951 } else { | 3455 } else { |
3952 // In SPDY 4+, duplicate settings are allowed; | 3456 // In SPDY 4+, duplicate settings are allowed; |
3953 // each setting replaces the previous value for that setting. | 3457 // each setting replaces the previous value for that setting. |
3954 EXPECT_EQ(3, visitor.setting_count_); | 3458 EXPECT_EQ(3, visitor.setting_count_); |
3955 EXPECT_EQ(0, visitor.error_count_); | 3459 EXPECT_EQ(0, visitor.error_count_); |
3956 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3460 EXPECT_EQ(1, visitor.settings_ack_sent_); |
3957 } | 3461 } |
3958 } | 3462 } |
3959 | 3463 |
3960 // Tests handling of SETTINGS frame with a setting we don't recognize. | 3464 // Tests handling of SETTINGS frame with a setting we don't recognize. |
3961 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { | 3465 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { |
3962 SpdyFramer framer(spdy_version_); | 3466 SpdyFramer framer(spdy_version_); |
3963 | 3467 |
3964 const unsigned char kV2FrameData[] = { | |
3965 0x80, spdy_version_ch_, 0x00, 0x04, | |
3966 0x00, 0x00, 0x00, 0x1C, | |
3967 0x00, 0x00, 0x00, 0x01, | |
3968 0x10, 0x00, 0x00, 0x00, // 1st Setting | |
3969 0x00, 0x00, 0x00, 0x02, | |
3970 }; | |
3971 const unsigned char kV3FrameData[] = { | 3468 const unsigned char kV3FrameData[] = { |
3972 0x80, spdy_version_ch_, 0x00, 0x04, | 3469 0x80, spdy_version_ch_, 0x00, 0x04, |
3973 0x00, 0x00, 0x00, 0x1C, | 3470 0x00, 0x00, 0x00, 0x1C, |
3974 0x00, 0x00, 0x00, 0x01, | 3471 0x00, 0x00, 0x00, 0x01, |
3975 0x00, 0x00, 0x00, 0x10, // 1st Setting | 3472 0x00, 0x00, 0x00, 0x10, // 1st Setting |
3976 0x00, 0x00, 0x00, 0x02, | 3473 0x00, 0x00, 0x00, 0x02, |
3977 }; | 3474 }; |
3978 const unsigned char kV4FrameData[] = { | 3475 const unsigned char kV4FrameData[] = { |
3979 0x00, 0x00, 0x06, 0x04, | 3476 0x00, 0x00, 0x06, 0x04, |
3980 0x00, 0x00, 0x00, 0x00, | 3477 0x00, 0x00, 0x00, 0x00, |
3981 0x00, 0x00, 0x10, // 1st Setting | 3478 0x00, 0x00, 0x10, // 1st Setting |
3982 0x00, 0x00, 0x00, 0x02, | 3479 0x00, 0x00, 0x00, 0x02, |
3983 }; | 3480 }; |
3984 | 3481 |
3985 TestSpdyVisitor visitor(spdy_version_); | 3482 TestSpdyVisitor visitor(spdy_version_); |
3986 visitor.use_compression_ = false; | 3483 visitor.use_compression_ = false; |
3987 if (IsSpdy2()) { | 3484 if (IsSpdy3()) { |
3988 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | |
3989 } else if (IsSpdy3()) { | |
3990 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3485 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
3991 } else { | 3486 } else { |
3992 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3487 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
3993 } | 3488 } |
3994 | 3489 |
3995 if (!IsSpdy4()) { | 3490 if (!IsSpdy4()) { |
3996 EXPECT_EQ(0, visitor.setting_count_); | 3491 EXPECT_EQ(0, visitor.setting_count_); |
3997 EXPECT_EQ(1, visitor.error_count_); | 3492 EXPECT_EQ(1, visitor.error_count_); |
3998 } else { | 3493 } else { |
3999 // In SPDY 4+, we ignore unknown settings because of extensions. | 3494 // In SPDY 4+, we ignore unknown settings because of extensions. |
4000 EXPECT_EQ(0, visitor.setting_count_); | 3495 EXPECT_EQ(0, visitor.setting_count_); |
4001 EXPECT_EQ(0, visitor.error_count_); | 3496 EXPECT_EQ(0, visitor.error_count_); |
4002 } | 3497 } |
4003 } | 3498 } |
4004 | 3499 |
4005 // Tests handling of SETTINGS frame with entries out of order. | 3500 // Tests handling of SETTINGS frame with entries out of order. |
4006 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 3501 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
4007 SpdyFramer framer(spdy_version_); | 3502 SpdyFramer framer(spdy_version_); |
4008 | 3503 |
4009 const unsigned char kV2FrameData[] = { | |
4010 0x80, spdy_version_ch_, 0x00, 0x04, | |
4011 0x00, 0x00, 0x00, 0x1C, | |
4012 0x00, 0x00, 0x00, 0x03, | |
4013 0x02, 0x00, 0x00, 0x00, // 1st Setting | |
4014 0x00, 0x00, 0x00, 0x02, | |
4015 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting | |
4016 0x00, 0x00, 0x00, 0x03, | |
4017 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting | |
4018 0x00, 0x00, 0x00, 0x03, | |
4019 }; | |
4020 const unsigned char kV3FrameData[] = { | 3504 const unsigned char kV3FrameData[] = { |
4021 0x80, spdy_version_ch_, 0x00, 0x04, | 3505 0x80, spdy_version_ch_, 0x00, 0x04, |
4022 0x00, 0x00, 0x00, 0x1C, | 3506 0x00, 0x00, 0x00, 0x1C, |
4023 0x00, 0x00, 0x00, 0x03, | 3507 0x00, 0x00, 0x00, 0x03, |
4024 0x00, 0x00, 0x00, 0x02, // 1st Setting | 3508 0x00, 0x00, 0x00, 0x02, // 1st Setting |
4025 0x00, 0x00, 0x00, 0x02, | 3509 0x00, 0x00, 0x00, 0x02, |
4026 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting | 3510 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting |
4027 0x00, 0x00, 0x00, 0x03, | 3511 0x00, 0x00, 0x00, 0x03, |
4028 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting | 3512 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting |
4029 0x00, 0x00, 0x00, 0x03, | 3513 0x00, 0x00, 0x00, 0x03, |
4030 }; | 3514 }; |
4031 const unsigned char kV4FrameData[] = { | 3515 const unsigned char kV4FrameData[] = { |
4032 0x00, 0x00, 0x12, 0x04, | 3516 0x00, 0x00, 0x12, 0x04, |
4033 0x00, 0x00, 0x00, 0x00, | 3517 0x00, 0x00, 0x00, 0x00, |
4034 0x00, 0x00, 0x02, // 1st Setting | 3518 0x00, 0x00, 0x02, // 1st Setting |
4035 0x00, 0x00, 0x00, 0x02, | 3519 0x00, 0x00, 0x00, 0x02, |
4036 0x00, 0x01, // 2nd (out of order) Setting | 3520 0x00, 0x01, // 2nd (out of order) Setting |
4037 0x00, 0x00, 0x00, 0x03, | 3521 0x00, 0x00, 0x00, 0x03, |
4038 0x00, 0x03, // 3rd (unprocessed) Setting | 3522 0x00, 0x03, // 3rd (unprocessed) Setting |
4039 0x00, 0x00, 0x00, 0x03, | 3523 0x00, 0x00, 0x00, 0x03, |
4040 }; | 3524 }; |
4041 | 3525 |
4042 TestSpdyVisitor visitor(spdy_version_); | 3526 TestSpdyVisitor visitor(spdy_version_); |
4043 visitor.use_compression_ = false; | 3527 visitor.use_compression_ = false; |
4044 if (IsSpdy2()) { | 3528 if (IsSpdy3()) { |
4045 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | |
4046 } else if (IsSpdy3()) { | |
4047 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3529 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
4048 } else { | 3530 } else { |
4049 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3531 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
4050 } | 3532 } |
4051 | 3533 |
4052 if (!IsSpdy4()) { | 3534 if (!IsSpdy4()) { |
4053 EXPECT_EQ(1, visitor.setting_count_); | 3535 EXPECT_EQ(1, visitor.setting_count_); |
4054 EXPECT_EQ(1, visitor.error_count_); | 3536 EXPECT_EQ(1, visitor.error_count_); |
4055 } else { | 3537 } else { |
4056 // In SPDY 4+, settings are allowed in any order. | 3538 // In SPDY 4+, settings are allowed in any order. |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4680 EXPECT_EQ(9u, framer.GetBlockedSize()); | 4162 EXPECT_EQ(9u, framer.GetBlockedSize()); |
4681 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); | 4163 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); |
4682 EXPECT_EQ(18u, framer.GetAltSvcMinimumSize()); | 4164 EXPECT_EQ(18u, framer.GetAltSvcMinimumSize()); |
4683 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); | 4165 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); |
4684 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); | 4166 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); |
4685 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); | 4167 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); |
4686 } else { | 4168 } else { |
4687 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); | 4169 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); |
4688 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); | 4170 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); |
4689 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); | 4171 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); |
4690 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); | 4172 EXPECT_EQ(12u, framer.GetSynReplyMinimumSize()); |
4691 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); | 4173 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); |
4692 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); | 4174 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); |
4693 EXPECT_EQ(12u, framer.GetPingSize()); | 4175 EXPECT_EQ(12u, framer.GetPingSize()); |
4694 EXPECT_EQ(IsSpdy2() ? 12u : 16u, framer.GetGoAwayMinimumSize()); | 4176 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); |
4695 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetHeadersMinimumSize()); | 4177 EXPECT_EQ(12u, framer.GetHeadersMinimumSize()); |
4696 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); | 4178 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); |
4697 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); | 4179 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); |
4698 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize()); | 4180 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize()); |
4699 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload()); | 4181 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload()); |
4700 } | 4182 } |
4701 } | 4183 } |
4702 | 4184 |
4703 TEST_P(SpdyFramerTest, StateToStringTest) { | 4185 TEST_P(SpdyFramerTest, StateToStringTest) { |
4704 EXPECT_STREQ("ERROR", | 4186 EXPECT_STREQ("ERROR", |
4705 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); | 4187 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4928 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4410 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4929 } else { | 4411 } else { |
4930 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4412 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4931 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4413 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4932 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4414 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4933 } | 4415 } |
4934 } | 4416 } |
4935 } | 4417 } |
4936 | 4418 |
4937 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { | 4419 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { |
4938 if (!IsSpdy2() && !IsSpdy3()) { | 4420 if (!IsSpdy3()) { |
4939 // SYN_STREAM not supported in SPDY>3 | 4421 // SYN_STREAM not supported in SPDY>3 |
4940 return; | 4422 return; |
4941 } | 4423 } |
4942 for (int flags = 0; flags < 256; ++flags) { | 4424 for (int flags = 0; flags < 256; ++flags) { |
4943 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4425 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4944 | 4426 |
4945 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4427 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4946 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4428 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
4947 SpdyFramer framer(spdy_version_); | 4429 SpdyFramer framer(spdy_version_); |
4948 framer.set_visitor(&visitor); | 4430 framer.set_visitor(&visitor); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4982 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4464 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4983 } else { | 4465 } else { |
4984 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4466 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4985 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4467 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4986 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4468 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4987 } | 4469 } |
4988 } | 4470 } |
4989 } | 4471 } |
4990 | 4472 |
4991 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { | 4473 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { |
4992 if (!IsSpdy2() && !IsSpdy3()) { | 4474 if (!IsSpdy3()) { |
4993 // SYN_REPLY not supported in SPDY>3 | 4475 // SYN_REPLY not supported in SPDY>3 |
4994 return; | 4476 return; |
4995 } | 4477 } |
4996 for (int flags = 0; flags < 256; ++flags) { | 4478 for (int flags = 0; flags < 256; ++flags) { |
4997 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4479 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4998 | 4480 |
4999 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4481 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5000 SpdyFramer framer(spdy_version_); | 4482 SpdyFramer framer(spdy_version_); |
5001 framer.set_visitor(&visitor); | 4483 framer.set_visitor(&visitor); |
5002 | 4484 |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5429 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4911 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5430 } | 4912 } |
5431 } | 4913 } |
5432 } | 4914 } |
5433 | 4915 |
5434 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) | 4916 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
5435 | 4917 |
5436 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) | 4918 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) |
5437 | 4919 |
5438 TEST_P(SpdyFramerTest, EmptySynStream) { | 4920 TEST_P(SpdyFramerTest, EmptySynStream) { |
5439 if (!IsSpdy2() && !IsSpdy3()) { | 4921 if (!IsSpdy3()) { |
5440 // SYN_STREAM not supported in SPDY>3. | 4922 // SYN_STREAM not supported in SPDY>3. |
5441 return; | 4923 return; |
5442 } | 4924 } |
5443 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4925 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5444 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4926 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
5445 SpdyFramer framer(spdy_version_); | 4927 SpdyFramer framer(spdy_version_); |
5446 framer.set_visitor(&visitor); | 4928 framer.set_visitor(&visitor); |
5447 framer.set_debug_visitor(&debug_visitor); | 4929 framer.set_debug_visitor(&debug_visitor); |
5448 | 4930 |
5449 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); | 4931 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); |
(...skipping 13 matching lines...) Expand all Loading... | |
5463 | 4945 |
5464 framer.ProcessInput(frame->data(), framer.GetSynStreamMinimumSize()); | 4946 framer.ProcessInput(frame->data(), framer.GetSynStreamMinimumSize()); |
5465 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4947 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5466 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4948 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5467 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4949 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5468 } | 4950 } |
5469 | 4951 |
5470 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { | 4952 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { |
5471 const uint32 kId = 0x020304; | 4953 const uint32 kId = 0x020304; |
5472 const uint32 kFlags = 0x01; | 4954 const uint32 kFlags = 0x01; |
5473 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); | 4955 const uint32 kWireFormat = htonl(0x01020304); |
5474 | 4956 |
5475 SettingsFlagsAndId id_and_flags = | 4957 SettingsFlagsAndId id_and_flags = |
5476 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 4958 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
5477 EXPECT_EQ(kId, id_and_flags.id()); | 4959 EXPECT_EQ(kId, id_and_flags.id()); |
5478 EXPECT_EQ(kFlags, id_and_flags.flags()); | 4960 EXPECT_EQ(kFlags, id_and_flags.flags()); |
5479 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 4961 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
5480 } | 4962 } |
5481 | 4963 |
5482 // Test handling of a RST_STREAM with out-of-bounds status codes. | 4964 // Test handling of a RST_STREAM with out-of-bounds status codes. |
5483 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { | 4965 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5540 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), | 5022 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), |
5541 arraysize(kV3RstStreamNumStatusCodes)); | 5023 arraysize(kV3RstStreamNumStatusCodes)); |
5542 } | 5024 } |
5543 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5025 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5544 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5026 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5545 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5027 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5546 } | 5028 } |
5547 | 5029 |
5548 // Test handling of GOAWAY frames with out-of-bounds status code. | 5030 // Test handling of GOAWAY frames with out-of-bounds status code. |
5549 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { | 5031 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { |
5550 if (spdy_version_ <= SPDY2) { | |
5551 return; | |
5552 } | |
5553 SpdyFramer framer(spdy_version_); | 5032 SpdyFramer framer(spdy_version_); |
5554 | 5033 |
5555 const unsigned char kV3FrameData[] = { | 5034 const unsigned char kV3FrameData[] = { |
5556 0x80, spdy_version_ch_, 0x00, 0x07, | 5035 0x80, spdy_version_ch_, 0x00, 0x07, |
5557 0x00, 0x00, 0x00, 0x08, | 5036 0x00, 0x00, 0x00, 0x08, |
5558 0x00, 0x00, 0x00, 0x01, // Stream Id | 5037 0x00, 0x00, 0x00, 0x01, // Stream Id |
5559 0xff, 0xff, 0xff, 0xff, // Status | 5038 0xff, 0xff, 0xff, 0xff, // Status |
5560 }; | 5039 }; |
5561 const unsigned char kV4FrameData[] = { | 5040 const unsigned char kV4FrameData[] = { |
5562 0x00, 0x00, 0x0a, 0x07, | 5041 0x00, 0x00, 0x0a, 0x07, |
(...skipping 14 matching lines...) Expand all Loading... | |
5577 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), | 5056 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), |
5578 arraysize(kV4FrameData)); | 5057 arraysize(kV4FrameData)); |
5579 } | 5058 } |
5580 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5059 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5581 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5060 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5582 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5061 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5583 } | 5062 } |
5584 | 5063 |
5585 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 5064 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
5586 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { | 5065 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
5587 const unsigned char kV2FrameData[] = { | |
5588 0x80, spdy_version_ch_, 0x00, 0x07, | |
5589 0x00, 0x00, 0x00, 0x04, | |
5590 0xff, 0xff, 0xff, 0xff, | |
5591 }; | |
5592 const unsigned char kV3FrameData[] = { | 5066 const unsigned char kV3FrameData[] = { |
5593 0x80, spdy_version_ch_, 0x00, 0x07, | 5067 0x80, spdy_version_ch_, 0x00, 0x07, |
5594 0x00, 0x00, 0x00, 0x08, | 5068 0x00, 0x00, 0x00, 0x08, |
5595 0xff, 0xff, 0xff, 0xff, | 5069 0xff, 0xff, 0xff, 0xff, |
5596 0x00, 0x00, 0x00, 0x00, | 5070 0x00, 0x00, 0x00, 0x00, |
5597 }; | 5071 }; |
5598 const unsigned char kV4FrameData[] = { | 5072 const unsigned char kV4FrameData[] = { |
5599 0x00, 0x00, 0x08, 0x07, | 5073 0x00, 0x00, 0x08, 0x07, |
5600 0x00, 0x00, 0x00, 0x00, | 5074 0x00, 0x00, 0x00, 0x00, |
5601 0x00, 0xff, 0xff, 0xff, | 5075 0x00, 0xff, 0xff, 0xff, |
5602 0xff, 0x00, 0x00, 0x00, | 5076 0xff, 0x00, 0x00, 0x00, |
5603 0x00, | 5077 0x00, |
5604 }; | 5078 }; |
5605 | 5079 |
5606 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5080 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5607 SpdyFramer framer(spdy_version_); | 5081 SpdyFramer framer(spdy_version_); |
5608 framer.set_visitor(&visitor); | 5082 framer.set_visitor(&visitor); |
5609 | 5083 |
5610 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); | 5084 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); |
5611 if (IsSpdy2()) { | 5085 if (IsSpdy3()) { |
5612 framer.ProcessInput(reinterpret_cast<const char*>(kV2FrameData), | |
5613 arraysize(kV2FrameData)); | |
5614 } else if (IsSpdy3()) { | |
5615 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), | 5086 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), |
5616 arraysize(kV3FrameData)); | 5087 arraysize(kV3FrameData)); |
5617 } else { | 5088 } else { |
5618 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), | 5089 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), |
5619 arraysize(kV4FrameData)); | 5090 arraysize(kV4FrameData)); |
5620 } | 5091 } |
5621 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5092 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5622 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5093 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5623 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5094 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5624 } | 5095 } |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5915 TestSpdyVisitor visitor(spdy_version_); | 5386 TestSpdyVisitor visitor(spdy_version_); |
5916 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5387 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
5917 | 5388 |
5918 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5389 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
5919 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5390 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
5920 visitor.framer_.error_code()) | 5391 visitor.framer_.error_code()) |
5921 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5392 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
5922 } | 5393 } |
5923 | 5394 |
5924 } // namespace net | 5395 } // namespace net |
OLD | NEW |