| 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 3755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3766 TestSpdyVisitor visitor(spdy_version_); | 3766 TestSpdyVisitor visitor(spdy_version_); |
| 3767 visitor.use_compression_ = true; | 3767 visitor.use_compression_ = true; |
| 3768 visitor.SimulateInFramer( | 3768 visitor.SimulateInFramer( |
| 3769 reinterpret_cast<unsigned char*>(frame->data()), | 3769 reinterpret_cast<unsigned char*>(frame->data()), |
| 3770 frame->size()); | 3770 frame->size()); |
| 3771 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3771 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3772 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3772 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3773 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3773 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 3774 } | 3774 } |
| 3775 | 3775 |
| 3776 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndPadding) { | 3776 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3777 if (spdy_version_ <= SPDY3) { | 3777 if (spdy_version_ <= SPDY3) { |
| 3778 return; | 3778 return; |
| 3779 } | 3779 } |
| 3780 | 3780 |
| 3781 const unsigned char kInput[] = { | 3781 const unsigned char kInput[] = { |
| 3782 0x00, 0x14, 0x01, 0x08, // HEADERS: PAD_LOW | 3782 0x00, 0x14, 0x01, 0x08, // HEADERS: PAD_LOW |
| 3783 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3783 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3784 0x03, // Padding of 3. | 3784 0x03, // Padding of 3. |
| 3785 0x00, 0x06, 0x63, 0x6f, | 3785 0x00, 0x06, 0x63, 0x6f, |
| 3786 0x6f, 0x6b, 0x69, 0x65, | 3786 0x6f, 0x6b, 0x69, 0x65, |
| 3787 0x07, 0x66, 0x6f, 0x6f, | 3787 0x07, 0x66, 0x6f, 0x6f, |
| 3788 0x3d, 0x62, 0x61, 0x72, | 3788 0x3d, 0x62, 0x61, 0x72, |
| 3789 0x00, 0x00, 0x00, | 3789 0x00, 0x00, 0x00, |
| 3790 | 3790 |
| 3791 0x00, 0x1a, 0x09, 0x18, // CONTINUATION: PAD_LOW & PAD_HIGH | 3791 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
| 3792 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3792 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3793 0x00, 0x04, // Padding of 4. | |
| 3794 0x00, 0x06, 0x63, 0x6f, | 3793 0x00, 0x06, 0x63, 0x6f, |
| 3795 0x6f, 0x6b, 0x69, 0x65, | 3794 0x6f, 0x6b, 0x69, 0x65, |
| 3796 0x08, 0x62, 0x61, 0x7a, | 3795 0x08, 0x62, 0x61, 0x7a, |
| 3797 0x3d, 0x62, 0x69, 0x6e, | 3796 0x3d, 0x62, 0x69, 0x6e, |
| 3798 0x67, 0x00, 0x06, 0x63, | 3797 0x67, 0x00, 0x06, 0x63, |
| 3799 0x00, 0x00, 0x00, 0x00, | |
| 3800 | 3798 |
| 3801 0x00, 0x13, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS | 3799 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS |
| 3802 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3800 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3803 0x00, // Padding of 0. | |
| 3804 0x6f, 0x6f, 0x6b, 0x69, | 3801 0x6f, 0x6f, 0x6b, 0x69, |
| 3805 0x65, 0x00, 0x00, 0x04, | 3802 0x65, 0x00, 0x00, 0x04, |
| 3806 0x6e, 0x61, 0x6d, 0x65, | 3803 0x6e, 0x61, 0x6d, 0x65, |
| 3807 0x05, 0x76, 0x61, 0x6c, | 3804 0x05, 0x76, 0x61, 0x6c, |
| 3808 0x75, 0x65, | 3805 0x75, 0x65, |
| 3809 }; | 3806 }; |
| 3810 | 3807 |
| 3811 TestSpdyVisitor visitor(spdy_version_); | 3808 TestSpdyVisitor visitor(spdy_version_); |
| 3812 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3809 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3813 | 3810 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3861 EXPECT_EQ(2, visitor.continuation_count_); | 3858 EXPECT_EQ(2, visitor.continuation_count_); |
| 3862 EXPECT_EQ(1, visitor.fin_flag_count_); | 3859 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3863 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3860 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3864 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3861 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 3865 | 3862 |
| 3866 EXPECT_THAT(visitor.headers_, ElementsAre( | 3863 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3867 Pair("cookie", "foo=bar; baz=bing; "), | 3864 Pair("cookie", "foo=bar; baz=bing; "), |
| 3868 Pair("name", "value"))); | 3865 Pair("name", "value"))); |
| 3869 } | 3866 } |
| 3870 | 3867 |
| 3871 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuationAndPadding) { | 3868 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 3872 if (spdy_version_ <= SPDY3) { | 3869 if (spdy_version_ <= SPDY3) { |
| 3873 return; | 3870 return; |
| 3874 } | 3871 } |
| 3875 | 3872 |
| 3876 const unsigned char kInput[] = { | 3873 const unsigned char kInput[] = { |
| 3877 0x00, 0x18, 0x05, 0x18, // PUSH_PROMISE: PAD_LOW & PAD_HIGH | 3874 0x00, 0x18, 0x05, 0x18, // PUSH_PROMISE: PAD_LOW & PAD_HIGH |
| 3878 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3875 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3879 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3876 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
| 3880 0x00, 0x02, // Padding of 2. | 3877 0x00, 0x02, // Padding of 2. |
| 3881 0x00, 0x06, 0x63, 0x6f, | 3878 0x00, 0x06, 0x63, 0x6f, |
| 3882 0x6f, 0x6b, 0x69, 0x65, | 3879 0x6f, 0x6b, 0x69, 0x65, |
| 3883 0x07, 0x66, 0x6f, 0x6f, | 3880 0x07, 0x66, 0x6f, 0x6f, |
| 3884 0x3d, 0x62, 0x61, 0x72, | 3881 0x3d, 0x62, 0x61, 0x72, |
| 3885 0x00, 0x00, | 3882 0x00, 0x00, |
| 3886 | 3883 |
| 3887 0x00, 0x14, 0x09, 0x00, // CONTINUATION: | 3884 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
| 3888 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3885 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3889 0x00, 0x06, 0x63, 0x6f, | 3886 0x00, 0x06, 0x63, 0x6f, |
| 3890 0x6f, 0x6b, 0x69, 0x65, | 3887 0x6f, 0x6b, 0x69, 0x65, |
| 3891 0x08, 0x62, 0x61, 0x7a, | 3888 0x08, 0x62, 0x61, 0x7a, |
| 3892 0x3d, 0x62, 0x69, 0x6e, | 3889 0x3d, 0x62, 0x69, 0x6e, |
| 3893 0x67, 0x00, 0x06, 0x63, | 3890 0x67, 0x00, 0x06, 0x63, |
| 3894 | 3891 |
| 3895 0x00, 0x17, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS | 3892 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS |
| 3896 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3893 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3897 0x04, // Padding of 4. | |
| 3898 0x6f, 0x6f, 0x6b, 0x69, | 3894 0x6f, 0x6f, 0x6b, 0x69, |
| 3899 0x65, 0x00, 0x00, 0x04, | 3895 0x65, 0x00, 0x00, 0x04, |
| 3900 0x6e, 0x61, 0x6d, 0x65, | 3896 0x6e, 0x61, 0x6d, 0x65, |
| 3901 0x05, 0x76, 0x61, 0x6c, | 3897 0x05, 0x76, 0x61, 0x6c, |
| 3902 0x75, 0x65, 0x00, 0x00, | 3898 0x75, 0x65, |
| 3903 0x00, 0x00, | |
| 3904 }; | 3899 }; |
| 3905 | 3900 |
| 3906 SpdyFramer framer(spdy_version_); | 3901 SpdyFramer framer(spdy_version_); |
| 3907 TestSpdyVisitor visitor(spdy_version_); | 3902 TestSpdyVisitor visitor(spdy_version_); |
| 3908 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3903 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3909 | 3904 |
| 3910 EXPECT_EQ(0, visitor.error_count_); | 3905 EXPECT_EQ(0, visitor.error_count_); |
| 3911 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3906 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
| 3912 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3907 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
| 3913 EXPECT_EQ(2, visitor.continuation_count_); | 3908 EXPECT_EQ(2, visitor.continuation_count_); |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4900 | 4895 |
| 4901 SpdyHeadersIR headers_ir(42); | 4896 SpdyHeadersIR headers_ir(42); |
| 4902 headers_ir.SetHeader("foo", "bar"); | 4897 headers_ir.SetHeader("foo", "bar"); |
| 4903 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); | 4898 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); |
| 4904 SetFrameFlags(frame0.get(), 0, spdy_version_); | 4899 SetFrameFlags(frame0.get(), 0, spdy_version_); |
| 4905 | 4900 |
| 4906 SpdyContinuationIR continuation(42); | 4901 SpdyContinuationIR continuation(42); |
| 4907 continuation.SetHeader("foo", "bar"); | 4902 continuation.SetHeader("foo", "bar"); |
| 4908 scoped_ptr<SpdySerializedFrame> frame( | 4903 scoped_ptr<SpdySerializedFrame> frame( |
| 4909 framer.SerializeContinuation(continuation)); | 4904 framer.SerializeContinuation(continuation)); |
| 4910 // TODO(jgraettinger): Add padding to the eventual continuation | 4905 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4911 // serialization implementation. | |
| 4912 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; | |
| 4913 SetFrameFlags(frame.get(), set_flags, spdy_version_); | |
| 4914 | 4906 |
| 4915 if (flags & ~(HEADERS_FLAG_END_HEADERS | | 4907 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
| 4916 HEADERS_FLAG_PAD_LOW | | |
| 4917 HEADERS_FLAG_PAD_HIGH)) { | |
| 4918 EXPECT_CALL(visitor, OnError(_)); | 4908 EXPECT_CALL(visitor, OnError(_)); |
| 4919 } else { | 4909 } else { |
| 4920 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); | 4910 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); |
| 4921 EXPECT_CALL(visitor, OnContinuation(42, | 4911 EXPECT_CALL(visitor, OnContinuation(42, |
| 4922 flags & HEADERS_FLAG_END_HEADERS)); | 4912 flags & HEADERS_FLAG_END_HEADERS)); |
| 4923 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4913 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
| 4924 .WillRepeatedly(testing::Return(true)); | 4914 .WillRepeatedly(testing::Return(true)); |
| 4925 } | 4915 } |
| 4926 | 4916 |
| 4927 framer.ProcessInput(frame0->data(), frame0->size()); | 4917 framer.ProcessInput(frame0->data(), frame0->size()); |
| 4928 framer.ProcessInput(frame->data(), frame->size()); | 4918 framer.ProcessInput(frame->data(), frame->size()); |
| 4929 if (flags & ~(HEADERS_FLAG_END_HEADERS | | 4919 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
| 4930 HEADERS_FLAG_PAD_LOW | | |
| 4931 HEADERS_FLAG_PAD_HIGH)) { | |
| 4932 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4920 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4933 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4921 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4934 framer.error_code()) | 4922 framer.error_code()) |
| 4935 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4923 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4936 } else { | 4924 } else { |
| 4937 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4925 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4938 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4926 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4939 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4927 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4940 } | 4928 } |
| 4941 } | 4929 } |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5391 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); | 5379 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); |
| 5392 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); | 5380 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); |
| 5393 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); | 5381 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); |
| 5394 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); | 5382 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); |
| 5395 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); | 5383 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); |
| 5396 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); | 5384 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); |
| 5397 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); | 5385 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); |
| 5398 } | 5386 } |
| 5399 | 5387 |
| 5400 } // namespace net | 5388 } // namespace net |
| OLD | NEW |