Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: net/spdy/spdy_framer_test.cc

Issue 664803003: Update from chromium a8e7c94b1b79a0948d05a1fcfff53391d22ce37a (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2787 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 headers_ir.set_has_priority(true); 2798 headers_ir.set_has_priority(true);
2799 headers_ir.SetHeader("bar", "foo"); 2799 headers_ir.SetHeader("bar", "foo");
2800 headers_ir.SetHeader("foo", ""); 2800 headers_ir.SetHeader("foo", "");
2801 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2801 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2802 if (IsSpdy2() || IsSpdy3()) { 2802 if (IsSpdy2() || IsSpdy3()) {
2803 // HEADERS with priority not supported. 2803 // HEADERS with priority not supported.
2804 } else { 2804 } else {
2805 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2805 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2806 } 2806 }
2807 } 2807 }
2808
2809 {
2810 const char kDescription[] =
2811 "HEADERS frame with a 0-length header name, FIN, max stream ID, padded";
2812
2813 const unsigned char kV4FrameData[] = {
2814 0x00, 0x00, 0x15, 0x01, // Headers
2815 0x0d, 0x7f, 0xff, 0xff, // FIN | END_HEADERS | PADDED, Stream
2816 // 0x7fffffff
2817 0xff, 0x05, 0x00, 0x00, // Pad length field
2818 0x03, 0x66, 0x6f, 0x6f, // .foo
2819 0x00, 0x03, 0x66, 0x6f, // @.fo
2820 0x6f, 0x03, 0x62, 0x61, // o.ba
2821 0x72, // r
2822 // Padding payload
2823 0x00, 0x00, 0x00, 0x00, 0x00,
2824 };
2825 SpdyHeadersIR headers_ir(0x7fffffff);
2826 headers_ir.set_fin(true);
2827 headers_ir.SetHeader("", "foo");
2828 headers_ir.SetHeader("foo", "bar");
2829 headers_ir.set_padding_len(6);
2830 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2831 if (IsSpdy2() || IsSpdy3()) {
2832 // Padding is not supported.
2833 } else {
2834 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2835 }
2836 }
2808 } 2837 }
2809 2838
2810 // TODO(phajdan.jr): Clean up after we no longer need 2839 // TODO(phajdan.jr): Clean up after we no longer need
2811 // to workaround http://crbug.com/139744. 2840 // to workaround http://crbug.com/139744.
2812 #if !defined(USE_SYSTEM_ZLIB) 2841 #if !defined(USE_SYSTEM_ZLIB)
2813 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { 2842 TEST_P(SpdyFramerTest, CreateHeadersCompressed) {
2814 SpdyFramer framer(spdy_version_); 2843 SpdyFramer framer(spdy_version_);
2815 framer.set_enable_compression(true); 2844 framer.set_enable_compression(true);
2816 2845
2817 { 2846 {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
2975 framer.SerializeFrame(blocked_ir)); 3004 framer.SerializeFrame(blocked_ir));
2976 3005
2977 CompareFrames(kDescription, *frame_serialized, *frame_created); 3006 CompareFrames(kDescription, *frame_serialized, *frame_created);
2978 } 3007 }
2979 3008
2980 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { 3009 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) {
2981 if (spdy_version_ <= SPDY3) { 3010 if (spdy_version_ <= SPDY3) {
2982 return; 3011 return;
2983 } 3012 }
2984 3013
2985 SpdyFramer framer(spdy_version_); 3014 {
2986 framer.set_enable_compression(false); 3015 // Test framing PUSH_PROMISE without padding.
2987 const char kDescription[] = "PUSH_PROMISE frame"; 3016 SpdyFramer framer(spdy_version_);
3017 framer.set_enable_compression(false);
3018 const char kDescription[] = "PUSH_PROMISE frame without padding";
2988 3019
2989 const unsigned char kFrameData[] = { 3020 const unsigned char kFrameData[] = {
2990 0x00, 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS 3021 0x00, 0x00, 0x16, 0x05, // PUSH_PROMISE
2991 0x00, 0x00, 0x00, 0x2a, // Stream 42 3022 0x04, 0x00, 0x00, 0x00, // END_HEADERS
2992 0x00, 0x00, 0x00, 0x39, // Promised stream 57 3023 0x2a, 0x00, 0x00, 0x00, // Stream 42
2993 0x00, 0x03, 0x62, 0x61, // @.ba 3024 0x39, 0x00, 0x03, 0x62, // Promised stream 57, @.b
2994 0x72, 0x03, 0x66, 0x6f, // r.fo 3025 0x61, 0x72, 0x03, 0x66, // ar.f
2995 0x6f, 0x00, 0x03, 0x66, // o@.f 3026 0x6f, 0x6f, 0x00, 0x03, // oo@.
2996 0x6f, 0x6f, 0x03, 0x62, // oo.b 3027 0x66, 0x6f, 0x6f, 0x03, // foo.
2997 0x61, 0x72, // ar 3028 0x62, 0x61, 0x72, // bar
2998 }; 3029 };
2999 3030
3000 SpdyPushPromiseIR push_promise(42, 57); 3031 SpdyPushPromiseIR push_promise(42, 57);
3001 push_promise.SetHeader("bar", "foo"); 3032 push_promise.SetHeader("bar", "foo");
3002 push_promise.SetHeader("foo", "bar"); 3033 push_promise.SetHeader("foo", "bar");
3003 scoped_ptr<SpdySerializedFrame> frame( 3034 scoped_ptr<SpdySerializedFrame> frame(
3004 framer.SerializePushPromise(push_promise)); 3035 framer.SerializePushPromise(push_promise));
3005 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 3036 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3037 }
3038
3039 {
3040 // Test framing PUSH_PROMISE with one byte of padding.
3041 SpdyFramer framer(spdy_version_);
3042 framer.set_enable_compression(false);
3043 const char kDescription[] = "PUSH_PROMISE frame with one byte of padding";
3044
3045 const unsigned char kFrameData[] = {
3046 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE
3047 0x0c, 0x00, 0x00, 0x00, // END_HEADERS | PADDED
3048 0x2a, 0x00, 0x00, 0x00, // Stream 42, Pad length field
3049 0x00, 0x39, 0x00, 0x03, // Promised stream 57
3050 0x62, 0x61, 0x72, 0x03, // bar.
3051 0x66, 0x6f, 0x6f, 0x00, // foo@
3052 0x03, 0x66, 0x6f, 0x6f, // .foo
3053 0x03, 0x62, 0x61, 0x72, // .bar
3054 };
3055
3056 SpdyPushPromiseIR push_promise(42, 57);
3057 push_promise.set_padding_len(1);
3058 push_promise.SetHeader("bar", "foo");
3059 push_promise.SetHeader("foo", "bar");
3060 scoped_ptr<SpdySerializedFrame> frame(
3061 framer.SerializePushPromise(push_promise));
3062 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3063 }
3064
3065 {
3066 // Test framing PUSH_PROMISE with 177 bytes of padding.
3067 SpdyFramer framer(spdy_version_);
3068 framer.set_enable_compression(false);
3069 const char kDescription[] = "PUSH_PROMISE frame with 177 bytes of padding";
3070
3071 const unsigned char kFrameData[] = {
3072 0x00, 0x00, 0xc7, 0x05, // PUSH_PROMISE
3073 0x0c, 0x00, 0x00, 0x00, // END_HEADERS | PADDED
3074 0x2a, 0xb0, 0x00, 0x00, // Stream 42, Pad length field
3075 0x00, 0x39, 0x00, 0x03, // Promised stream 57
3076 0x62, 0x61, 0x72, 0x03, // bar.
3077 0x66, 0x6f, 0x6f, 0x00, // foo@
3078 0x03, 0x66, 0x6f, 0x6f, // .foo
3079 0x03, 0x62, 0x61, 0x72, // .bar
3080 // Padding of 176 0x00(s).
3081 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3082 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3083 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3084 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3085 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3086 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3087 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3088 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3089 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3090 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3091 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3092 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3093 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3094 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3095 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3096 };
3097
3098 SpdyPushPromiseIR push_promise(42, 57);
3099 push_promise.set_padding_len(177);
3100 push_promise.SetHeader("bar", "foo");
3101 push_promise.SetHeader("foo", "bar");
3102 scoped_ptr<SpdySerializedFrame> frame(
3103 framer.SerializePushPromise(push_promise));
3104 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3105 }
3006 } 3106 }
3007 3107
3008 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { 3108 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) {
3009 if (spdy_version_ <= SPDY3) { 3109 if (spdy_version_ <= SPDY3) {
3010 return; 3110 return;
3011 } 3111 }
3012 3112
3013 SpdyFramer framer(spdy_version_); 3113 SpdyFramer framer(spdy_version_);
3014 framer.set_enable_compression(false); 3114 framer.set_enable_compression(false);
3015 const char kDescription[] = "CONTINUATION frame"; 3115 const char kDescription[] = "CONTINUATION frame";
3016 3116
3017 const unsigned char kFrameData[] = { 3117 const unsigned char kFrameData[] = {
3018 0x00, 0x00, 0x12, 0x09, 0x00, // CONTINUATION 3118 0x00, 0x00, 0x12, 0x09, 0x00, // CONTINUATION
3019 0x00, 0x00, 0x00, 0x2a, // Stream 42 3119 0x00, 0x00, 0x00, 0x2a, // Stream 42
3020 0x00, 0x03, 0x62, 0x61, // @.ba 3120 0x00, 0x03, 0x62, 0x61, // @.ba
3021 0x72, 0x03, 0x66, 0x6f, // r.fo 3121 0x72, 0x03, 0x66, 0x6f, // r.fo
3022 0x6f, 0x00, 0x03, 0x66, // o@.f 3122 0x6f, 0x00, 0x03, 0x66, // o@.f
3023 0x6f, 0x6f, 0x03, 0x62, // oo.b 3123 0x6f, 0x6f, 0x03, 0x62, // oo.b
3024 0x61, 0x72, // ar 3124 0x61, 0x72, // ar
3025 }; 3125 };
3026 3126
3027 SpdyContinuationIR continuation(42); 3127 SpdyContinuationIR continuation(42);
3028 continuation.SetHeader("bar", "foo"); 3128 continuation.SetHeader("bar", "foo");
3029 continuation.SetHeader("foo", "bar"); 3129 continuation.SetHeader("foo", "bar");
3030 scoped_ptr<SpdySerializedFrame> frame( 3130 scoped_ptr<SpdySerializedFrame> frame(
3031 framer.SerializeContinuation(continuation)); 3131 framer.SerializeContinuation(continuation));
3032 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 3132 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3033 } 3133 }
3034 3134
3135 TEST_P(SpdyFramerTest, CreatePushPromiseThenContinuationUncompressed) {
3136 if (spdy_version_ <= SPDY3) {
3137 return;
3138 }
3139
3140 {
3141 // Test framing in a case such that a PUSH_PROMISE frame, with one byte of
3142 // padding, cannot hold all the data payload, which is overflowed to the
3143 // consecutive CONTINUATION frame.
3144 SpdyFramer framer(spdy_version_);
3145 framer.set_enable_compression(false);
3146 const char kDescription[] =
3147 "PUSH_PROMISE and CONTINUATION frames with one byte of padding";
3148
3149 const unsigned char kPartialPushPromiseFrameData[] = {
3150 0x00, 0x03, 0xf6, 0x05, // PUSH_PROMISE
3151 0x08, 0x00, 0x00, 0x00, // PADDED
3152 0x2a, 0x00, 0x00, 0x00, // Stream 42
3153 0x00, 0x39, 0x00, 0x03, // Promised stream 57
3154 0x78, 0x78, 0x78, 0x7f, // xxx.
3155 0x80, 0x07, 0x78, 0x78, // ..xx
3156 0x78, 0x78, 0x78, 0x78, // xxxx
3157 0x78, 0x78, 0x78, 0x78, // xxxx
3158 0x78, 0x78, 0x78, 0x78, // xxxx
3159 0x78, 0x78, 0x78, 0x78, // xxxx
3160 0x78, 0x78, 0x78, 0x78, // xxxx
3161 0x78, 0x78, 0x78, 0x78, // xxxx
3162 0x78, 0x78, 0x78, 0x78, // xxxx
3163 0x78, 0x78, 0x78, 0x78, // xxxx
3164 0x78, 0x78, 0x78, 0x78, // xxxx
3165 0x78, 0x78, 0x78, 0x78, // xxxx
3166 0x78, 0x78, 0x78, 0x78, // xxxx
3167 0x78, 0x78, 0x78, 0x78, // xxxx
3168 0x78, 0x78, 0x78, 0x78, // xxxx
3169 0x78, 0x78, 0x78, 0x78, // xxxx
3170 0x78, 0x78, 0x78, 0x78, // xxxx
3171 0x78, 0x78, 0x78, 0x78, // xxxx
3172 0x78, 0x78, 0x78, 0x78, // xxxx
3173 0x78, 0x78, 0x78, 0x78, // xxxx
3174 0x78, 0x78, 0x78, 0x78, // xxxx
3175 0x78, 0x78, 0x78, 0x78, // xxxx
3176 0x78, 0x78, // xx
3177 };
3178
3179 const unsigned char kContinuationFrameData[] = {
3180 0x00, 0x00, 0x16, 0x09, // CONTINUATION
3181 0x04, 0x00, 0x00, 0x00, // END_HEADERS
3182 0x2a, 0x78, 0x78, 0x78, // Stream 42, xxx
3183 0x78, 0x78, 0x78, 0x78, // xxxx
3184 0x78, 0x78, 0x78, 0x78, // xxxx
3185 0x78, 0x78, 0x78, 0x78, // xxxx
3186 0x78, 0x78, 0x78, 0x78, // xxxx
3187 0x78, 0x78,
3188 };
3189
3190 SpdyPushPromiseIR push_promise(42, 57);
3191 push_promise.set_padding_len(1);
3192 string big_value(framer.GetHeaderFragmentMaxSize(), 'x');
3193 push_promise.SetHeader("xxx", big_value);
3194 scoped_ptr<SpdySerializedFrame> frame(
3195 framer.SerializePushPromise(push_promise));
3196
3197 // The entire frame should look like below:
3198 // Name Length in Byte
3199 // ------------------------------------------- Begin of PUSH_PROMISE frame
3200 // PUSH_PROMISE header 9
3201 // Pad length field 1
3202 // Promised stream 4
3203 // Length field of key 2
3204 // Content of key 3
3205 // Length field of value 3
3206 // Part of big_value 16361
3207 // ------------------------------------------- Begin of CONTINUATION frame
3208 // CONTINUATION header 9
3209 // Remaining of big_value 22
3210 // ------------------------------------------- End
3211
3212 // Length of everything listed above except big_value.
3213 int len_non_data_payload = 31;
3214 EXPECT_EQ(framer.GetHeaderFragmentMaxSize() + len_non_data_payload,
3215 frame->size());
3216
3217 // Partially compare the PUSH_PROMISE frame against the template.
3218 const unsigned char* frame_data =
3219 reinterpret_cast<const unsigned char*>(frame->data());
3220 CompareCharArraysWithHexError(kDescription,
3221 frame_data,
3222 arraysize(kPartialPushPromiseFrameData),
3223 kPartialPushPromiseFrameData,
3224 arraysize(kPartialPushPromiseFrameData));
3225
3226 // Compare the CONTINUATION frame against the template.
3227 frame_data += framer.GetHeaderFragmentMaxSize();
3228 CompareCharArraysWithHexError(kDescription,
3229 frame_data,
3230 arraysize(kContinuationFrameData),
3231 kContinuationFrameData,
3232 arraysize(kContinuationFrameData));
3233 }
3234 }
3235
3035 TEST_P(SpdyFramerTest, CreateAltSvc) { 3236 TEST_P(SpdyFramerTest, CreateAltSvc) {
3036 if (spdy_version_ <= SPDY3) { 3237 if (spdy_version_ <= SPDY3) {
3037 return; 3238 return;
3038 } 3239 }
3039 3240
3040 SpdyFramer framer(spdy_version_); 3241 SpdyFramer framer(spdy_version_);
3041 3242
3042 const char kDescription[] = "ALTSVC frame"; 3243 const char kDescription[] = "ALTSVC frame";
3043 const unsigned char kType = static_cast<unsigned char>( 3244 const unsigned char kType = static_cast<unsigned char>(
3044 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); 3245 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 EXPECT_EQ(0u, visitor.header_buffer_length_); 3457 EXPECT_EQ(0u, visitor.header_buffer_length_);
3257 } 3458 }
3258 3459
3259 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { 3460 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) {
3260 if (spdy_version_ <= SPDY3) { 3461 if (spdy_version_ <= SPDY3) {
3261 return; 3462 return;
3262 } 3463 }
3263 SpdyFramer framer(spdy_version_); 3464 SpdyFramer framer(spdy_version_);
3264 framer.set_enable_compression(false); 3465 framer.set_enable_compression(false);
3265 SpdyHeadersIR headers(1); 3466 SpdyHeadersIR headers(1);
3467 headers.set_padding_len(256);
3266 3468
3267 // Exact payload length will change with HPACK, but this should be long 3469 // Exact payload length will change with HPACK, but this should be long
3268 // enough to cause an overflow. 3470 // enough to cause an overflow.
3269 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); 3471 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize();
3270 string big_value(kBigValueSize, 'x'); 3472 string big_value(kBigValueSize, 'x');
3271 headers.SetHeader("aa", big_value); 3473 headers.SetHeader("aa", big_value);
3272 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); 3474 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers));
3273 EXPECT_TRUE(control_frame.get() != NULL); 3475 EXPECT_TRUE(control_frame.get() != NULL);
3274 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); 3476 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize());
3275 3477
3276 TestSpdyVisitor visitor(spdy_version_); 3478 TestSpdyVisitor visitor(spdy_version_);
3277 visitor.SimulateInFramer( 3479 visitor.SimulateInFramer(
3278 reinterpret_cast<unsigned char*>(control_frame->data()), 3480 reinterpret_cast<unsigned char*>(control_frame->data()),
3279 control_frame->size()); 3481 control_frame->size());
3280 EXPECT_TRUE(visitor.header_buffer_valid_); 3482 EXPECT_TRUE(visitor.header_buffer_valid_);
3281 EXPECT_EQ(0, visitor.error_count_); 3483 EXPECT_EQ(0, visitor.error_count_);
3282 EXPECT_EQ(1, visitor.headers_frame_count_); 3484 EXPECT_EQ(1, visitor.headers_frame_count_);
3283 EXPECT_EQ(16, visitor.continuation_count_); 3485 EXPECT_EQ(16, visitor.continuation_count_);
3284 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); 3486 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_);
3285 } 3487 }
3286 3488
3287 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { 3489 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) {
3288 if (spdy_version_ <= SPDY3) { 3490 if (spdy_version_ <= SPDY3) {
3289 return; 3491 return;
3290 } 3492 }
3291 SpdyFramer framer(spdy_version_); 3493 SpdyFramer framer(spdy_version_);
3292 framer.set_enable_compression(false); 3494 framer.set_enable_compression(false);
3293 SpdyPushPromiseIR push_promise(1, 2); 3495 SpdyPushPromiseIR push_promise(1, 2);
3496 push_promise.set_padding_len(256);
3294 3497
3295 // Exact payload length will change with HPACK, but this should be long 3498 // Exact payload length will change with HPACK, but this should be long
3296 // enough to cause an overflow. 3499 // enough to cause an overflow.
3297 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); 3500 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize();
3298 string big_value(kBigValueSize, 'x'); 3501 string big_value(kBigValueSize, 'x');
3299 push_promise.SetHeader("aa", big_value); 3502 push_promise.SetHeader("aa", big_value);
3300 scoped_ptr<SpdyFrame> control_frame( 3503 scoped_ptr<SpdyFrame> control_frame(
3301 framer.SerializePushPromise(push_promise)); 3504 framer.SerializePushPromise(push_promise));
3302 EXPECT_TRUE(control_frame.get() != NULL); 3505 EXPECT_TRUE(control_frame.get() != NULL);
3303 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); 3506 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize());
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
3722 3925
3723 int bytes_consumed = 0; 3926 int bytes_consumed = 0;
3724 3927
3725 // Send the frame header. 3928 // Send the frame header.
3726 EXPECT_CALL(visitor, OnDataFrameHeader(1, 3929 EXPECT_CALL(visitor, OnDataFrameHeader(1,
3727 kPaddingLen + strlen(data_payload), 3930 kPaddingLen + strlen(data_payload),
3728 false)); 3931 false));
3729 CHECK_EQ(framer.GetDataFrameMinimumSize(), 3932 CHECK_EQ(framer.GetDataFrameMinimumSize(),
3730 framer.ProcessInput(frame->data(), 3933 framer.ProcessInput(frame->data(),
3731 framer.GetDataFrameMinimumSize())); 3934 framer.GetDataFrameMinimumSize()));
3732 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); 3935 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_DATA_FRAME_PADDING_LENGTH);
3733 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); 3936 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR);
3734 bytes_consumed += framer.GetDataFrameMinimumSize(); 3937 bytes_consumed += framer.GetDataFrameMinimumSize();
3735 3938
3736 // Send the padding length field. 3939 // Send the padding length field.
3737 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); 3940 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1));
3738 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); 3941 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME);
3739 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); 3942 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR);
3740 bytes_consumed += 1; 3943 bytes_consumed += 1;
3741 3944
3742 // Send the first two bytes of the data payload, i.e., "he". 3945 // Send the first two bytes of the data payload, i.e., "he".
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
3959 Pair("cookie", "foo=bar; baz=bing; "), 4162 Pair("cookie", "foo=bar; baz=bing; "),
3960 Pair("name", "value"))); 4163 Pair("name", "value")));
3961 } 4164 }
3962 4165
3963 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { 4166 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) {
3964 if (spdy_version_ <= SPDY3) { 4167 if (spdy_version_ <= SPDY3) {
3965 return; 4168 return;
3966 } 4169 }
3967 4170
3968 const unsigned char kInput[] = { 4171 const unsigned char kInput[] = {
3969 0x00, 0x00, 0x17, 0x05, 0x08, // PUSH_PROMISE: PADDED 4172 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE
3970 0x00, 0x00, 0x00, 0x01, // Stream 1 4173 0x08, 0x00, 0x00, 0x00, // PADDED
3971 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 4174 0x01, 0x02, 0x00, 0x00, // Stream 1, Pad length field
3972 0x02, // Padding of 2. 4175 0x00, 0x2A, 0x00, 0x06, // Promised stream 42
3973 0x00, 0x06, 0x63, 0x6f, 4176 0x63, 0x6f, 0x6f, 0x6b,
3974 0x6f, 0x6b, 0x69, 0x65, 4177 0x69, 0x65, 0x07, 0x66,
3975 0x07, 0x66, 0x6f, 0x6f, 4178 0x6f, 0x6f, 0x3d, 0x62,
3976 0x3d, 0x62, 0x61, 0x72, 4179 0x61, 0x72, 0x00, 0x00,
3977 0x00, 0x00,
3978 4180
3979 0x00, 0x00, 0x14, 0x09, 0x00, // CONTINUATION 4181 0x00, 0x00, 0x14, 0x09, // CONTINUATION
3980 0x00, 0x00, 0x00, 0x01, // Stream 1 4182 0x00, 0x00, 0x00, 0x00,
3981 0x00, 0x06, 0x63, 0x6f, 4183 0x01, 0x00, 0x06, 0x63, // Stream 1
3982 0x6f, 0x6b, 0x69, 0x65, 4184 0x6f, 0x6f, 0x6b, 0x69,
3983 0x08, 0x62, 0x61, 0x7a, 4185 0x65, 0x08, 0x62, 0x61,
3984 0x3d, 0x62, 0x69, 0x6e, 4186 0x7a, 0x3d, 0x62, 0x69,
3985 0x67, 0x00, 0x06, 0x63, 4187 0x6e, 0x67, 0x00, 0x06,
4188 0x63,
3986 4189
3987 0x00, 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS 4190 0x00, 0x00, 0x12, 0x09, // CONTINUATION
3988 0x00, 0x00, 0x00, 0x01, // Stream 1 4191 0x04, 0x00, 0x00, 0x00, // END_HEADERS
3989 0x6f, 0x6f, 0x6b, 0x69, 4192 0x01, 0x6f, 0x6f, 0x6b, // Stream 1
3990 0x65, 0x00, 0x00, 0x04, 4193 0x69, 0x65, 0x00, 0x00,
3991 0x6e, 0x61, 0x6d, 0x65, 4194 0x04, 0x6e, 0x61, 0x6d,
3992 0x05, 0x76, 0x61, 0x6c, 4195 0x65, 0x05, 0x76, 0x61,
3993 0x75, 0x65, 4196 0x6c, 0x75, 0x65,
3994 }; 4197 };
3995 4198
3996 SpdyFramer framer(spdy_version_); 4199 SpdyFramer framer(spdy_version_);
3997 TestSpdyVisitor visitor(spdy_version_); 4200 TestSpdyVisitor visitor(spdy_version_);
3998 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4201 visitor.SimulateInFramer(kInput, sizeof(kInput));
3999 4202
4000 EXPECT_EQ(0, visitor.error_count_); 4203 EXPECT_EQ(0, visitor.error_count_);
4001 EXPECT_EQ(1u, visitor.last_push_promise_stream_); 4204 EXPECT_EQ(1u, visitor.last_push_promise_stream_);
4002 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); 4205 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_);
4003 EXPECT_EQ(2, visitor.continuation_count_); 4206 EXPECT_EQ(2, visitor.continuation_count_);
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after
5539 TestSpdyVisitor visitor(spdy_version_); 5742 TestSpdyVisitor visitor(spdy_version_);
5540 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); 5743 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData));
5541 5744
5542 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); 5745 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state());
5543 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 5746 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5544 visitor.framer_.error_code()) 5747 visitor.framer_.error_code())
5545 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); 5748 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code());
5546 } 5749 }
5547 5750
5548 } // namespace net 5751 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698