| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/core/spdy_framer.h" | 5 #include "net/spdy/core/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> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <tuple> | 12 #include <tuple> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" | |
| 19 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 20 #include "net/quic/platform/api/quic_flags.h" | 19 #include "net/quic/platform/api/quic_flags.h" |
| 21 #include "net/spdy/chromium/spdy_flags.h" | 20 #include "net/spdy/chromium/spdy_flags.h" |
| 22 #include "net/spdy/core/array_output_buffer.h" | 21 #include "net/spdy/core/array_output_buffer.h" |
| 23 #include "net/spdy/core/hpack/hpack_constants.h" | 22 #include "net/spdy/core/hpack/hpack_constants.h" |
| 24 #include "net/spdy/core/mock_spdy_framer_visitor.h" | 23 #include "net/spdy/core/mock_spdy_framer_visitor.h" |
| 25 #include "net/spdy/core/spdy_frame_builder.h" | 24 #include "net/spdy/core/spdy_frame_builder.h" |
| 26 #include "net/spdy/core/spdy_frame_reader.h" | 25 #include "net/spdy/core/spdy_frame_reader.h" |
| 27 #include "net/spdy/core/spdy_protocol.h" | 26 #include "net/spdy/core/spdy_protocol.h" |
| 28 #include "net/spdy/core/spdy_test_utils.h" | 27 #include "net/spdy/core/spdy_test_utils.h" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 header_stream_id_ = stream_id; | 428 header_stream_id_ = stream_id; |
| 430 } | 429 } |
| 431 | 430 |
| 432 void OnStreamFrameData(SpdyStreamId stream_id, | 431 void OnStreamFrameData(SpdyStreamId stream_id, |
| 433 const char* data, | 432 const char* data, |
| 434 size_t len) override { | 433 size_t len) override { |
| 435 VLOG(1) << "OnStreamFrameData(" << stream_id << ", data, " << len << ", " | 434 VLOG(1) << "OnStreamFrameData(" << stream_id << ", data, " << len << ", " |
| 436 << ") data:\n" | 435 << ") data:\n" |
| 437 << base::HexEncode(data, len); | 436 << base::HexEncode(data, len); |
| 438 EXPECT_EQ(header_stream_id_, stream_id); | 437 EXPECT_EQ(header_stream_id_, stream_id); |
| 438 |
| 439 data_bytes_ += len; | 439 data_bytes_ += len; |
| 440 } | 440 } |
| 441 | 441 |
| 442 void OnStreamEnd(SpdyStreamId stream_id) override { | 442 void OnStreamEnd(SpdyStreamId stream_id) override { |
| 443 VLOG(1) << "OnStreamEnd(" << stream_id << ")"; | 443 VLOG(1) << "OnStreamEnd(" << stream_id << ")"; |
| 444 EXPECT_EQ(header_stream_id_, stream_id); | 444 EXPECT_EQ(header_stream_id_, stream_id); |
| 445 ++end_of_stream_count_; | 445 ++end_of_stream_count_; |
| 446 } | 446 } |
| 447 | 447 |
| 448 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override { | 448 void OnStreamPadding(SpdyStreamId stream_id, size_t len) override { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 467 headers_handler_.reset(); | 467 headers_handler_.reset(); |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 | 470 |
| 471 void OnRstStream(SpdyStreamId stream_id, SpdyErrorCode error_code) override { | 471 void OnRstStream(SpdyStreamId stream_id, SpdyErrorCode error_code) override { |
| 472 VLOG(1) << "OnRstStream(" << stream_id << ", " << error_code << ")"; | 472 VLOG(1) << "OnRstStream(" << stream_id << ", " << error_code << ")"; |
| 473 ++fin_frame_count_; | 473 ++fin_frame_count_; |
| 474 } | 474 } |
| 475 | 475 |
| 476 void OnSetting(SpdySettingsIds id, uint32_t value) override { | 476 void OnSetting(SpdySettingsIds id, uint32_t value) override { |
| 477 VLOG(1) << "OnSetting(" << id << ", " << std::hex << ", " << value << ")"; | 477 VLOG(1) << "OnSetting(" << id << ", " << std::hex << value << ")"; |
| 478 ++setting_count_; | 478 ++setting_count_; |
| 479 } | 479 } |
| 480 | 480 |
| 481 void OnSettingsAck() override { | 481 void OnSettingsAck() override { |
| 482 VLOG(1) << "OnSettingsAck"; | 482 VLOG(1) << "OnSettingsAck"; |
| 483 ++settings_ack_received_; | 483 ++settings_ack_received_; |
| 484 } | 484 } |
| 485 | 485 |
| 486 void OnSettingsEnd() override { | 486 void OnSettingsEnd() override { |
| 487 VLOG(1) << "OnSettingsEnd"; | 487 VLOG(1) << "OnSettingsEnd"; |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 headers.SetHeader("alpha", "beta"); | 846 headers.SetHeader("alpha", "beta"); |
| 847 headers.SetHeader("gamma", "charlie"); | 847 headers.SetHeader("gamma", "charlie"); |
| 848 SpdySerializedFrame frame( | 848 SpdySerializedFrame frame( |
| 849 SpdyFramerPeer::SerializeHeaders(&framer, headers, &output_)); | 849 SpdyFramerPeer::SerializeHeaders(&framer, headers, &output_)); |
| 850 | 850 |
| 851 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); | 851 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 852 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), | 852 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame.data()), |
| 853 frame.size() - 2); | 853 frame.size() - 2); |
| 854 | 854 |
| 855 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 855 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 856 EXPECT_EQ(0u, visitor.headers_.size()); | 856 EXPECT_THAT(visitor.headers_, testing::IsEmpty()); |
| 857 } | 857 } |
| 858 | 858 |
| 859 // Test that we can encode and decode stream dependency values in a header | 859 // Test that we can encode and decode stream dependency values in a header |
| 860 // frame. | 860 // frame. |
| 861 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { | 861 TEST_P(SpdyFramerTest, HeaderStreamDependencyValues) { |
| 862 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); | 862 SpdyFramer framer(SpdyFramer::DISABLE_COMPRESSION); |
| 863 | 863 |
| 864 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; | 864 const SpdyStreamId parent_stream_id_test_array[] = {0, 3}; |
| 865 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { | 865 for (SpdyStreamId parent_stream_id : parent_stream_id_test_array) { |
| 866 const bool exclusive_test_array[] = {true, false}; | 866 const bool exclusive_test_array[] = {true, false}; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 0x08, // Flags: PADDED | 1050 0x08, // Flags: PADDED |
| 1051 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 1051 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 1052 0x04, // PadLen: 4 trailing bytes | 1052 0x04, // PadLen: 4 trailing bytes |
| 1053 0x00, 0x00, 0x00, 0x00, // Padding | 1053 0x00, 0x00, 0x00, 0x00, // Padding |
| 1054 }; | 1054 }; |
| 1055 | 1055 |
| 1056 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1056 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1057 | 1057 |
| 1058 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); | 1058 EXPECT_CALL(visitor, OnHeaders(1, false, 0, 0, false, false, false)); |
| 1059 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); | 1059 EXPECT_CALL(visitor, OnHeaderFrameStart(1)).Times(1); |
| 1060 |
| 1060 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1061 EXPECT_EQ(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1061 EXPECT_FALSE(framer.HasError()); | 1062 EXPECT_FALSE(framer.HasError()); |
| 1062 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) | 1063 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) |
| 1063 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 1064 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 1064 } | 1065 } |
| 1065 | 1066 |
| 1066 // Test that if we receive a DATA with stream ID zero, we signal an error | 1067 // Test that if we receive a DATA with stream ID zero, we signal an error |
| 1067 // (but don't crash). | 1068 // (but don't crash). |
| 1068 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { | 1069 TEST_P(SpdyFramerTest, DataWithStreamIdZero) { |
| 1069 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1070 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error | 1128 // Test that if we receive a RST_STREAM with stream ID zero, we signal an error |
| 1128 // (but don't crash). | 1129 // (but don't crash). |
| 1129 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { | 1130 TEST_P(SpdyFramerTest, RstStreamWithStreamIdZero) { |
| 1130 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1131 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1131 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 1132 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1132 framer.set_visitor(&visitor); | 1133 framer.set_visitor(&visitor); |
| 1133 | 1134 |
| 1134 SpdyRstStreamIR rst_stream_ir(0, ERROR_CODE_PROTOCOL_ERROR); | 1135 SpdyRstStreamIR rst_stream_ir(0, ERROR_CODE_PROTOCOL_ERROR); |
| 1135 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); | 1136 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream_ir)); |
| 1136 if (use_output_) { | 1137 if (use_output_) { |
| 1137 ASSERT_TRUE(framer.SerializeRstStream(rst_stream_ir, &output_)); | 1138 EXPECT_TRUE(framer.SerializeRstStream(rst_stream_ir, &output_)); |
| 1138 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 1139 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 1139 } | 1140 } |
| 1140 | 1141 |
| 1141 // We shouldn't have to read the whole frame before we signal an error. | 1142 // We shouldn't have to read the whole frame before we signal an error. |
| 1142 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1143 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1143 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1144 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1144 EXPECT_TRUE(framer.HasError()); | 1145 EXPECT_TRUE(framer.HasError()); |
| 1145 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) | 1146 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) |
| 1146 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 1147 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 1147 } | 1148 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); | 1195 SpdySerializedFrame frame(kH2FrameData, sizeof(kH2FrameData), false); |
| 1195 | 1196 |
| 1196 // We shouldn't have to read the whole frame before we signal an error. | 1197 // We shouldn't have to read the whole frame before we signal an error. |
| 1197 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1198 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1198 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1199 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1199 EXPECT_TRUE(framer.HasError()); | 1200 EXPECT_TRUE(framer.HasError()); |
| 1200 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) | 1201 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) |
| 1201 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 1202 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 1202 } | 1203 } |
| 1203 | 1204 |
| 1204 // Test that if we receive a CONTINUATION with stream ID zero, we signal an | 1205 // Test that if we receive a CONTINUATION with stream ID zero, we signal |
| 1205 // SPDY_INVALID_STREAM_ID. | 1206 // SPDY_INVALID_STREAM_ID. |
| 1206 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { | 1207 TEST_P(SpdyFramerTest, ContinuationWithStreamIdZero) { |
| 1207 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1208 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1208 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 1209 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1209 framer.set_visitor(&visitor); | 1210 framer.set_visitor(&visitor); |
| 1210 | 1211 |
| 1211 SpdyContinuationIR continuation(0); | 1212 SpdyContinuationIR continuation(0); |
| 1212 auto some_nonsense_encoding = | 1213 auto some_nonsense_encoding = |
| 1213 SpdyMakeUnique<SpdyString>("some nonsense encoding"); | 1214 SpdyMakeUnique<SpdyString>("some nonsense encoding"); |
| 1214 continuation.take_encoding(std::move(some_nonsense_encoding)); | 1215 continuation.take_encoding(std::move(some_nonsense_encoding)); |
| 1215 continuation.set_end_headers(true); | 1216 continuation.set_end_headers(true); |
| 1216 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); | 1217 SpdySerializedFrame frame(framer.SerializeContinuation(continuation)); |
| 1217 if (use_output_) { | 1218 if (use_output_) { |
| 1218 ASSERT_TRUE(framer.SerializeContinuation(continuation, &output_)); | 1219 ASSERT_TRUE(framer.SerializeContinuation(continuation, &output_)); |
| 1219 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 1220 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 1220 } | 1221 } |
| 1221 | 1222 |
| 1222 // We shouldn't have to read the whole frame before we signal an error. | 1223 // We shouldn't have to read the whole frame before we signal an error. |
| 1223 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1224 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1224 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1225 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1225 EXPECT_TRUE(framer.HasError()); | 1226 EXPECT_TRUE(framer.HasError()); |
| 1226 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) | 1227 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) |
| 1227 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 1228 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 1228 } | 1229 } |
| 1229 | 1230 |
| 1230 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 1231 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal |
| 1231 // SPDY_INVALID_STREAM_ID. | 1232 // SPDY_INVALID_STREAM_ID. |
| 1232 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 1233 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
| 1233 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1234 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1234 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 1235 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1235 framer.set_visitor(&visitor); | 1236 framer.set_visitor(&visitor); |
| 1236 | 1237 |
| 1237 SpdyPushPromiseIR push_promise(0, 4); | 1238 SpdyPushPromiseIR push_promise(0, 4); |
| 1238 push_promise.SetHeader("alpha", "beta"); | 1239 push_promise.SetHeader("alpha", "beta"); |
| 1239 SpdySerializedFrame frame(SpdyFramerPeer::SerializePushPromise( | 1240 SpdySerializedFrame frame(SpdyFramerPeer::SerializePushPromise( |
| 1240 &framer, push_promise, use_output_ ? &output_ : nullptr)); | 1241 &framer, push_promise, use_output_ ? &output_ : nullptr)); |
| 1241 | 1242 |
| 1242 // We shouldn't have to read the whole frame before we signal an error. | 1243 // We shouldn't have to read the whole frame before we signal an error. |
| 1243 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 1244 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 1244 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); | 1245 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); |
| 1245 EXPECT_TRUE(framer.HasError()); | 1246 EXPECT_TRUE(framer.HasError()); |
| 1246 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) | 1247 EXPECT_EQ(SpdyFramer::SPDY_INVALID_STREAM_ID, framer.spdy_framer_error()) |
| 1247 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 1248 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 1248 } | 1249 } |
| 1249 | 1250 |
| 1250 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 1251 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
| 1251 // signal SPDY_INVALID_STREAM_ID. | 1252 // signal SPDY_INVALID_CONTROL_FRAME. |
| 1252 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 1253 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
| 1253 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 1254 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 1254 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 1255 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1255 framer.set_visitor(&visitor); | 1256 framer.set_visitor(&visitor); |
| 1256 | 1257 |
| 1257 SpdyPushPromiseIR push_promise(3, 0); | 1258 SpdyPushPromiseIR push_promise(3, 0); |
| 1258 push_promise.SetHeader("alpha", "beta"); | 1259 push_promise.SetHeader("alpha", "beta"); |
| 1259 SpdySerializedFrame frame(SpdyFramerPeer::SerializePushPromise( | 1260 SpdySerializedFrame frame(SpdyFramerPeer::SerializePushPromise( |
| 1260 &framer, push_promise, use_output_ ? &output_ : nullptr)); | 1261 &framer, push_promise, use_output_ ? &output_ : nullptr)); |
| 1261 | 1262 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1290 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); | 1291 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 1291 visitor.SimulateInFramer( | 1292 visitor.SimulateInFramer( |
| 1292 reinterpret_cast<unsigned char*>(control_frame.data()), | 1293 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 1293 control_frame.size()); | 1294 control_frame.size()); |
| 1294 | 1295 |
| 1295 EXPECT_THAT(visitor.headers_, testing::ElementsAre(testing::Pair( | 1296 EXPECT_THAT(visitor.headers_, testing::ElementsAre(testing::Pair( |
| 1296 "name", SpdyStringPiece(value)))); | 1297 "name", SpdyStringPiece(value)))); |
| 1297 } | 1298 } |
| 1298 | 1299 |
| 1299 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { | 1300 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { |
| 1300 // See crbug.com/172383 | 1301 // See https://crbug.com/172383/ |
| 1301 SpdyHeadersIR headers(1); | 1302 SpdyHeadersIR headers(1); |
| 1302 headers.SetHeader("server", "SpdyServer 1.0"); | 1303 headers.SetHeader("server", "SpdyServer 1.0"); |
| 1303 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 1304 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| 1304 headers.SetHeader("status", "200"); | 1305 headers.SetHeader("status", "200"); |
| 1305 headers.SetHeader("version", "HTTP/1.1"); | 1306 headers.SetHeader("version", "HTTP/1.1"); |
| 1306 headers.SetHeader("content-type", "text/html"); | 1307 headers.SetHeader("content-type", "text/html"); |
| 1307 headers.SetHeader("content-length", "12"); | 1308 headers.SetHeader("content-length", "12"); |
| 1308 headers.SetHeader("x-empty-header", ""); | 1309 headers.SetHeader("x-empty-header", ""); |
| 1309 | 1310 |
| 1310 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 1311 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1751 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 1751 if (use_output_) { | 1752 if (use_output_) { |
| 1752 ASSERT_TRUE(framer.SerializeRstStream(rst_stream, &output_)); | 1753 ASSERT_TRUE(framer.SerializeRstStream(rst_stream, &output_)); |
| 1753 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 1754 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 1754 } | 1755 } |
| 1755 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1756 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1756 } | 1757 } |
| 1757 | 1758 |
| 1758 { | 1759 { |
| 1759 const char kDescription[] = "RST_STREAM frame with max stream ID"; | 1760 const char kDescription[] = "RST_STREAM frame with max stream ID"; |
| 1761 // clang-format off |
| 1760 const unsigned char kH2FrameData[] = { | 1762 const unsigned char kH2FrameData[] = { |
| 1761 0x00, 0x00, 0x04, // Length: 4 | 1763 0x00, 0x00, 0x04, // Length: 4 |
| 1762 0x03, // Type: RST_STREAM | 1764 0x03, // Type: RST_STREAM |
| 1763 0x00, // Flags: none | 1765 0x00, // Flags: none |
| 1764 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff | 1766 0x7f, 0xff, 0xff, 0xff, // Stream: 0x7fffffff |
| 1765 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR | 1767 0x00, 0x00, 0x00, 0x01, // Error: PROTOCOL_ERROR |
| 1766 }; | 1768 }; |
| 1767 SpdyRstStreamIR rst_stream(0x7FFFFFFF, ERROR_CODE_PROTOCOL_ERROR); | 1769 SpdyRstStreamIR rst_stream(0x7FFFFFFF, ERROR_CODE_PROTOCOL_ERROR); |
| 1768 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); | 1770 SpdySerializedFrame frame(framer.SerializeRstStream(rst_stream)); |
| 1769 if (use_output_) { | 1771 if (use_output_) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1792 } | 1794 } |
| 1793 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1795 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1794 } | 1796 } |
| 1795 } | 1797 } |
| 1796 | 1798 |
| 1797 TEST_P(SpdyFramerTest, CreateSettings) { | 1799 TEST_P(SpdyFramerTest, CreateSettings) { |
| 1798 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 1800 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 1799 | 1801 |
| 1800 { | 1802 { |
| 1801 const char kDescription[] = "Network byte order SETTINGS frame"; | 1803 const char kDescription[] = "Network byte order SETTINGS frame"; |
| 1802 | |
| 1803 const unsigned char kH2FrameData[] = { | 1804 const unsigned char kH2FrameData[] = { |
| 1804 0x00, 0x00, 0x06, // Length: 6 | 1805 0x00, 0x00, 0x06, // Length: 6 |
| 1805 0x04, // Type: SETTINGS | 1806 0x04, // Type: SETTINGS |
| 1806 0x00, // Flags: none | 1807 0x00, // Flags: none |
| 1807 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1808 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1808 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1809 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| 1809 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 | 1810 0x0a, 0x0b, 0x0c, 0x0d, // Value: 168496141 |
| 1810 }; | 1811 }; |
| 1811 | 1812 |
| 1812 uint32_t kValue = 0x0a0b0c0d; | 1813 uint32_t kValue = 0x0a0b0c0d; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 output_.Reset(); | 1854 output_.Reset(); |
| 1854 ASSERT_TRUE(framer.SerializeSettings(settings_ir, &output_)); | 1855 ASSERT_TRUE(framer.SerializeSettings(settings_ir, &output_)); |
| 1855 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 1856 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 1856 } | 1857 } |
| 1857 | 1858 |
| 1858 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1859 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1859 } | 1860 } |
| 1860 | 1861 |
| 1861 { | 1862 { |
| 1862 const char kDescription[] = "Empty SETTINGS frame"; | 1863 const char kDescription[] = "Empty SETTINGS frame"; |
| 1863 | |
| 1864 const unsigned char kH2FrameData[] = { | 1864 const unsigned char kH2FrameData[] = { |
| 1865 0x00, 0x00, 0x00, // Length: 0 | 1865 0x00, 0x00, 0x00, // Length: 0 |
| 1866 0x04, // Type: SETTINGS | 1866 0x04, // Type: SETTINGS |
| 1867 0x00, // Flags: none | 1867 0x00, // Flags: none |
| 1868 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1868 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1869 }; | 1869 }; |
| 1870 SpdySettingsIR settings_ir; | 1870 SpdySettingsIR settings_ir; |
| 1871 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1871 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 1872 if (use_output_) { | 1872 if (use_output_) { |
| 1873 output_.Reset(); | 1873 output_.Reset(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1893 0x9a, 0xbc, 0xde, 0xff, // Data | 1893 0x9a, 0xbc, 0xde, 0xff, // Data |
| 1894 }; | 1894 }; |
| 1895 const unsigned char kH2FrameDataWithAck[] = { | 1895 const unsigned char kH2FrameDataWithAck[] = { |
| 1896 0x00, 0x00, 0x08, // Length: 8 | 1896 0x00, 0x00, 0x08, // Length: 8 |
| 1897 0x06, // Type: PING | 1897 0x06, // Type: PING |
| 1898 0x01, // Flags: ACK | 1898 0x01, // Flags: ACK |
| 1899 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1899 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1900 0x12, 0x34, 0x56, 0x78, // Opaque | 1900 0x12, 0x34, 0x56, 0x78, // Opaque |
| 1901 0x9a, 0xbc, 0xde, 0xff, // Data | 1901 0x9a, 0xbc, 0xde, 0xff, // Data |
| 1902 }; | 1902 }; |
| 1903 SpdySerializedFrame frame; | |
| 1904 const SpdyPingId kPingId = 0x123456789abcdeffULL; | 1903 const SpdyPingId kPingId = 0x123456789abcdeffULL; |
| 1905 SpdyPingIR ping_ir(kPingId); | 1904 SpdyPingIR ping_ir(kPingId); |
| 1906 // Tests SpdyPingIR when the ping is not an ack. | 1905 // Tests SpdyPingIR when the ping is not an ack. |
| 1907 ASSERT_FALSE(ping_ir.is_ack()); | 1906 ASSERT_FALSE(ping_ir.is_ack()); |
| 1908 frame = framer.SerializePing(ping_ir); | 1907 SpdySerializedFrame frame(framer.SerializePing(ping_ir)); |
| 1909 if (use_output_) { | 1908 if (use_output_) { |
| 1910 ASSERT_TRUE(framer.SerializePing(ping_ir, &output_)); | 1909 ASSERT_TRUE(framer.SerializePing(ping_ir, &output_)); |
| 1911 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 1910 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 1912 } | 1911 } |
| 1913 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1912 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1914 | 1913 |
| 1915 // Tests SpdyPingIR when the ping is an ack. | 1914 // Tests SpdyPingIR when the ping is an ack. |
| 1916 ping_ir.set_is_ack(true); | 1915 ping_ir.set_is_ack(true); |
| 1917 frame = framer.SerializePing(ping_ir); | 1916 frame = framer.SerializePing(ping_ir); |
| 1918 if (use_output_) { | 1917 if (use_output_) { |
| (...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2874 EXPECT_TRUE(it->HasNextFrame()); | 2873 EXPECT_TRUE(it->HasNextFrame()); |
| 2875 EXPECT_EQ(it->NextFrame(&output_), frame.size()); | 2874 EXPECT_EQ(it->NextFrame(&output_), frame.size()); |
| 2876 EXPECT_FALSE(it->HasNextFrame()); | 2875 EXPECT_FALSE(it->HasNextFrame()); |
| 2877 } | 2876 } |
| 2878 | 2877 |
| 2879 private: | 2878 private: |
| 2880 ArrayOutputBuffer output_; | 2879 ArrayOutputBuffer output_; |
| 2881 }; | 2880 }; |
| 2882 | 2881 |
| 2883 TEST_F(SpdyControlFrameIteratorTest, RstStreamFrameWithIterator) { | 2882 TEST_F(SpdyControlFrameIteratorTest, RstStreamFrameWithIterator) { |
| 2884 auto ir = base::MakeUnique<SpdyRstStreamIR>(0, ERROR_CODE_PROTOCOL_ERROR); | 2883 auto ir = SpdyMakeUnique<SpdyRstStreamIR>(0, ERROR_CODE_PROTOCOL_ERROR); |
| 2885 RunTest(std::move(ir)); | 2884 RunTest(std::move(ir)); |
| 2886 } | 2885 } |
| 2887 | 2886 |
| 2888 TEST_F(SpdyControlFrameIteratorTest, SettingsFrameWithIterator) { | 2887 TEST_F(SpdyControlFrameIteratorTest, SettingsFrameWithIterator) { |
| 2889 auto ir = base::MakeUnique<SpdySettingsIR>(); | 2888 auto ir = SpdyMakeUnique<SpdySettingsIR>(); |
| 2890 uint32_t kValue = 0x0a0b0c0d; | 2889 uint32_t kValue = 0x0a0b0c0d; |
| 2891 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; | 2890 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; |
| 2892 ir->AddSetting(kId, kValue); | 2891 ir->AddSetting(kId, kValue); |
| 2893 RunTest(std::move(ir)); | 2892 RunTest(std::move(ir)); |
| 2894 } | 2893 } |
| 2895 | 2894 |
| 2896 TEST_F(SpdyControlFrameIteratorTest, PingFrameWithIterator) { | 2895 TEST_F(SpdyControlFrameIteratorTest, PingFrameWithIterator) { |
| 2897 const SpdyPingId kPingId = 0x123456789abcdeffULL; | 2896 const SpdyPingId kPingId = 0x123456789abcdeffULL; |
| 2898 auto ir = base::MakeUnique<SpdyPingIR>(kPingId); | 2897 auto ir = SpdyMakeUnique<SpdyPingIR>(kPingId); |
| 2899 RunTest(std::move(ir)); | 2898 RunTest(std::move(ir)); |
| 2900 } | 2899 } |
| 2901 | 2900 |
| 2902 TEST_F(SpdyControlFrameIteratorTest, GoAwayFrameWithIterator) { | 2901 TEST_F(SpdyControlFrameIteratorTest, GoAwayFrameWithIterator) { |
| 2903 auto ir = base::MakeUnique<SpdyGoAwayIR>(0, ERROR_CODE_NO_ERROR, "GA"); | 2902 auto ir = SpdyMakeUnique<SpdyGoAwayIR>(0, ERROR_CODE_NO_ERROR, "GA"); |
| 2904 RunTest(std::move(ir)); | 2903 RunTest(std::move(ir)); |
| 2905 } | 2904 } |
| 2906 | 2905 |
| 2907 TEST_F(SpdyControlFrameIteratorTest, WindowUpdateFrameWithIterator) { | 2906 TEST_F(SpdyControlFrameIteratorTest, WindowUpdateFrameWithIterator) { |
| 2908 auto ir = base::MakeUnique<SpdyWindowUpdateIR>(1, 1); | 2907 auto ir = SpdyMakeUnique<SpdyWindowUpdateIR>(1, 1); |
| 2909 RunTest(std::move(ir)); | 2908 RunTest(std::move(ir)); |
| 2910 } | 2909 } |
| 2911 | 2910 |
| 2912 TEST_F(SpdyControlFrameIteratorTest, AtlSvcFrameWithIterator) { | 2911 TEST_F(SpdyControlFrameIteratorTest, AtlSvcFrameWithIterator) { |
| 2913 auto ir = base::MakeUnique<SpdyAltSvcIR>(3); | 2912 auto ir = SpdyMakeUnique<SpdyAltSvcIR>(3); |
| 2914 ir->set_origin("origin"); | 2913 ir->set_origin("origin"); |
| 2915 ir->add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2914 ir->add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2916 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); | 2915 "pid1", "host", 443, 5, SpdyAltSvcWireFormat::VersionVector())); |
| 2917 ir->add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 2916 ir->add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 2918 "p\"=i:d", "h_\\o\"st", 123, 42, | 2917 "p\"=i:d", "h_\\o\"st", 123, 42, |
| 2919 SpdyAltSvcWireFormat::VersionVector{24})); | 2918 SpdyAltSvcWireFormat::VersionVector{24})); |
| 2920 RunTest(std::move(ir)); | 2919 RunTest(std::move(ir)); |
| 2921 } | 2920 } |
| 2922 | 2921 |
| 2923 TEST_F(SpdyControlFrameIteratorTest, PriorityFrameWithIterator) { | 2922 TEST_F(SpdyControlFrameIteratorTest, PriorityFrameWithIterator) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 // Zero-len settings frames are permitted as of HTTP/2. | 3030 // Zero-len settings frames are permitted as of HTTP/2. |
| 3032 EXPECT_EQ(0, visitor.error_count_); | 3031 EXPECT_EQ(0, visitor.error_count_); |
| 3033 } | 3032 } |
| 3034 | 3033 |
| 3035 // Tests handling of SETTINGS frames with invalid length. | 3034 // Tests handling of SETTINGS frames with invalid length. |
| 3036 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 3035 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| 3037 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 3036 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3038 SpdySettingsIR settings_ir; | 3037 SpdySettingsIR settings_ir; |
| 3039 | 3038 |
| 3040 // Add settings to more than fill the frame so that we don't get a buffer | 3039 // Add settings to more than fill the frame so that we don't get a buffer |
| 3041 // overflow when calling SimulateInFramer() below. These settings must be | 3040 // overflow when calling SimulateInFramer() below. These settings must be |
| 3042 // distinct parameters because SpdySettingsIR has a map for settings, and will | 3041 // distinct parameters because SpdySettingsIR has a map for settings, and |
| 3043 // collapse multiple copies of the same parameter. | 3042 // will collapse multiple copies of the same parameter. |
| 3044 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0x00000002); | 3043 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0x00000002); |
| 3045 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, 0x00000002); | 3044 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, 0x00000002); |
| 3046 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3045 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3047 if (use_output_) { | 3046 if (use_output_) { |
| 3048 ASSERT_TRUE(framer.SerializeSettings(settings_ir, &output_)); | 3047 ASSERT_TRUE(framer.SerializeSettings(settings_ir, &output_)); |
| 3049 control_frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 3048 control_frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 3050 } | 3049 } |
| 3051 const size_t kNewLength = 8; | 3050 const size_t kNewLength = 8; |
| 3052 SetFrameLength(&control_frame, kNewLength); | 3051 SetFrameLength(&control_frame, kNewLength); |
| 3053 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); | 3052 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3421 | 3420 |
| 3422 EXPECT_THAT( | 3421 EXPECT_THAT( |
| 3423 visitor.headers_, | 3422 visitor.headers_, |
| 3424 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), | 3423 testing::ElementsAre(testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 3425 testing::Pair("name", "value"))); | 3424 testing::Pair("name", "value"))); |
| 3426 } | 3425 } |
| 3427 | 3426 |
| 3428 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3427 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 3429 // frame-format off | 3428 // frame-format off |
| 3430 const unsigned char kInput[] = { | 3429 const unsigned char kInput[] = { |
| 3431 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE | 3430 0x00, 0x00, 0x17, // Length: 23 |
| 3432 0x08, 0x00, 0x00, 0x00, // PADDED | 3431 0x05, // Type: PUSH_PROMISE |
| 3433 0x01, 0x02, 0x00, 0x00, // Stream 1, Pad length field | 3432 0x08, // Flags: PADDED |
| 3434 0x00, 0x2A, 0x00, 0x06, // Promised stream 42 | 3433 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3435 'c', 'o', 'o', 'k', | 3434 0x02, // PadLen: 2 trailing bytes |
| 3436 'i', 'e', 0x07, 'f', | 3435 0x00, 0x00, 0x00, 0x2a, // Promise: 42 |
| 3437 'o', 'o', '=', 'b', | 3436 0x00, // Unindexed Entry |
| 3438 'a', 'r', 0x00, 0x00, | 3437 0x06, // Name Len: 6 |
| 3438 'c', 'o', 'o', 'k', 'i', 'e', // Name |
| 3439 0x07, // Value Len: 7 |
| 3440 'f', 'o', 'o', '=', 'b', 'a', 'r', // Value |
| 3441 0x00, 0x00, // Padding |
| 3439 | 3442 |
| 3440 0x00, 0x00, 0x14, 0x09, // CONTINUATION | 3443 0x00, 0x00, 0x14, // Length: 20 |
| 3441 0x00, 0x00, 0x00, 0x00, | 3444 0x09, // Type: CONTINUATION |
| 3442 0x01, 0x00, 0x06, 'c', // Stream 1 | 3445 0x00, // Flags: none |
| 3443 'o', 'o', 'k', 'i', | 3446 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3444 'e', 0x08, 'b', 'a', | 3447 0x00, // Unindexed Entry |
| 3445 'z', '=', 'b', 'i', | 3448 0x06, // Name Len: 6 |
| 3446 'n', 'g', 0x00, 0x06, | 3449 'c', 'o', 'o', 'k', 'i', 'e', // Name |
| 3447 'c', | 3450 0x08, // Value Len: 7 |
| 3451 'b', 'a', 'z', '=', 'b', 'i', 'n', 'g', // Value |
| 3452 0x00, // Unindexed Entry |
| 3453 0x06, // Name Len: 6 |
| 3454 'c', // Name (split) |
| 3448 | 3455 |
| 3449 0x00, 0x00, 0x12, 0x09, // CONTINUATION | 3456 0x00, 0x00, 0x12, // Length: 18 |
| 3450 0x04, 0x00, 0x00, 0x00, // END_HEADERS | 3457 0x09, // Type: CONTINUATION |
| 3451 0x01, 'o', 'o', 'k', // Stream 1 | 3458 0x04, // Flags: END_HEADERS |
| 3452 'i', 'e', 0x00, 0x00, | 3459 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 3453 0x04, 'n', 'a', 'm', | 3460 'o', 'o', 'k', 'i', 'e', // Name (continued) |
| 3454 'e', 0x05, 'v', 'a', | 3461 0x00, // Value Len: 0 |
| 3455 'l', 'u', 'e', | 3462 0x00, // Unindexed Entry |
| 3463 0x04, // Name Len: 4 |
| 3464 'n', 'a', 'm', 'e', // Name |
| 3465 0x05, // Value Len: 5 |
| 3466 'v', 'a', 'l', 'u', 'e', // Value |
| 3456 }; | 3467 }; |
| 3457 // frame-format on | 3468 // frame-format on |
| 3458 | 3469 |
| 3459 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 3470 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3460 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); | 3471 TestSpdyVisitor visitor(SpdyFramer::DISABLE_COMPRESSION); |
| 3461 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3472 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3462 | 3473 |
| 3463 EXPECT_EQ(0, visitor.error_count_); | 3474 EXPECT_EQ(0, visitor.error_count_); |
| 3464 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3475 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
| 3465 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3476 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3724 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, 10); | 3735 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, 10); |
| 3725 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3736 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3726 if (use_output_) { | 3737 if (use_output_) { |
| 3727 ASSERT_TRUE(framer.SerializeSettings(settings_ir, &output_)); | 3738 ASSERT_TRUE(framer.SerializeSettings(settings_ir, &output_)); |
| 3728 control_frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 3739 control_frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 3729 } | 3740 } |
| 3730 visitor.SimulateInFramer( | 3741 visitor.SimulateInFramer( |
| 3731 reinterpret_cast<unsigned char*>(control_frame.data()), | 3742 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3732 control_frame.size()); | 3743 control_frame.size()); |
| 3733 EXPECT_EQ(0, visitor.error_count_); | 3744 EXPECT_EQ(0, visitor.error_count_); |
| 3734 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3745 EXPECT_EQ(1, visitor.setting_count_); |
| 3735 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3746 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3736 } | 3747 } |
| 3737 | 3748 |
| 3738 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrameWithExtension) { | 3749 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrameWithExtension) { |
| 3739 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 3750 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3740 | 3751 |
| 3741 // The unrecognized frame type should still have a valid length. | 3752 // The unrecognized frame type should still have a valid length. |
| 3742 const unsigned char unknown_frame[] = { | 3753 const unsigned char unknown_frame[] = { |
| 3743 0x00, 0x00, 0x14, // Length: 20 | 3754 0x00, 0x00, 0x14, // Length: 20 |
| 3744 0xff, // Type: UnknownFrameType(255) | 3755 0xff, // Type: UnknownFrameType(255) |
| 3745 0xff, // Flags: 0xff | 3756 0xff, // Flags: 0xff |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3763 | 3774 |
| 3764 // Follow it up with a valid control frame to make sure we handle | 3775 // Follow it up with a valid control frame to make sure we handle |
| 3765 // subsequent frames correctly. | 3776 // subsequent frames correctly. |
| 3766 SpdySettingsIR settings_ir; | 3777 SpdySettingsIR settings_ir; |
| 3767 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, 10); | 3778 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, 10); |
| 3768 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3779 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3769 visitor.SimulateInFramer( | 3780 visitor.SimulateInFramer( |
| 3770 reinterpret_cast<unsigned char*>(control_frame.data()), | 3781 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3771 control_frame.size()); | 3782 control_frame.size()); |
| 3772 EXPECT_EQ(0, visitor.error_count_); | 3783 EXPECT_EQ(0, visitor.error_count_); |
| 3773 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3784 EXPECT_EQ(1, visitor.setting_count_); |
| 3774 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3785 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3775 } | 3786 } |
| 3776 | 3787 |
| 3777 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { | 3788 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { |
| 3778 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); | 3789 SpdyFramer framer(SpdyFramer::ENABLE_COMPRESSION); |
| 3779 const unsigned char kFrameData[] = { | 3790 const unsigned char kFrameData[] = { |
| 3780 0x00, 0x00, 0x08, // Length: 8 | 3791 0x00, 0x00, 0x08, // Length: 8 |
| 3781 0xff, // Type: UnknownFrameType(255) | 3792 0xff, // Type: UnknownFrameType(255) |
| 3782 0xff, // Flags: 0xff | 3793 0xff, // Flags: 0xff |
| 3783 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) | 3794 0xff, 0xff, 0xff, 0xff, // Stream: 0x7fffffff (R-bit set) |
| 3784 0xff, 0xff, 0xff, 0xff, // Payload | 3795 0xff, 0xff, 0xff, 0xff, // Payload |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4081 } | 4092 } |
| 4082 headers_ir.SetHeader("foo", "bar"); | 4093 headers_ir.SetHeader("foo", "bar"); |
| 4083 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders( | 4094 SpdySerializedFrame frame(SpdyFramerPeer::SerializeHeaders( |
| 4084 &framer, headers_ir, use_output_ ? &output_ : nullptr)); | 4095 &framer, headers_ir, use_output_ ? &output_ : nullptr)); |
| 4085 uint8_t set_flags = flags & ~HEADERS_FLAG_PADDED; | 4096 uint8_t set_flags = flags & ~HEADERS_FLAG_PADDED; |
| 4086 SetFrameFlags(&frame, set_flags); | 4097 SetFrameFlags(&frame, set_flags); |
| 4087 | 4098 |
| 4088 // Expected callback values | 4099 // Expected callback values |
| 4089 SpdyStreamId stream_id = 57; | 4100 SpdyStreamId stream_id = 57; |
| 4090 bool has_priority = false; | 4101 bool has_priority = false; |
| 4091 SpdyPriority priority = 0; | 4102 int weight = 0; |
| 4092 SpdyStreamId parent_stream_id = 0; | 4103 SpdyStreamId parent_stream_id = 0; |
| 4093 bool exclusive = false; | 4104 bool exclusive = false; |
| 4094 bool fin = flags & CONTROL_FLAG_FIN; | 4105 bool fin = flags & CONTROL_FLAG_FIN; |
| 4095 bool end = flags & HEADERS_FLAG_END_HEADERS; | 4106 bool end = flags & HEADERS_FLAG_END_HEADERS; |
| 4096 if (flags & HEADERS_FLAG_PRIORITY) { | 4107 if (flags & HEADERS_FLAG_PRIORITY) { |
| 4097 has_priority = true; | 4108 has_priority = true; |
| 4098 priority = 3; | 4109 weight = 3; |
| 4099 parent_stream_id = 5; | 4110 parent_stream_id = 5; |
| 4100 exclusive = true; | 4111 exclusive = true; |
| 4101 } | 4112 } |
| 4102 EXPECT_CALL(visitor, OnHeaders(stream_id, has_priority, priority, | 4113 EXPECT_CALL(visitor, OnHeaders(stream_id, has_priority, weight, |
| 4103 parent_stream_id, exclusive, fin, end)); | 4114 parent_stream_id, exclusive, fin, end)); |
| 4104 EXPECT_CALL(visitor, OnHeaderFrameStart(57)).Times(1); | 4115 EXPECT_CALL(visitor, OnHeaderFrameStart(57)).Times(1); |
| 4105 if (end) { | 4116 if (end) { |
| 4106 EXPECT_CALL(visitor, OnHeaderFrameEnd(57, _)).Times(1); | 4117 EXPECT_CALL(visitor, OnHeaderFrameEnd(57, _)).Times(1); |
| 4107 } | 4118 } |
| 4108 if (flags & DATA_FLAG_FIN && end) { | 4119 if (flags & DATA_FLAG_FIN && end) { |
| 4109 EXPECT_CALL(visitor, OnStreamEnd(_)); | 4120 EXPECT_CALL(visitor, OnStreamEnd(_)); |
| 4110 } else { | 4121 } else { |
| 4111 // Do not close the stream if we are expecting a CONTINUATION frame. | 4122 // Do not close the stream if we are expecting a CONTINUATION frame. |
| 4112 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); | 4123 EXPECT_CALL(visitor, OnStreamEnd(_)).Times(0); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4260 } | 4271 } |
| 4261 | 4272 |
| 4262 framer.ProcessInput(frame0.data(), frame0.size()); | 4273 framer.ProcessInput(frame0.data(), frame0.size()); |
| 4263 framer.ProcessInput(frame1.data(), frame1.size()); | 4274 framer.ProcessInput(frame1.data(), frame1.size()); |
| 4264 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4275 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4265 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) | 4276 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) |
| 4266 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 4277 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 4267 } while (++flags != 0); | 4278 } while (++flags != 0); |
| 4268 } | 4279 } |
| 4269 | 4280 |
| 4270 // TODO(mlavan): Add TEST_F(SpdyFramerTest, AltSvcFrameFlags) | 4281 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
| 4271 | 4282 |
| 4272 // Test handling of a RST_STREAM with out-of-bounds status codes. | 4283 // Test handling of a RST_STREAM with out-of-bounds status codes. |
| 4273 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { | 4284 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
| 4274 const unsigned char kH2RstStreamInvalid[] = { | 4285 const unsigned char kH2RstStreamInvalid[] = { |
| 4275 0x00, 0x00, 0x04, // Length: 4 | 4286 0x00, 0x00, 0x04, // Length: 4 |
| 4276 0x03, // Type: RST_STREAM | 4287 0x03, // Type: RST_STREAM |
| 4277 0x00, // Flags: none | 4288 0x00, // Flags: none |
| 4278 0x00, 0x00, 0x00, 0x01, // Stream: 1 | 4289 0x00, 0x00, 0x00, 0x01, // Stream: 1 |
| 4279 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR | 4290 0x00, 0x00, 0x00, 0x00, // Error: NO_ERROR |
| 4280 }; | 4291 }; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4564 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); | 4575 frame = SpdySerializedFrame(output_.Begin(), output_.Size(), false); |
| 4565 } | 4576 } |
| 4566 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4577 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4567 framer.set_visitor(&visitor); | 4578 framer.set_visitor(&visitor); |
| 4568 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); | 4579 EXPECT_CALL(visitor, OnPriority(3, 1, 256, false)); |
| 4569 framer.ProcessInput(frame.data(), frame.size()); | 4580 framer.ProcessInput(frame.data(), frame.size()); |
| 4570 | 4581 |
| 4571 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 4582 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
| 4572 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) | 4583 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.spdy_framer_error()) |
| 4573 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); | 4584 << SpdyFramer::SpdyFramerErrorToString(framer.spdy_framer_error()); |
| 4574 // TODO(mlavan): once we actually maintain a priority tree, | |
| 4575 // check that state is adjusted correctly. | |
| 4576 } | 4585 } |
| 4577 | 4586 |
| 4578 // Tests handling of PRIORITY frame with incorrect size. | 4587 // Tests handling of PRIORITY frame with incorrect size. |
| 4579 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { | 4588 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
| 4580 // PRIORITY frame of size 4, which isn't correct. | 4589 // PRIORITY frame of size 4, which isn't correct. |
| 4581 const unsigned char kFrameData[] = { | 4590 const unsigned char kFrameData[] = { |
| 4582 0x00, 0x00, 0x04, // Length: 4 | 4591 0x00, 0x00, 0x04, // Length: 4 |
| 4583 0x02, // Type: PRIORITY | 4592 0x02, // Type: PRIORITY |
| 4584 0x00, // Flags: none | 4593 0x00, // Flags: none |
| 4585 0x00, 0x00, 0x00, 0x03, // Stream: 3 | 4594 0x00, 0x00, 0x00, 0x03, // Stream: 3 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4808 | 4817 |
| 4809 EXPECT_EQ(1, visitor->data_frame_count_); | 4818 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4810 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4819 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4811 EXPECT_EQ(0, visitor->headers_frame_count_); | 4820 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4812 } | 4821 } |
| 4813 } | 4822 } |
| 4814 | 4823 |
| 4815 } // namespace test | 4824 } // namespace test |
| 4816 | 4825 |
| 4817 } // namespace net | 4826 } // namespace net |
| OLD | NEW |