| 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 2887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2898 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2898 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
| 2899 if (IsSpdy4()) { | 2899 if (IsSpdy4()) { |
| 2900 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2900 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2901 } else { | 2901 } else { |
| 2902 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2902 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2903 } | 2903 } |
| 2904 } | 2904 } |
| 2905 } | 2905 } |
| 2906 | 2906 |
| 2907 TEST_P(SpdyFramerTest, SerializeBlocked) { | 2907 TEST_P(SpdyFramerTest, SerializeBlocked) { |
| 2908 if (spdy_version_ < SPDY4) { | 2908 if (spdy_version_ <= SPDY3) { |
| 2909 return; | 2909 return; |
| 2910 } | 2910 } |
| 2911 | 2911 |
| 2912 SpdyFramer framer(spdy_version_); | 2912 SpdyFramer framer(spdy_version_); |
| 2913 | 2913 |
| 2914 const char kDescription[] = "BLOCKED frame"; | 2914 const char kDescription[] = "BLOCKED frame"; |
| 2915 const char kType = static_cast<unsigned char>( | 2915 const char kType = static_cast<unsigned char>( |
| 2916 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); | 2916 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); |
| 2917 const unsigned char kFrameData[] = { | 2917 const unsigned char kFrameData[] = { |
| 2918 0x00, 0x00, kType, 0x00, | 2918 0x00, 0x00, kType, 0x00, |
| 2919 0x00, 0x00, 0x00, 0x00, | 2919 0x00, 0x00, 0x00, 0x00, |
| 2920 }; | 2920 }; |
| 2921 SpdyBlockedIR blocked_ir(0); | 2921 SpdyBlockedIR blocked_ir(0); |
| 2922 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 2922 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 2923 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2923 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 2924 } | 2924 } |
| 2925 | 2925 |
| 2926 TEST_P(SpdyFramerTest, CreateBlocked) { | 2926 TEST_P(SpdyFramerTest, CreateBlocked) { |
| 2927 if (spdy_version_ < SPDY4) { | 2927 if (spdy_version_ <= SPDY3) { |
| 2928 return; | 2928 return; |
| 2929 } | 2929 } |
| 2930 | 2930 |
| 2931 SpdyFramer framer(spdy_version_); | 2931 SpdyFramer framer(spdy_version_); |
| 2932 | 2932 |
| 2933 const char kDescription[] = "BLOCKED frame"; | 2933 const char kDescription[] = "BLOCKED frame"; |
| 2934 const SpdyStreamId kStreamId = 3; | 2934 const SpdyStreamId kStreamId = 3; |
| 2935 | 2935 |
| 2936 scoped_ptr<SpdySerializedFrame> frame_serialized( | 2936 scoped_ptr<SpdySerializedFrame> frame_serialized( |
| 2937 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2937 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
| 2938 SpdyBlockedIR blocked_ir(kStreamId); | 2938 SpdyBlockedIR blocked_ir(kStreamId); |
| 2939 scoped_ptr<SpdySerializedFrame> frame_created( | 2939 scoped_ptr<SpdySerializedFrame> frame_created( |
| 2940 framer.SerializeFrame(blocked_ir)); | 2940 framer.SerializeFrame(blocked_ir)); |
| 2941 | 2941 |
| 2942 CompareFrames(kDescription, *frame_serialized, *frame_created); | 2942 CompareFrames(kDescription, *frame_serialized, *frame_created); |
| 2943 } | 2943 } |
| 2944 | 2944 |
| 2945 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2945 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
| 2946 if (spdy_version_ < SPDY4) { | 2946 if (spdy_version_ <= SPDY3) { |
| 2947 return; | 2947 return; |
| 2948 } | 2948 } |
| 2949 | 2949 |
| 2950 SpdyFramer framer(spdy_version_); | 2950 SpdyFramer framer(spdy_version_); |
| 2951 framer.set_enable_compression(false); | 2951 framer.set_enable_compression(false); |
| 2952 const char kDescription[] = "PUSH_PROMISE frame"; | 2952 const char kDescription[] = "PUSH_PROMISE frame"; |
| 2953 | 2953 |
| 2954 const unsigned char kFrameData[] = { | 2954 const unsigned char kFrameData[] = { |
| 2955 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS | 2955 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS |
| 2956 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 2956 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
| 2957 0x00, 0x00, 0x00, 0x39, // Promised stream 57 | 2957 0x00, 0x00, 0x00, 0x39, // Promised stream 57 |
| 2958 0x00, 0x03, 0x62, 0x61, // @.ba | 2958 0x00, 0x03, 0x62, 0x61, // @.ba |
| 2959 0x72, 0x03, 0x66, 0x6f, // r.fo | 2959 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2960 0x6f, 0x00, 0x03, 0x66, // o@.f | 2960 0x6f, 0x00, 0x03, 0x66, // o@.f |
| 2961 0x6f, 0x6f, 0x03, 0x62, // oo.b | 2961 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 2962 0x61, 0x72, // ar | 2962 0x61, 0x72, // ar |
| 2963 }; | 2963 }; |
| 2964 | 2964 |
| 2965 SpdyPushPromiseIR push_promise(42, 57); | 2965 SpdyPushPromiseIR push_promise(42, 57); |
| 2966 push_promise.SetHeader("bar", "foo"); | 2966 push_promise.SetHeader("bar", "foo"); |
| 2967 push_promise.SetHeader("foo", "bar"); | 2967 push_promise.SetHeader("foo", "bar"); |
| 2968 scoped_ptr<SpdySerializedFrame> frame( | 2968 scoped_ptr<SpdySerializedFrame> frame( |
| 2969 framer.SerializePushPromise(push_promise)); | 2969 framer.SerializePushPromise(push_promise)); |
| 2970 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2970 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 2971 } | 2971 } |
| 2972 | 2972 |
| 2973 TEST_P(SpdyFramerTest, CreateAltSvc) { | 2973 TEST_P(SpdyFramerTest, CreateAltSvc) { |
| 2974 if (spdy_version_ < SPDY4) { | 2974 if (spdy_version_ <= SPDY3) { |
| 2975 return; | 2975 return; |
| 2976 } | 2976 } |
| 2977 | 2977 |
| 2978 SpdyFramer framer(spdy_version_); | 2978 SpdyFramer framer(spdy_version_); |
| 2979 | 2979 |
| 2980 const char kDescription[] = "ALTSVC frame"; | 2980 const char kDescription[] = "ALTSVC frame"; |
| 2981 const char kType = static_cast<unsigned char>( | 2981 const char kType = static_cast<unsigned char>( |
| 2982 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | 2982 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
| 2983 const unsigned char kFrameData[] = { | 2983 const unsigned char kFrameData[] = { |
| 2984 0x00, 0x17, kType, 0x00, | 2984 0x00, 0x17, kType, 0x00, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3160 EXPECT_FALSE(visitor.header_buffer_valid_); | 3160 EXPECT_FALSE(visitor.header_buffer_valid_); |
| 3161 EXPECT_EQ(1, visitor.error_count_); | 3161 EXPECT_EQ(1, visitor.error_count_); |
| 3162 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, | 3162 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, |
| 3163 visitor.framer_.error_code()) | 3163 visitor.framer_.error_code()) |
| 3164 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3164 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3165 EXPECT_EQ(0, visitor.syn_frame_count_); | 3165 EXPECT_EQ(0, visitor.syn_frame_count_); |
| 3166 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3166 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3167 } | 3167 } |
| 3168 | 3168 |
| 3169 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { | 3169 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
| 3170 if (spdy_version_ < SPDY4) { | 3170 if (spdy_version_ <= SPDY3) { |
| 3171 return; | 3171 return; |
| 3172 } | 3172 } |
| 3173 SpdyFramer framer(spdy_version_); | 3173 SpdyFramer framer(spdy_version_); |
| 3174 framer.set_enable_compression(false); | 3174 framer.set_enable_compression(false); |
| 3175 SpdyHeadersIR headers(1); | 3175 SpdyHeadersIR headers(1); |
| 3176 | 3176 |
| 3177 // Exact payload length will change with HPACK, but this should be long | 3177 // Exact payload length will change with HPACK, but this should be long |
| 3178 // enough to cause an overflow. | 3178 // enough to cause an overflow. |
| 3179 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); | 3179 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); |
| 3180 string big_value(kBigValueSize, 'x'); | 3180 string big_value(kBigValueSize, 'x'); |
| 3181 headers.SetHeader("aa", big_value); | 3181 headers.SetHeader("aa", big_value); |
| 3182 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); | 3182 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); |
| 3183 EXPECT_TRUE(control_frame.get() != NULL); | 3183 EXPECT_TRUE(control_frame.get() != NULL); |
| 3184 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); | 3184 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); |
| 3185 | 3185 |
| 3186 TestSpdyVisitor visitor(spdy_version_); | 3186 TestSpdyVisitor visitor(spdy_version_); |
| 3187 visitor.SimulateInFramer( | 3187 visitor.SimulateInFramer( |
| 3188 reinterpret_cast<unsigned char*>(control_frame->data()), | 3188 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3189 control_frame->size()); | 3189 control_frame->size()); |
| 3190 EXPECT_TRUE(visitor.header_buffer_valid_); | 3190 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 3191 EXPECT_EQ(0, visitor.error_count_); | 3191 EXPECT_EQ(0, visitor.error_count_); |
| 3192 EXPECT_EQ(1, visitor.headers_frame_count_); | 3192 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3193 EXPECT_EQ(1, visitor.continuation_count_); | 3193 EXPECT_EQ(1, visitor.continuation_count_); |
| 3194 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3194 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3195 } | 3195 } |
| 3196 | 3196 |
| 3197 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 3197 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
| 3198 if (spdy_version_ < SPDY4) { | 3198 if (spdy_version_ <= SPDY3) { |
| 3199 return; | 3199 return; |
| 3200 } | 3200 } |
| 3201 SpdyFramer framer(spdy_version_); | 3201 SpdyFramer framer(spdy_version_); |
| 3202 framer.set_enable_compression(false); | 3202 framer.set_enable_compression(false); |
| 3203 SpdyPushPromiseIR push_promise(1, 2); | 3203 SpdyPushPromiseIR push_promise(1, 2); |
| 3204 | 3204 |
| 3205 // Exact payload length will change with HPACK, but this should be long | 3205 // Exact payload length will change with HPACK, but this should be long |
| 3206 // enough to cause an overflow. | 3206 // enough to cause an overflow. |
| 3207 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); | 3207 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); |
| 3208 string big_value(kBigValueSize, 'x'); | 3208 string big_value(kBigValueSize, 'x'); |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3709 control_frame->size())); | 3709 control_frame->size())); |
| 3710 visitor.SimulateInFramer( | 3710 visitor.SimulateInFramer( |
| 3711 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), | 3711 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), |
| 3712 multiple_frame_data.length()); | 3712 multiple_frame_data.length()); |
| 3713 EXPECT_EQ(0, visitor.error_count_); | 3713 EXPECT_EQ(0, visitor.error_count_); |
| 3714 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3714 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 3715 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 3715 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
| 3716 } | 3716 } |
| 3717 | 3717 |
| 3718 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { | 3718 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
| 3719 if (spdy_version_ < SPDY4) { | 3719 if (spdy_version_ <= SPDY3) { |
| 3720 return; | 3720 return; |
| 3721 } | 3721 } |
| 3722 | 3722 |
| 3723 SpdyFramer framer(spdy_version_); | 3723 SpdyFramer framer(spdy_version_); |
| 3724 framer.set_enable_compression(false); | 3724 framer.set_enable_compression(false); |
| 3725 const char kDescription[] = "CONTINUATION frame"; | 3725 const char kDescription[] = "CONTINUATION frame"; |
| 3726 | 3726 |
| 3727 const unsigned char kFrameData[] = { | 3727 const unsigned char kFrameData[] = { |
| 3728 0x00, 0x12, 0x09, 0x00, // CONTINUATION | 3728 0x00, 0x12, 0x09, 0x00, // CONTINUATION |
| 3729 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 3729 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
| (...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4736 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4736 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4737 } else { | 4737 } else { |
| 4738 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4738 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4739 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4739 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4740 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4740 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4741 } | 4741 } |
| 4742 } | 4742 } |
| 4743 } | 4743 } |
| 4744 | 4744 |
| 4745 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { | 4745 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { |
| 4746 if (spdy_version_ < SPDY4) { | 4746 if (spdy_version_ <= SPDY3) { |
| 4747 return; | 4747 return; |
| 4748 } | 4748 } |
| 4749 | 4749 |
| 4750 for (int flags = 0; flags < 256; ++flags) { | 4750 for (int flags = 0; flags < 256; ++flags) { |
| 4751 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4751 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4752 | 4752 |
| 4753 testing::StrictMock<net::test::MockSpdyFramerVisitor> visitor; | 4753 testing::StrictMock<net::test::MockSpdyFramerVisitor> visitor; |
| 4754 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 4754 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
| 4755 SpdyFramer framer(spdy_version_); | 4755 SpdyFramer framer(spdy_version_); |
| 4756 framer.set_visitor(&visitor); | 4756 framer.set_visitor(&visitor); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4782 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4782 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4783 } else { | 4783 } else { |
| 4784 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4784 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4785 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4785 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4786 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4786 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4787 } | 4787 } |
| 4788 } | 4788 } |
| 4789 } | 4789 } |
| 4790 | 4790 |
| 4791 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { | 4791 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { |
| 4792 if (spdy_version_ < SPDY4) { | 4792 if (spdy_version_ <= SPDY3) { |
| 4793 return; | 4793 return; |
| 4794 } | 4794 } |
| 4795 | 4795 |
| 4796 for (int flags = 0; flags < 256; ++flags) { | 4796 for (int flags = 0; flags < 256; ++flags) { |
| 4797 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4797 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4798 | 4798 |
| 4799 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4799 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4800 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 4800 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
| 4801 SpdyFramer framer(spdy_version_); | 4801 SpdyFramer framer(spdy_version_); |
| 4802 framer.set_visitor(&visitor); | 4802 framer.set_visitor(&visitor); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4838 framer.error_code()) | 4838 framer.error_code()) |
| 4839 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4839 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4840 } else { | 4840 } else { |
| 4841 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4841 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4842 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4842 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4843 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4843 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4844 } | 4844 } |
| 4845 } | 4845 } |
| 4846 } | 4846 } |
| 4847 | 4847 |
| 4848 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
| 4849 |
| 4850 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) |
| 4851 |
| 4848 TEST_P(SpdyFramerTest, EmptySynStream) { | 4852 TEST_P(SpdyFramerTest, EmptySynStream) { |
| 4849 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4853 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4850 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4854 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 4851 SpdyFramer framer(spdy_version_); | 4855 SpdyFramer framer(spdy_version_); |
| 4852 framer.set_visitor(&visitor); | 4856 framer.set_visitor(&visitor); |
| 4853 framer.set_debug_visitor(&debug_visitor); | 4857 framer.set_debug_visitor(&debug_visitor); |
| 4854 | 4858 |
| 4855 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); | 4859 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); |
| 4856 | 4860 |
| 4857 SpdySynStreamIR syn_stream(1); | 4861 SpdySynStreamIR syn_stream(1); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4989 } else { | 4993 } else { |
| 4990 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), | 4994 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), |
| 4991 arraysize(kV4FrameData)); | 4995 arraysize(kV4FrameData)); |
| 4992 } | 4996 } |
| 4993 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4997 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4994 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4998 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4995 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4999 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4996 } | 5000 } |
| 4997 | 5001 |
| 4998 TEST_P(SpdyFramerTest, OnBlocked) { | 5002 TEST_P(SpdyFramerTest, OnBlocked) { |
| 4999 if (spdy_version_ < SPDY4) { | 5003 if (spdy_version_ <= SPDY3) { |
| 5000 return; | 5004 return; |
| 5001 } | 5005 } |
| 5002 | 5006 |
| 5003 const SpdyStreamId kStreamId = 0; | 5007 const SpdyStreamId kStreamId = 0; |
| 5004 | 5008 |
| 5005 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5009 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5006 SpdyFramer framer(spdy_version_); | 5010 SpdyFramer framer(spdy_version_); |
| 5007 framer.set_visitor(&visitor); | 5011 framer.set_visitor(&visitor); |
| 5008 | 5012 |
| 5009 EXPECT_CALL(visitor, OnBlocked(kStreamId)); | 5013 EXPECT_CALL(visitor, OnBlocked(kStreamId)); |
| 5010 | 5014 |
| 5011 SpdyBlockedIR blocked_ir(0); | 5015 SpdyBlockedIR blocked_ir(0); |
| 5012 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 5016 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 5013 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 5017 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
| 5014 | 5018 |
| 5015 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5019 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5016 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5020 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5017 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5021 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5018 } | 5022 } |
| 5019 | 5023 |
| 5020 TEST_P(SpdyFramerTest, OnAltSvc) { | 5024 TEST_P(SpdyFramerTest, OnAltSvc) { |
| 5021 if (spdy_version_ < SPDY4) { | 5025 if (spdy_version_ <= SPDY3) { |
| 5022 return; | 5026 return; |
| 5023 } | 5027 } |
| 5024 | 5028 |
| 5025 const SpdyStreamId kStreamId = 1; | 5029 const SpdyStreamId kStreamId = 1; |
| 5026 | 5030 |
| 5027 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5031 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5028 SpdyFramer framer(spdy_version_); | 5032 SpdyFramer framer(spdy_version_); |
| 5029 framer.set_visitor(&visitor); | 5033 framer.set_visitor(&visitor); |
| 5030 | 5034 |
| 5031 EXPECT_CALL(visitor, OnAltSvc(kStreamId, | 5035 EXPECT_CALL(visitor, OnAltSvc(kStreamId, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5046 altsvc_ir.protocol_id().length() + | 5050 altsvc_ir.protocol_id().length() + |
| 5047 altsvc_ir.host().length() + | 5051 altsvc_ir.host().length() + |
| 5048 altsvc_ir.origin().length()); | 5052 altsvc_ir.origin().length()); |
| 5049 | 5053 |
| 5050 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5054 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5051 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5055 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5052 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5056 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5053 } | 5057 } |
| 5054 | 5058 |
| 5055 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { | 5059 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
| 5056 if (spdy_version_ < SPDY4) { | 5060 if (spdy_version_ <= SPDY3) { |
| 5057 return; | 5061 return; |
| 5058 } | 5062 } |
| 5059 | 5063 |
| 5060 const SpdyStreamId kStreamId = 1; | 5064 const SpdyStreamId kStreamId = 1; |
| 5061 | 5065 |
| 5062 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5066 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5063 SpdyFramer framer(spdy_version_); | 5067 SpdyFramer framer(spdy_version_); |
| 5064 framer.set_visitor(&visitor); | 5068 framer.set_visitor(&visitor); |
| 5065 | 5069 |
| 5066 EXPECT_CALL(visitor, OnAltSvc(kStreamId, | 5070 EXPECT_CALL(visitor, OnAltSvc(kStreamId, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 5079 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + | 5083 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + |
| 5080 altsvc_ir.protocol_id().length() + | 5084 altsvc_ir.protocol_id().length() + |
| 5081 altsvc_ir.host().length()); | 5085 altsvc_ir.host().length()); |
| 5082 | 5086 |
| 5083 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5087 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5084 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5088 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5085 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5089 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5086 } | 5090 } |
| 5087 | 5091 |
| 5088 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { | 5092 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
| 5089 if (spdy_version_ < SPDY4) { | 5093 if (spdy_version_ <= SPDY3) { |
| 5090 return; | 5094 return; |
| 5091 } | 5095 } |
| 5092 | 5096 |
| 5093 const char kType = static_cast<unsigned char>( | 5097 const char kType = static_cast<unsigned char>( |
| 5094 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | 5098 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
| 5095 { | 5099 { |
| 5096 TestSpdyVisitor visitor(spdy_version_); | 5100 TestSpdyVisitor visitor(spdy_version_); |
| 5097 SpdyFramer framer(spdy_version_); | 5101 SpdyFramer framer(spdy_version_); |
| 5098 framer.set_visitor(&visitor); | 5102 framer.set_visitor(&visitor); |
| 5099 | 5103 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5178 visitor.SimulateInFramer(kFrameDataSmallPIDLen, | 5182 visitor.SimulateInFramer(kFrameDataSmallPIDLen, |
| 5179 sizeof(kFrameDataSmallPIDLen)); | 5183 sizeof(kFrameDataSmallPIDLen)); |
| 5180 EXPECT_EQ(1, visitor.error_count_); | 5184 EXPECT_EQ(1, visitor.error_count_); |
| 5181 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5185 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5182 visitor.framer_.error_code()); | 5186 visitor.framer_.error_code()); |
| 5183 } | 5187 } |
| 5184 } | 5188 } |
| 5185 | 5189 |
| 5186 // Tests handling of ALTSVC frames delivered in small chunks. | 5190 // Tests handling of ALTSVC frames delivered in small chunks. |
| 5187 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 5191 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
| 5188 if (spdy_version_ < SPDY4) { | 5192 if (spdy_version_ <= SPDY3) { |
| 5189 return; | 5193 return; |
| 5190 } | 5194 } |
| 5191 SpdyFramer framer(spdy_version_); | 5195 SpdyFramer framer(spdy_version_); |
| 5192 SpdyAltSvcIR altsvc_ir(1); | 5196 SpdyAltSvcIR altsvc_ir(1); |
| 5193 altsvc_ir.set_max_age(20); | 5197 altsvc_ir.set_max_age(20); |
| 5194 altsvc_ir.set_port(443); | 5198 altsvc_ir.set_port(443); |
| 5195 altsvc_ir.set_protocol_id("protocolid"); | 5199 altsvc_ir.set_protocol_id("protocolid"); |
| 5196 altsvc_ir.set_host("hostname"); | 5200 altsvc_ir.set_host("hostname"); |
| 5197 | 5201 |
| 5198 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); | 5202 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 5212 framed_data += to_read; | 5216 framed_data += to_read; |
| 5213 } | 5217 } |
| 5214 EXPECT_EQ(0, visitor.error_count_); | 5218 EXPECT_EQ(0, visitor.error_count_); |
| 5215 EXPECT_EQ(1, visitor.altsvc_count_); | 5219 EXPECT_EQ(1, visitor.altsvc_count_); |
| 5216 EXPECT_EQ(20u, visitor.test_altsvc_ir_.max_age()); | 5220 EXPECT_EQ(20u, visitor.test_altsvc_ir_.max_age()); |
| 5217 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); | 5221 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); |
| 5218 EXPECT_EQ("protocolid", visitor.test_altsvc_ir_.protocol_id()); | 5222 EXPECT_EQ("protocolid", visitor.test_altsvc_ir_.protocol_id()); |
| 5219 EXPECT_EQ("hostname", visitor.test_altsvc_ir_.host()); | 5223 EXPECT_EQ("hostname", visitor.test_altsvc_ir_.host()); |
| 5220 } | 5224 } |
| 5221 | 5225 |
| 5226 // Tests handling of PRIORITY frames. |
| 5227 TEST_P(SpdyFramerTest, ReadPriority) { |
| 5228 if (spdy_version_ <= SPDY3) { |
| 5229 return; |
| 5230 } |
| 5231 |
| 5232 const unsigned char kFrameData[] = { |
| 5233 0x00, 0x05, 0x02, 0x00, // PRIORITY frame |
| 5234 0x00, 0x00, 0x00, 0x03, // stream ID 3 |
| 5235 0x00, 0x00, 0x00, 0x01, // dependent on stream id 1 |
| 5236 0x00 // weight 0 |
| 5237 }; |
| 5238 |
| 5239 TestSpdyVisitor visitor(spdy_version_); |
| 5240 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 5241 |
| 5242 EXPECT_EQ(SpdyFramer::SPDY_RESET, visitor.framer_.state()); |
| 5243 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, visitor.framer_.error_code()) |
| 5244 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 5245 } |
| 5246 |
| 5247 // Tests handling of PRIORITY frame with incorrect size. |
| 5248 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
| 5249 if (spdy_version_ <= SPDY3) { |
| 5250 return; |
| 5251 } |
| 5252 |
| 5253 // PRIORITY frame of size 4, which isn't correct. |
| 5254 const unsigned char kFrameData[] = { |
| 5255 0x00, 0x04, 0x02, 0x00, |
| 5256 0x00, 0x00, 0x00, 0x03, |
| 5257 0x00, 0x00, 0x00, 0x01, |
| 5258 }; |
| 5259 |
| 5260 TestSpdyVisitor visitor(spdy_version_); |
| 5261 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 5262 |
| 5263 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 5264 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5265 visitor.framer_.error_code()) |
| 5266 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 5267 } |
| 5268 |
| 5222 } // namespace net | 5269 } // namespace net |
| OLD | NEW |