Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: net/spdy/spdy_framer_test.cc

Issue 1561203003: Remove SPDY/2 code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re: #3. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_headers_block_parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_framer.h" 5 #include "net/spdy/spdy_framer.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 const SpdyFrame& expected_frame, 673 const SpdyFrame& expected_frame,
674 const SpdyFrame& actual_frame) { 674 const SpdyFrame& actual_frame) {
675 CompareCharArraysWithHexError( 675 CompareCharArraysWithHexError(
676 description, 676 description,
677 reinterpret_cast<const unsigned char*>(expected_frame.data()), 677 reinterpret_cast<const unsigned char*>(expected_frame.data()),
678 expected_frame.size(), 678 expected_frame.size(),
679 reinterpret_cast<const unsigned char*>(actual_frame.data()), 679 reinterpret_cast<const unsigned char*>(actual_frame.data()),
680 actual_frame.size()); 680 actual_frame.size());
681 } 681 }
682 682
683 bool IsSpdy2() { return spdy_version_ == SPDY2; }
684 bool IsSpdy3() { return spdy_version_ == SPDY3; } 683 bool IsSpdy3() { return spdy_version_ == SPDY3; }
685 bool IsHttp2() { return spdy_version_ == HTTP2; } 684 bool IsHttp2() { return spdy_version_ == HTTP2; }
686 685
687 // Version of SPDY protocol to be used. 686 // Version of SPDY protocol to be used.
688 SpdyMajorVersion spdy_version_; 687 SpdyMajorVersion spdy_version_;
689 unsigned char spdy_version_ch_; 688 unsigned char spdy_version_ch_;
690 }; 689 };
691 690
692 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, HTTP/2. 691 // All tests are run with SPDY/3 and HTTP/2.
693 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, 692 INSTANTIATE_TEST_CASE_P(SpdyFramerTests,
694 SpdyFramerTest, 693 SpdyFramerTest,
695 ::testing::Values(SPDY2, SPDY3, HTTP2)); 694 ::testing::Values(SPDY3, HTTP2));
696 695
697 // Test that we ignore cookie where both name and value are empty. 696 // Test that we ignore cookie where both name and value are empty.
698 TEST_P(SpdyFramerTest, HeaderBlockWithEmptyCookie) { 697 TEST_P(SpdyFramerTest, HeaderBlockWithEmptyCookie) {
699 if (spdy_version_ > SPDY3) { 698 if (spdy_version_ > SPDY3) {
700 // Not implemented for hpack. 699 // Not implemented for hpack.
701 return; 700 return;
702 } 701 }
703 702
704 SpdyFramer framer(spdy_version_); 703 SpdyFramer framer(spdy_version_);
705 framer.set_enable_compression(true); 704 framer.set_enable_compression(true);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 if (spdy_version_ <= SPDY3) { 906 if (spdy_version_ <= SPDY3) {
908 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); 907 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE);
909 frame.WriteUInt32(3); // stream_id 908 frame.WriteUInt32(3); // stream_id
910 frame.WriteUInt32(0); // associated stream id 909 frame.WriteUInt32(0); // associated stream id
911 frame.WriteUInt16(0); // Priority. 910 frame.WriteUInt16(0); // Priority.
912 } else { 911 } else {
913 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); 912 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3);
914 frame.WriteUInt32(framer.GetHighestPriority()); 913 frame.WriteUInt32(framer.GetHighestPriority());
915 } 914 }
916 915
917 if (IsSpdy2()) { 916 frame.WriteUInt32(2); // Number of headers.
918 frame.WriteUInt16(2); // Number of headers. 917 frame.WriteStringPiece32("name");
919 frame.WriteStringPiece16("name"); 918 frame.WriteStringPiece32("value1");
920 frame.WriteStringPiece16("value1"); 919 frame.WriteStringPiece32("name");
921 frame.WriteStringPiece16("name"); 920 frame.WriteStringPiece32("value2");
922 frame.WriteStringPiece16("value2");
923 } else {
924 frame.WriteUInt32(2); // Number of headers.
925 frame.WriteStringPiece32("name");
926 frame.WriteStringPiece32("value1");
927 frame.WriteStringPiece32("name");
928 frame.WriteStringPiece32("value2");
929 }
930 // write the length 921 // write the length
931 frame.RewriteLength(framer); 922 frame.RewriteLength(framer);
932 923
933 SpdyHeaderBlock new_headers; 924 SpdyHeaderBlock new_headers;
934 framer.set_enable_compression(false); 925 framer.set_enable_compression(false);
935 scoped_ptr<SpdyFrame> control_frame(frame.take()); 926 scoped_ptr<SpdyFrame> control_frame(frame.take());
936 StringPiece serialized_headers = 927 StringPiece serialized_headers =
937 GetSerializedHeaders(control_frame.get(), framer); 928 GetSerializedHeaders(control_frame.get(), framer);
938 // This should fail because duplicate headers are verboten by the spec. 929 // This should fail because duplicate headers are verboten by the spec.
939 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), 930 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(),
(...skipping 13 matching lines...) Expand all
953 } else { 944 } else {
954 frame.BeginNewFrame(framer, 945 frame.BeginNewFrame(framer,
955 HEADERS, 946 HEADERS,
956 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 947 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS,
957 3); 948 3);
958 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. 949 frame.WriteUInt32(0); // Priority exclusivity and dependent stream.
959 frame.WriteUInt8(255); // Priority weight. 950 frame.WriteUInt8(255); // Priority weight.
960 } 951 }
961 952
962 string value("value1\0value2", 13); 953 string value("value1\0value2", 13);
963 if (IsSpdy2()) { 954 if (spdy_version_ > SPDY3) {
964 frame.WriteUInt16(1); // Number of headers.
965 frame.WriteStringPiece16("name");
966 frame.WriteStringPiece16(value);
967 } else if (spdy_version_ > SPDY3) {
968 // TODO(jgraettinger): If this pattern appears again, move to test class. 955 // TODO(jgraettinger): If this pattern appears again, move to test class.
969 SpdyHeaderBlock header_set; 956 SpdyHeaderBlock header_set;
970 header_set["name"] = value; 957 header_set["name"] = value;
971 string buffer; 958 string buffer;
972 HpackEncoder encoder(ObtainHpackHuffmanTable()); 959 HpackEncoder encoder(ObtainHpackHuffmanTable());
973 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); 960 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer);
974 frame.WriteBytes(&buffer[0], buffer.size()); 961 frame.WriteBytes(&buffer[0], buffer.size());
975 } else { 962 } else {
976 frame.WriteUInt32(1); // Number of headers. 963 frame.WriteUInt32(1); // Number of headers.
977 frame.WriteStringPiece32("name"); 964 frame.WriteStringPiece32("name");
(...skipping 28 matching lines...) Expand all
1006 syn_stream.SetHeader("server", "SpdyServer 1.0"); 993 syn_stream.SetHeader("server", "SpdyServer 1.0");
1007 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); 994 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST");
1008 syn_stream.SetHeader("status", "200"); 995 syn_stream.SetHeader("status", "200");
1009 syn_stream.SetHeader("version", "HTTP/1.1"); 996 syn_stream.SetHeader("version", "HTTP/1.1");
1010 syn_stream.SetHeader("content-type", "text/html"); 997 syn_stream.SetHeader("content-type", "text/html");
1011 syn_stream.SetHeader("content-length", "12"); 998 syn_stream.SetHeader("content-length", "12");
1012 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); 999 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream));
1013 size_t uncompressed_size1 = visitor->last_payload_len_; 1000 size_t uncompressed_size1 = visitor->last_payload_len_;
1014 size_t compressed_size1 = 1001 size_t compressed_size1 =
1015 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); 1002 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize();
1016 if (IsSpdy2()) { 1003 EXPECT_EQ(165u, uncompressed_size1);
1017 EXPECT_EQ(139u, uncompressed_size1);
1018 #if defined(USE_SYSTEM_ZLIB) 1004 #if defined(USE_SYSTEM_ZLIB)
1019 EXPECT_EQ(155u, compressed_size1); 1005 EXPECT_EQ(181u, compressed_size1);
1020 #else // !defined(USE_SYSTEM_ZLIB) 1006 #else // !defined(USE_SYSTEM_ZLIB)
1021 EXPECT_EQ(135u, compressed_size1); 1007 EXPECT_EQ(117u, compressed_size1);
1022 #endif // !defined(USE_SYSTEM_ZLIB) 1008 #endif // !defined(USE_SYSTEM_ZLIB)
1023 } else {
1024 EXPECT_EQ(165u, uncompressed_size1);
1025 #if defined(USE_SYSTEM_ZLIB)
1026 EXPECT_EQ(181u, compressed_size1);
1027 #else // !defined(USE_SYSTEM_ZLIB)
1028 EXPECT_EQ(117u, compressed_size1);
1029 #endif // !defined(USE_SYSTEM_ZLIB)
1030 }
1031 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); 1009 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream));
1032 size_t uncompressed_size2 = visitor->last_payload_len_; 1010 size_t uncompressed_size2 = visitor->last_payload_len_;
1033 size_t compressed_size2 = 1011 size_t compressed_size2 =
1034 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); 1012 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize();
1035 1013
1036 // Expect the second frame to be more compact than the first. 1014 // Expect the second frame to be more compact than the first.
1037 EXPECT_LE(frame2->size(), frame1->size()); 1015 EXPECT_LE(frame2->size(), frame1->size());
1038 1016
1039 // Decompress the first frame 1017 // Decompress the first frame
1040 scoped_ptr<SpdyFrame> frame3( 1018 scoped_ptr<SpdyFrame> frame3(
1041 SpdyFramerTestUtil::DecompressFrame(&framer, *frame1)); 1019 SpdyFramerTestUtil::DecompressFrame(&framer, *frame1));
1042 1020
1043 // Decompress the second frame 1021 // Decompress the second frame
1044 visitor.reset(new TestSpdyVisitor(spdy_version_)); 1022 visitor.reset(new TestSpdyVisitor(spdy_version_));
1045 framer.set_debug_visitor(visitor.get()); 1023 framer.set_debug_visitor(visitor.get());
1046 scoped_ptr<SpdyFrame> frame4( 1024 scoped_ptr<SpdyFrame> frame4(
1047 SpdyFramerTestUtil::DecompressFrame(&framer, *frame2)); 1025 SpdyFramerTestUtil::DecompressFrame(&framer, *frame2));
1048 size_t uncompressed_size4 = 1026 size_t uncompressed_size4 =
1049 frame4->size() - framer.GetSynStreamMinimumSize(); 1027 frame4->size() - framer.GetSynStreamMinimumSize();
1050 size_t compressed_size4 = 1028 size_t compressed_size4 =
1051 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); 1029 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize();
1052 if (IsSpdy2()) { 1030 EXPECT_EQ(165u, uncompressed_size4);
1053 EXPECT_EQ(139u, uncompressed_size4);
1054 #if defined(USE_SYSTEM_ZLIB) 1031 #if defined(USE_SYSTEM_ZLIB)
1055 EXPECT_EQ(149u, compressed_size4); 1032 EXPECT_EQ(175u, compressed_size4);
1056 #else // !defined(USE_SYSTEM_ZLIB) 1033 #else // !defined(USE_SYSTEM_ZLIB)
1057 EXPECT_EQ(99u, compressed_size4); 1034 EXPECT_EQ(99u, compressed_size4);
1058 #endif // !defined(USE_SYSTEM_ZLIB) 1035 #endif // !defined(USE_SYSTEM_ZLIB)
1059 } else {
1060 EXPECT_EQ(165u, uncompressed_size4);
1061 #if defined(USE_SYSTEM_ZLIB)
1062 EXPECT_EQ(175u, compressed_size4);
1063 #else // !defined(USE_SYSTEM_ZLIB)
1064 EXPECT_EQ(99u, compressed_size4);
1065 #endif // !defined(USE_SYSTEM_ZLIB)
1066 }
1067 1036
1068 EXPECT_EQ(uncompressed_size1, uncompressed_size2); 1037 EXPECT_EQ(uncompressed_size1, uncompressed_size2);
1069 EXPECT_EQ(uncompressed_size1, uncompressed_size4); 1038 EXPECT_EQ(uncompressed_size1, uncompressed_size4);
1070 EXPECT_EQ(compressed_size2, compressed_size4); 1039 EXPECT_EQ(compressed_size2, compressed_size4);
1071 1040
1072 // Expect frames 3 & 4 to be the same. 1041 // Expect frames 3 & 4 to be the same.
1073 CompareFrames("Uncompressed SYN_STREAM", *frame3, *frame4); 1042 CompareFrames("Uncompressed SYN_STREAM", *frame3, *frame4);
1074 1043
1075 // Expect frames 3 to be the same as a uncompressed frame created 1044 // Expect frames 3 to be the same as a uncompressed frame created
1076 // from scratch. 1045 // from scratch.
(...skipping 13 matching lines...) Expand all
1090 headers.SetHeader("content-type", "text/html"); 1059 headers.SetHeader("content-type", "text/html");
1091 headers.SetHeader("content-length", "12"); 1060 headers.SetHeader("content-length", "12");
1092 headers.SetHeader("x-empty-header", ""); 1061 headers.SetHeader("x-empty-header", "");
1093 1062
1094 SpdyFramer framer(spdy_version_); 1063 SpdyFramer framer(spdy_version_);
1095 framer.set_enable_compression(true); 1064 framer.set_enable_compression(true);
1096 scoped_ptr<SpdyFrame> frame1(framer.SerializeHeaders(headers)); 1065 scoped_ptr<SpdyFrame> frame1(framer.SerializeHeaders(headers));
1097 } 1066 }
1098 1067
1099 TEST_P(SpdyFramerTest, Basic) { 1068 TEST_P(SpdyFramerTest, Basic) {
1100 const unsigned char kV2Input[] = {
1101 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1
1102 0x00, 0x00, 0x00, 0x14,
1103 0x00, 0x00, 0x00, 0x01,
1104 0x00, 0x00, 0x00, 0x00,
1105 0x00, 0x00, 0x00, 0x01,
1106 0x00, 0x02, 'h', 'h',
1107 0x00, 0x02, 'v', 'v',
1108
1109 0x80, spdy_version_ch_, 0x00, 0x08, // HEADERS on Stream #1
1110 0x00, 0x00, 0x00, 0x18,
1111 0x00, 0x00, 0x00, 0x01,
1112 0x00, 0x00, 0x00, 0x02,
1113 0x00, 0x02, 'h', '2',
1114 0x00, 0x02, 'v', '2',
1115 0x00, 0x02, 'h', '3',
1116 0x00, 0x02, 'v', '3',
1117
1118 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
1119 0x00, 0x00, 0x00, 0x0c,
1120 0xde, 0xad, 0xbe, 0xef,
1121 0xde, 0xad, 0xbe, 0xef,
1122 0xde, 0xad, 0xbe, 0xef,
1123
1124 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #3
1125 0x00, 0x00, 0x00, 0x0c,
1126 0x00, 0x00, 0x00, 0x03,
1127 0x00, 0x00, 0x00, 0x00,
1128 0x00, 0x00, 0x00, 0x00,
1129
1130 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3
1131 0x00, 0x00, 0x00, 0x08,
1132 0xde, 0xad, 0xbe, 0xef,
1133 0xde, 0xad, 0xbe, 0xef,
1134
1135 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
1136 0x00, 0x00, 0x00, 0x04,
1137 0xde, 0xad, 0xbe, 0xef,
1138
1139 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1
1140 0x00, 0x00, 0x00, 0x08,
1141 0x00, 0x00, 0x00, 0x01,
1142 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL
1143
1144 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3
1145 0x00, 0x00, 0x00, 0x00,
1146
1147 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3
1148 0x00, 0x00, 0x00, 0x08,
1149 0x00, 0x00, 0x00, 0x03,
1150 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL
1151 };
1152
1153 const unsigned char kV3Input[] = { 1069 const unsigned char kV3Input[] = {
1154 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 1070 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1
1155 0x00, 0x00, 0x00, 0x1a, 1071 0x00, 0x00, 0x00, 0x1a,
1156 0x00, 0x00, 0x00, 0x01, 1072 0x00, 0x00, 0x00, 0x01,
1157 0x00, 0x00, 0x00, 0x00, 1073 0x00, 0x00, 0x00, 0x00,
1158 0x00, 0x00, 0x00, 0x00, 1074 0x00, 0x00, 0x00, 0x00,
1159 0x00, 0x01, 0x00, 0x00, 1075 0x00, 0x01, 0x00, 0x00,
1160 0x00, 0x02, 'h', 'h', 1076 0x00, 0x02, 'h', 'h',
1161 0x00, 0x00, 0x00, 0x02, 1077 0x00, 0x00, 0x00, 0x02,
1162 'v', 'v', 1078 'v', 'v',
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 1171
1256 0x00, 0x00, 0x0f, 0x03, // RST_STREAM on Stream #3 1172 0x00, 0x00, 0x0f, 0x03, // RST_STREAM on Stream #3
1257 0x00, 0x00, 0x00, 0x00, 1173 0x00, 0x00, 0x00, 0x00,
1258 0x03, 0x00, 0x00, 0x00, // RST_STREAM_CANCEL 1174 0x03, 0x00, 0x00, 0x00, // RST_STREAM_CANCEL
1259 0x08, 0x52, 0x45, 0x53, // opaque data 1175 0x08, 0x52, 0x45, 0x53, // opaque data
1260 0x45, 0x54, 0x53, 0x54, 1176 0x45, 0x54, 0x53, 0x54,
1261 0x52, 0x45, 0x41, 0x4d, 1177 0x52, 0x45, 0x41, 0x4d,
1262 }; 1178 };
1263 1179
1264 TestSpdyVisitor visitor(spdy_version_); 1180 TestSpdyVisitor visitor(spdy_version_);
1265 if (IsSpdy2()) { 1181 if (IsSpdy3()) {
1266 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1267 } else if (IsSpdy3()) {
1268 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1182 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1269 } else { 1183 } else {
1270 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); 1184 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input));
1271 } 1185 }
1272 1186
1273 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 1187 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
1274 EXPECT_EQ(24, visitor.data_bytes_); 1188 EXPECT_EQ(24, visitor.data_bytes_);
1275 EXPECT_EQ(0, visitor.error_count_); 1189 EXPECT_EQ(0, visitor.error_count_);
1276 EXPECT_EQ(2, visitor.fin_frame_count_); 1190 EXPECT_EQ(2, visitor.fin_frame_count_);
1277 1191
1278 if (IsHttp2()) { 1192 if (IsHttp2()) {
1279 EXPECT_EQ(3, visitor.headers_frame_count_); 1193 EXPECT_EQ(3, visitor.headers_frame_count_);
1280 EXPECT_EQ(0, visitor.syn_frame_count_); 1194 EXPECT_EQ(0, visitor.syn_frame_count_);
1281 StringPiece reset_stream = "RESETSTREAM"; 1195 StringPiece reset_stream = "RESETSTREAM";
1282 EXPECT_EQ(reset_stream, visitor.fin_opaque_data_); 1196 EXPECT_EQ(reset_stream, visitor.fin_opaque_data_);
1283 } else { 1197 } else {
1284 EXPECT_EQ(1, visitor.headers_frame_count_); 1198 EXPECT_EQ(1, visitor.headers_frame_count_);
1285 EXPECT_EQ(2, visitor.syn_frame_count_); 1199 EXPECT_EQ(2, visitor.syn_frame_count_);
1286 EXPECT_TRUE(visitor.fin_opaque_data_.empty()); 1200 EXPECT_TRUE(visitor.fin_opaque_data_.empty());
1287 } 1201 }
1288 1202
1289 EXPECT_EQ(0, visitor.fin_flag_count_); 1203 EXPECT_EQ(0, visitor.fin_flag_count_);
1290 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); 1204 EXPECT_EQ(0, visitor.zero_length_data_frame_count_);
1291 EXPECT_EQ(4, visitor.data_frame_count_); 1205 EXPECT_EQ(4, visitor.data_frame_count_);
1292 visitor.fin_opaque_data_.clear(); 1206 visitor.fin_opaque_data_.clear();
1293 } 1207 }
1294 1208
1295 // Test that the FIN flag on a data frame signifies EOF. 1209 // Test that the FIN flag on a data frame signifies EOF.
1296 TEST_P(SpdyFramerTest, FinOnDataFrame) { 1210 TEST_P(SpdyFramerTest, FinOnDataFrame) {
1297 const unsigned char kV2Input[] = {
1298 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1
1299 0x00, 0x00, 0x00, 0x14,
1300 0x00, 0x00, 0x00, 0x01,
1301 0x00, 0x00, 0x00, 0x00,
1302 0x00, 0x00, 0x00, 0x01,
1303 0x00, 0x02, 'h', 'h',
1304 0x00, 0x02, 'v', 'v',
1305
1306 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1
1307 0x00, 0x00, 0x00, 0x10,
1308 0x00, 0x00, 0x00, 0x01,
1309 0x00, 0x00, 0x00, 0x01,
1310 0x00, 0x02, 'a', 'a',
1311 0x00, 0x02, 'b', 'b',
1312
1313 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
1314 0x00, 0x00, 0x00, 0x0c,
1315 0xde, 0xad, 0xbe, 0xef,
1316 0xde, 0xad, 0xbe, 0xef,
1317 0xde, 0xad, 0xbe, 0xef,
1318
1319 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF
1320 0x01, 0x00, 0x00, 0x04,
1321 0xde, 0xad, 0xbe, 0xef,
1322 };
1323 const unsigned char kV3Input[] = { 1211 const unsigned char kV3Input[] = {
1324 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 1212 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1
1325 0x00, 0x00, 0x00, 0x1a, 1213 0x00, 0x00, 0x00, 0x1a,
1326 0x00, 0x00, 0x00, 0x01, 1214 0x00, 0x00, 0x00, 0x01,
1327 0x00, 0x00, 0x00, 0x00, 1215 0x00, 0x00, 0x00, 0x00,
1328 0x00, 0x00, 0x00, 0x00, 1216 0x00, 0x00, 0x00, 0x00,
1329 0x00, 0x01, 0x00, 0x00, 1217 0x00, 0x01, 0x00, 0x00,
1330 0x00, 0x02, 'h', 'h', 1218 0x00, 0x02, 'h', 'h',
1331 0x00, 0x00, 0x00, 0x02, 1219 0x00, 0x00, 0x00, 0x02,
1332 'v', 'v', 1220 'v', 'v',
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 0xef, 0xde, 0xad, 0xbe, 1257 0xef, 0xde, 0xad, 0xbe,
1370 0xef, 1258 0xef,
1371 1259
1372 0x00, 0x00, 0x04, 0x00, // DATA on Stream #1, with FIN 1260 0x00, 0x00, 0x04, 0x00, // DATA on Stream #1, with FIN
1373 0x01, 0x00, 0x00, 0x00, 1261 0x01, 0x00, 0x00, 0x00,
1374 0x01, 0xde, 0xad, 0xbe, 1262 0x01, 0xde, 0xad, 0xbe,
1375 0xef, 1263 0xef,
1376 }; 1264 };
1377 1265
1378 TestSpdyVisitor visitor(spdy_version_); 1266 TestSpdyVisitor visitor(spdy_version_);
1379 if (IsSpdy2()) { 1267 if (IsSpdy3()) {
1380 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1381 } else if (IsSpdy3()) {
1382 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1268 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1383 } else { 1269 } else {
1384 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); 1270 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input));
1385 } 1271 }
1386 1272
1387 EXPECT_EQ(0, visitor.error_count_); 1273 EXPECT_EQ(0, visitor.error_count_);
1388 if (IsHttp2()) { 1274 if (IsHttp2()) {
1389 EXPECT_EQ(0, visitor.syn_frame_count_); 1275 EXPECT_EQ(0, visitor.syn_frame_count_);
1390 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 1276 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
1391 EXPECT_EQ(2, visitor.headers_frame_count_); 1277 EXPECT_EQ(2, visitor.headers_frame_count_);
1392 } else { 1278 } else {
1393 EXPECT_EQ(1, visitor.syn_frame_count_); 1279 EXPECT_EQ(1, visitor.syn_frame_count_);
1394 EXPECT_EQ(1, visitor.syn_reply_frame_count_); 1280 EXPECT_EQ(1, visitor.syn_reply_frame_count_);
1395 EXPECT_EQ(0, visitor.headers_frame_count_); 1281 EXPECT_EQ(0, visitor.headers_frame_count_);
1396 } 1282 }
1397 EXPECT_EQ(16, visitor.data_bytes_); 1283 EXPECT_EQ(16, visitor.data_bytes_);
1398 EXPECT_EQ(0, visitor.fin_frame_count_); 1284 EXPECT_EQ(0, visitor.fin_frame_count_);
1399 EXPECT_EQ(0, visitor.fin_flag_count_); 1285 EXPECT_EQ(0, visitor.fin_flag_count_);
1400 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); 1286 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
1401 EXPECT_EQ(2, visitor.data_frame_count_); 1287 EXPECT_EQ(2, visitor.data_frame_count_);
1402 } 1288 }
1403 1289
1404 // Test that the FIN flag on a SYN reply frame signifies EOF. 1290 // Test that the FIN flag on a SYN reply frame signifies EOF.
1405 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { 1291 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) {
1406 const unsigned char kV2Input[] = {
1407 0x80, spdy_version_ch_, 0x00, // SYN Stream #1
1408 0x01, 0x00, 0x00, 0x00,
1409 0x14, 0x00, 0x00, 0x00,
1410 0x01, 0x00, 0x00, 0x00,
1411 0x00, 0x00, 0x00, 0x00,
1412 0x01, 0x00, 0x02, 'h',
1413 'h', 0x00, 0x02, 'v',
1414 'v',
1415
1416 0x80, spdy_version_ch_, 0x00, // SYN REPLY Stream #1
1417 0x02, 0x01, 0x00, 0x00,
1418 0x10, 0x00, 0x00, 0x00,
1419 0x01, 0x00, 0x00, 0x00,
1420 0x01, 0x00, 0x02, 'a',
1421 'a', 0x00, 0x02, 'b',
1422 'b',
1423 };
1424 const unsigned char kV3Input[] = { 1292 const unsigned char kV3Input[] = {
1425 0x80, spdy_version_ch_, 0x00, // SYN Stream #1 1293 0x80, spdy_version_ch_, 0x00, // SYN Stream #1
1426 0x01, 0x00, 0x00, 0x00, 1294 0x01, 0x00, 0x00, 0x00,
1427 0x1a, 0x00, 0x00, 0x00, 1295 0x1a, 0x00, 0x00, 0x00,
1428 0x01, 0x00, 0x00, 0x00, 1296 0x01, 0x00, 0x00, 0x00,
1429 0x00, 0x00, 0x00, 0x00, 1297 0x00, 0x00, 0x00, 0x00,
1430 0x00, 0x00, 0x01, 0x00, 1298 0x00, 0x00, 0x01, 0x00,
1431 0x00, 0x00, 0x02, 'h', 1299 0x00, 0x00, 0x02, 'h',
1432 'h', 0x00, 0x00, 0x00, 1300 'h', 0x00, 0x00, 0x00,
1433 0x02, 'v', 'v', 1301 0x02, 'v', 'v',
(...skipping 15 matching lines...) Expand all
1449 0x24, 0x00, 0x00, 0x00, 1317 0x24, 0x00, 0x00, 0x00,
1450 0x01, 0x00, 0x00, 0x00, // Stream 1, Priority 0 1318 0x01, 0x00, 0x00, 0x00, // Stream 1, Priority 0
1451 0x00, 0x82, // :method: GET 1319 0x00, 0x82, // :method: GET
1452 1320
1453 0x00, 0x00, 0x01, 0x01, // HEADERS: FIN | END_HEADERS 1321 0x00, 0x00, 0x01, 0x01, // HEADERS: FIN | END_HEADERS
1454 0x05, 0x00, 0x00, 0x00, 1322 0x05, 0x00, 0x00, 0x00,
1455 0x01, 0x8c, // Stream 1, :status: 200 1323 0x01, 0x8c, // Stream 1, :status: 200
1456 }; 1324 };
1457 1325
1458 TestSpdyVisitor visitor(spdy_version_); 1326 TestSpdyVisitor visitor(spdy_version_);
1459 if (IsSpdy2()) { 1327 if (IsSpdy3()) {
1460 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1461 } else if (IsSpdy3()) {
1462 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1328 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1463 } else { 1329 } else {
1464 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input)); 1330 visitor.SimulateInFramer(kH2Input, sizeof(kH2Input));
1465 } 1331 }
1466 1332
1467 EXPECT_EQ(0, visitor.error_count_); 1333 EXPECT_EQ(0, visitor.error_count_);
1468 if (IsHttp2()) { 1334 if (IsHttp2()) {
1469 EXPECT_EQ(0, visitor.syn_frame_count_); 1335 EXPECT_EQ(0, visitor.syn_frame_count_);
1470 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 1336 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
1471 EXPECT_EQ(2, visitor.headers_frame_count_); 1337 EXPECT_EQ(2, visitor.headers_frame_count_);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1597 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); 1463 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
1598 EXPECT_EQ(1, visitor.data_frame_count_); 1464 EXPECT_EQ(1, visitor.data_frame_count_);
1599 } 1465 }
1600 1466
1601 TEST_P(SpdyFramerTest, WindowUpdateFrame) { 1467 TEST_P(SpdyFramerTest, WindowUpdateFrame) {
1602 SpdyFramer framer(spdy_version_); 1468 SpdyFramer framer(spdy_version_);
1603 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( 1469 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate(
1604 SpdyWindowUpdateIR(1, 0x12345678))); 1470 SpdyWindowUpdateIR(1, 0x12345678)));
1605 1471
1606 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; 1472 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678";
1607 const unsigned char kV3FrameData[] = { // Also applies for V2. 1473 const unsigned char kV3FrameData[] = {
1608 0x80, spdy_version_ch_, 0x00, 0x09, 1474 0x80, spdy_version_ch_, 0x00, 0x09,
1609 0x00, 0x00, 0x00, 0x08, 1475 0x00, 0x00, 0x00, 0x08,
1610 0x00, 0x00, 0x00, 0x01, 1476 0x00, 0x00, 0x00, 0x01,
1611 0x12, 0x34, 0x56, 0x78 1477 0x12, 0x34, 0x56, 0x78
1612 }; 1478 };
1613 const unsigned char kH2FrameData[] = { 1479 const unsigned char kH2FrameData[] = {
1614 0x00, 0x00, 0x04, 0x08, 1480 0x00, 0x00, 0x04, 0x08,
1615 0x00, 0x00, 0x00, 0x00, 1481 0x00, 0x00, 0x00, 0x00,
1616 0x01, 0x12, 0x34, 0x56, 1482 0x01, 0x12, 0x34, 0x56,
1617 0x78 1483 0x78
1618 }; 1484 };
1619 1485
1620 if (IsHttp2()) { 1486 if (IsHttp2()) {
1621 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 1487 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
1622 } else { 1488 } else {
1623 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1489 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1624 } 1490 }
1625 } 1491 }
1626 1492
1627 TEST_P(SpdyFramerTest, CreateDataFrame) { 1493 TEST_P(SpdyFramerTest, CreateDataFrame) {
1628 SpdyFramer framer(spdy_version_); 1494 SpdyFramer framer(spdy_version_);
1629 1495
1630 { 1496 {
1631 const char kDescription[] = "'hello' data frame, no FIN"; 1497 const char kDescription[] = "'hello' data frame, no FIN";
1632 const unsigned char kV3FrameData[] = { // Also applies for V2. 1498 const unsigned char kV3FrameData[] = {
1633 0x00, 0x00, 0x00, 0x01, 1499 0x00, 0x00, 0x00, 0x01,
1634 0x00, 0x00, 0x00, 0x05, 1500 0x00, 0x00, 0x00, 0x05,
1635 'h', 'e', 'l', 'l', 1501 'h', 'e', 'l', 'l',
1636 'o' 1502 'o'
1637 }; 1503 };
1638 const unsigned char kH2FrameData[] = {0x00, 1504 const unsigned char kH2FrameData[] = {0x00,
1639 0x00, 1505 0x00,
1640 0x05, 1506 0x05,
1641 0x00, 1507 0x00,
1642 0x00, 1508 0x00,
(...skipping 23 matching lines...) Expand all
1666 data_header_ir)); 1532 data_header_ir));
1667 CompareCharArraysWithHexError( 1533 CompareCharArraysWithHexError(
1668 kDescription, reinterpret_cast<const unsigned char*>(frame->data()), 1534 kDescription, reinterpret_cast<const unsigned char*>(frame->data()),
1669 framer.GetDataFrameMinimumSize(), 1535 framer.GetDataFrameMinimumSize(),
1670 IsHttp2() ? kH2FrameData : kV3FrameData, 1536 IsHttp2() ? kH2FrameData : kV3FrameData,
1671 framer.GetDataFrameMinimumSize()); 1537 framer.GetDataFrameMinimumSize());
1672 } 1538 }
1673 1539
1674 { 1540 {
1675 const char kDescription[] = "'hello' data frame with more padding, no FIN"; 1541 const char kDescription[] = "'hello' data frame with more padding, no FIN";
1676 const unsigned char kV3FrameData[] = { // Also applies for V2. 1542 const unsigned char kV3FrameData[] = {
1677 0x00, 0x00, 0x00, 0x01, 1543 0x00, 0x00, 0x00, 0x01,
1678 0x00, 0x00, 0x00, 0x05, 1544 0x00, 0x00, 0x00, 0x05,
1679 'h', 'e', 'l', 'l', 1545 'h', 'e', 'l', 'l',
1680 'o' 1546 'o'
1681 }; 1547 };
1682 1548
1683 const unsigned char kH2FrameData[] = { 1549 const unsigned char kH2FrameData[] = {
1684 0x00, 0x00, 0xfd, 0x00, // Length = 253. PADDED set. 1550 0x00, 0x00, 0xfd, 0x00, // Length = 253. PADDED set.
1685 0x08, 0x00, 0x00, 0x00, 1551 0x08, 0x00, 0x00, 0x00,
1686 0x01, 0xf7, // Pad length field. 1552 0x01, 0xf7, // Pad length field.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); 1592 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir));
1727 CompareCharArraysWithHexError( 1593 CompareCharArraysWithHexError(
1728 kDescription, reinterpret_cast<const unsigned char*>(frame->data()), 1594 kDescription, reinterpret_cast<const unsigned char*>(frame->data()),
1729 framer.GetDataFrameMinimumSize(), 1595 framer.GetDataFrameMinimumSize(),
1730 IsHttp2() ? kH2FrameData : kV3FrameData, 1596 IsHttp2() ? kH2FrameData : kV3FrameData,
1731 framer.GetDataFrameMinimumSize()); 1597 framer.GetDataFrameMinimumSize());
1732 } 1598 }
1733 1599
1734 { 1600 {
1735 const char kDescription[] = "'hello' data frame with few padding, no FIN"; 1601 const char kDescription[] = "'hello' data frame with few padding, no FIN";
1736 const unsigned char kV3FrameData[] = { // Also applies for V2. 1602 const unsigned char kV3FrameData[] = {
1737 0x00, 0x00, 0x00, 0x01, 1603 0x00, 0x00, 0x00, 0x01,
1738 0x00, 0x00, 0x00, 0x05, 1604 0x00, 0x00, 0x00, 0x05,
1739 'h', 'e', 'l', 'l', 1605 'h', 'e', 'l', 'l',
1740 'o' 1606 'o'
1741 }; 1607 };
1742 1608
1743 const unsigned char kH2FrameData[] = { 1609 const unsigned char kH2FrameData[] = {
1744 0x00, 0x00, 0x0d, 0x00, // Length = 13. PADDED set. 1610 0x00, 0x00, 0x0d, 0x00, // Length = 13. PADDED set.
1745 0x08, 0x00, 0x00, 0x00, 1611 0x08, 0x00, 0x00, 0x00,
1746 0x01, 0x07, // Pad length field. 1612 0x01, 0x07, // Pad length field.
(...skipping 12 matching lines...) Expand all
1759 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 1625 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
1760 } else { 1626 } else {
1761 CompareFrame( 1627 CompareFrame(
1762 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1628 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1763 } 1629 }
1764 } 1630 }
1765 1631
1766 { 1632 {
1767 const char kDescription[] = 1633 const char kDescription[] =
1768 "'hello' data frame with 1 byte padding, no FIN"; 1634 "'hello' data frame with 1 byte padding, no FIN";
1769 const unsigned char kV3FrameData[] = { // Also applies for V2. 1635 const unsigned char kV3FrameData[] = {
1770 0x00, 0x00, 0x00, 0x01, 1636 0x00, 0x00, 0x00, 0x01,
1771 0x00, 0x00, 0x00, 0x05, 1637 0x00, 0x00, 0x00, 0x05,
1772 'h', 'e', 'l', 'l', 1638 'h', 'e', 'l', 'l',
1773 'o' 1639 'o'
1774 }; 1640 };
1775 1641
1776 const unsigned char kH2FrameData[] = { 1642 const unsigned char kH2FrameData[] = {
1777 0x00, 0x00, 0x06, 0x00, // Length = 6. PADDED set. 1643 0x00, 0x00, 0x06, 0x00, // Length = 6. PADDED set.
1778 0x08, 0x00, 0x00, 0x00, 1644 0x08, 0x00, 0x00, 0x00,
1779 0x01, 0x00, // Pad length field. 1645 0x01, 0x00, // Pad length field.
(...skipping 17 matching lines...) Expand all
1797 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); 1663 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir));
1798 CompareCharArraysWithHexError( 1664 CompareCharArraysWithHexError(
1799 kDescription, reinterpret_cast<const unsigned char*>(frame->data()), 1665 kDescription, reinterpret_cast<const unsigned char*>(frame->data()),
1800 framer.GetDataFrameMinimumSize(), 1666 framer.GetDataFrameMinimumSize(),
1801 IsHttp2() ? kH2FrameData : kV3FrameData, 1667 IsHttp2() ? kH2FrameData : kV3FrameData,
1802 framer.GetDataFrameMinimumSize()); 1668 framer.GetDataFrameMinimumSize());
1803 } 1669 }
1804 1670
1805 { 1671 {
1806 const char kDescription[] = "Data frame with negative data byte, no FIN"; 1672 const char kDescription[] = "Data frame with negative data byte, no FIN";
1807 const unsigned char kV3FrameData[] = { // Also applies for V2. 1673 const unsigned char kV3FrameData[] = {
1808 0x00, 0x00, 0x00, 0x01, 1674 0x00, 0x00, 0x00, 0x01,
1809 0x00, 0x00, 0x00, 0x01, 1675 0x00, 0x00, 0x00, 0x01,
1810 0xff 1676 0xff
1811 }; 1677 };
1812 const unsigned char kH2FrameData[] = { 1678 const unsigned char kH2FrameData[] = {
1813 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff}; 1679 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff};
1814 SpdyDataIR data_ir(1, "\xff"); 1680 SpdyDataIR data_ir(1, "\xff");
1815 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1681 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1816 if (IsHttp2()) { 1682 if (IsHttp2()) {
1817 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 1683 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
1818 } else { 1684 } else {
1819 CompareFrame( 1685 CompareFrame(
1820 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1686 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1821 } 1687 }
1822 } 1688 }
1823 1689
1824 { 1690 {
1825 const char kDescription[] = "'hello' data frame, with FIN"; 1691 const char kDescription[] = "'hello' data frame, with FIN";
1826 const unsigned char kV3FrameData[] = { // Also applies for V2. 1692 const unsigned char kV3FrameData[] = {
1827 0x00, 0x00, 0x00, 0x01, 1693 0x00, 0x00, 0x00, 0x01,
1828 0x01, 0x00, 0x00, 0x05, 1694 0x01, 0x00, 0x00, 0x05,
1829 'h', 'e', 'l', 'l', 1695 'h', 'e', 'l', 'l',
1830 'o' 1696 'o'
1831 }; 1697 };
1832 const unsigned char kH2FrameData[] = { 1698 const unsigned char kH2FrameData[] = {
1833 0x00, 0x00, 0x05, 0x00, 1699 0x00, 0x00, 0x05, 0x00,
1834 0x01, 0x00, 0x00, 0x00, 1700 0x01, 0x00, 0x00, 0x00,
1835 0x01, 'h', 'e', 'l', 1701 0x01, 'h', 'e', 'l',
1836 'l', 'o' 1702 'l', 'o'
1837 }; 1703 };
1838 SpdyDataIR data_ir(1, "hello"); 1704 SpdyDataIR data_ir(1, "hello");
1839 data_ir.set_fin(true); 1705 data_ir.set_fin(true);
1840 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1706 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1841 if (IsHttp2()) { 1707 if (IsHttp2()) {
1842 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 1708 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
1843 } else { 1709 } else {
1844 CompareFrame( 1710 CompareFrame(
1845 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1711 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1846 } 1712 }
1847 } 1713 }
1848 1714
1849 { 1715 {
1850 const char kDescription[] = "Empty data frame"; 1716 const char kDescription[] = "Empty data frame";
1851 const unsigned char kV3FrameData[] = { // Also applies for V2. 1717 const unsigned char kV3FrameData[] = {
1852 0x00, 0x00, 0x00, 0x01, 1718 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
1853 0x00, 0x00, 0x00, 0x00,
1854 }; 1719 };
1855 const unsigned char kH2FrameData[] = { 1720 const unsigned char kH2FrameData[] = {
1856 0x00, 0x00, 0x00, 0x00, 1721 0x00, 0x00, 0x00, 0x00,
1857 0x00, 0x00, 0x00, 0x00, 1722 0x00, 0x00, 0x00, 0x00,
1858 0x01, 1723 0x01,
1859 }; 1724 };
1860 SpdyDataIR data_ir(1, ""); 1725 SpdyDataIR data_ir(1, "");
1861 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1726 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1862 if (IsHttp2()) { 1727 if (IsHttp2()) {
1863 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 1728 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
1864 } else { 1729 } else {
1865 CompareFrame( 1730 CompareFrame(
1866 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1731 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1867 } 1732 }
1868 1733
1869 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); 1734 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir));
1870 CompareCharArraysWithHexError( 1735 CompareCharArraysWithHexError(
1871 kDescription, reinterpret_cast<const unsigned char*>(frame->data()), 1736 kDescription, reinterpret_cast<const unsigned char*>(frame->data()),
1872 framer.GetDataFrameMinimumSize(), 1737 framer.GetDataFrameMinimumSize(),
1873 IsHttp2() ? kH2FrameData : kV3FrameData, 1738 IsHttp2() ? kH2FrameData : kV3FrameData,
1874 framer.GetDataFrameMinimumSize()); 1739 framer.GetDataFrameMinimumSize());
1875 } 1740 }
1876 1741
1877 { 1742 {
1878 const char kDescription[] = "Data frame with max stream ID"; 1743 const char kDescription[] = "Data frame with max stream ID";
1879 const unsigned char kV3FrameData[] = { // Also applies for V2. 1744 const unsigned char kV3FrameData[] = {
1880 0x7f, 0xff, 0xff, 0xff, 1745 0x7f, 0xff, 0xff, 0xff,
1881 0x01, 0x00, 0x00, 0x05, 1746 0x01, 0x00, 0x00, 0x05,
1882 'h', 'e', 'l', 'l', 1747 'h', 'e', 'l', 'l',
1883 'o' 1748 'o'
1884 }; 1749 };
1885 const unsigned char kH2FrameData[] = { 1750 const unsigned char kH2FrameData[] = {
1886 0x00, 0x00, 0x05, 0x00, 1751 0x00, 0x00, 0x05, 0x00,
1887 0x01, 0x7f, 0xff, 0xff, 1752 0x01, 0x7f, 0xff, 0xff,
1888 0xff, 'h', 'e', 'l', 1753 0xff, 'h', 'e', 'l',
1889 'l', 'o' 1754 'l', 'o'
(...skipping 27 matching lines...) Expand all
1917 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); 1782 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize);
1918 1783
1919 SpdyDataIR data_ir(1, kData); 1784 SpdyDataIR data_ir(1, kData);
1920 data_ir.set_fin(true); 1785 data_ir.set_fin(true);
1921 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1786 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1922 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); 1787 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize);
1923 } 1788 }
1924 } 1789 }
1925 1790
1926 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 1791 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) {
1927 if (!IsSpdy2() && !IsSpdy3()) { 1792 if (!IsSpdy3()) {
1928 // SYN_STREAM unsupported in SPDY>3 1793 // SYN_STREAM unsupported in SPDY>3
1929 return; 1794 return;
1930 } 1795 }
1931 SpdyFramer framer(spdy_version_); 1796 SpdyFramer framer(spdy_version_);
1932 framer.set_enable_compression(false); 1797 framer.set_enable_compression(false);
1933 1798
1934 { 1799 {
1935 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; 1800 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN";
1936 1801
1937 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0;
1938 const unsigned char kV2FrameData[] = {
1939 0x80, spdy_version_ch_, 0x00, 0x01,
1940 0x00, 0x00, 0x00, 0x20,
1941 0x00, 0x00, 0x00, 0x01,
1942 0x00, 0x00, 0x00, 0x00,
1943 kPri, 0x00, 0x00, 0x02,
1944 0x00, 0x03, 'b', 'a',
1945 'r', 0x00, 0x03, 'f',
1946 'o', 'o', 0x00, 0x03,
1947 'f', 'o', 'o', 0x00,
1948 0x03, 'b', 'a', 'r'
1949 };
1950 const unsigned char kV3FrameData[] = { 1802 const unsigned char kV3FrameData[] = {
1951 0x80, spdy_version_ch_, 0x00, 0x01, 1803 0x80, spdy_version_ch_, 0x00, 0x01,
1952 0x00, 0x00, 0x00, 0x2a, 1804 0x00, 0x00, 0x00, 0x2a,
1953 0x00, 0x00, 0x00, 0x01, 1805 0x00, 0x00, 0x00, 0x01,
1954 0x00, 0x00, 0x00, 0x00, 1806 0x00, 0x00, 0x00, 0x00,
1955 kPri, 0x00, 0x00, 0x00, 1807 0xE0, 0x00, 0x00, 0x00,
1956 0x00, 0x02, 0x00, 0x00, 1808 0x00, 0x02, 0x00, 0x00,
1957 0x00, 0x03, 'b', 'a', 1809 0x00, 0x03, 'b', 'a',
1958 'r', 0x00, 0x00, 0x00, 1810 'r', 0x00, 0x00, 0x00,
1959 0x03, 'f', 'o', 'o', 1811 0x03, 'f', 'o', 'o',
1960 0x00, 0x00, 0x00, 0x03, 1812 0x00, 0x00, 0x00, 0x03,
1961 'f', 'o', 'o', 0x00, 1813 'f', 'o', 'o', 0x00,
1962 0x00, 0x00, 0x03, 'b', 1814 0x00, 0x00, 0x03, 'b',
1963 'a', 'r' 1815 'a', 'r'
1964 }; 1816 };
1965 SpdySynStreamIR syn_stream(1); 1817 SpdySynStreamIR syn_stream(1);
1966 syn_stream.set_priority(framer.GetLowestPriority()); 1818 syn_stream.set_priority(framer.GetLowestPriority());
1967 syn_stream.SetHeader("bar", "foo"); 1819 syn_stream.SetHeader("bar", "foo");
1968 syn_stream.SetHeader("foo", "bar"); 1820 syn_stream.SetHeader("foo", "bar");
1969 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1821 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
1970 if (IsSpdy2()) { 1822 if (IsSpdy3()) {
1971 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
1972 } else if (IsSpdy3()) {
1973 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1823 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1974 } else { 1824 } else {
1975 LOG(FATAL) << "Unsupported version in test."; 1825 LOG(FATAL) << "Unsupported version in test.";
1976 } 1826 }
1977 } 1827 }
1978 1828
1979 { 1829 {
1980 const char kDescription[] = 1830 const char kDescription[] =
1981 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " 1831 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, "
1982 "max stream ID"; 1832 "max stream ID";
1983 1833
1984 const unsigned char kV2FrameData[] = {
1985 0x80, spdy_version_ch_, 0x00, 0x01,
1986 0x01, 0x00, 0x00, 0x1D,
1987 0x7f, 0xff, 0xff, 0xff,
1988 0x7f, 0xff, 0xff, 0xff,
1989 0x00, 0x00, 0x00, 0x02,
1990 0x00, 0x00, 0x00, 0x03,
1991 'f', 'o', 'o', 0x00,
1992 0x03, 'f', 'o', 'o',
1993 0x00, 0x03, 'b', 'a',
1994 'r'
1995 };
1996 const unsigned char kV3FrameData[] = { 1834 const unsigned char kV3FrameData[] = {
1997 0x80, spdy_version_ch_, 0x00, 0x01, 1835 0x80, spdy_version_ch_, 0x00, 0x01,
1998 0x01, 0x00, 0x00, 0x27, 1836 0x01, 0x00, 0x00, 0x27,
1999 0x7f, 0xff, 0xff, 0xff, 1837 0x7f, 0xff, 0xff, 0xff,
2000 0x7f, 0xff, 0xff, 0xff, 1838 0x7f, 0xff, 0xff, 0xff,
2001 0x00, 0x00, 0x00, 0x00, 1839 0x00, 0x00, 0x00, 0x00,
2002 0x00, 0x02, 0x00, 0x00, 1840 0x00, 0x02, 0x00, 0x00,
2003 0x00, 0x00, 0x00, 0x00, 1841 0x00, 0x00, 0x00, 0x00,
2004 0x00, 0x03, 'f', 'o', 1842 0x00, 0x03, 'f', 'o',
2005 'o', 0x00, 0x00, 0x00, 1843 'o', 0x00, 0x00, 0x00,
2006 0x03, 'f', 'o', 'o', 1844 0x03, 'f', 'o', 'o',
2007 0x00, 0x00, 0x00, 0x03, 1845 0x00, 0x00, 0x00, 0x03,
2008 'b', 'a', 'r' 1846 'b', 'a', 'r'
2009 }; 1847 };
2010 SpdySynStreamIR syn_stream(0x7fffffff); 1848 SpdySynStreamIR syn_stream(0x7fffffff);
2011 syn_stream.set_associated_to_stream_id(0x7fffffff); 1849 syn_stream.set_associated_to_stream_id(0x7fffffff);
2012 syn_stream.set_priority(framer.GetHighestPriority()); 1850 syn_stream.set_priority(framer.GetHighestPriority());
2013 syn_stream.set_fin(true); 1851 syn_stream.set_fin(true);
2014 syn_stream.SetHeader("", "foo"); 1852 syn_stream.SetHeader("", "foo");
2015 syn_stream.SetHeader("foo", "bar"); 1853 syn_stream.SetHeader("foo", "bar");
2016 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1854 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
2017 if (IsSpdy2()) { 1855 if (IsSpdy3()) {
2018 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2019 } else if (IsSpdy3()) {
2020 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1856 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2021 } else { 1857 } else {
2022 LOG(FATAL) << "Unsupported version in test."; 1858 LOG(FATAL) << "Unsupported version in test.";
2023 } 1859 }
2024 } 1860 }
2025 1861
2026 { 1862 {
2027 const char kDescription[] = 1863 const char kDescription[] =
2028 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " 1864 "SYN_STREAM frame with a 0-length header val, high pri, FIN, "
2029 "max stream ID"; 1865 "max stream ID";
2030 1866
2031 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20;
2032 const unsigned char kV2FrameData[] = {
2033 0x80, spdy_version_ch_, 0x00, 0x01,
2034 0x01, 0x00, 0x00, 0x1D,
2035 0x7f, 0xff, 0xff, 0xff,
2036 0x7f, 0xff, 0xff, 0xff,
2037 kPri, 0x00, 0x00, 0x02,
2038 0x00, 0x03, 'b', 'a',
2039 'r', 0x00, 0x03, 'f',
2040 'o', 'o', 0x00, 0x03,
2041 'f', 'o', 'o', 0x00,
2042 0x00
2043 };
2044 const unsigned char kV3FrameData[] = { 1867 const unsigned char kV3FrameData[] = {
2045 0x80, spdy_version_ch_, 0x00, 0x01, 1868 0x80, spdy_version_ch_, 0x00, 0x01,
2046 0x01, 0x00, 0x00, 0x27, 1869 0x01, 0x00, 0x00, 0x27,
2047 0x7f, 0xff, 0xff, 0xff, 1870 0x7f, 0xff, 0xff, 0xff,
2048 0x7f, 0xff, 0xff, 0xff, 1871 0x7f, 0xff, 0xff, 0xff,
2049 kPri, 0x00, 0x00, 0x00, 1872 0x20, 0x00, 0x00, 0x00,
2050 0x00, 0x02, 0x00, 0x00, 1873 0x00, 0x02, 0x00, 0x00,
2051 0x00, 0x03, 'b', 'a', 1874 0x00, 0x03, 'b', 'a',
2052 'r', 0x00, 0x00, 0x00, 1875 'r', 0x00, 0x00, 0x00,
2053 0x03, 'f', 'o', 'o', 1876 0x03, 'f', 'o', 'o',
2054 0x00, 0x00, 0x00, 0x03, 1877 0x00, 0x00, 0x00, 0x03,
2055 'f', 'o', 'o', 0x00, 1878 'f', 'o', 'o', 0x00,
2056 0x00, 0x00, 0x00 1879 0x00, 0x00, 0x00
2057 }; 1880 };
2058 SpdySynStreamIR syn_stream(0x7fffffff); 1881 SpdySynStreamIR syn_stream(0x7fffffff);
2059 syn_stream.set_associated_to_stream_id(0x7fffffff); 1882 syn_stream.set_associated_to_stream_id(0x7fffffff);
2060 syn_stream.set_priority(1); 1883 syn_stream.set_priority(1);
2061 syn_stream.set_fin(true); 1884 syn_stream.set_fin(true);
2062 syn_stream.SetHeader("bar", "foo"); 1885 syn_stream.SetHeader("bar", "foo");
2063 syn_stream.SetHeader("foo", ""); 1886 syn_stream.SetHeader("foo", "");
2064 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1887 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
2065 if (IsSpdy2()) { 1888 if (IsSpdy3()) {
2066 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2067 } else if (IsSpdy3()) {
2068 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1889 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2069 } else { 1890 } else {
2070 LOG(FATAL) << "Unsupported version in test."; 1891 LOG(FATAL) << "Unsupported version in test.";
2071 } 1892 }
2072 } 1893 }
2073 } 1894 }
2074 1895
2075 // TODO(phajdan.jr): Clean up after we no longer need 1896 // TODO(phajdan.jr): Clean up after we no longer need
2076 // to workaround http://crbug.com/139744. 1897 // to workaround http://crbug.com/139744.
2077 #if !defined(USE_SYSTEM_ZLIB) 1898 #if !defined(USE_SYSTEM_ZLIB)
2078 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { 1899 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) {
2079 if (!IsSpdy2() && !IsSpdy3()) { 1900 if (!IsSpdy3()) {
2080 // SYN_STREAM not supported for SPDY>3 1901 // SYN_STREAM not supported for SPDY>3
2081 return; 1902 return;
2082 } 1903 }
2083 SpdyFramer framer(spdy_version_); 1904 SpdyFramer framer(spdy_version_);
2084 framer.set_enable_compression(true); 1905 framer.set_enable_compression(true);
2085 1906
2086 { 1907 {
2087 const char kDescription[] = 1908 const char kDescription[] =
2088 "SYN_STREAM frame, low pri, no FIN"; 1909 "SYN_STREAM frame, low pri, no FIN";
2089 const SpdyPriority priority = IsSpdy2() ? 2 : 4;
2090 1910
2091 const unsigned char kV2FrameData[] = {
2092 0x80, spdy_version_ch_, 0x00, 0x01,
2093 0x00, 0x00, 0x00, 0x36,
2094 0x00, 0x00, 0x00, 0x01,
2095 0x00, 0x00, 0x00, 0x00,
2096 0x80, 0x00, 0x38, 0xea,
2097 0xdf, 0xa2, 0x51, 0xb2,
2098 0x62, 0x60, 0x62, 0x60,
2099 0x4e, 0x4a, 0x2c, 0x62,
2100 0x60, 0x06, 0x08, 0xa0,
2101 0xb4, 0xfc, 0x7c, 0x80,
2102 0x00, 0x62, 0x60, 0x4e,
2103 0xcb, 0xcf, 0x67, 0x60,
2104 0x06, 0x08, 0xa0, 0xa4,
2105 0xc4, 0x22, 0x80, 0x00,
2106 0x02, 0x00, 0x00, 0x00,
2107 0xff, 0xff,
2108 };
2109 const unsigned char kV3FrameData[] = { 1911 const unsigned char kV3FrameData[] = {
2110 0x80, spdy_version_ch_, 0x00, 0x01, 1912 0x80, spdy_version_ch_, 0x00, 0x01,
2111 0x00, 0x00, 0x00, 0x37, 1913 0x00, 0x00, 0x00, 0x37,
2112 0x00, 0x00, 0x00, 0x01, 1914 0x00, 0x00, 0x00, 0x01,
2113 0x00, 0x00, 0x00, 0x00, 1915 0x00, 0x00, 0x00, 0x00,
2114 0x80, 0x00, 0x38, 0xEA, 1916 0x80, 0x00, 0x38, 0xEA,
2115 0xE3, 0xC6, 0xA7, 0xC2, 1917 0xE3, 0xC6, 0xA7, 0xC2,
2116 0x02, 0xE5, 0x0E, 0x50, 1918 0x02, 0xE5, 0x0E, 0x50,
2117 0xC2, 0x4B, 0x4A, 0x04, 1919 0xC2, 0x4B, 0x4A, 0x04,
2118 0xE5, 0x0B, 0x66, 0x80, 1920 0xE5, 0x0B, 0x66, 0x80,
2119 0x00, 0x4A, 0xCB, 0xCF, 1921 0x00, 0x4A, 0xCB, 0xCF,
2120 0x07, 0x08, 0x20, 0x10, 1922 0x07, 0x08, 0x20, 0x10,
2121 0x95, 0x96, 0x9F, 0x0F, 1923 0x95, 0x96, 0x9F, 0x0F,
2122 0xA2, 0x00, 0x02, 0x28, 1924 0xA2, 0x00, 0x02, 0x28,
2123 0x29, 0xB1, 0x08, 0x20, 1925 0x29, 0xB1, 0x08, 0x20,
2124 0x80, 0x00, 0x00, 0x00, 1926 0x80, 0x00, 0x00, 0x00,
2125 0x00, 0xFF, 0xFF, 1927 0x00, 0xFF, 0xFF,
2126 }; 1928 };
2127 const unsigned char kV2SIMDFrameData[] = {
2128 0x80, spdy_version_ch_, 0x00, 0x01,
2129 0x00, 0x00, 0x00, 0x33,
2130 0x00, 0x00, 0x00, 0x01,
2131 0x00, 0x00, 0x00, 0x00,
2132 0x80, 0x00, 0x38, 0xea,
2133 0xdf, 0xa2, 0x51, 0xb2,
2134 0x62, 0x60, 0x62, 0x60,
2135 0x4e, 0x4a, 0x2c, 0x62,
2136 0x60, 0x06, 0x08, 0xa0,
2137 0xb4, 0xfc, 0x7c, 0x80,
2138 0x00, 0x62, 0x60, 0x06,
2139 0x13, 0x00, 0x01, 0x94,
2140 0x94, 0x58, 0x04, 0x10,
2141 0x40, 0x00, 0x00, 0x00,
2142 0x00, 0xff, 0xff,
2143 };
2144 const unsigned char kV3SIMDFrameData[] = { 1929 const unsigned char kV3SIMDFrameData[] = {
2145 0x80, spdy_version_ch_, 0x00, 0x01, 1930 0x80, spdy_version_ch_, 0x00, 0x01,
2146 0x00, 0x00, 0x00, 0x32, 1931 0x00, 0x00, 0x00, 0x32,
2147 0x00, 0x00, 0x00, 0x01, 1932 0x00, 0x00, 0x00, 0x01,
2148 0x00, 0x00, 0x00, 0x00, 1933 0x00, 0x00, 0x00, 0x00,
2149 0x80, 0x00, 0x38, 0xea, 1934 0x80, 0x00, 0x38, 0xea,
2150 0xe3, 0xc6, 0xa7, 0xc2, 1935 0xe3, 0xc6, 0xa7, 0xc2,
2151 0x02, 0xe5, 0x0e, 0x50, 1936 0x02, 0xe5, 0x0e, 0x50,
2152 0xc2, 0x4b, 0x4a, 0x04, 1937 0xc2, 0x4b, 0x4a, 0x04,
2153 0xe5, 0x0b, 0x66, 0x80, 1938 0xe5, 0x0b, 0x66, 0x80,
2154 0x00, 0x4a, 0xcb, 0xcf, 1939 0x00, 0x4a, 0xcb, 0xcf,
2155 0x07, 0x08, 0x20, 0x24, 1940 0x07, 0x08, 0x20, 0x24,
2156 0x0a, 0x20, 0x80, 0x92, 1941 0x0a, 0x20, 0x80, 0x92,
2157 0x12, 0x8b, 0x00, 0x02, 1942 0x12, 0x8b, 0x00, 0x02,
2158 0x08, 0x00, 0x00, 0x00, 1943 0x08, 0x00, 0x00, 0x00,
2159 0xff, 0xff, 1944 0xff, 0xff,
2160 }; 1945 };
2161 1946
2162 SpdySynStreamIR syn_stream(1); 1947 SpdySynStreamIR syn_stream(1);
2163 syn_stream.set_priority(priority); 1948 syn_stream.set_priority(4);
2164 syn_stream.SetHeader("bar", "foo"); 1949 syn_stream.SetHeader("bar", "foo");
2165 syn_stream.SetHeader("foo", "bar"); 1950 syn_stream.SetHeader("foo", "bar");
2166 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1951 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
2167 const unsigned char* frame_data = 1952 const unsigned char* frame_data =
2168 reinterpret_cast<const unsigned char*>(frame->data()); 1953 reinterpret_cast<const unsigned char*>(frame->data());
2169 if (IsSpdy2()) { 1954 if (IsSpdy3()) {
2170 // Try comparing with SIMD version, if that fails, do a failing check
2171 // with pretty printing against non-SIMD version
2172 if (memcmp(frame_data,
2173 kV2SIMDFrameData,
2174 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) {
2175 CompareCharArraysWithHexError(kDescription,
2176 frame_data,
2177 frame->size(),
2178 kV2FrameData,
2179 arraysize(kV2FrameData));
2180 }
2181 } else if (IsSpdy3()) {
2182 if (memcmp(frame_data, 1955 if (memcmp(frame_data,
2183 kV3SIMDFrameData, 1956 kV3SIMDFrameData,
2184 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { 1957 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) {
2185 CompareCharArraysWithHexError(kDescription, 1958 CompareCharArraysWithHexError(kDescription,
2186 frame_data, 1959 frame_data,
2187 frame->size(), 1960 frame->size(),
2188 kV3FrameData, 1961 kV3FrameData,
2189 arraysize(kV3FrameData)); 1962 arraysize(kV3FrameData));
2190 } 1963 }
2191 } else { 1964 } else {
2192 LOG(FATAL) << "Unsupported version in test."; 1965 LOG(FATAL) << "Unsupported version in test.";
2193 } 1966 }
2194 } 1967 }
2195 } 1968 }
2196 #endif // !defined(USE_SYSTEM_ZLIB) 1969 #endif // !defined(USE_SYSTEM_ZLIB)
2197 1970
2198 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { 1971 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) {
2199 if (spdy_version_ > SPDY3) { 1972 if (spdy_version_ > SPDY3) {
2200 // SYN_REPLY unsupported in SPDY>3 1973 // SYN_REPLY unsupported in SPDY>3
2201 return; 1974 return;
2202 } 1975 }
2203 SpdyFramer framer(spdy_version_); 1976 SpdyFramer framer(spdy_version_);
2204 framer.set_enable_compression(false); 1977 framer.set_enable_compression(false);
2205 1978
2206 { 1979 {
2207 const char kDescription[] = "SYN_REPLY frame, no FIN"; 1980 const char kDescription[] = "SYN_REPLY frame, no FIN";
2208 1981
2209 const unsigned char kV2FrameData[] = {
2210 0x80, spdy_version_ch_, 0x00, 0x02,
2211 0x00, 0x00, 0x00, 0x1C,
2212 0x00, 0x00, 0x00, 0x01,
2213 0x00, 0x00, 0x00, 0x02,
2214 0x00, 0x03, 'b', 'a',
2215 'r', 0x00, 0x03, 'f',
2216 'o', 'o', 0x00, 0x03,
2217 'f', 'o', 'o', 0x00,
2218 0x03, 'b', 'a', 'r'
2219 };
2220 const unsigned char kV3FrameData[] = { 1982 const unsigned char kV3FrameData[] = {
2221 0x80, spdy_version_ch_, 0x00, 0x02, 1983 0x80, spdy_version_ch_, 0x00, 0x02,
2222 0x00, 0x00, 0x00, 0x24, 1984 0x00, 0x00, 0x00, 0x24,
2223 0x00, 0x00, 0x00, 0x01, 1985 0x00, 0x00, 0x00, 0x01,
2224 0x00, 0x00, 0x00, 0x02, 1986 0x00, 0x00, 0x00, 0x02,
2225 0x00, 0x00, 0x00, 0x03, 1987 0x00, 0x00, 0x00, 0x03,
2226 'b', 'a', 'r', 0x00, 1988 'b', 'a', 'r', 0x00,
2227 0x00, 0x00, 0x03, 'f', 1989 0x00, 0x00, 0x03, 'f',
2228 'o', 'o', 0x00, 0x00, 1990 'o', 'o', 0x00, 0x00,
2229 0x00, 0x03, 'f', 'o', 1991 0x00, 0x03, 'f', 'o',
2230 'o', 0x00, 0x00, 0x00, 1992 'o', 0x00, 0x00, 0x00,
2231 0x03, 'b', 'a', 'r' 1993 0x03, 'b', 'a', 'r'
2232 }; 1994 };
2233 SpdySynReplyIR syn_reply(1); 1995 SpdySynReplyIR syn_reply(1);
2234 syn_reply.SetHeader("bar", "foo"); 1996 syn_reply.SetHeader("bar", "foo");
2235 syn_reply.SetHeader("foo", "bar"); 1997 syn_reply.SetHeader("foo", "bar");
2236 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 1998 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2237 if (IsSpdy2()) { 1999 if (IsSpdy3()) {
2238 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2239 } else if (IsSpdy3()) {
2240 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2000 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2241 } else { 2001 } else {
2242 LOG(FATAL) << "Unsupported version in test."; 2002 LOG(FATAL) << "Unsupported version in test.";
2243 } 2003 }
2244 } 2004 }
2245 2005
2246 { 2006 {
2247 const char kDescription[] = 2007 const char kDescription[] =
2248 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; 2008 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID";
2249 2009
2250 const unsigned char kV2FrameData[] = {
2251 0x80, spdy_version_ch_, 0x00, 0x02,
2252 0x01, 0x00, 0x00, 0x19,
2253 0x7f, 0xff, 0xff, 0xff,
2254 0x00, 0x00, 0x00, 0x02,
2255 0x00, 0x00, 0x00, 0x03,
2256 'f', 'o', 'o', 0x00,
2257 0x03, 'f', 'o', 'o',
2258 0x00, 0x03, 'b', 'a',
2259 'r'
2260 };
2261 const unsigned char kV3FrameData[] = { 2010 const unsigned char kV3FrameData[] = {
2262 0x80, spdy_version_ch_, 0x00, 0x02, 2011 0x80, spdy_version_ch_, 0x00, 0x02,
2263 0x01, 0x00, 0x00, 0x21, 2012 0x01, 0x00, 0x00, 0x21,
2264 0x7f, 0xff, 0xff, 0xff, 2013 0x7f, 0xff, 0xff, 0xff,
2265 0x00, 0x00, 0x00, 0x02, 2014 0x00, 0x00, 0x00, 0x02,
2266 0x00, 0x00, 0x00, 0x00, 2015 0x00, 0x00, 0x00, 0x00,
2267 0x00, 0x00, 0x00, 0x03, 2016 0x00, 0x00, 0x00, 0x03,
2268 'f', 'o', 'o', 0x00, 2017 'f', 'o', 'o', 0x00,
2269 0x00, 0x00, 0x03, 'f', 2018 0x00, 0x00, 0x03, 'f',
2270 'o', 'o', 0x00, 0x00, 2019 'o', 'o', 0x00, 0x00,
2271 0x00, 0x03, 'b', 'a', 2020 0x00, 0x03, 'b', 'a',
2272 'r' 2021 'r'
2273 }; 2022 };
2274 SpdySynReplyIR syn_reply(0x7fffffff); 2023 SpdySynReplyIR syn_reply(0x7fffffff);
2275 syn_reply.set_fin(true); 2024 syn_reply.set_fin(true);
2276 syn_reply.SetHeader("", "foo"); 2025 syn_reply.SetHeader("", "foo");
2277 syn_reply.SetHeader("foo", "bar"); 2026 syn_reply.SetHeader("foo", "bar");
2278 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2027 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2279 if (IsSpdy2()) { 2028 if (IsSpdy3()) {
2280 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2281 } else if (IsSpdy3()) {
2282 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2029 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2283 } else { 2030 } else {
2284 LOG(FATAL) << "Unsupported version in test."; 2031 LOG(FATAL) << "Unsupported version in test.";
2285 } 2032 }
2286 } 2033 }
2287 2034
2288 { 2035 {
2289 const char kDescription[] = 2036 const char kDescription[] =
2290 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; 2037 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID";
2291 2038
2292 const unsigned char kV2FrameData[] = {
2293 0x80, spdy_version_ch_, 0x00, 0x02,
2294 0x01, 0x00, 0x00, 0x19,
2295 0x7f, 0xff, 0xff, 0xff,
2296 0x00, 0x00, 0x00, 0x02,
2297 0x00, 0x03, 'b', 'a',
2298 'r', 0x00, 0x03, 'f',
2299 'o', 'o', 0x00, 0x03,
2300 'f', 'o', 'o', 0x00,
2301 0x00
2302 };
2303 const unsigned char kV3FrameData[] = { 2039 const unsigned char kV3FrameData[] = {
2304 0x80, spdy_version_ch_, 0x00, 0x02, 2040 0x80, spdy_version_ch_, 0x00, 0x02,
2305 0x01, 0x00, 0x00, 0x21, 2041 0x01, 0x00, 0x00, 0x21,
2306 0x7f, 0xff, 0xff, 0xff, 2042 0x7f, 0xff, 0xff, 0xff,
2307 0x00, 0x00, 0x00, 0x02, 2043 0x00, 0x00, 0x00, 0x02,
2308 0x00, 0x00, 0x00, 0x03, 2044 0x00, 0x00, 0x00, 0x03,
2309 'b', 'a', 'r', 0x00, 2045 'b', 'a', 'r', 0x00,
2310 0x00, 0x00, 0x03, 'f', 2046 0x00, 0x00, 0x03, 'f',
2311 'o', 'o', 0x00, 0x00, 2047 'o', 'o', 0x00, 0x00,
2312 0x00, 0x03, 'f', 'o', 2048 0x00, 0x03, 'f', 'o',
2313 'o', 0x00, 0x00, 0x00, 2049 'o', 0x00, 0x00, 0x00,
2314 0x00 2050 0x00
2315 }; 2051 };
2316 SpdySynReplyIR syn_reply(0x7fffffff); 2052 SpdySynReplyIR syn_reply(0x7fffffff);
2317 syn_reply.set_fin(true); 2053 syn_reply.set_fin(true);
2318 syn_reply.SetHeader("bar", "foo"); 2054 syn_reply.SetHeader("bar", "foo");
2319 syn_reply.SetHeader("foo", ""); 2055 syn_reply.SetHeader("foo", "");
2320 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2056 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2321 if (IsSpdy2()) { 2057 if (IsSpdy3()) {
2322 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2323 } else if (IsSpdy3()) {
2324 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2058 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2325 } else { 2059 } else {
2326 LOG(FATAL) << "Unsupported version in test."; 2060 LOG(FATAL) << "Unsupported version in test.";
2327 } 2061 }
2328 } 2062 }
2329 } 2063 }
2330 2064
2331 // TODO(phajdan.jr): Clean up after we no longer need 2065 // TODO(phajdan.jr): Clean up after we no longer need
2332 // to workaround http://crbug.com/139744. 2066 // to workaround http://crbug.com/139744.
2333 #if !defined(USE_SYSTEM_ZLIB) 2067 #if !defined(USE_SYSTEM_ZLIB)
2334 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { 2068 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) {
2335 if (spdy_version_ > SPDY3) { 2069 if (spdy_version_ > SPDY3) {
2336 // SYN_REPLY unsupported in SPDY>3 2070 // SYN_REPLY unsupported in SPDY>3
2337 return; 2071 return;
2338 } 2072 }
2339 SpdyFramer framer(spdy_version_); 2073 SpdyFramer framer(spdy_version_);
2340 framer.set_enable_compression(true); 2074 framer.set_enable_compression(true);
2341 2075
2342 { 2076 {
2343 const char kDescription[] = "SYN_REPLY frame, no FIN"; 2077 const char kDescription[] = "SYN_REPLY frame, no FIN";
2344 2078
2345 const unsigned char kV2FrameData[] = {
2346 0x80, spdy_version_ch_, 0x00, 0x02,
2347 0x00, 0x00, 0x00, 0x32,
2348 0x00, 0x00, 0x00, 0x01,
2349 0x00, 0x00, 0x38, 0xea,
2350 0xdf, 0xa2, 0x51, 0xb2,
2351 0x62, 0x60, 0x62, 0x60,
2352 0x4e, 0x4a, 0x2c, 0x62,
2353 0x60, 0x06, 0x08, 0xa0,
2354 0xb4, 0xfc, 0x7c, 0x80,
2355 0x00, 0x62, 0x60, 0x4e,
2356 0xcb, 0xcf, 0x67, 0x60,
2357 0x06, 0x08, 0xa0, 0xa4,
2358 0xc4, 0x22, 0x80, 0x00,
2359 0x02, 0x00, 0x00, 0x00,
2360 0xff, 0xff,
2361 };
2362 const unsigned char kV3FrameData[] = { 2079 const unsigned char kV3FrameData[] = {
2363 0x80, spdy_version_ch_, 0x00, 0x02, 2080 0x80, spdy_version_ch_, 0x00, 0x02,
2364 0x00, 0x00, 0x00, 0x31, 2081 0x00, 0x00, 0x00, 0x31,
2365 0x00, 0x00, 0x00, 0x01, 2082 0x00, 0x00, 0x00, 0x01,
2366 0x38, 0xea, 0xe3, 0xc6, 2083 0x38, 0xea, 0xe3, 0xc6,
2367 0xa7, 0xc2, 0x02, 0xe5, 2084 0xa7, 0xc2, 0x02, 0xe5,
2368 0x0e, 0x50, 0xc2, 0x4b, 2085 0x0e, 0x50, 0xc2, 0x4b,
2369 0x4a, 0x04, 0xe5, 0x0b, 2086 0x4a, 0x04, 0xe5, 0x0b,
2370 0x66, 0x80, 0x00, 0x4a, 2087 0x66, 0x80, 0x00, 0x4a,
2371 0xcb, 0xcf, 0x07, 0x08, 2088 0xcb, 0xcf, 0x07, 0x08,
2372 0x20, 0x10, 0x95, 0x96, 2089 0x20, 0x10, 0x95, 0x96,
2373 0x9f, 0x0f, 0xa2, 0x00, 2090 0x9f, 0x0f, 0xa2, 0x00,
2374 0x02, 0x28, 0x29, 0xb1, 2091 0x02, 0x28, 0x29, 0xb1,
2375 0x08, 0x20, 0x80, 0x00, 2092 0x08, 0x20, 0x80, 0x00,
2376 0x00, 0x00, 0x00, 0xff, 2093 0x00, 0x00, 0x00, 0xff,
2377 0xff, 2094 0xff,
2378 }; 2095 };
2379 const unsigned char kV2SIMDFrameData[] = {
2380 0x80, spdy_version_ch_, 0x00, 0x02,
2381 0x00, 0x00, 0x00, 0x2f,
2382 0x00, 0x00, 0x00, 0x01,
2383 0x00, 0x00, 0x38, 0xea,
2384 0xdf, 0xa2, 0x51, 0xb2,
2385 0x62, 0x60, 0x62, 0x60,
2386 0x4e, 0x4a, 0x2c, 0x62,
2387 0x60, 0x06, 0x08, 0xa0,
2388 0xb4, 0xfc, 0x7c, 0x80,
2389 0x00, 0x62, 0x60, 0x06,
2390 0x13, 0x00, 0x01, 0x94,
2391 0x94, 0x58, 0x04, 0x10,
2392 0x40, 0x00, 0x00, 0x00,
2393 0x00, 0xff, 0xff,
2394 };
2395 const unsigned char kV3SIMDFrameData[] = { 2096 const unsigned char kV3SIMDFrameData[] = {
2396 0x80, spdy_version_ch_, 0x00, 0x02, 2097 0x80, spdy_version_ch_, 0x00, 0x02,
2397 0x00, 0x00, 0x00, 0x2c, 2098 0x00, 0x00, 0x00, 0x2c,
2398 0x00, 0x00, 0x00, 0x01, 2099 0x00, 0x00, 0x00, 0x01,
2399 0x38, 0xea, 0xe3, 0xc6, 2100 0x38, 0xea, 0xe3, 0xc6,
2400 0xa7, 0xc2, 0x02, 0xe5, 2101 0xa7, 0xc2, 0x02, 0xe5,
2401 0x0e, 0x50, 0xc2, 0x4b, 2102 0x0e, 0x50, 0xc2, 0x4b,
2402 0x4a, 0x04, 0xe5, 0x0b, 2103 0x4a, 0x04, 0xe5, 0x0b,
2403 0x66, 0x80, 0x00, 0x4a, 2104 0x66, 0x80, 0x00, 0x4a,
2404 0xcb, 0xcf, 0x07, 0x08, 2105 0xcb, 0xcf, 0x07, 0x08,
2405 0x20, 0x24, 0x0a, 0x20, 2106 0x20, 0x24, 0x0a, 0x20,
2406 0x80, 0x92, 0x12, 0x8b, 2107 0x80, 0x92, 0x12, 0x8b,
2407 0x00, 0x02, 0x08, 0x00, 2108 0x00, 0x02, 0x08, 0x00,
2408 0x00, 0x00, 0xff, 0xff, 2109 0x00, 0x00, 0xff, 0xff,
2409 }; 2110 };
2410 2111
2411 SpdySynReplyIR syn_reply(1); 2112 SpdySynReplyIR syn_reply(1);
2412 syn_reply.SetHeader("bar", "foo"); 2113 syn_reply.SetHeader("bar", "foo");
2413 syn_reply.SetHeader("foo", "bar"); 2114 syn_reply.SetHeader("foo", "bar");
2414 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2115 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2415 const unsigned char* frame_data = 2116 const unsigned char* frame_data =
2416 reinterpret_cast<const unsigned char*>(frame->data()); 2117 reinterpret_cast<const unsigned char*>(frame->data());
2417 if (IsSpdy2()) { 2118 if (IsSpdy3()) {
2418 // Try comparing with SIMD version, if that fails, do a failing check
2419 // with pretty printing against non-SIMD version
2420 if (memcmp(frame_data,
2421 kV2SIMDFrameData,
2422 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) {
2423 CompareCharArraysWithHexError(kDescription,
2424 frame_data,
2425 frame->size(),
2426 kV2FrameData,
2427 arraysize(kV2FrameData));
2428 }
2429 } else if (IsSpdy3()) {
2430 if (memcmp(frame_data, 2119 if (memcmp(frame_data,
2431 kV3SIMDFrameData, 2120 kV3SIMDFrameData,
2432 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { 2121 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) {
2433 CompareCharArraysWithHexError(kDescription, 2122 CompareCharArraysWithHexError(kDescription,
2434 frame_data, 2123 frame_data,
2435 frame->size(), 2124 frame->size(),
2436 kV3FrameData, 2125 kV3FrameData,
2437 arraysize(kV3FrameData)); 2126 arraysize(kV3FrameData));
2438 } 2127 }
2439 } else { 2128 } else {
2440 LOG(FATAL) << "Unsupported version in test."; 2129 LOG(FATAL) << "Unsupported version in test.";
2441 } 2130 }
2442 } 2131 }
2443 } 2132 }
2444 #endif // !defined(USE_SYSTEM_ZLIB) 2133 #endif // !defined(USE_SYSTEM_ZLIB)
2445 2134
2446 TEST_P(SpdyFramerTest, CreateRstStream) { 2135 TEST_P(SpdyFramerTest, CreateRstStream) {
2447 SpdyFramer framer(spdy_version_); 2136 SpdyFramer framer(spdy_version_);
2448 2137
2449 { 2138 {
2450 const char kDescription[] = "RST_STREAM frame"; 2139 const char kDescription[] = "RST_STREAM frame";
2451 const unsigned char kV3FrameData[] = { // Also applies for V2. 2140 const unsigned char kV3FrameData[] = {
2452 0x80, spdy_version_ch_, 0x00, 0x03, 2141 0x80, spdy_version_ch_, 0x00, 0x03,
2453 0x00, 0x00, 0x00, 0x08, 2142 0x00, 0x00, 0x00, 0x08,
2454 0x00, 0x00, 0x00, 0x01, 2143 0x00, 0x00, 0x00, 0x01,
2455 0x00, 0x00, 0x00, 0x01, 2144 0x00, 0x00, 0x00, 0x01,
2456 }; 2145 };
2457 const unsigned char kH2FrameData[] = { 2146 const unsigned char kH2FrameData[] = {
2458 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, 2147 0x00, 0x00, 0x04, 0x03, 0x00, 0x00, 0x00,
2459 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 2148 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
2460 }; 2149 };
2461 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR); 2150 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR);
2462 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); 2151 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream));
2463 if (IsHttp2()) { 2152 if (IsHttp2()) {
2464 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2153 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2465 } else { 2154 } else {
2466 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2155 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2467 } 2156 }
2468 } 2157 }
2469 2158
2470 { 2159 {
2471 const char kDescription[] = "RST_STREAM frame with max stream ID"; 2160 const char kDescription[] = "RST_STREAM frame with max stream ID";
2472 const unsigned char kV3FrameData[] = { // Also applies for V2. 2161 const unsigned char kV3FrameData[] = {
2473 0x80, spdy_version_ch_, 0x00, 0x03, 2162 0x80, spdy_version_ch_, 0x00, 0x03,
2474 0x00, 0x00, 0x00, 0x08, 2163 0x00, 0x00, 0x00, 0x08,
2475 0x7f, 0xff, 0xff, 0xff, 2164 0x7f, 0xff, 0xff, 0xff,
2476 0x00, 0x00, 0x00, 0x01, 2165 0x00, 0x00, 0x00, 0x01,
2477 }; 2166 };
2478 const unsigned char kH2FrameData[] = { 2167 const unsigned char kH2FrameData[] = {
2479 0x00, 0x00, 0x04, 0x03, 2168 0x00, 0x00, 0x04, 0x03,
2480 0x00, 0x7f, 0xff, 0xff, 2169 0x00, 0x7f, 0xff, 0xff,
2481 0xff, 0x00, 0x00, 0x00, 2170 0xff, 0x00, 0x00, 0x00,
2482 0x01, 2171 0x01,
2483 }; 2172 };
2484 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_PROTOCOL_ERROR); 2173 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_PROTOCOL_ERROR);
2485 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); 2174 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream));
2486 if (IsHttp2()) { 2175 if (IsHttp2()) {
2487 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2176 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2488 } else { 2177 } else {
2489 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2178 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2490 } 2179 }
2491 } 2180 }
2492 2181
2493 { 2182 {
2494 const char kDescription[] = "RST_STREAM frame with max status code"; 2183 const char kDescription[] = "RST_STREAM frame with max status code";
2495 const unsigned char kV3FrameData[] = { // Also applies for V2. 2184 const unsigned char kV3FrameData[] = {
2496 0x80, spdy_version_ch_, 0x00, 0x03, 2185 0x80, spdy_version_ch_, 0x00, 0x03,
2497 0x00, 0x00, 0x00, 0x08, 2186 0x00, 0x00, 0x00, 0x08,
2498 0x7f, 0xff, 0xff, 0xff, 2187 0x7f, 0xff, 0xff, 0xff,
2499 0x00, 0x00, 0x00, 0x06, 2188 0x00, 0x00, 0x00, 0x06,
2500 }; 2189 };
2501 const unsigned char kH2FrameData[] = { 2190 const unsigned char kH2FrameData[] = {
2502 0x00, 0x00, 0x04, 0x03, 2191 0x00, 0x00, 0x04, 0x03,
2503 0x00, 0x7f, 0xff, 0xff, 2192 0x00, 0x7f, 0xff, 0xff,
2504 0xff, 0x00, 0x00, 0x00, 2193 0xff, 0x00, 0x00, 0x00,
2505 0x02, 2194 0x02,
2506 }; 2195 };
2507 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR); 2196 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR);
2508 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); 2197 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream));
2509 if (IsHttp2()) { 2198 if (IsHttp2()) {
2510 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2199 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2511 } else { 2200 } else {
2512 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2201 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2513 } 2202 }
2514 } 2203 }
2515 } 2204 }
2516 2205
2517 TEST_P(SpdyFramerTest, CreateSettings) { 2206 TEST_P(SpdyFramerTest, CreateSettings) {
2518 SpdyFramer framer(spdy_version_); 2207 SpdyFramer framer(spdy_version_);
2519 2208
2520 { 2209 {
2521 const char kDescription[] = "Network byte order SETTINGS frame"; 2210 const char kDescription[] = "Network byte order SETTINGS frame";
2522 2211
2523 const unsigned char kV2FrameData[] = {
2524 0x80, spdy_version_ch_, 0x00, 0x04,
2525 0x00, 0x00, 0x00, 0x0c,
2526 0x00, 0x00, 0x00, 0x01,
2527 0x07, 0x00, 0x00, 0x01,
2528 0x0a, 0x0b, 0x0c, 0x0d,
2529 };
2530 const unsigned char kV3FrameData[] = { 2212 const unsigned char kV3FrameData[] = {
2531 0x80, spdy_version_ch_, 0x00, 0x04, 2213 0x80, spdy_version_ch_, 0x00, 0x04,
2532 0x00, 0x00, 0x00, 0x0c, 2214 0x00, 0x00, 0x00, 0x0c,
2533 0x00, 0x00, 0x00, 0x01, 2215 0x00, 0x00, 0x00, 0x01,
2534 0x01, 0x00, 0x00, 0x07, 2216 0x01, 0x00, 0x00, 0x07,
2535 0x0a, 0x0b, 0x0c, 0x0d, 2217 0x0a, 0x0b, 0x0c, 0x0d,
2536 }; 2218 };
2537 const unsigned char kH2FrameData[] = { 2219 const unsigned char kH2FrameData[] = {
2538 0x00, 0x00, 0x06, 0x04, 2220 0x00, 0x00, 0x06, 0x04,
2539 0x00, 0x00, 0x00, 0x00, 2221 0x00, 0x00, 0x00, 0x00,
2540 0x00, 0x00, 0x04, 0x0a, 2222 0x00, 0x00, 0x04, 0x0a,
2541 0x0b, 0x0c, 0x0d, 2223 0x0b, 0x0c, 0x0d,
2542 }; 2224 };
2543 2225
2544 uint32_t kValue = 0x0a0b0c0d; 2226 uint32_t kValue = 0x0a0b0c0d;
2545 SpdySettingsIR settings_ir; 2227 SpdySettingsIR settings_ir;
2546 2228
2547 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); 2229 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01);
2548 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; 2230 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE;
2549 settings_ir.AddSetting(kId, 2231 settings_ir.AddSetting(kId,
2550 kFlags & SETTINGS_FLAG_PLEASE_PERSIST, 2232 kFlags & SETTINGS_FLAG_PLEASE_PERSIST,
2551 kFlags & SETTINGS_FLAG_PERSISTED, 2233 kFlags & SETTINGS_FLAG_PERSISTED,
2552 kValue); 2234 kValue);
2553 2235
2554 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); 2236 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir));
2555 if (IsSpdy2()) { 2237 if (IsSpdy3()) {
2556 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2557 } else if (IsSpdy3()) {
2558 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2238 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2559 } else { 2239 } else {
2560 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2240 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2561 } 2241 }
2562 } 2242 }
2563 2243
2564 { 2244 {
2565 const char kDescription[] = "Basic SETTINGS frame"; 2245 const char kDescription[] = "Basic SETTINGS frame";
2566 2246
2567 const unsigned char kV2FrameData[] = {
2568 0x80, spdy_version_ch_, 0x00, 0x04,
2569 0x00, 0x00, 0x00, 0x24,
2570 0x00, 0x00, 0x00, 0x04,
2571 0x01, 0x00, 0x00, 0x00, // 1st Setting
2572 0x00, 0x00, 0x00, 0x05,
2573 0x02, 0x00, 0x00, 0x00, // 2nd Setting
2574 0x00, 0x00, 0x00, 0x06,
2575 0x03, 0x00, 0x00, 0x00, // 3rd Setting
2576 0x00, 0x00, 0x00, 0x07,
2577 0x04, 0x00, 0x00, 0x00, // 4th Setting
2578 0x00, 0x00, 0x00, 0x08,
2579 };
2580 const unsigned char kV3FrameData[] = { 2247 const unsigned char kV3FrameData[] = {
2581 0x80, spdy_version_ch_, 0x00, 0x04, 2248 0x80, spdy_version_ch_, 0x00, 0x04,
2582 0x00, 0x00, 0x00, 0x24, 2249 0x00, 0x00, 0x00, 0x24,
2583 0x00, 0x00, 0x00, 0x04, 2250 0x00, 0x00, 0x00, 0x04,
2584 0x00, 0x00, 0x00, 0x01, // 1st Setting 2251 0x00, 0x00, 0x00, 0x01, // 1st Setting
2585 0x00, 0x00, 0x00, 0x05, 2252 0x00, 0x00, 0x00, 0x05,
2586 0x00, 0x00, 0x00, 0x02, // 2nd Setting 2253 0x00, 0x00, 0x00, 0x02, // 2nd Setting
2587 0x00, 0x00, 0x00, 0x06, 2254 0x00, 0x00, 0x00, 0x06,
2588 0x00, 0x00, 0x00, 0x03, // 3rd Setting 2255 0x00, 0x00, 0x00, 0x03, // 3rd Setting
2589 0x00, 0x00, 0x00, 0x07, 2256 0x00, 0x00, 0x00, 0x07,
(...skipping 28 matching lines...) Expand all
2618 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), 2285 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3),
2619 false, // persist 2286 false, // persist
2620 false, // persisted 2287 false, // persisted
2621 7); 2288 7);
2622 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4), 2289 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 4),
2623 false, // persist 2290 false, // persist
2624 false, // persisted 2291 false, // persisted
2625 8); 2292 8);
2626 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); 2293 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir));
2627 2294
2628 if (IsSpdy2()) { 2295 if (IsSpdy3()) {
2629 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2630 } else if (IsSpdy3()) {
2631 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2296 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2632 } else { 2297 } else {
2633 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2298 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2634 } 2299 }
2635 } 2300 }
2636 2301
2637 { 2302 {
2638 const char kDescription[] = "Empty SETTINGS frame"; 2303 const char kDescription[] = "Empty SETTINGS frame";
2639 2304
2640 const unsigned char kV3FrameData[] = { // Also applies for V2. 2305 const unsigned char kV3FrameData[] = {
2641 0x80, spdy_version_ch_, 0x00, 0x04, 2306 0x80, spdy_version_ch_, 0x00, 0x04,
2642 0x00, 0x00, 0x00, 0x04, 2307 0x00, 0x00, 0x00, 0x04,
2643 0x00, 0x00, 0x00, 0x00, 2308 0x00, 0x00, 0x00, 0x00,
2644 }; 2309 };
2645 const unsigned char kH2FrameData[] = { 2310 const unsigned char kH2FrameData[] = {
2646 0x00, 0x00, 0x00, 0x04, 2311 0x00, 0x00, 0x00, 0x04,
2647 0x00, 0x00, 0x00, 0x00, 2312 0x00, 0x00, 0x00, 0x00,
2648 0x00, 2313 0x00,
2649 }; 2314 };
2650 SpdySettingsIR settings_ir; 2315 SpdySettingsIR settings_ir;
2651 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); 2316 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir));
2652 if (IsHttp2()) { 2317 if (IsHttp2()) {
2653 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2318 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2654 } else { 2319 } else {
2655 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2320 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2656 } 2321 }
2657 } 2322 }
2658 } 2323 }
2659 2324
2660 TEST_P(SpdyFramerTest, CreatePingFrame) { 2325 TEST_P(SpdyFramerTest, CreatePingFrame) {
2661 SpdyFramer framer(spdy_version_); 2326 SpdyFramer framer(spdy_version_);
2662 2327
2663 { 2328 {
2664 const char kDescription[] = "PING frame"; 2329 const char kDescription[] = "PING frame";
2665 const unsigned char kV3FrameData[] = { // Also applies for V2. 2330 const unsigned char kV3FrameData[] = {
2666 0x80, spdy_version_ch_, 0x00, 0x06, 2331 0x80, spdy_version_ch_, 0x00, 0x06,
2667 0x00, 0x00, 0x00, 0x04, 2332 0x00, 0x00, 0x00, 0x04,
2668 0x12, 0x34, 0x56, 0x78, 2333 0x12, 0x34, 0x56, 0x78,
2669 }; 2334 };
2670 const unsigned char kH2FrameData[] = { 2335 const unsigned char kH2FrameData[] = {
2671 0x00, 0x00, 0x08, 0x06, 2336 0x00, 0x00, 0x08, 0x06,
2672 0x00, 0x00, 0x00, 0x00, 2337 0x00, 0x00, 0x00, 0x00,
2673 0x00, 0x12, 0x34, 0x56, 2338 0x00, 0x12, 0x34, 0x56,
2674 0x78, 0x9a, 0xbc, 0xde, 2339 0x78, 0x9a, 0xbc, 0xde,
2675 0xff, 2340 0xff,
(...skipping 25 matching lines...) Expand all
2701 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2366 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2702 } 2367 }
2703 } 2368 }
2704 } 2369 }
2705 2370
2706 TEST_P(SpdyFramerTest, CreateGoAway) { 2371 TEST_P(SpdyFramerTest, CreateGoAway) {
2707 SpdyFramer framer(spdy_version_); 2372 SpdyFramer framer(spdy_version_);
2708 2373
2709 { 2374 {
2710 const char kDescription[] = "GOAWAY frame"; 2375 const char kDescription[] = "GOAWAY frame";
2711 const unsigned char kV2FrameData[] = {
2712 0x80, spdy_version_ch_, 0x00, 0x07,
2713 0x00, 0x00, 0x00, 0x04,
2714 0x00, 0x00, 0x00, 0x00, // Stream Id
2715 };
2716 const unsigned char kV3FrameData[] = { 2376 const unsigned char kV3FrameData[] = {
2717 0x80, spdy_version_ch_, 0x00, 0x07, 2377 0x80, spdy_version_ch_, 0x00, 0x07,
2718 0x00, 0x00, 0x00, 0x08, 2378 0x00, 0x00, 0x00, 0x08,
2719 0x00, 0x00, 0x00, 0x00, // Stream Id 2379 0x00, 0x00, 0x00, 0x00, // Stream Id
2720 0x00, 0x00, 0x00, 0x00, // Status 2380 0x00, 0x00, 0x00, 0x00, // Status
2721 }; 2381 };
2722 const unsigned char kH2FrameData[] = { 2382 const unsigned char kH2FrameData[] = {
2723 0x00, 0x00, 0x0a, 0x07, 2383 0x00, 0x00, 0x0a, 0x07,
2724 0x00, 0x00, 0x00, 0x00, 2384 0x00, 0x00, 0x00, 0x00,
2725 0x00, 0x00, 0x00, 0x00, // Stream id 2385 0x00, 0x00, 0x00, 0x00, // Stream id
2726 0x00, 0x00, 0x00, 0x00, // Status 2386 0x00, 0x00, 0x00, 0x00, // Status
2727 0x00, 0x47, 0x41, // Opaque Description 2387 0x00, 0x47, 0x41, // Opaque Description
2728 }; 2388 };
2729 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); 2389 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA");
2730 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); 2390 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir));
2731 if (IsSpdy2()) { 2391 if (IsSpdy3()) {
2732 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2733 } else if (IsSpdy3()) {
2734 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2392 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2735 } else { 2393 } else {
2736 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2394 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2737 } 2395 }
2738 } 2396 }
2739 2397
2740 { 2398 {
2741 const char kDescription[] = "GOAWAY frame with max stream ID, status"; 2399 const char kDescription[] = "GOAWAY frame with max stream ID, status";
2742 const unsigned char kV2FrameData[] = {
2743 0x80, spdy_version_ch_, 0x00, 0x07,
2744 0x00, 0x00, 0x00, 0x04,
2745 0x7f, 0xff, 0xff, 0xff, // Stream Id
2746 };
2747 const unsigned char kV3FrameData[] = { 2400 const unsigned char kV3FrameData[] = {
2748 0x80, spdy_version_ch_, 0x00, 0x07, 2401 0x80, spdy_version_ch_, 0x00, 0x07,
2749 0x00, 0x00, 0x00, 0x08, 2402 0x00, 0x00, 0x00, 0x08,
2750 0x7f, 0xff, 0xff, 0xff, // Stream Id 2403 0x7f, 0xff, 0xff, 0xff, // Stream Id
2751 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR. 2404 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR.
2752 }; 2405 };
2753 const unsigned char kH2FrameData[] = { 2406 const unsigned char kH2FrameData[] = {
2754 0x00, 0x00, 0x0a, 0x07, 2407 0x00, 0x00, 0x0a, 0x07,
2755 0x00, 0x00, 0x00, 0x00, 2408 0x00, 0x00, 0x00, 0x00,
2756 0x00, 0x7f, 0xff, 0xff, // Stream Id 2409 0x00, 0x7f, 0xff, 0xff, // Stream Id
2757 0xff, 0x00, 0x00, 0x00, // Status: INTERNAL_ERROR. 2410 0xff, 0x00, 0x00, 0x00, // Status: INTERNAL_ERROR.
2758 0x02, 0x47, 0x41, // Opaque Description 2411 0x02, 0x47, 0x41, // Opaque Description
2759 }; 2412 };
2760 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); 2413 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA");
2761 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); 2414 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir));
2762 if (IsSpdy2()) { 2415 if (IsSpdy3()) {
2763 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2764 } else if (IsSpdy3()) {
2765 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2416 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2766 } else { 2417 } else {
2767 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2418 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2768 } 2419 }
2769 } 2420 }
2770 } 2421 }
2771 2422
2772 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { 2423 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) {
2773 SpdyFramer framer(spdy_version_); 2424 SpdyFramer framer(spdy_version_);
2774 framer.set_enable_compression(false); 2425 framer.set_enable_compression(false);
2775 2426
2776 { 2427 {
2777 const char kDescription[] = "HEADERS frame, no FIN"; 2428 const char kDescription[] = "HEADERS frame, no FIN";
2778 2429
2779 const unsigned char kV2FrameData[] = {
2780 0x80, spdy_version_ch_, 0x00, 0x08,
2781 0x00, 0x00, 0x00, 0x1C,
2782 0x00, 0x00, 0x00, 0x01,
2783 0x00, 0x00, 0x00, 0x02,
2784 0x00, 0x03, 'b', 'a',
2785 'r', 0x00, 0x03, 'f',
2786 'o', 'o', 0x00, 0x03,
2787 'f', 'o', 'o', 0x00,
2788 0x03, 'b', 'a', 'r'
2789 };
2790 const unsigned char kV3FrameData[] = { 2430 const unsigned char kV3FrameData[] = {
2791 0x80, spdy_version_ch_, 0x00, 0x08, 2431 0x80, spdy_version_ch_, 0x00, 0x08,
2792 0x00, 0x00, 0x00, 0x24, 2432 0x00, 0x00, 0x00, 0x24,
2793 0x00, 0x00, 0x00, 0x01, 2433 0x00, 0x00, 0x00, 0x01,
2794 0x00, 0x00, 0x00, 0x02, 2434 0x00, 0x00, 0x00, 0x02,
2795 0x00, 0x00, 0x00, 0x03, 2435 0x00, 0x00, 0x00, 0x03,
2796 'b', 'a', 'r', 0x00, 2436 'b', 'a', 'r', 0x00,
2797 0x00, 0x00, 0x03, 'f', 2437 0x00, 0x00, 0x03, 'f',
2798 'o', 'o', 0x00, 0x00, 2438 'o', 'o', 0x00, 0x00,
2799 0x00, 0x03, 'f', 'o', 2439 0x00, 0x03, 'f', 'o',
2800 'o', 0x00, 0x00, 0x00, 2440 'o', 0x00, 0x00, 0x00,
2801 0x03, 'b', 'a', 'r' 2441 0x03, 'b', 'a', 'r'
2802 }; 2442 };
2803 const unsigned char kH2FrameData[] = { 2443 const unsigned char kH2FrameData[] = {
2804 0x00, 0x00, 0x12, 0x01, // Headers: END_HEADERS 2444 0x00, 0x00, 0x12, 0x01, // Headers: END_HEADERS
2805 0x04, 0x00, 0x00, 0x00, // Stream 1 2445 0x04, 0x00, 0x00, 0x00, // Stream 1
2806 0x01, 0x00, 0x03, 0x62, // @.ba 2446 0x01, 0x00, 0x03, 0x62, // @.ba
2807 0x61, 0x72, 0x03, 0x66, // r.fo 2447 0x61, 0x72, 0x03, 0x66, // r.fo
2808 0x6f, 0x6f, 0x00, 0x03, // o@.f 2448 0x6f, 0x6f, 0x00, 0x03, // o@.f
2809 0x66, 0x6f, 0x6f, 0x03, // oo.b 2449 0x66, 0x6f, 0x6f, 0x03, // oo.b
2810 0x62, 0x61, 0x72, // ar 2450 0x62, 0x61, 0x72, // ar
2811 }; 2451 };
2812 SpdyHeadersIR headers_ir(1); 2452 SpdyHeadersIR headers_ir(1);
2813 headers_ir.SetHeader("bar", "foo"); 2453 headers_ir.SetHeader("bar", "foo");
2814 headers_ir.SetHeader("foo", "bar"); 2454 headers_ir.SetHeader("foo", "bar");
2815 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2455 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2816 if (IsSpdy2()) { 2456 if (IsSpdy3()) {
2817 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2818 } else if (IsSpdy3()) {
2819 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2457 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2820 } else { 2458 } else {
2821 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2459 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2822 } 2460 }
2823 } 2461 }
2824 2462
2825 { 2463 {
2826 const char kDescription[] = 2464 const char kDescription[] =
2827 "HEADERS frame with a 0-length header name, FIN, max stream ID"; 2465 "HEADERS frame with a 0-length header name, FIN, max stream ID";
2828 2466
2829 const unsigned char kV2FrameData[] = {
2830 0x80, spdy_version_ch_, 0x00, 0x08,
2831 0x01, 0x00, 0x00, 0x19,
2832 0x7f, 0xff, 0xff, 0xff,
2833 0x00, 0x00, 0x00, 0x02,
2834 0x00, 0x00, 0x00, 0x03,
2835 'f', 'o', 'o', 0x00,
2836 0x03, 'f', 'o', 'o',
2837 0x00, 0x03, 'b', 'a',
2838 'r'
2839 };
2840 const unsigned char kV3FrameData[] = { 2467 const unsigned char kV3FrameData[] = {
2841 0x80, spdy_version_ch_, 0x00, 0x08, 2468 0x80, spdy_version_ch_, 0x00, 0x08,
2842 0x01, 0x00, 0x00, 0x21, 2469 0x01, 0x00, 0x00, 0x21,
2843 0x7f, 0xff, 0xff, 0xff, 2470 0x7f, 0xff, 0xff, 0xff,
2844 0x00, 0x00, 0x00, 0x02, 2471 0x00, 0x00, 0x00, 0x02,
2845 0x00, 0x00, 0x00, 0x00, 2472 0x00, 0x00, 0x00, 0x00,
2846 0x00, 0x00, 0x00, 0x03, 2473 0x00, 0x00, 0x00, 0x03,
2847 'f', 'o', 'o', 0x00, 2474 'f', 'o', 'o', 0x00,
2848 0x00, 0x00, 0x03, 'f', 2475 0x00, 0x00, 0x03, 'f',
2849 'o', 'o', 0x00, 0x00, 2476 'o', 'o', 0x00, 0x00,
2850 0x00, 0x03, 'b', 'a', 2477 0x00, 0x03, 'b', 'a',
2851 'r' 2478 'r'
2852 }; 2479 };
2853 const unsigned char kH2FrameData[] = { 2480 const unsigned char kH2FrameData[] = {
2854 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS 2481 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS
2855 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff 2482 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff
2856 0xff, 0x00, 0x00, 0x03, // @.. 2483 0xff, 0x00, 0x00, 0x03, // @..
2857 0x66, 0x6f, 0x6f, 0x00, // foo@ 2484 0x66, 0x6f, 0x6f, 0x00, // foo@
2858 0x03, 0x66, 0x6f, 0x6f, // .foo 2485 0x03, 0x66, 0x6f, 0x6f, // .foo
2859 0x03, 0x62, 0x61, 0x72, // .bar 2486 0x03, 0x62, 0x61, 0x72, // .bar
2860 }; 2487 };
2861 SpdyHeadersIR headers_ir(0x7fffffff); 2488 SpdyHeadersIR headers_ir(0x7fffffff);
2862 headers_ir.set_fin(true); 2489 headers_ir.set_fin(true);
2863 headers_ir.SetHeader("", "foo"); 2490 headers_ir.SetHeader("", "foo");
2864 headers_ir.SetHeader("foo", "bar"); 2491 headers_ir.SetHeader("foo", "bar");
2865 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2492 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2866 if (IsSpdy2()) { 2493 if (IsSpdy3()) {
2867 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2868 } else if (IsSpdy3()) {
2869 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2494 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2870 } else { 2495 } else {
2871 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2496 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2872 } 2497 }
2873 } 2498 }
2874 2499
2875 { 2500 {
2876 const char kDescription[] = 2501 const char kDescription[] =
2877 "HEADERS frame with a 0-length header val, FIN, max stream ID"; 2502 "HEADERS frame with a 0-length header val, FIN, max stream ID";
2878 2503
2879 const unsigned char kV2FrameData[] = {
2880 0x80, spdy_version_ch_, 0x00, 0x08,
2881 0x01, 0x00, 0x00, 0x19,
2882 0x7f, 0xff, 0xff, 0xff,
2883 0x00, 0x00, 0x00, 0x02,
2884 0x00, 0x03, 'b', 'a',
2885 'r', 0x00, 0x03, 'f',
2886 'o', 'o', 0x00, 0x03,
2887 'f', 'o', 'o', 0x00,
2888 0x00
2889 };
2890 const unsigned char kV3FrameData[] = { 2504 const unsigned char kV3FrameData[] = {
2891 0x80, spdy_version_ch_, 0x00, 0x08, 2505 0x80, spdy_version_ch_, 0x00, 0x08,
2892 0x01, 0x00, 0x00, 0x21, 2506 0x01, 0x00, 0x00, 0x21,
2893 0x7f, 0xff, 0xff, 0xff, 2507 0x7f, 0xff, 0xff, 0xff,
2894 0x00, 0x00, 0x00, 0x02, 2508 0x00, 0x00, 0x00, 0x02,
2895 0x00, 0x00, 0x00, 0x03, 2509 0x00, 0x00, 0x00, 0x03,
2896 'b', 'a', 'r', 0x00, 2510 'b', 'a', 'r', 0x00,
2897 0x00, 0x00, 0x03, 'f', 2511 0x00, 0x00, 0x03, 'f',
2898 'o', 'o', 0x00, 0x00, 2512 'o', 'o', 0x00, 0x00,
2899 0x00, 0x03, 'f', 'o', 2513 0x00, 0x03, 'f', 'o',
2900 'o', 0x00, 0x00, 0x00, 2514 'o', 0x00, 0x00, 0x00,
2901 0x00 2515 0x00
2902 }; 2516 };
2903 const unsigned char kH2FrameData[] = { 2517 const unsigned char kH2FrameData[] = {
2904 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS 2518 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS
2905 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff 2519 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff
2906 0xff, 0x00, 0x03, 0x62, // @.b 2520 0xff, 0x00, 0x03, 0x62, // @.b
2907 0x61, 0x72, 0x03, 0x66, // ar.f 2521 0x61, 0x72, 0x03, 0x66, // ar.f
2908 0x6f, 0x6f, 0x00, 0x03, // oo@. 2522 0x6f, 0x6f, 0x00, 0x03, // oo@.
2909 0x66, 0x6f, 0x6f, 0x00, // foo. 2523 0x66, 0x6f, 0x6f, 0x00, // foo.
2910 }; 2524 };
2911 SpdyHeadersIR headers_ir(0x7fffffff); 2525 SpdyHeadersIR headers_ir(0x7fffffff);
2912 headers_ir.set_fin(true); 2526 headers_ir.set_fin(true);
2913 headers_ir.SetHeader("bar", "foo"); 2527 headers_ir.SetHeader("bar", "foo");
2914 headers_ir.SetHeader("foo", ""); 2528 headers_ir.SetHeader("foo", "");
2915 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2529 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2916 if (IsSpdy2()) { 2530 if (IsSpdy3()) {
2917 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2918 } else if (IsSpdy3()) {
2919 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2531 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2920 } else { 2532 } else {
2921 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2533 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2922 } 2534 }
2923 } 2535 }
2924 2536
2925 { 2537 {
2926 const char kDescription[] = 2538 const char kDescription[] =
2927 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; 2539 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri";
2928 2540
2929 const unsigned char kH2FrameData[] = { 2541 const unsigned char kH2FrameData[] = {
2930 0x00, 0x00, 0x14, 0x01, // Headers: FIN | END_HEADERS | PRIORITY 2542 0x00, 0x00, 0x14, 0x01, // Headers: FIN | END_HEADERS | PRIORITY
2931 0x25, 0x7f, 0xff, 0xff, // Stream 0x7fffffff 2543 0x25, 0x7f, 0xff, 0xff, // Stream 0x7fffffff
2932 0xff, 0x00, 0x00, 0x00, // exclusive, parent stream 2544 0xff, 0x00, 0x00, 0x00, // exclusive, parent stream
2933 0x00, 0xdb, // weight 2545 0x00, 0xdb, // weight
2934 0x00, 0x03, 0x62, 0x61, // @.ba 2546 0x00, 0x03, 0x62, 0x61, // @.ba
2935 0x72, 0x03, 0x66, 0x6f, // r.fo 2547 0x72, 0x03, 0x66, 0x6f, // r.fo
2936 0x6f, 0x00, 0x03, 0x66, // o@.f 2548 0x6f, 0x00, 0x03, 0x66, // o@.f
2937 0x6f, 0x6f, 0x00, // oo. 2549 0x6f, 0x6f, 0x00, // oo.
2938 }; 2550 };
2939 SpdyHeadersIR headers_ir(0x7fffffff); 2551 SpdyHeadersIR headers_ir(0x7fffffff);
2940 headers_ir.set_fin(true); 2552 headers_ir.set_fin(true);
2941 headers_ir.set_priority(1); 2553 headers_ir.set_priority(1);
2942 headers_ir.set_has_priority(true); 2554 headers_ir.set_has_priority(true);
2943 headers_ir.SetHeader("bar", "foo"); 2555 headers_ir.SetHeader("bar", "foo");
2944 headers_ir.SetHeader("foo", ""); 2556 headers_ir.SetHeader("foo", "");
2945 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2557 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2946 if (IsSpdy2() || IsSpdy3()) { 2558 if (IsSpdy3()) {
2947 // HEADERS with priority not supported. 2559 // HEADERS with priority not supported.
2948 } else { 2560 } else {
2949 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2561 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2950 } 2562 }
2951 } 2563 }
2952 2564
2953 { 2565 {
2954 const char kDescription[] = 2566 const char kDescription[] =
2955 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, " 2567 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, "
2956 "exclusive=true, parent_stream=0"; 2568 "exclusive=true, parent_stream=0";
(...skipping 10 matching lines...) Expand all
2967 }; 2579 };
2968 SpdyHeadersIR headers_ir(0x7fffffff); 2580 SpdyHeadersIR headers_ir(0x7fffffff);
2969 headers_ir.set_fin(true); 2581 headers_ir.set_fin(true);
2970 headers_ir.set_priority(1); 2582 headers_ir.set_priority(1);
2971 headers_ir.set_has_priority(true); 2583 headers_ir.set_has_priority(true);
2972 headers_ir.set_exclusive(true); 2584 headers_ir.set_exclusive(true);
2973 headers_ir.set_parent_stream_id(0); 2585 headers_ir.set_parent_stream_id(0);
2974 headers_ir.SetHeader("bar", "foo"); 2586 headers_ir.SetHeader("bar", "foo");
2975 headers_ir.SetHeader("foo", ""); 2587 headers_ir.SetHeader("foo", "");
2976 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2588 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2977 if (IsSpdy2() || IsSpdy3()) { 2589 if (IsSpdy3()) {
2978 // HEADERS with priority not supported. 2590 // HEADERS with priority not supported.
2979 } else { 2591 } else {
2980 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2592 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
2981 } 2593 }
2982 } 2594 }
2983 2595
2984 { 2596 {
2985 const char kDescription[] = 2597 const char kDescription[] =
2986 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, " 2598 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri, "
2987 "exclusive=false, parent_stream=max stream ID"; 2599 "exclusive=false, parent_stream=max stream ID";
(...skipping 10 matching lines...) Expand all
2998 }; 2610 };
2999 SpdyHeadersIR headers_ir(0x7fffffff); 2611 SpdyHeadersIR headers_ir(0x7fffffff);
3000 headers_ir.set_fin(true); 2612 headers_ir.set_fin(true);
3001 headers_ir.set_priority(1); 2613 headers_ir.set_priority(1);
3002 headers_ir.set_has_priority(true); 2614 headers_ir.set_has_priority(true);
3003 headers_ir.set_exclusive(false); 2615 headers_ir.set_exclusive(false);
3004 headers_ir.set_parent_stream_id(0x7fffffff); 2616 headers_ir.set_parent_stream_id(0x7fffffff);
3005 headers_ir.SetHeader("bar", "foo"); 2617 headers_ir.SetHeader("bar", "foo");
3006 headers_ir.SetHeader("foo", ""); 2618 headers_ir.SetHeader("foo", "");
3007 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2619 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
3008 if (IsSpdy2() || IsSpdy3()) { 2620 if (IsSpdy3()) {
3009 // HEADERS with priority not supported. 2621 // HEADERS with priority not supported.
3010 } else { 2622 } else {
3011 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2623 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
3012 } 2624 }
3013 } 2625 }
3014 2626
3015 { 2627 {
3016 const char kDescription[] = 2628 const char kDescription[] =
3017 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded"; 2629 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded";
3018 2630
3019 const unsigned char kH2FrameData[] = { 2631 const unsigned char kH2FrameData[] = {
3020 0x00, 0x00, 0x15, 0x01, // Headers 2632 0x00, 0x00, 0x15, 0x01, // Headers
3021 0x0d, 0x7f, 0xff, 0xff, // FIN | END_HEADERS | PADDED, Stream 2633 0x0d, 0x7f, 0xff, 0xff, // FIN | END_HEADERS | PADDED, Stream
3022 // 0x7fffffff 2634 // 0x7fffffff
3023 0xff, 0x05, 0x00, 0x00, // Pad length field 2635 0xff, 0x05, 0x00, 0x00, // Pad length field
3024 0x03, 0x66, 0x6f, 0x6f, // .foo 2636 0x03, 0x66, 0x6f, 0x6f, // .foo
3025 0x00, 0x03, 0x66, 0x6f, // @.fo 2637 0x00, 0x03, 0x66, 0x6f, // @.fo
3026 0x6f, 0x03, 0x62, 0x61, // o.ba 2638 0x6f, 0x03, 0x62, 0x61, // o.ba
3027 0x72, // r 2639 0x72, // r
3028 // Padding payload 2640 // Padding payload
3029 0x00, 0x00, 0x00, 0x00, 0x00, 2641 0x00, 0x00, 0x00, 0x00, 0x00,
3030 }; 2642 };
3031 SpdyHeadersIR headers_ir(0x7fffffff); 2643 SpdyHeadersIR headers_ir(0x7fffffff);
3032 headers_ir.set_fin(true); 2644 headers_ir.set_fin(true);
3033 headers_ir.SetHeader("", "foo"); 2645 headers_ir.SetHeader("", "foo");
3034 headers_ir.SetHeader("foo", "bar"); 2646 headers_ir.SetHeader("foo", "bar");
3035 headers_ir.set_padding_len(6); 2647 headers_ir.set_padding_len(6);
3036 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2648 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
3037 if (IsSpdy2() || IsSpdy3()) { 2649 if (IsSpdy3()) {
3038 // Padding is not supported. 2650 // Padding is not supported.
3039 } else { 2651 } else {
3040 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2652 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
3041 } 2653 }
3042 } 2654 }
3043 } 2655 }
3044 2656
3045 // TODO(phajdan.jr): Clean up after we no longer need 2657 // TODO(phajdan.jr): Clean up after we no longer need
3046 // to workaround http://crbug.com/139744. 2658 // to workaround http://crbug.com/139744.
3047 #if !defined(USE_SYSTEM_ZLIB) 2659 #if !defined(USE_SYSTEM_ZLIB)
3048 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { 2660 TEST_P(SpdyFramerTest, CreateHeadersCompressed) {
3049 SpdyFramer framer(spdy_version_); 2661 SpdyFramer framer(spdy_version_);
3050 framer.set_enable_compression(true); 2662 framer.set_enable_compression(true);
3051 2663
3052 { 2664 {
3053 const char kDescription[] = "HEADERS frame, no FIN"; 2665 const char kDescription[] = "HEADERS frame, no FIN";
3054 2666
3055 const unsigned char kV2FrameData[] = {
3056 0x80, spdy_version_ch_, 0x00, 0x08,
3057 0x00, 0x00, 0x00, 0x32,
3058 0x00, 0x00, 0x00, 0x01,
3059 0x00, 0x00, 0x38, 0xea,
3060 0xdf, 0xa2, 0x51, 0xb2,
3061 0x62, 0x60, 0x62, 0x60,
3062 0x4e, 0x4a, 0x2c, 0x62,
3063 0x60, 0x06, 0x08, 0xa0,
3064 0xb4, 0xfc, 0x7c, 0x80,
3065 0x00, 0x62, 0x60, 0x4e,
3066 0xcb, 0xcf, 0x67, 0x60,
3067 0x06, 0x08, 0xa0, 0xa4,
3068 0xc4, 0x22, 0x80, 0x00,
3069 0x02, 0x00, 0x00, 0x00,
3070 0xff, 0xff,
3071 };
3072 const unsigned char kV3FrameData[] = { 2667 const unsigned char kV3FrameData[] = {
3073 0x80, spdy_version_ch_, 0x00, 0x08, 2668 0x80, spdy_version_ch_, 0x00, 0x08,
3074 0x00, 0x00, 0x00, 0x31, 2669 0x00, 0x00, 0x00, 0x31,
3075 0x00, 0x00, 0x00, 0x01, 2670 0x00, 0x00, 0x00, 0x01,
3076 0x38, 0xea, 0xe3, 0xc6, 2671 0x38, 0xea, 0xe3, 0xc6,
3077 0xa7, 0xc2, 0x02, 0xe5, 2672 0xa7, 0xc2, 0x02, 0xe5,
3078 0x0e, 0x50, 0xc2, 0x4b, 2673 0x0e, 0x50, 0xc2, 0x4b,
3079 0x4a, 0x04, 0xe5, 0x0b, 2674 0x4a, 0x04, 0xe5, 0x0b,
3080 0x66, 0x80, 0x00, 0x4a, 2675 0x66, 0x80, 0x00, 0x4a,
3081 0xcb, 0xcf, 0x07, 0x08, 2676 0xcb, 0xcf, 0x07, 0x08,
3082 0x20, 0x10, 0x95, 0x96, 2677 0x20, 0x10, 0x95, 0x96,
3083 0x9f, 0x0f, 0xa2, 0x00, 2678 0x9f, 0x0f, 0xa2, 0x00,
3084 0x02, 0x28, 0x29, 0xb1, 2679 0x02, 0x28, 0x29, 0xb1,
3085 0x08, 0x20, 0x80, 0x00, 2680 0x08, 0x20, 0x80, 0x00,
3086 0x00, 0x00, 0x00, 0xff, 2681 0x00, 0x00, 0x00, 0xff,
3087 0xff, 2682 0xff,
3088 }; 2683 };
3089 const unsigned char kV2SIMDFrameData[] = {
3090 0x80, spdy_version_ch_, 0x00, 0x08,
3091 0x00, 0x00, 0x00, 0x2f,
3092 0x00, 0x00, 0x00, 0x01,
3093 0x00, 0x00, 0x38, 0xea,
3094 0xdf, 0xa2, 0x51, 0xb2,
3095 0x62, 0x60, 0x62, 0x60,
3096 0x4e, 0x4a, 0x2c, 0x62,
3097 0x60, 0x06, 0x08, 0xa0,
3098 0xb4, 0xfc, 0x7c, 0x80,
3099 0x00, 0x62, 0x60, 0x06,
3100 0x13, 0x00, 0x01, 0x94,
3101 0x94, 0x58, 0x04, 0x10,
3102 0x40, 0x00, 0x00, 0x00,
3103 0x00, 0xff, 0xff,
3104 };
3105 const unsigned char kV3SIMDFrameData[] = { 2684 const unsigned char kV3SIMDFrameData[] = {
3106 0x80, spdy_version_ch_, 0x00, 0x08, 2685 0x80, spdy_version_ch_, 0x00, 0x08,
3107 0x00, 0x00, 0x00, 0x2c, 2686 0x00, 0x00, 0x00, 0x2c,
3108 0x00, 0x00, 0x00, 0x01, 2687 0x00, 0x00, 0x00, 0x01,
3109 0x38, 0xea, 0xe3, 0xc6, 2688 0x38, 0xea, 0xe3, 0xc6,
3110 0xa7, 0xc2, 0x02, 0xe5, 2689 0xa7, 0xc2, 0x02, 0xe5,
3111 0x0e, 0x50, 0xc2, 0x4b, 2690 0x0e, 0x50, 0xc2, 0x4b,
3112 0x4a, 0x04, 0xe5, 0x0b, 2691 0x4a, 0x04, 0xe5, 0x0b,
3113 0x66, 0x80, 0x00, 0x4a, 2692 0x66, 0x80, 0x00, 0x4a,
3114 0xcb, 0xcf, 0x07, 0x08, 2693 0xcb, 0xcf, 0x07, 0x08,
3115 0x20, 0x24, 0x0a, 0x20, 2694 0x20, 0x24, 0x0a, 0x20,
3116 0x80, 0x92, 0x12, 0x8b, 2695 0x80, 0x92, 0x12, 0x8b,
3117 0x00, 0x02, 0x08, 0x00, 2696 0x00, 0x02, 0x08, 0x00,
3118 0x00, 0x00, 0xff, 0xff, 2697 0x00, 0x00, 0xff, 0xff,
3119 }; 2698 };
3120 2699
3121 SpdyHeadersIR headers_ir(1); 2700 SpdyHeadersIR headers_ir(1);
3122 headers_ir.SetHeader("bar", "foo"); 2701 headers_ir.SetHeader("bar", "foo");
3123 headers_ir.SetHeader("foo", "bar"); 2702 headers_ir.SetHeader("foo", "bar");
3124 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2703 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
3125 const unsigned char* frame_data = 2704 const unsigned char* frame_data =
3126 reinterpret_cast<const unsigned char*>(frame->data()); 2705 reinterpret_cast<const unsigned char*>(frame->data());
3127 if (IsSpdy2()) { 2706 if (IsSpdy3()) {
3128 // Try comparing with SIMD version, if that fails, do a failing check
3129 // with pretty printing against non-SIMD version
3130 if (memcmp(frame_data,
3131 kV2SIMDFrameData,
3132 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) {
3133 CompareCharArraysWithHexError(kDescription,
3134 frame_data,
3135 frame->size(),
3136 kV2FrameData,
3137 arraysize(kV2FrameData));
3138 }
3139 } else if (IsSpdy3()) {
3140 if (memcmp(frame_data, 2707 if (memcmp(frame_data,
3141 kV3SIMDFrameData, 2708 kV3SIMDFrameData,
3142 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { 2709 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) {
3143 CompareCharArraysWithHexError(kDescription, 2710 CompareCharArraysWithHexError(kDescription,
3144 frame_data, 2711 frame_data,
3145 frame->size(), 2712 frame->size(),
3146 kV3FrameData, 2713 kV3FrameData,
3147 arraysize(kV3FrameData)); 2714 arraysize(kV3FrameData));
3148 } 2715 }
3149 } else { 2716 } else {
3150 // Deflate compression doesn't apply to HPACK. 2717 // Deflate compression doesn't apply to HPACK.
3151 } 2718 }
3152 } 2719 }
3153 } 2720 }
3154 #endif // !defined(USE_SYSTEM_ZLIB) 2721 #endif // !defined(USE_SYSTEM_ZLIB)
3155 2722
3156 TEST_P(SpdyFramerTest, CreateWindowUpdate) { 2723 TEST_P(SpdyFramerTest, CreateWindowUpdate) {
3157 SpdyFramer framer(spdy_version_); 2724 SpdyFramer framer(spdy_version_);
3158 2725
3159 { 2726 {
3160 const char kDescription[] = "WINDOW_UPDATE frame"; 2727 const char kDescription[] = "WINDOW_UPDATE frame";
3161 const unsigned char kV3FrameData[] = { // Also applies for V2. 2728 const unsigned char kV3FrameData[] = {
3162 0x80, spdy_version_ch_, 0x00, 0x09, 2729 0x80, spdy_version_ch_, 0x00, 0x09,
3163 0x00, 0x00, 0x00, 0x08, 2730 0x00, 0x00, 0x00, 0x08,
3164 0x00, 0x00, 0x00, 0x01, 2731 0x00, 0x00, 0x00, 0x01,
3165 0x00, 0x00, 0x00, 0x01, 2732 0x00, 0x00, 0x00, 0x01,
3166 }; 2733 };
3167 const unsigned char kH2FrameData[] = { 2734 const unsigned char kH2FrameData[] = {
3168 0x00, 0x00, 0x04, 0x08, 2735 0x00, 0x00, 0x04, 0x08,
3169 0x00, 0x00, 0x00, 0x00, 2736 0x00, 0x00, 0x00, 0x00,
3170 0x01, 0x00, 0x00, 0x00, 2737 0x01, 0x00, 0x00, 0x00,
3171 0x01, 2738 0x01,
3172 }; 2739 };
3173 scoped_ptr<SpdyFrame> frame( 2740 scoped_ptr<SpdyFrame> frame(
3174 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); 2741 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1)));
3175 if (IsHttp2()) { 2742 if (IsHttp2()) {
3176 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2743 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
3177 } else { 2744 } else {
3178 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2745 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
3179 } 2746 }
3180 } 2747 }
3181 2748
3182 { 2749 {
3183 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; 2750 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID";
3184 const unsigned char kV3FrameData[] = { // Also applies for V2. 2751 const unsigned char kV3FrameData[] = {
3185 0x80, spdy_version_ch_, 0x00, 0x09, 2752 0x80, spdy_version_ch_, 0x00, 0x09,
3186 0x00, 0x00, 0x00, 0x08, 2753 0x00, 0x00, 0x00, 0x08,
3187 0x7f, 0xff, 0xff, 0xff, 2754 0x7f, 0xff, 0xff, 0xff,
3188 0x00, 0x00, 0x00, 0x01, 2755 0x00, 0x00, 0x00, 0x01,
3189 }; 2756 };
3190 const unsigned char kH2FrameData[] = { 2757 const unsigned char kH2FrameData[] = {
3191 0x00, 0x00, 0x04, 0x08, 2758 0x00, 0x00, 0x04, 0x08,
3192 0x00, 0x7f, 0xff, 0xff, 2759 0x00, 0x7f, 0xff, 0xff,
3193 0xff, 0x00, 0x00, 0x00, 2760 0xff, 0x00, 0x00, 0x00,
3194 0x01, 2761 0x01,
3195 }; 2762 };
3196 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( 2763 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate(
3197 SpdyWindowUpdateIR(0x7FFFFFFF, 1))); 2764 SpdyWindowUpdateIR(0x7FFFFFFF, 1)));
3198 if (IsHttp2()) { 2765 if (IsHttp2()) {
3199 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData)); 2766 CompareFrame(kDescription, *frame, kH2FrameData, arraysize(kH2FrameData));
3200 } else { 2767 } else {
3201 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2768 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
3202 } 2769 }
3203 } 2770 }
3204 2771
3205 { 2772 {
3206 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; 2773 const char kDescription[] = "WINDOW_UPDATE frame with max window delta";
3207 const unsigned char kV3FrameData[] = { // Also applies for V2. 2774 const unsigned char kV3FrameData[] = {
3208 0x80, spdy_version_ch_, 0x00, 0x09, 2775 0x80, spdy_version_ch_, 0x00, 0x09,
3209 0x00, 0x00, 0x00, 0x08, 2776 0x00, 0x00, 0x00, 0x08,
3210 0x00, 0x00, 0x00, 0x01, 2777 0x00, 0x00, 0x00, 0x01,
3211 0x7f, 0xff, 0xff, 0xff, 2778 0x7f, 0xff, 0xff, 0xff,
3212 }; 2779 };
3213 const unsigned char kH2FrameData[] = { 2780 const unsigned char kH2FrameData[] = {
3214 0x00, 0x00, 0x04, 0x08, 2781 0x00, 0x00, 0x04, 0x08,
3215 0x00, 0x00, 0x00, 0x00, 2782 0x00, 0x00, 0x00, 0x00,
3216 0x01, 0x7f, 0xff, 0xff, 2783 0x01, 0x7f, 0xff, 0xff,
3217 0xff, 2784 0xff,
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
3866 << SpdyFramer::ErrorCodeToString(framer.error_code()); 3433 << SpdyFramer::ErrorCodeToString(framer.error_code());
3867 EXPECT_EQ(0u, visitor.header_buffer_length_); 3434 EXPECT_EQ(0u, visitor.header_buffer_length_);
3868 } 3435 }
3869 3436
3870 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { 3437 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) {
3871 SpdyFramer framer(spdy_version_); 3438 SpdyFramer framer(spdy_version_);
3872 // Create a GoAway frame that has a few extra bytes at the end. 3439 // Create a GoAway frame that has a few extra bytes at the end.
3873 // We create enough overhead to overflow the framer's control frame buffer. 3440 // We create enough overhead to overflow the framer's control frame buffer.
3874 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u); 3441 ASSERT_LE(SpdyFramerPeer::ControlFrameBufferSize(), 250u);
3875 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1; 3442 const size_t length = SpdyFramerPeer::ControlFrameBufferSize() + 1;
3876 const unsigned char kV3FrameData[] = { // Also applies for V2. 3443 const unsigned char kV3FrameData[] = {
3877 0x80, spdy_version_ch_, 0x00, 0x07, 3444 0x80, spdy_version_ch_, 0x00, 0x07,
3878 0x00, 0x00, 0x00, static_cast<unsigned char>(length), 3445 0x00, 0x00, 0x00, static_cast<unsigned char>(length),
3879 0x00, 0x00, 0x00, 0x00, // Stream ID 3446 0x00, 0x00, 0x00, 0x00, // Stream ID
3880 0x00, 0x00, 0x00, 0x00, // Status 3447 0x00, 0x00, 0x00, 0x00, // Status
3881 }; 3448 };
3882 3449
3883 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length, 3450 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length,
3884 // since it may carry opaque data. Verify that minimal length is tested. 3451 // since it may carry opaque data. Verify that minimal length is tested.
3885 ASSERT_GT(framer.GetGoAwayMinimumSize(), framer.GetControlFrameHeaderSize()); 3452 ASSERT_GT(framer.GetGoAwayMinimumSize(), framer.GetControlFrameHeaderSize());
3886 const size_t less_than_min_length = 3453 const size_t less_than_min_length =
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
4006 EXPECT_EQ(3 * 2, visitor.setting_count_); 3573 EXPECT_EQ(3 * 2, visitor.setting_count_);
4007 if (spdy_version_ > SPDY3) { 3574 if (spdy_version_ > SPDY3) {
4008 EXPECT_EQ(2, visitor.settings_ack_sent_); 3575 EXPECT_EQ(2, visitor.settings_ack_sent_);
4009 } 3576 }
4010 } 3577 }
4011 3578
4012 // Tests handling of SETTINGS frame with duplicate entries. 3579 // Tests handling of SETTINGS frame with duplicate entries.
4013 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { 3580 TEST_P(SpdyFramerTest, ReadDuplicateSettings) {
4014 SpdyFramer framer(spdy_version_); 3581 SpdyFramer framer(spdy_version_);
4015 3582
4016 const unsigned char kV2FrameData[] = {
4017 0x80, spdy_version_ch_, 0x00, 0x04,
4018 0x00, 0x00, 0x00, 0x1C,
4019 0x00, 0x00, 0x00, 0x03,
4020 0x01, 0x00, 0x00, 0x00, // 1st Setting
4021 0x00, 0x00, 0x00, 0x02,
4022 0x01, 0x00, 0x00, 0x00, // 2nd (duplicate) Setting
4023 0x00, 0x00, 0x00, 0x03,
4024 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting
4025 0x00, 0x00, 0x00, 0x03,
4026 };
4027 const unsigned char kV3FrameData[] = { 3583 const unsigned char kV3FrameData[] = {
4028 0x80, spdy_version_ch_, 0x00, 0x04, 3584 0x80, spdy_version_ch_, 0x00, 0x04,
4029 0x00, 0x00, 0x00, 0x1C, 3585 0x00, 0x00, 0x00, 0x1C,
4030 0x00, 0x00, 0x00, 0x03, 3586 0x00, 0x00, 0x00, 0x03,
4031 0x00, 0x00, 0x00, 0x01, // 1st Setting 3587 0x00, 0x00, 0x00, 0x01, // 1st Setting
4032 0x00, 0x00, 0x00, 0x02, 3588 0x00, 0x00, 0x00, 0x02,
4033 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting 3589 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting
4034 0x00, 0x00, 0x00, 0x03, 3590 0x00, 0x00, 0x00, 0x03,
4035 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting 3591 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting
4036 0x00, 0x00, 0x00, 0x03, 3592 0x00, 0x00, 0x00, 0x03,
4037 }; 3593 };
4038 const unsigned char kH2FrameData[] = { 3594 const unsigned char kH2FrameData[] = {
4039 0x00, 0x00, 0x12, 0x04, 3595 0x00, 0x00, 0x12, 0x04,
4040 0x00, 0x00, 0x00, 0x00, 3596 0x00, 0x00, 0x00, 0x00,
4041 0x00, 0x00, 0x01, // 1st Setting 3597 0x00, 0x00, 0x01, // 1st Setting
4042 0x00, 0x00, 0x00, 0x02, 3598 0x00, 0x00, 0x00, 0x02,
4043 0x00, 0x01, // 2nd (duplicate) Setting 3599 0x00, 0x01, // 2nd (duplicate) Setting
4044 0x00, 0x00, 0x00, 0x03, 3600 0x00, 0x00, 0x00, 0x03,
4045 0x00, 0x03, // 3rd (unprocessed) Setting 3601 0x00, 0x03, // 3rd (unprocessed) Setting
4046 0x00, 0x00, 0x00, 0x03, 3602 0x00, 0x00, 0x00, 0x03,
4047 }; 3603 };
4048 3604
4049 TestSpdyVisitor visitor(spdy_version_); 3605 TestSpdyVisitor visitor(spdy_version_);
4050 visitor.use_compression_ = false; 3606 visitor.use_compression_ = false;
4051 if (IsSpdy2()) { 3607 if (IsSpdy3()) {
4052 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData));
4053 } else if (IsSpdy3()) {
4054 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); 3608 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData));
4055 } else { 3609 } else {
4056 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); 3610 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData));
4057 } 3611 }
4058 3612
4059 if (!IsHttp2()) { 3613 if (!IsHttp2()) {
4060 EXPECT_EQ(1, visitor.setting_count_); 3614 EXPECT_EQ(1, visitor.setting_count_);
4061 EXPECT_EQ(1, visitor.error_count_); 3615 EXPECT_EQ(1, visitor.error_count_);
4062 } else { 3616 } else {
4063 // In HTTP/2, duplicate settings are allowed; 3617 // In HTTP/2, duplicate settings are allowed;
4064 // each setting replaces the previous value for that setting. 3618 // each setting replaces the previous value for that setting.
4065 EXPECT_EQ(3, visitor.setting_count_); 3619 EXPECT_EQ(3, visitor.setting_count_);
4066 EXPECT_EQ(0, visitor.error_count_); 3620 EXPECT_EQ(0, visitor.error_count_);
4067 EXPECT_EQ(1, visitor.settings_ack_sent_); 3621 EXPECT_EQ(1, visitor.settings_ack_sent_);
4068 } 3622 }
4069 } 3623 }
4070 3624
4071 // Tests handling of SETTINGS frame with a setting we don't recognize. 3625 // Tests handling of SETTINGS frame with a setting we don't recognize.
4072 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) { 3626 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) {
4073 SpdyFramer framer(spdy_version_); 3627 SpdyFramer framer(spdy_version_);
4074 3628
4075 const unsigned char kV2FrameData[] = {
4076 0x80, spdy_version_ch_, 0x00, 0x04,
4077 0x00, 0x00, 0x00, 0x1C,
4078 0x00, 0x00, 0x00, 0x01,
4079 0x10, 0x00, 0x00, 0x00, // 1st Setting
4080 0x00, 0x00, 0x00, 0x02,
4081 };
4082 const unsigned char kV3FrameData[] = { 3629 const unsigned char kV3FrameData[] = {
4083 0x80, spdy_version_ch_, 0x00, 0x04, 3630 0x80, spdy_version_ch_, 0x00, 0x04,
4084 0x00, 0x00, 0x00, 0x1C, 3631 0x00, 0x00, 0x00, 0x1C,
4085 0x00, 0x00, 0x00, 0x01, 3632 0x00, 0x00, 0x00, 0x01,
4086 0x00, 0x00, 0x00, 0x10, // 1st Setting 3633 0x00, 0x00, 0x00, 0x10, // 1st Setting
4087 0x00, 0x00, 0x00, 0x02, 3634 0x00, 0x00, 0x00, 0x02,
4088 }; 3635 };
4089 const unsigned char kH2FrameData[] = { 3636 const unsigned char kH2FrameData[] = {
4090 0x00, 0x00, 0x06, 0x04, 3637 0x00, 0x00, 0x06, 0x04,
4091 0x00, 0x00, 0x00, 0x00, 3638 0x00, 0x00, 0x00, 0x00,
4092 0x00, 0x00, 0x10, // 1st Setting 3639 0x00, 0x00, 0x10, // 1st Setting
4093 0x00, 0x00, 0x00, 0x02, 3640 0x00, 0x00, 0x00, 0x02,
4094 }; 3641 };
4095 3642
4096 TestSpdyVisitor visitor(spdy_version_); 3643 TestSpdyVisitor visitor(spdy_version_);
4097 visitor.use_compression_ = false; 3644 visitor.use_compression_ = false;
4098 if (IsSpdy2()) { 3645 if (IsSpdy3()) {
4099 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData));
4100 } else if (IsSpdy3()) {
4101 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); 3646 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData));
4102 } else { 3647 } else {
4103 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); 3648 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData));
4104 } 3649 }
4105 3650
4106 if (!IsHttp2()) { 3651 if (!IsHttp2()) {
4107 EXPECT_EQ(0, visitor.setting_count_); 3652 EXPECT_EQ(0, visitor.setting_count_);
4108 EXPECT_EQ(1, visitor.error_count_); 3653 EXPECT_EQ(1, visitor.error_count_);
4109 } else { 3654 } else {
4110 // In HTTP/2, we ignore unknown settings because of extensions. 3655 // In HTTP/2, we ignore unknown settings because of extensions.
4111 EXPECT_EQ(0, visitor.setting_count_); 3656 EXPECT_EQ(0, visitor.setting_count_);
4112 EXPECT_EQ(0, visitor.error_count_); 3657 EXPECT_EQ(0, visitor.error_count_);
4113 } 3658 }
4114 } 3659 }
4115 3660
4116 // Tests handling of SETTINGS frame with entries out of order. 3661 // Tests handling of SETTINGS frame with entries out of order.
4117 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { 3662 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) {
4118 SpdyFramer framer(spdy_version_); 3663 SpdyFramer framer(spdy_version_);
4119 3664
4120 const unsigned char kV2FrameData[] = {
4121 0x80, spdy_version_ch_, 0x00, 0x04,
4122 0x00, 0x00, 0x00, 0x1C,
4123 0x00, 0x00, 0x00, 0x03,
4124 0x02, 0x00, 0x00, 0x00, // 1st Setting
4125 0x00, 0x00, 0x00, 0x02,
4126 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting
4127 0x00, 0x00, 0x00, 0x03,
4128 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting
4129 0x00, 0x00, 0x00, 0x03,
4130 };
4131 const unsigned char kV3FrameData[] = { 3665 const unsigned char kV3FrameData[] = {
4132 0x80, spdy_version_ch_, 0x00, 0x04, 3666 0x80, spdy_version_ch_, 0x00, 0x04,
4133 0x00, 0x00, 0x00, 0x1C, 3667 0x00, 0x00, 0x00, 0x1C,
4134 0x00, 0x00, 0x00, 0x03, 3668 0x00, 0x00, 0x00, 0x03,
4135 0x00, 0x00, 0x00, 0x02, // 1st Setting 3669 0x00, 0x00, 0x00, 0x02, // 1st Setting
4136 0x00, 0x00, 0x00, 0x02, 3670 0x00, 0x00, 0x00, 0x02,
4137 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting 3671 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting
4138 0x00, 0x00, 0x00, 0x03, 3672 0x00, 0x00, 0x00, 0x03,
4139 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting 3673 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting
4140 0x00, 0x00, 0x00, 0x03, 3674 0x00, 0x00, 0x00, 0x03,
4141 }; 3675 };
4142 const unsigned char kH2FrameData[] = { 3676 const unsigned char kH2FrameData[] = {
4143 0x00, 0x00, 0x12, 0x04, 3677 0x00, 0x00, 0x12, 0x04,
4144 0x00, 0x00, 0x00, 0x00, 3678 0x00, 0x00, 0x00, 0x00,
4145 0x00, 0x00, 0x02, // 1st Setting 3679 0x00, 0x00, 0x02, // 1st Setting
4146 0x00, 0x00, 0x00, 0x02, 3680 0x00, 0x00, 0x00, 0x02,
4147 0x00, 0x01, // 2nd (out of order) Setting 3681 0x00, 0x01, // 2nd (out of order) Setting
4148 0x00, 0x00, 0x00, 0x03, 3682 0x00, 0x00, 0x00, 0x03,
4149 0x00, 0x03, // 3rd (unprocessed) Setting 3683 0x00, 0x03, // 3rd (unprocessed) Setting
4150 0x00, 0x00, 0x00, 0x03, 3684 0x00, 0x00, 0x00, 0x03,
4151 }; 3685 };
4152 3686
4153 TestSpdyVisitor visitor(spdy_version_); 3687 TestSpdyVisitor visitor(spdy_version_);
4154 visitor.use_compression_ = false; 3688 visitor.use_compression_ = false;
4155 if (IsSpdy2()) { 3689 if (IsSpdy3()) {
4156 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData));
4157 } else if (IsSpdy3()) {
4158 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); 3690 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData));
4159 } else { 3691 } else {
4160 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData)); 3692 visitor.SimulateInFramer(kH2FrameData, sizeof(kH2FrameData));
4161 } 3693 }
4162 3694
4163 if (!IsHttp2()) { 3695 if (!IsHttp2()) {
4164 EXPECT_EQ(1, visitor.setting_count_); 3696 EXPECT_EQ(1, visitor.setting_count_);
4165 EXPECT_EQ(1, visitor.error_count_); 3697 EXPECT_EQ(1, visitor.error_count_);
4166 } else { 3698 } else {
4167 // In HTTP/2, settings are allowed in any order. 3699 // In HTTP/2, settings are allowed in any order.
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
4729 EXPECT_EQ(9u, framer.GetBlockedSize()); 4261 EXPECT_EQ(9u, framer.GetBlockedSize());
4730 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); 4262 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize());
4731 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize()); 4263 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize());
4732 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); 4264 EXPECT_EQ(9u, framer.GetFrameMinimumSize());
4733 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); 4265 EXPECT_EQ(16393u, framer.GetFrameMaximumSize());
4734 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); 4266 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload());
4735 } else { 4267 } else {
4736 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); 4268 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize());
4737 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); 4269 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize());
4738 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); 4270 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize());
4739 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); 4271 EXPECT_EQ(12u, framer.GetSynReplyMinimumSize());
4740 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); 4272 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize());
4741 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); 4273 EXPECT_EQ(12u, framer.GetSettingsMinimumSize());
4742 EXPECT_EQ(12u, framer.GetPingSize()); 4274 EXPECT_EQ(12u, framer.GetPingSize());
4743 EXPECT_EQ(IsSpdy2() ? 12u : 16u, framer.GetGoAwayMinimumSize()); 4275 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize());
4744 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetHeadersMinimumSize()); 4276 EXPECT_EQ(12u, framer.GetHeadersMinimumSize());
4745 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); 4277 EXPECT_EQ(16u, framer.GetWindowUpdateSize());
4746 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); 4278 EXPECT_EQ(8u, framer.GetFrameMinimumSize());
4747 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize()); 4279 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize());
4748 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload()); 4280 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload());
4749 } 4281 }
4750 } 4282 }
4751 4283
4752 TEST_P(SpdyFramerTest, StateToStringTest) { 4284 TEST_P(SpdyFramerTest, StateToStringTest) {
4753 EXPECT_STREQ("ERROR", 4285 EXPECT_STREQ("ERROR",
4754 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); 4286 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR));
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
4978 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4510 << SpdyFramer::ErrorCodeToString(framer.error_code());
4979 } else { 4511 } else {
4980 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); 4512 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state());
4981 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4513 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4982 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4514 << SpdyFramer::ErrorCodeToString(framer.error_code());
4983 } 4515 }
4984 } while (++flags != 0); 4516 } while (++flags != 0);
4985 } 4517 }
4986 4518
4987 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { 4519 TEST_P(SpdyFramerTest, SynStreamFrameFlags) {
4988 if (!IsSpdy2() && !IsSpdy3()) { 4520 if (!IsSpdy3()) {
4989 // SYN_STREAM not supported in SPDY>3 4521 // SYN_STREAM not supported in SPDY>3
4990 return; 4522 return;
4991 } 4523 }
4992 uint8_t flags = 0; 4524 uint8_t flags = 0;
4993 do { 4525 do {
4994 SCOPED_TRACE(testing::Message() << "Flags " << flags); 4526 SCOPED_TRACE(testing::Message() << "Flags " << flags);
4995 4527
4996 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4528 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
4997 testing::StrictMock<test::MockDebugVisitor> debug_visitor; 4529 testing::StrictMock<test::MockDebugVisitor> debug_visitor;
4998 SpdyFramer framer(spdy_version_); 4530 SpdyFramer framer(spdy_version_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5032 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4564 << SpdyFramer::ErrorCodeToString(framer.error_code());
5033 } else { 4565 } else {
5034 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); 4566 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state());
5035 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4567 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5036 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4568 << SpdyFramer::ErrorCodeToString(framer.error_code());
5037 } 4569 }
5038 } while (++flags != 0); 4570 } while (++flags != 0);
5039 } 4571 }
5040 4572
5041 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { 4573 TEST_P(SpdyFramerTest, SynReplyFrameFlags) {
5042 if (!IsSpdy2() && !IsSpdy3()) { 4574 if (!IsSpdy3()) {
5043 // SYN_REPLY not supported in SPDY>3 4575 // SYN_REPLY not supported in SPDY>3
5044 return; 4576 return;
5045 } 4577 }
5046 uint8_t flags = 0; 4578 uint8_t flags = 0;
5047 do { 4579 do {
5048 SCOPED_TRACE(testing::Message() << "Flags " << flags); 4580 SCOPED_TRACE(testing::Message() << "Flags " << flags);
5049 4581
5050 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4582 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5051 SpdyFramer framer(spdy_version_); 4583 SpdyFramer framer(spdy_version_);
5052 framer.set_visitor(&visitor); 4584 framer.set_visitor(&visitor);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
5494 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5026 << SpdyFramer::ErrorCodeToString(framer.error_code());
5495 } 5027 }
5496 } while (++flags != 0); 5028 } while (++flags != 0);
5497 } 5029 }
5498 5030
5499 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) 5031 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags)
5500 5032
5501 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) 5033 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags)
5502 5034
5503 TEST_P(SpdyFramerTest, EmptySynStream) { 5035 TEST_P(SpdyFramerTest, EmptySynStream) {
5504 if (!IsSpdy2() && !IsSpdy3()) { 5036 if (!IsSpdy3()) {
5505 // SYN_STREAM not supported in SPDY>3. 5037 // SYN_STREAM not supported in SPDY>3.
5506 return; 5038 return;
5507 } 5039 }
5508 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5040 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5509 testing::StrictMock<test::MockDebugVisitor> debug_visitor; 5041 testing::StrictMock<test::MockDebugVisitor> debug_visitor;
5510 SpdyFramer framer(spdy_version_); 5042 SpdyFramer framer(spdy_version_);
5511 framer.set_visitor(&visitor); 5043 framer.set_visitor(&visitor);
5512 framer.set_debug_visitor(&debug_visitor); 5044 framer.set_debug_visitor(&debug_visitor);
5513 5045
5514 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); 5046 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _));
(...skipping 13 matching lines...) Expand all
5528 5060
5529 framer.ProcessInput(frame->data(), framer.GetSynStreamMinimumSize()); 5061 framer.ProcessInput(frame->data(), framer.GetSynStreamMinimumSize());
5530 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); 5062 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state());
5531 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5063 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5532 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5064 << SpdyFramer::ErrorCodeToString(framer.error_code());
5533 } 5065 }
5534 5066
5535 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { 5067 TEST_P(SpdyFramerTest, SettingsFlagsAndId) {
5536 const uint32_t kId = 0x020304; 5068 const uint32_t kId = 0x020304;
5537 const uint32_t kFlags = 0x01; 5069 const uint32_t kFlags = 0x01;
5538 const uint32_t kWireFormat = 5070 const uint32_t kWireFormat = base::HostToNet32(0x01020304);
5539 base::HostToNet32(IsSpdy2() ? 0x04030201 : 0x01020304);
5540 5071
5541 SettingsFlagsAndId id_and_flags = 5072 SettingsFlagsAndId id_and_flags =
5542 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); 5073 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat);
5543 EXPECT_EQ(kId, id_and_flags.id()); 5074 EXPECT_EQ(kId, id_and_flags.id());
5544 EXPECT_EQ(kFlags, id_and_flags.flags()); 5075 EXPECT_EQ(kFlags, id_and_flags.flags());
5545 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); 5076 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_));
5546 } 5077 }
5547 5078
5548 // Test handling of a RST_STREAM with out-of-bounds status codes. 5079 // Test handling of a RST_STREAM with out-of-bounds status codes.
5549 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { 5080 TEST_P(SpdyFramerTest, RstStreamStatusBounds) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
5606 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), 5137 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes),
5607 arraysize(kV3RstStreamNumStatusCodes)); 5138 arraysize(kV3RstStreamNumStatusCodes));
5608 } 5139 }
5609 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); 5140 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state());
5610 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5141 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5611 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5142 << SpdyFramer::ErrorCodeToString(framer.error_code());
5612 } 5143 }
5613 5144
5614 // Test handling of GOAWAY frames with out-of-bounds status code. 5145 // Test handling of GOAWAY frames with out-of-bounds status code.
5615 TEST_P(SpdyFramerTest, GoAwayStatusBounds) { 5146 TEST_P(SpdyFramerTest, GoAwayStatusBounds) {
5616 if (spdy_version_ <= SPDY2) {
5617 return;
5618 }
5619 SpdyFramer framer(spdy_version_); 5147 SpdyFramer framer(spdy_version_);
5620 5148
5621 const unsigned char kV3FrameData[] = { 5149 const unsigned char kV3FrameData[] = {
5622 0x80, spdy_version_ch_, 0x00, 0x07, 5150 0x80, spdy_version_ch_, 0x00, 0x07,
5623 0x00, 0x00, 0x00, 0x08, 5151 0x00, 0x00, 0x00, 0x08,
5624 0x00, 0x00, 0x00, 0x01, // Stream Id 5152 0x00, 0x00, 0x00, 0x01, // Stream Id
5625 0xff, 0xff, 0xff, 0xff, // Status 5153 0xff, 0xff, 0xff, 0xff, // Status
5626 }; 5154 };
5627 const unsigned char kH2FrameData[] = { 5155 const unsigned char kH2FrameData[] = {
5628 0x00, 0x00, 0x0a, 0x07, 5156 0x00, 0x00, 0x0a, 0x07,
(...skipping 14 matching lines...) Expand all
5643 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), 5171 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData),
5644 arraysize(kH2FrameData)); 5172 arraysize(kH2FrameData));
5645 } 5173 }
5646 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); 5174 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state());
5647 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5175 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5648 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5176 << SpdyFramer::ErrorCodeToString(framer.error_code());
5649 } 5177 }
5650 5178
5651 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. 5179 // Tests handling of a GOAWAY frame with out-of-bounds stream ID.
5652 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { 5180 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) {
5653 const unsigned char kV2FrameData[] = {
5654 0x80, spdy_version_ch_, 0x00, 0x07,
5655 0x00, 0x00, 0x00, 0x04,
5656 0xff, 0xff, 0xff, 0xff,
5657 };
5658 const unsigned char kV3FrameData[] = { 5181 const unsigned char kV3FrameData[] = {
5659 0x80, spdy_version_ch_, 0x00, 0x07, 5182 0x80, spdy_version_ch_, 0x00, 0x07,
5660 0x00, 0x00, 0x00, 0x08, 5183 0x00, 0x00, 0x00, 0x08,
5661 0xff, 0xff, 0xff, 0xff, 5184 0xff, 0xff, 0xff, 0xff,
5662 0x00, 0x00, 0x00, 0x00, 5185 0x00, 0x00, 0x00, 0x00,
5663 }; 5186 };
5664 const unsigned char kH2FrameData[] = { 5187 const unsigned char kH2FrameData[] = {
5665 0x00, 0x00, 0x08, 0x07, 5188 0x00, 0x00, 0x08, 0x07,
5666 0x00, 0x00, 0x00, 0x00, 5189 0x00, 0x00, 0x00, 0x00,
5667 0x00, 0xff, 0xff, 0xff, 5190 0x00, 0xff, 0xff, 0xff,
5668 0xff, 0x00, 0x00, 0x00, 5191 0xff, 0x00, 0x00, 0x00,
5669 0x00, 5192 0x00,
5670 }; 5193 };
5671 5194
5672 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5195 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5673 SpdyFramer framer(spdy_version_); 5196 SpdyFramer framer(spdy_version_);
5674 framer.set_visitor(&visitor); 5197 framer.set_visitor(&visitor);
5675 5198
5676 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); 5199 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK));
5677 if (IsSpdy2()) { 5200 if (IsSpdy3()) {
5678 framer.ProcessInput(reinterpret_cast<const char*>(kV2FrameData),
5679 arraysize(kV2FrameData));
5680 } else if (IsSpdy3()) {
5681 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), 5201 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData),
5682 arraysize(kV3FrameData)); 5202 arraysize(kV3FrameData));
5683 } else { 5203 } else {
5684 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData), 5204 framer.ProcessInput(reinterpret_cast<const char*>(kH2FrameData),
5685 arraysize(kH2FrameData)); 5205 arraysize(kH2FrameData));
5686 } 5206 }
5687 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); 5207 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state());
5688 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5208 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5689 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5209 << SpdyFramer::ErrorCodeToString(framer.error_code());
5690 } 5210 }
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
6068 5588
6069 EXPECT_EQ(1, visitor->data_frame_count_); 5589 EXPECT_EQ(1, visitor->data_frame_count_);
6070 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); 5590 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_));
6071 EXPECT_EQ(0, visitor->headers_frame_count_); 5591 EXPECT_EQ(0, visitor->headers_frame_count_);
6072 } 5592 }
6073 } 5593 }
6074 5594
6075 } // namespace test 5595 } // namespace test
6076 5596
6077 } // namespace net 5597 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_headers_block_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698