| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 0xde, 0xad, 0xbe, 0xef, | 1067 0xde, 0xad, 0xbe, 0xef, |
| 1068 0xde, 0xad, 0xbe, 0xef, | 1068 0xde, 0xad, 0xbe, 0xef, |
| 1069 | 1069 |
| 1070 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 1070 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1071 0x00, 0x00, 0x00, 0x04, | 1071 0x00, 0x00, 0x00, 0x04, |
| 1072 0xde, 0xad, 0xbe, 0xef, | 1072 0xde, 0xad, 0xbe, 0xef, |
| 1073 | 1073 |
| 1074 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | 1074 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 |
| 1075 0x00, 0x00, 0x00, 0x08, | 1075 0x00, 0x00, 0x00, 0x08, |
| 1076 0x00, 0x00, 0x00, 0x01, | 1076 0x00, 0x00, 0x00, 0x01, |
| 1077 0x00, 0x00, 0x00, 0x00, | 1077 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1078 | 1078 |
| 1079 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 1079 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 1080 0x00, 0x00, 0x00, 0x00, | 1080 0x00, 0x00, 0x00, 0x00, |
| 1081 | 1081 |
| 1082 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | 1082 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 1083 0x00, 0x00, 0x00, 0x08, | 1083 0x00, 0x00, 0x00, 0x08, |
| 1084 0x00, 0x00, 0x00, 0x03, | 1084 0x00, 0x00, 0x00, 0x03, |
| 1085 0x00, 0x00, 0x00, 0x00, | 1085 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1086 }; | 1086 }; |
| 1087 | 1087 |
| 1088 const unsigned char kV3Input[] = { | 1088 const unsigned char kV3Input[] = { |
| 1089 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1089 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 1090 0x00, 0x00, 0x00, 0x1a, | 1090 0x00, 0x00, 0x00, 0x1a, |
| 1091 0x00, 0x00, 0x00, 0x01, | 1091 0x00, 0x00, 0x00, 0x01, |
| 1092 0x00, 0x00, 0x00, 0x00, | 1092 0x00, 0x00, 0x00, 0x00, |
| 1093 0x00, 0x00, 0x00, 0x00, | 1093 0x00, 0x00, 0x00, 0x00, |
| 1094 0x00, 0x01, 0x00, 0x00, | 1094 0x00, 0x01, 0x00, 0x00, |
| 1095 0x00, 0x02, 'h', 'h', | 1095 0x00, 0x02, 'h', 'h', |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1126 0xde, 0xad, 0xbe, 0xef, | 1126 0xde, 0xad, 0xbe, 0xef, |
| 1127 0xde, 0xad, 0xbe, 0xef, | 1127 0xde, 0xad, 0xbe, 0xef, |
| 1128 | 1128 |
| 1129 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 1129 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1130 0x00, 0x00, 0x00, 0x04, | 1130 0x00, 0x00, 0x00, 0x04, |
| 1131 0xde, 0xad, 0xbe, 0xef, | 1131 0xde, 0xad, 0xbe, 0xef, |
| 1132 | 1132 |
| 1133 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | 1133 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 |
| 1134 0x00, 0x00, 0x00, 0x08, | 1134 0x00, 0x00, 0x00, 0x08, |
| 1135 0x00, 0x00, 0x00, 0x01, | 1135 0x00, 0x00, 0x00, 0x01, |
| 1136 0x00, 0x00, 0x00, 0x00, | 1136 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1137 | 1137 |
| 1138 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 1138 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 1139 0x00, 0x00, 0x00, 0x00, | 1139 0x00, 0x00, 0x00, 0x00, |
| 1140 | 1140 |
| 1141 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | 1141 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 1142 0x00, 0x00, 0x00, 0x08, | 1142 0x00, 0x00, 0x00, 0x08, |
| 1143 0x00, 0x00, 0x00, 0x03, | 1143 0x00, 0x00, 0x00, 0x03, |
| 1144 0x00, 0x00, 0x00, 0x00, | 1144 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1145 }; | 1145 }; |
| 1146 | 1146 |
| 1147 // SYN_STREAM doesn't exist in SPDY4, so instead we send | 1147 // SYN_STREAM doesn't exist in SPDY4, so instead we send |
| 1148 // HEADERS frames with PRIORITY and END_HEADERS set. | 1148 // HEADERS frames with PRIORITY and END_HEADERS set. |
| 1149 const unsigned char kV4Input[] = { | 1149 const unsigned char kV4Input[] = { |
| 1150 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1150 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS |
| 1151 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1151 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1152 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1152 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1153 0x82, // :method: GET | 1153 0x82, // :method: GET |
| 1154 | 1154 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1171 0x00, 0x00, 0x00, 0x03, | 1171 0x00, 0x00, 0x00, 0x03, |
| 1172 0xde, 0xad, 0xbe, 0xef, | 1172 0xde, 0xad, 0xbe, 0xef, |
| 1173 0xde, 0xad, 0xbe, 0xef, | 1173 0xde, 0xad, 0xbe, 0xef, |
| 1174 | 1174 |
| 1175 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 | 1175 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 |
| 1176 0x00, 0x00, 0x00, 0x01, | 1176 0x00, 0x00, 0x00, 0x01, |
| 1177 0xde, 0xad, 0xbe, 0xef, | 1177 0xde, 0xad, 0xbe, 0xef, |
| 1178 | 1178 |
| 1179 0x00, 0x04, 0x03, 0x00, // RST_STREAM on Stream #1 | 1179 0x00, 0x04, 0x03, 0x00, // RST_STREAM on Stream #1 |
| 1180 0x00, 0x00, 0x00, 0x01, | 1180 0x00, 0x00, 0x00, 0x01, |
| 1181 0x00, 0x00, 0x00, 0x00, | 1181 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL |
| 1182 | 1182 |
| 1183 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 | 1183 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 |
| 1184 0x00, 0x00, 0x00, 0x03, | 1184 0x00, 0x00, 0x00, 0x03, |
| 1185 | 1185 |
| 1186 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream #3 | 1186 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream #3 |
| 1187 0x00, 0x00, 0x00, 0x03, | 1187 0x00, 0x00, 0x00, 0x03, |
| 1188 0x00, 0x00, 0x00, 0x00, | 1188 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL |
| 1189 0x52, 0x45, 0x53, 0x45, // opaque data | 1189 0x52, 0x45, 0x53, 0x45, // opaque data |
| 1190 0x54, 0x53, 0x54, 0x52, | 1190 0x54, 0x53, 0x54, 0x52, |
| 1191 0x45, 0x41, 0x4d, | 1191 0x45, 0x41, 0x4d, |
| 1192 }; | 1192 }; |
| 1193 | 1193 |
| 1194 TestSpdyVisitor visitor(spdy_version_); | 1194 TestSpdyVisitor visitor(spdy_version_); |
| 1195 if (IsSpdy2()) { | 1195 if (IsSpdy2()) { |
| 1196 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1196 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1197 } else if (IsSpdy3()) { | 1197 } else if (IsSpdy3()) { |
| 1198 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1198 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| (...skipping 3686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4885 const unsigned char kV4RstStreamNumStatusCodes[] = { | 4885 const unsigned char kV4RstStreamNumStatusCodes[] = { |
| 4886 0x00, 0x04, 0x03, 0x00, | 4886 0x00, 0x04, 0x03, 0x00, |
| 4887 0x00, 0x00, 0x00, 0x01, | 4887 0x00, 0x00, 0x00, 0x01, |
| 4888 0x00, 0x00, 0x00, kRstStreamStatusTooHigh | 4888 0x00, 0x00, 0x00, kRstStreamStatusTooHigh |
| 4889 }; | 4889 }; |
| 4890 | 4890 |
| 4891 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4891 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4892 SpdyFramer framer(spdy_version_); | 4892 SpdyFramer framer(spdy_version_); |
| 4893 framer.set_visitor(&visitor); | 4893 framer.set_visitor(&visitor); |
| 4894 | 4894 |
| 4895 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); | |
| 4896 if (IsSpdy4()) { | 4895 if (IsSpdy4()) { |
| 4896 EXPECT_CALL(visitor, OnError(_)); |
| 4897 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), | 4897 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), |
| 4898 arraysize(kV4RstStreamInvalid)); | 4898 arraysize(kV4RstStreamInvalid)); |
| 4899 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4900 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4901 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4899 } else { | 4902 } else { |
| 4903 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 4900 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), | 4904 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), |
| 4901 arraysize(kV3RstStreamInvalid)); | 4905 arraysize(kV3RstStreamInvalid)); |
| 4906 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4907 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4908 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4902 } | 4909 } |
| 4903 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | |
| 4904 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
| 4905 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
| 4906 | 4910 |
| 4907 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); | 4911 |
| 4912 framer.Reset(); |
| 4913 |
| 4908 if (IsSpdy4()) { | 4914 if (IsSpdy4()) { |
| 4915 EXPECT_CALL(visitor, OnError(_)); |
| 4909 framer.ProcessInput( | 4916 framer.ProcessInput( |
| 4910 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), | 4917 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), |
| 4911 arraysize(kV4RstStreamNumStatusCodes)); | 4918 arraysize(kV4RstStreamNumStatusCodes)); |
| 4919 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4920 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4921 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4912 } else { | 4922 } else { |
| 4923 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 4913 framer.ProcessInput( | 4924 framer.ProcessInput( |
| 4914 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), | 4925 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), |
| 4915 arraysize(kV3RstStreamNumStatusCodes)); | 4926 arraysize(kV3RstStreamNumStatusCodes)); |
| 4927 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4928 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4929 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4916 } | 4930 } |
| 4917 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | |
| 4918 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | |
| 4919 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
| 4920 } | 4931 } |
| 4921 | 4932 |
| 4922 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 4933 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
| 4923 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { | 4934 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
| 4924 const unsigned char kV2FrameData[] = { | 4935 const unsigned char kV2FrameData[] = { |
| 4925 0x80, spdy_version_ch_, 0x00, 0x07, | 4936 0x80, spdy_version_ch_, 0x00, 0x07, |
| 4926 0x00, 0x00, 0x00, 0x04, | 4937 0x00, 0x00, 0x00, 0x04, |
| 4927 0xff, 0xff, 0xff, 0xff, | 4938 0xff, 0xff, 0xff, 0xff, |
| 4928 }; | 4939 }; |
| 4929 const unsigned char kV3FrameData[] = { | 4940 const unsigned char kV3FrameData[] = { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4975 SpdyBlockedIR blocked_ir(0); | 4986 SpdyBlockedIR blocked_ir(0); |
| 4976 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 4987 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 4977 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 4988 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
| 4978 | 4989 |
| 4979 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4990 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4980 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4991 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4981 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4992 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4982 } | 4993 } |
| 4983 | 4994 |
| 4984 } // namespace net | 4995 } // namespace net |
| OLD | NEW |