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 3766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3777 TestSpdyVisitor visitor(spdy_version_); | 3777 TestSpdyVisitor visitor(spdy_version_); |
3778 visitor.use_compression_ = true; | 3778 visitor.use_compression_ = true; |
3779 visitor.SimulateInFramer( | 3779 visitor.SimulateInFramer( |
3780 reinterpret_cast<unsigned char*>(frame->data()), | 3780 reinterpret_cast<unsigned char*>(frame->data()), |
3781 frame->size()); | 3781 frame->size()); |
3782 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3782 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
3783 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3783 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
3784 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3784 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
3785 } | 3785 } |
3786 | 3786 |
3787 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3787 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndPadding) { |
3788 if (spdy_version_ <= SPDY3) { | 3788 if (spdy_version_ <= SPDY3) { |
3789 return; | 3789 return; |
3790 } | 3790 } |
3791 | 3791 |
3792 const unsigned char kInput[] = { | 3792 const unsigned char kInput[] = { |
3793 0x00, 0x10, 0x01, 0x00, // HEADERS | 3793 0x00, 0x14, 0x01, 0x08, // HEADERS: PAD_LOW |
3794 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3794 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3795 0x03, // Padding of 3. |
3795 0x00, 0x06, 0x63, 0x6f, | 3796 0x00, 0x06, 0x63, 0x6f, |
3796 0x6f, 0x6b, 0x69, 0x65, | 3797 0x6f, 0x6b, 0x69, 0x65, |
3797 0x07, 0x66, 0x6f, 0x6f, | 3798 0x07, 0x66, 0x6f, 0x6f, |
3798 0x3d, 0x62, 0x61, 0x72, | 3799 0x3d, 0x62, 0x61, 0x72, |
| 3800 0x00, 0x00, 0x00, |
3799 | 3801 |
3800 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3802 0x00, 0x1a, 0x09, 0x18, // CONTINUATION: PAD_LOW & PAD_HIGH |
3801 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3803 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3804 0x00, 0x04, // Padding of 4. |
3802 0x00, 0x06, 0x63, 0x6f, | 3805 0x00, 0x06, 0x63, 0x6f, |
3803 0x6f, 0x6b, 0x69, 0x65, | 3806 0x6f, 0x6b, 0x69, 0x65, |
3804 0x08, 0x62, 0x61, 0x7a, | 3807 0x08, 0x62, 0x61, 0x7a, |
3805 0x3d, 0x62, 0x69, 0x6e, | 3808 0x3d, 0x62, 0x69, 0x6e, |
3806 0x67, 0x00, 0x06, 0x63, | 3809 0x67, 0x00, 0x06, 0x63, |
| 3810 0x00, 0x00, 0x00, 0x00, |
3807 | 3811 |
3808 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | 3812 0x00, 0x13, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS |
3809 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3813 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3814 0x00, // Padding of 0. |
3810 0x6f, 0x6f, 0x6b, 0x69, | 3815 0x6f, 0x6f, 0x6b, 0x69, |
3811 0x65, 0x00, 0x00, 0x04, | 3816 0x65, 0x00, 0x00, 0x04, |
3812 0x6e, 0x61, 0x6d, 0x65, | 3817 0x6e, 0x61, 0x6d, 0x65, |
3813 0x05, 0x76, 0x61, 0x6c, | 3818 0x05, 0x76, 0x61, 0x6c, |
3814 0x75, 0x65, | 3819 0x75, 0x65, |
3815 }; | 3820 }; |
3816 | 3821 |
3817 SpdyFramer framer(spdy_version_); | |
3818 TestSpdyVisitor visitor(spdy_version_); | 3822 TestSpdyVisitor visitor(spdy_version_); |
3819 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3823 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
3820 | 3824 |
3821 EXPECT_EQ(0, visitor.error_count_); | 3825 EXPECT_EQ(0, visitor.error_count_); |
3822 EXPECT_EQ(1, visitor.headers_frame_count_); | 3826 EXPECT_EQ(1, visitor.headers_frame_count_); |
3823 EXPECT_EQ(2, visitor.continuation_count_); | 3827 EXPECT_EQ(2, visitor.continuation_count_); |
3824 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3828 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3825 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3829 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
3826 | 3830 |
3827 EXPECT_THAT(visitor.headers_, ElementsAre( | 3831 EXPECT_THAT(visitor.headers_, ElementsAre( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3868 EXPECT_EQ(2, visitor.continuation_count_); | 3872 EXPECT_EQ(2, visitor.continuation_count_); |
3869 EXPECT_EQ(1, visitor.fin_flag_count_); | 3873 EXPECT_EQ(1, visitor.fin_flag_count_); |
3870 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3874 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3871 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3875 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
3872 | 3876 |
3873 EXPECT_THAT(visitor.headers_, ElementsAre( | 3877 EXPECT_THAT(visitor.headers_, ElementsAre( |
3874 Pair("cookie", "foo=bar; baz=bing; "), | 3878 Pair("cookie", "foo=bar; baz=bing; "), |
3875 Pair("name", "value"))); | 3879 Pair("name", "value"))); |
3876 } | 3880 } |
3877 | 3881 |
3878 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3882 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuationAndPadding) { |
3879 if (spdy_version_ <= SPDY3) { | 3883 if (spdy_version_ <= SPDY3) { |
3880 return; | 3884 return; |
3881 } | 3885 } |
3882 | 3886 |
3883 const unsigned char kInput[] = { | 3887 const unsigned char kInput[] = { |
3884 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE | 3888 0x00, 0x18, 0x05, 0x18, // PUSH_PROMISE: PAD_LOW & PAD_HIGH |
3885 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3889 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3886 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3890 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
| 3891 0x00, 0x02, // Padding of 2. |
3887 0x00, 0x06, 0x63, 0x6f, | 3892 0x00, 0x06, 0x63, 0x6f, |
3888 0x6f, 0x6b, 0x69, 0x65, | 3893 0x6f, 0x6b, 0x69, 0x65, |
3889 0x07, 0x66, 0x6f, 0x6f, | 3894 0x07, 0x66, 0x6f, 0x6f, |
3890 0x3d, 0x62, 0x61, 0x72, | 3895 0x3d, 0x62, 0x61, 0x72, |
| 3896 0x00, 0x00, |
3891 | 3897 |
3892 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3898 0x00, 0x14, 0x09, 0x00, // CONTINUATION: |
3893 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3899 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3894 0x00, 0x06, 0x63, 0x6f, | 3900 0x00, 0x06, 0x63, 0x6f, |
3895 0x6f, 0x6b, 0x69, 0x65, | 3901 0x6f, 0x6b, 0x69, 0x65, |
3896 0x08, 0x62, 0x61, 0x7a, | 3902 0x08, 0x62, 0x61, 0x7a, |
3897 0x3d, 0x62, 0x69, 0x6e, | 3903 0x3d, 0x62, 0x69, 0x6e, |
3898 0x67, 0x00, 0x06, 0x63, | 3904 0x67, 0x00, 0x06, 0x63, |
3899 | 3905 |
3900 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | 3906 0x00, 0x17, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS |
3901 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3907 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3908 0x04, // Padding of 4. |
3902 0x6f, 0x6f, 0x6b, 0x69, | 3909 0x6f, 0x6f, 0x6b, 0x69, |
3903 0x65, 0x00, 0x00, 0x04, | 3910 0x65, 0x00, 0x00, 0x04, |
3904 0x6e, 0x61, 0x6d, 0x65, | 3911 0x6e, 0x61, 0x6d, 0x65, |
3905 0x05, 0x76, 0x61, 0x6c, | 3912 0x05, 0x76, 0x61, 0x6c, |
3906 0x75, 0x65, | 3913 0x75, 0x65, 0x00, 0x00, |
| 3914 0x00, 0x00, |
3907 }; | 3915 }; |
3908 | 3916 |
3909 SpdyFramer framer(spdy_version_); | 3917 SpdyFramer framer(spdy_version_); |
3910 TestSpdyVisitor visitor(spdy_version_); | 3918 TestSpdyVisitor visitor(spdy_version_); |
3911 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3919 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
3912 | 3920 |
3913 EXPECT_EQ(0, visitor.error_count_); | 3921 EXPECT_EQ(0, visitor.error_count_); |
3914 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3922 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
3915 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3923 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
3916 EXPECT_EQ(2, visitor.continuation_count_); | 3924 EXPECT_EQ(2, visitor.continuation_count_); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4048 EXPECT_EQ(1, visitor.error_count_); | 4056 EXPECT_EQ(1, visitor.error_count_); |
4049 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 4057 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, |
4050 visitor.framer_.error_code()) | 4058 visitor.framer_.error_code()) |
4051 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4059 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4052 EXPECT_EQ(1, visitor.headers_frame_count_); | 4060 EXPECT_EQ(1, visitor.headers_frame_count_); |
4053 EXPECT_EQ(0, visitor.continuation_count_); | 4061 EXPECT_EQ(0, visitor.continuation_count_); |
4054 EXPECT_EQ(0u, visitor.header_buffer_length_); | 4062 EXPECT_EQ(0u, visitor.header_buffer_length_); |
4055 EXPECT_EQ(0, visitor.data_frame_count_); | 4063 EXPECT_EQ(0, visitor.data_frame_count_); |
4056 } | 4064 } |
4057 | 4065 |
| 4066 TEST_P(SpdyFramerTest, EndSegmentOnDataFrame) { |
| 4067 if (spdy_version_ <= SPDY3) { |
| 4068 return; |
| 4069 } |
| 4070 const unsigned char kInput[] = { |
| 4071 0x00, 0x0c, 0x00, 0x02, // DATA: END_SEGMENT |
| 4072 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4073 0xde, 0xad, 0xbe, 0xef, |
| 4074 0xde, 0xad, 0xbe, 0xef, |
| 4075 0xde, 0xad, 0xbe, 0xef, |
| 4076 }; |
| 4077 |
| 4078 TestSpdyVisitor visitor(spdy_version_); |
| 4079 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4080 |
| 4081 // TODO(jgraettinger): Verify END_SEGMENT when support is added. |
| 4082 EXPECT_EQ(0, visitor.error_count_); |
| 4083 EXPECT_EQ(12, visitor.data_bytes_); |
| 4084 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 4085 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 4086 } |
| 4087 |
| 4088 TEST_P(SpdyFramerTest, EndSegmentOnHeadersFrame) { |
| 4089 if (spdy_version_ <= SPDY3) { |
| 4090 return; |
| 4091 } |
| 4092 const unsigned char kInput[] = { |
| 4093 0x00, 0x10, 0x01, 0x06, // HEADERS: END_SEGMENT | END_HEADERS |
| 4094 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4095 0x00, 0x06, 0x63, 0x6f, |
| 4096 0x6f, 0x6b, 0x69, 0x65, |
| 4097 0x07, 0x66, 0x6f, 0x6f, |
| 4098 0x3d, 0x62, 0x61, 0x72, |
| 4099 }; |
| 4100 |
| 4101 TestSpdyVisitor visitor(spdy_version_); |
| 4102 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4103 |
| 4104 // TODO(jgraettinger): Verify END_SEGMENT when support is added. |
| 4105 EXPECT_EQ(0, visitor.error_count_); |
| 4106 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 4107 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 4108 |
| 4109 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 4110 Pair("cookie", "foo=bar"))); |
| 4111 } |
| 4112 |
4058 TEST_P(SpdyFramerTest, ReadGarbage) { | 4113 TEST_P(SpdyFramerTest, ReadGarbage) { |
4059 SpdyFramer framer(spdy_version_); | 4114 SpdyFramer framer(spdy_version_); |
4060 unsigned char garbage_frame[256]; | 4115 unsigned char garbage_frame[256]; |
4061 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 4116 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
4062 TestSpdyVisitor visitor(spdy_version_); | 4117 TestSpdyVisitor visitor(spdy_version_); |
4063 visitor.use_compression_ = false; | 4118 visitor.use_compression_ = false; |
4064 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 4119 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
4065 EXPECT_EQ(1, visitor.error_count_); | 4120 EXPECT_EQ(1, visitor.error_count_); |
4066 } | 4121 } |
4067 | 4122 |
(...skipping 23 matching lines...) Expand all Loading... |
4091 const unsigned char kFrameData[] = { | 4146 const unsigned char kFrameData[] = { |
4092 0x80, spdy_version_ch_, 0xff, 0xff, | 4147 0x80, spdy_version_ch_, 0xff, 0xff, |
4093 0xff, 0xff, 0xff, 0xff, | 4148 0xff, 0xff, 0xff, 0xff, |
4094 }; | 4149 }; |
4095 TestSpdyVisitor visitor(spdy_version_); | 4150 TestSpdyVisitor visitor(spdy_version_); |
4096 visitor.use_compression_ = false; | 4151 visitor.use_compression_ = false; |
4097 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 4152 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
4098 EXPECT_EQ(1, visitor.error_count_); | 4153 EXPECT_EQ(1, visitor.error_count_); |
4099 } | 4154 } |
4100 | 4155 |
| 4156 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { |
| 4157 if (spdy_version_ <= SPDY3) { |
| 4158 return; |
| 4159 } |
| 4160 const unsigned char kInput[] = { |
| 4161 0x00, 0x12, 0x01, 0x04, // HEADER: END_HEADERS |
| 4162 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4163 0xef, 0xef, 0xff, 0xff, |
| 4164 0xff, 0xff, 0xff, 0xff, |
| 4165 0xff, 0xff, 0xff, 0xff, |
| 4166 0xff, 0xff, 0xff, 0xff, |
| 4167 0xff, 0xff, |
| 4168 }; |
| 4169 |
| 4170 TestSpdyVisitor visitor(spdy_version_); |
| 4171 visitor.SimulateInFramer(kInput, arraysize(kInput)); |
| 4172 EXPECT_EQ(1, visitor.error_count_); |
| 4173 } |
| 4174 |
4101 TEST_P(SpdyFramerTest, SizesTest) { | 4175 TEST_P(SpdyFramerTest, SizesTest) { |
4102 SpdyFramer framer(spdy_version_); | 4176 SpdyFramer framer(spdy_version_); |
4103 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); | 4177 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); |
4104 if (IsSpdy4() || IsSpdy5()) { | 4178 if (IsSpdy4() || IsSpdy5()) { |
4105 EXPECT_EQ(8u, framer.GetSynReplyMinimumSize()); | 4179 EXPECT_EQ(8u, framer.GetSynReplyMinimumSize()); |
4106 EXPECT_EQ(12u, framer.GetRstStreamMinimumSize()); | 4180 EXPECT_EQ(12u, framer.GetRstStreamMinimumSize()); |
4107 EXPECT_EQ(8u, framer.GetSettingsMinimumSize()); | 4181 EXPECT_EQ(8u, framer.GetSettingsMinimumSize()); |
4108 EXPECT_EQ(16u, framer.GetPingSize()); | 4182 EXPECT_EQ(16u, framer.GetPingSize()); |
4109 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); | 4183 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); |
4110 EXPECT_EQ(8u, framer.GetHeadersMinimumSize()); | 4184 EXPECT_EQ(8u, framer.GetHeadersMinimumSize()); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4382 | 4456 |
4383 SpdySynStreamIR syn_stream(8); | 4457 SpdySynStreamIR syn_stream(8); |
4384 syn_stream.set_associated_to_stream_id(3); | 4458 syn_stream.set_associated_to_stream_id(3); |
4385 syn_stream.set_priority(1); | 4459 syn_stream.set_priority(1); |
4386 syn_stream.SetHeader("foo", "bar"); | 4460 syn_stream.SetHeader("foo", "bar"); |
4387 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 4461 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
4388 int set_flags = flags; | 4462 int set_flags = flags; |
4389 if (IsSpdy4()) { | 4463 if (IsSpdy4()) { |
4390 // PRIORITY required for SYN_STREAM simulation. | 4464 // PRIORITY required for SYN_STREAM simulation. |
4391 set_flags |= HEADERS_FLAG_PRIORITY; | 4465 set_flags |= HEADERS_FLAG_PRIORITY; |
| 4466 |
| 4467 // TODO(jgraettinger): Add padding to SynStreamIR, and implement framing. |
| 4468 set_flags &= ~HEADERS_FLAG_PAD_LOW; |
| 4469 set_flags &= ~HEADERS_FLAG_PAD_HIGH; |
4392 } | 4470 } |
4393 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4471 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4394 | 4472 |
4395 if (!IsSpdy4() && | 4473 if (!IsSpdy4() && |
4396 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 4474 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
4397 EXPECT_CALL(visitor, OnError(_)); | 4475 EXPECT_CALL(visitor, OnError(_)); |
4398 } else if (IsSpdy4() && | 4476 } else if (IsSpdy4() && |
4399 flags & ~(CONTROL_FLAG_FIN | | 4477 flags & ~(CONTROL_FLAG_FIN | |
4400 HEADERS_FLAG_PRIORITY | | 4478 HEADERS_FLAG_PRIORITY | |
4401 HEADERS_FLAG_END_HEADERS)) { | 4479 HEADERS_FLAG_END_HEADERS | |
| 4480 HEADERS_FLAG_END_SEGMENT | |
| 4481 HEADERS_FLAG_PAD_LOW | |
| 4482 HEADERS_FLAG_PAD_HIGH)) { |
4402 EXPECT_CALL(visitor, OnError(_)); | 4483 EXPECT_CALL(visitor, OnError(_)); |
4403 } else { | 4484 } else { |
4404 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); | 4485 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); |
4405 if (IsSpdy4()) { | 4486 if (IsSpdy4()) { |
4406 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, | 4487 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, |
4407 false)); | 4488 false)); |
4408 } else { | 4489 } else { |
4409 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, | 4490 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, |
4410 flags & CONTROL_FLAG_UNIDIRECTIONAL)); | 4491 flags & CONTROL_FLAG_UNIDIRECTIONAL)); |
4411 } | 4492 } |
(...skipping 11 matching lines...) Expand all Loading... |
4423 framer.ProcessInput(frame->data(), frame->size()); | 4504 framer.ProcessInput(frame->data(), frame->size()); |
4424 if (!IsSpdy4() && | 4505 if (!IsSpdy4() && |
4425 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 4506 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
4426 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4507 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4427 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4508 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4428 framer.error_code()) | 4509 framer.error_code()) |
4429 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4510 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4430 } else if (IsSpdy4() && | 4511 } else if (IsSpdy4() && |
4431 flags & ~(CONTROL_FLAG_FIN | | 4512 flags & ~(CONTROL_FLAG_FIN | |
4432 HEADERS_FLAG_PRIORITY | | 4513 HEADERS_FLAG_PRIORITY | |
4433 HEADERS_FLAG_END_HEADERS)) { | 4514 HEADERS_FLAG_END_HEADERS | |
| 4515 HEADERS_FLAG_END_SEGMENT | |
| 4516 HEADERS_FLAG_PAD_LOW | |
| 4517 HEADERS_FLAG_PAD_HIGH)) { |
4434 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4518 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4435 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4519 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4436 framer.error_code()) | 4520 framer.error_code()) |
4437 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4521 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4438 } else { | 4522 } else { |
4439 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4523 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4440 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4524 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4441 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4525 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4442 } | 4526 } |
4443 } | 4527 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4640 } | 4724 } |
4641 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4725 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4642 | 4726 |
4643 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4727 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4644 SpdyFramer framer(spdy_version_); | 4728 SpdyFramer framer(spdy_version_); |
4645 framer.set_visitor(&visitor); | 4729 framer.set_visitor(&visitor); |
4646 | 4730 |
4647 SpdyHeadersIR headers_ir(57); | 4731 SpdyHeadersIR headers_ir(57); |
4648 headers_ir.SetHeader("foo", "bar"); | 4732 headers_ir.SetHeader("foo", "bar"); |
4649 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 4733 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
4650 SetFrameFlags(frame.get(), flags, spdy_version_); | 4734 int set_flags = flags; |
| 4735 if (IsSpdy4()) { |
| 4736 // TODO(jgraettinger): Add padding to SpdyHeadersIR, |
| 4737 // and implement framing. |
| 4738 set_flags &= ~HEADERS_FLAG_PAD_LOW; |
| 4739 set_flags &= ~HEADERS_FLAG_PAD_HIGH; |
| 4740 } |
| 4741 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4651 | 4742 |
4652 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4743 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4653 EXPECT_CALL(visitor, OnError(_)); | 4744 EXPECT_CALL(visitor, OnError(_)); |
4654 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4745 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4655 HEADERS_FLAG_END_HEADERS)) { | 4746 HEADERS_FLAG_END_HEADERS | |
| 4747 HEADERS_FLAG_END_SEGMENT | |
| 4748 HEADERS_FLAG_PAD_LOW | |
| 4749 HEADERS_FLAG_PAD_HIGH)) { |
4656 EXPECT_CALL(visitor, OnError(_)); | 4750 EXPECT_CALL(visitor, OnError(_)); |
4657 } else { | 4751 } else { |
4658 EXPECT_CALL(visitor, OnHeaders(57, | 4752 EXPECT_CALL(visitor, OnHeaders(57, |
4659 flags & CONTROL_FLAG_FIN, | 4753 flags & CONTROL_FLAG_FIN, |
4660 (flags & HEADERS_FLAG_END_HEADERS) || | 4754 (flags & HEADERS_FLAG_END_HEADERS) || |
4661 !IsSpdy4())); | 4755 !IsSpdy4())); |
4662 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) | 4756 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) |
4663 .WillRepeatedly(testing::Return(true)); | 4757 .WillRepeatedly(testing::Return(true)); |
4664 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || | 4758 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || |
4665 flags & HEADERS_FLAG_END_HEADERS)) { | 4759 flags & HEADERS_FLAG_END_HEADERS)) { |
4666 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4760 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
4667 } else { | 4761 } else { |
4668 // Do not close the stream if we are expecting a CONTINUATION frame. | 4762 // Do not close the stream if we are expecting a CONTINUATION frame. |
4669 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 4763 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
4670 } | 4764 } |
4671 } | 4765 } |
4672 | 4766 |
4673 framer.ProcessInput(frame->data(), frame->size()); | 4767 framer.ProcessInput(frame->data(), frame->size()); |
4674 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4768 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4675 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4769 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4676 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4770 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4677 framer.error_code()) | 4771 framer.error_code()) |
4678 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4772 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4679 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY | | 4773 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4680 HEADERS_FLAG_END_HEADERS)) { | 4774 HEADERS_FLAG_END_HEADERS | |
| 4775 HEADERS_FLAG_END_SEGMENT | |
| 4776 HEADERS_FLAG_PAD_LOW | |
| 4777 HEADERS_FLAG_PAD_HIGH)) { |
4681 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4778 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4682 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4779 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4683 framer.error_code()) | 4780 framer.error_code()) |
4684 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4781 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4685 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { | 4782 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { |
4686 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4783 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4687 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4784 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4688 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4785 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4689 } else { | 4786 } else { |
4690 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4787 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4774 SpdyFramer framer(spdy_version_); | 4871 SpdyFramer framer(spdy_version_); |
4775 framer.set_visitor(&visitor); | 4872 framer.set_visitor(&visitor); |
4776 framer.set_debug_visitor(&debug_visitor); | 4873 framer.set_debug_visitor(&debug_visitor); |
4777 | 4874 |
4778 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); | 4875 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); |
4779 | 4876 |
4780 SpdyPushPromiseIR push_promise(42, 57); | 4877 SpdyPushPromiseIR push_promise(42, 57); |
4781 push_promise.SetHeader("foo", "bar"); | 4878 push_promise.SetHeader("foo", "bar"); |
4782 scoped_ptr<SpdySerializedFrame> frame( | 4879 scoped_ptr<SpdySerializedFrame> frame( |
4783 framer.SerializePushPromise(push_promise)); | 4880 framer.SerializePushPromise(push_promise)); |
4784 SetFrameFlags(frame.get(), flags, spdy_version_); | 4881 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
| 4882 // and implement framing. |
| 4883 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; |
| 4884 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4785 | 4885 |
4786 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { | 4886 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | |
| 4887 HEADERS_FLAG_PAD_LOW | |
| 4888 HEADERS_FLAG_PAD_HIGH)) { |
4787 EXPECT_CALL(visitor, OnError(_)); | 4889 EXPECT_CALL(visitor, OnError(_)); |
4788 } else { | 4890 } else { |
4789 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); | 4891 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); |
4790 EXPECT_CALL(visitor, OnPushPromise(42, 57, | 4892 EXPECT_CALL(visitor, OnPushPromise(42, 57, |
4791 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); | 4893 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); |
4792 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4894 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4793 .WillRepeatedly(testing::Return(true)); | 4895 .WillRepeatedly(testing::Return(true)); |
4794 } | 4896 } |
4795 | 4897 |
4796 framer.ProcessInput(frame->data(), frame->size()); | 4898 framer.ProcessInput(frame->data(), frame->size()); |
4797 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { | 4899 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | |
| 4900 HEADERS_FLAG_PAD_LOW | |
| 4901 HEADERS_FLAG_PAD_HIGH)) { |
4798 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4902 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4799 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4903 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4800 framer.error_code()) | 4904 framer.error_code()) |
4801 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4905 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4802 } else { | 4906 } else { |
4803 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4907 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4804 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4908 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4805 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4909 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4806 } | 4910 } |
4807 } | 4911 } |
(...skipping 22 matching lines...) Expand all Loading... |
4830 | 4934 |
4831 SpdyHeadersIR headers_ir(42); | 4935 SpdyHeadersIR headers_ir(42); |
4832 headers_ir.SetHeader("foo", "bar"); | 4936 headers_ir.SetHeader("foo", "bar"); |
4833 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); | 4937 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); |
4834 SetFrameFlags(frame0.get(), 0, spdy_version_); | 4938 SetFrameFlags(frame0.get(), 0, spdy_version_); |
4835 | 4939 |
4836 SpdyContinuationIR continuation(42); | 4940 SpdyContinuationIR continuation(42); |
4837 continuation.SetHeader("foo", "bar"); | 4941 continuation.SetHeader("foo", "bar"); |
4838 scoped_ptr<SpdySerializedFrame> frame( | 4942 scoped_ptr<SpdySerializedFrame> frame( |
4839 framer.SerializeContinuation(continuation)); | 4943 framer.SerializeContinuation(continuation)); |
4840 SetFrameFlags(frame.get(), flags, spdy_version_); | 4944 // TODO(jgraettinger): Add padding to the eventual continuation |
| 4945 // serialization implementation. |
| 4946 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; |
| 4947 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4841 | 4948 |
4842 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 4949 if (flags & ~(HEADERS_FLAG_END_HEADERS | |
| 4950 HEADERS_FLAG_PAD_LOW | |
| 4951 HEADERS_FLAG_PAD_HIGH)) { |
4843 EXPECT_CALL(visitor, OnError(_)); | 4952 EXPECT_CALL(visitor, OnError(_)); |
4844 } else { | 4953 } else { |
4845 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); | 4954 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); |
4846 EXPECT_CALL(visitor, OnContinuation(42, | 4955 EXPECT_CALL(visitor, OnContinuation(42, |
4847 flags & HEADERS_FLAG_END_HEADERS)); | 4956 flags & HEADERS_FLAG_END_HEADERS)); |
4848 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4957 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4849 .WillRepeatedly(testing::Return(true)); | 4958 .WillRepeatedly(testing::Return(true)); |
4850 } | 4959 } |
4851 | 4960 |
4852 framer.ProcessInput(frame0->data(), frame0->size()); | 4961 framer.ProcessInput(frame0->data(), frame0->size()); |
4853 framer.ProcessInput(frame->data(), frame->size()); | 4962 framer.ProcessInput(frame->data(), frame->size()); |
4854 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 4963 if (flags & ~(HEADERS_FLAG_END_HEADERS | |
| 4964 HEADERS_FLAG_PAD_LOW | |
| 4965 HEADERS_FLAG_PAD_HIGH)) { |
4855 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4966 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4856 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4967 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4857 framer.error_code()) | 4968 framer.error_code()) |
4858 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4969 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4859 } else { | 4970 } else { |
4860 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4971 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4861 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4972 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4862 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4973 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4863 } | 4974 } |
4864 } | 4975 } |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5279 TestSpdyVisitor visitor(spdy_version_); | 5390 TestSpdyVisitor visitor(spdy_version_); |
5280 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5391 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
5281 | 5392 |
5282 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5393 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
5283 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5394 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
5284 visitor.framer_.error_code()) | 5395 visitor.framer_.error_code()) |
5285 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5396 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
5286 } | 5397 } |
5287 | 5398 |
5288 } // namespace net | 5399 } // namespace net |
OLD | NEW |