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 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2042 if (!IsSpdy2() && !IsSpdy3()) { | 2042 if (!IsSpdy2() && !IsSpdy3()) { |
2043 // SYN_STREAM not supported for SPDY>3 | 2043 // SYN_STREAM not supported for SPDY>3 |
2044 return; | 2044 return; |
2045 } | 2045 } |
2046 SpdyFramer framer(spdy_version_); | 2046 SpdyFramer framer(spdy_version_); |
2047 framer.set_enable_compression(true); | 2047 framer.set_enable_compression(true); |
2048 | 2048 |
2049 { | 2049 { |
2050 const char kDescription[] = | 2050 const char kDescription[] = |
2051 "SYN_STREAM frame, low pri, no FIN"; | 2051 "SYN_STREAM frame, low pri, no FIN"; |
2052 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | |
2052 | 2053 |
2053 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | 2054 #if !defined(ZLIB_X86_SIMD) |
agl
2014/10/17 00:45:34
Let's not add another #define. How about memcmping
robert.bradford
2014/10/20 16:45:54
Sounds good. Only needed memcmp() against one, if
| |
2054 const unsigned char kV2FrameData[] = { | 2055 const unsigned char kV2FrameData[] = { |
2055 0x80, spdy_version_ch_, 0x00, 0x01, | 2056 0x80, spdy_version_ch_, 0x00, 0x01, |
2056 0x00, 0x00, 0x00, 0x36, | 2057 0x00, 0x00, 0x00, 0x36, |
2057 0x00, 0x00, 0x00, 0x01, | 2058 0x00, 0x00, 0x00, 0x01, |
2058 0x00, 0x00, 0x00, 0x00, | 2059 0x00, 0x00, 0x00, 0x00, |
2059 0x80, 0x00, 0x38, 0xea, | 2060 0x80, 0x00, 0x38, 0xea, |
2060 0xdf, 0xa2, 0x51, 0xb2, | 2061 0xdf, 0xa2, 0x51, 0xb2, |
2061 0x62, 0x60, 0x62, 0x60, | 2062 0x62, 0x60, 0x62, 0x60, |
2062 0x4e, 0x4a, 0x2c, 0x62, | 2063 0x4e, 0x4a, 0x2c, 0x62, |
2063 0x60, 0x06, 0x08, 0xa0, | 2064 0x60, 0x06, 0x08, 0xa0, |
(...skipping 16 matching lines...) Expand all Loading... | |
2080 0xC2, 0x4B, 0x4A, 0x04, | 2081 0xC2, 0x4B, 0x4A, 0x04, |
2081 0xE5, 0x0B, 0x66, 0x80, | 2082 0xE5, 0x0B, 0x66, 0x80, |
2082 0x00, 0x4A, 0xCB, 0xCF, | 2083 0x00, 0x4A, 0xCB, 0xCF, |
2083 0x07, 0x08, 0x20, 0x10, | 2084 0x07, 0x08, 0x20, 0x10, |
2084 0x95, 0x96, 0x9F, 0x0F, | 2085 0x95, 0x96, 0x9F, 0x0F, |
2085 0xA2, 0x00, 0x02, 0x28, | 2086 0xA2, 0x00, 0x02, 0x28, |
2086 0x29, 0xB1, 0x08, 0x20, | 2087 0x29, 0xB1, 0x08, 0x20, |
2087 0x80, 0x00, 0x00, 0x00, | 2088 0x80, 0x00, 0x00, 0x00, |
2088 0x00, 0xFF, 0xFF, | 2089 0x00, 0xFF, 0xFF, |
2089 }; | 2090 }; |
2091 #else | |
2092 const unsigned char kV2FrameData[] = { | |
2093 0x80, spdy_version_ch_, 0x00, 0x01, | |
2094 0x00, 0x00, 0x00, 0x33, | |
2095 0x00, 0x00, 0x00, 0x01, | |
2096 0x00, 0x00, 0x00, 0x00, | |
2097 0x80, 0x00, 0x38, 0xea, | |
2098 0xdf, 0xa2, 0x51, 0xb2, | |
2099 0x62, 0x60, 0x62, 0x60, | |
2100 0x4e, 0x4a, 0x2c, 0x62, | |
2101 0x60, 0x06, 0x08, 0xa0, | |
2102 0xb4, 0xfc, 0x7c, 0x80, | |
2103 0x00, 0x62, 0x60, 0x06, | |
2104 0x13, 0x00, 0x01, 0x94, | |
2105 0x94, 0x58, 0x04, 0x10, | |
2106 0x40, 0x00, 0x00, 0x00, | |
2107 0x00, 0xff, 0xff, | |
2108 }; | |
2109 const unsigned char kV3FrameData[] = { | |
2110 0x80, spdy_version_ch_, 0x00, 0x01, | |
2111 0x00, 0x00, 0x00, 0x32, | |
2112 0x00, 0x00, 0x00, 0x01, | |
2113 0x00, 0x00, 0x00, 0x00, | |
2114 0x80, 0x00, 0x38, 0xea, | |
2115 0xe3, 0xc6, 0xa7, 0xc2, | |
2116 0x02, 0xe5, 0x0e, 0x50, | |
2117 0xc2, 0x4b, 0x4a, 0x04, | |
2118 0xe5, 0x0b, 0x66, 0x80, | |
2119 0x00, 0x4a, 0xcb, 0xcf, | |
2120 0x07, 0x08, 0x20, 0x24, | |
2121 0x0a, 0x20, 0x80, 0x92, | |
2122 0x12, 0x8b, 0x00, 0x02, | |
2123 0x08, 0x00, 0x00, 0x00, | |
2124 0xff, 0xff, | |
2125 }; | |
2126 #endif //!defined(ZLIB_X86_SIMD) | |
2127 | |
2090 SpdySynStreamIR syn_stream(1); | 2128 SpdySynStreamIR syn_stream(1); |
2091 syn_stream.set_priority(priority); | 2129 syn_stream.set_priority(priority); |
2092 syn_stream.SetHeader("bar", "foo"); | 2130 syn_stream.SetHeader("bar", "foo"); |
2093 syn_stream.SetHeader("foo", "bar"); | 2131 syn_stream.SetHeader("foo", "bar"); |
2094 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 2132 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
2095 if (IsSpdy2()) { | 2133 if (IsSpdy2()) { |
2096 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2134 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2097 } else if (IsSpdy3()) { | 2135 } else if (IsSpdy3()) { |
2098 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2136 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2099 } else { | 2137 } else { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2243 if (spdy_version_ > SPDY3) { | 2281 if (spdy_version_ > SPDY3) { |
2244 // SYN_REPLY unsupported in SPDY>3 | 2282 // SYN_REPLY unsupported in SPDY>3 |
2245 return; | 2283 return; |
2246 } | 2284 } |
2247 SpdyFramer framer(spdy_version_); | 2285 SpdyFramer framer(spdy_version_); |
2248 framer.set_enable_compression(true); | 2286 framer.set_enable_compression(true); |
2249 | 2287 |
2250 { | 2288 { |
2251 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 2289 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2252 | 2290 |
2291 #if !defined(ZLIB_X86_SIMD) | |
2253 const unsigned char kV2FrameData[] = { | 2292 const unsigned char kV2FrameData[] = { |
2254 0x80, spdy_version_ch_, 0x00, 0x02, | 2293 0x80, spdy_version_ch_, 0x00, 0x02, |
2255 0x00, 0x00, 0x00, 0x32, | 2294 0x00, 0x00, 0x00, 0x32, |
2256 0x00, 0x00, 0x00, 0x01, | 2295 0x00, 0x00, 0x00, 0x01, |
2257 0x00, 0x00, 0x38, 0xea, | 2296 0x00, 0x00, 0x38, 0xea, |
2258 0xdf, 0xa2, 0x51, 0xb2, | 2297 0xdf, 0xa2, 0x51, 0xb2, |
2259 0x62, 0x60, 0x62, 0x60, | 2298 0x62, 0x60, 0x62, 0x60, |
2260 0x4e, 0x4a, 0x2c, 0x62, | 2299 0x4e, 0x4a, 0x2c, 0x62, |
2261 0x60, 0x06, 0x08, 0xa0, | 2300 0x60, 0x06, 0x08, 0xa0, |
2262 0xb4, 0xfc, 0x7c, 0x80, | 2301 0xb4, 0xfc, 0x7c, 0x80, |
(...skipping 14 matching lines...) Expand all Loading... | |
2277 0x4a, 0x04, 0xe5, 0x0b, | 2316 0x4a, 0x04, 0xe5, 0x0b, |
2278 0x66, 0x80, 0x00, 0x4a, | 2317 0x66, 0x80, 0x00, 0x4a, |
2279 0xcb, 0xcf, 0x07, 0x08, | 2318 0xcb, 0xcf, 0x07, 0x08, |
2280 0x20, 0x10, 0x95, 0x96, | 2319 0x20, 0x10, 0x95, 0x96, |
2281 0x9f, 0x0f, 0xa2, 0x00, | 2320 0x9f, 0x0f, 0xa2, 0x00, |
2282 0x02, 0x28, 0x29, 0xb1, | 2321 0x02, 0x28, 0x29, 0xb1, |
2283 0x08, 0x20, 0x80, 0x00, | 2322 0x08, 0x20, 0x80, 0x00, |
2284 0x00, 0x00, 0x00, 0xff, | 2323 0x00, 0x00, 0x00, 0xff, |
2285 0xff, | 2324 0xff, |
2286 }; | 2325 }; |
2326 #else | |
2327 const unsigned char kV2FrameData[] = { | |
2328 0x80, spdy_version_ch_, 0x00, 0x02, | |
2329 0x00, 0x00, 0x00, 0x2f, | |
2330 0x00, 0x00, 0x00, 0x01, | |
2331 0x00, 0x00, 0x38, 0xea, | |
2332 0xdf, 0xa2, 0x51, 0xb2, | |
2333 0x62, 0x60, 0x62, 0x60, | |
2334 0x4e, 0x4a, 0x2c, 0x62, | |
2335 0x60, 0x06, 0x08, 0xa0, | |
2336 0xb4, 0xfc, 0x7c, 0x80, | |
2337 0x00, 0x62, 0x60, 0x06, | |
2338 0x13, 0x00, 0x01, 0x94, | |
2339 0x94, 0x58, 0x04, 0x10, | |
2340 0x40, 0x00, 0x00, 0x00, | |
2341 0x00, 0xff, 0xff, | |
2342 }; | |
2343 const unsigned char kV3FrameData[] = { | |
2344 0x80, spdy_version_ch_, 0x00, 0x02, | |
2345 0x00, 0x00, 0x00, 0x2c, | |
2346 0x00, 0x00, 0x00, 0x01, | |
2347 0x38, 0xea, 0xe3, 0xc6, | |
2348 0xa7, 0xc2, 0x02, 0xe5, | |
2349 0x0e, 0x50, 0xc2, 0x4b, | |
2350 0x4a, 0x04, 0xe5, 0x0b, | |
2351 0x66, 0x80, 0x00, 0x4a, | |
2352 0xcb, 0xcf, 0x07, 0x08, | |
2353 0x20, 0x24, 0x0a, 0x20, | |
2354 0x80, 0x92, 0x12, 0x8b, | |
2355 0x00, 0x02, 0x08, 0x00, | |
2356 0x00, 0x00, 0xff, 0xff, | |
2357 }; | |
2358 #endif //!defined(ZLIB_X86_SIMD) | |
2359 | |
2287 SpdySynReplyIR syn_reply(1); | 2360 SpdySynReplyIR syn_reply(1); |
2288 syn_reply.SetHeader("bar", "foo"); | 2361 syn_reply.SetHeader("bar", "foo"); |
2289 syn_reply.SetHeader("foo", "bar"); | 2362 syn_reply.SetHeader("foo", "bar"); |
2290 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2363 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2291 if (IsSpdy2()) { | 2364 if (IsSpdy2()) { |
2292 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2365 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2293 } else if (IsSpdy3()) { | 2366 } else if (IsSpdy3()) { |
2294 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2367 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2295 } else { | 2368 } else { |
2296 LOG(FATAL) << "Unsupported version in test."; | 2369 LOG(FATAL) << "Unsupported version in test."; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2820 // TODO(phajdan.jr): Clean up after we no longer need | 2893 // TODO(phajdan.jr): Clean up after we no longer need |
2821 // to workaround http://crbug.com/139744. | 2894 // to workaround http://crbug.com/139744. |
2822 #if !defined(USE_SYSTEM_ZLIB) | 2895 #if !defined(USE_SYSTEM_ZLIB) |
2823 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { | 2896 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
2824 SpdyFramer framer(spdy_version_); | 2897 SpdyFramer framer(spdy_version_); |
2825 framer.set_enable_compression(true); | 2898 framer.set_enable_compression(true); |
2826 | 2899 |
2827 { | 2900 { |
2828 const char kDescription[] = "HEADERS frame, no FIN"; | 2901 const char kDescription[] = "HEADERS frame, no FIN"; |
2829 | 2902 |
2903 #if !defined(ZLIB_X86_SIMD) | |
2830 const unsigned char kV2FrameData[] = { | 2904 const unsigned char kV2FrameData[] = { |
2831 0x80, spdy_version_ch_, 0x00, 0x08, | 2905 0x80, spdy_version_ch_, 0x00, 0x08, |
2832 0x00, 0x00, 0x00, 0x32, | 2906 0x00, 0x00, 0x00, 0x32, |
2833 0x00, 0x00, 0x00, 0x01, | 2907 0x00, 0x00, 0x00, 0x01, |
2834 0x00, 0x00, 0x38, 0xea, | 2908 0x00, 0x00, 0x38, 0xea, |
2835 0xdf, 0xa2, 0x51, 0xb2, | 2909 0xdf, 0xa2, 0x51, 0xb2, |
2836 0x62, 0x60, 0x62, 0x60, | 2910 0x62, 0x60, 0x62, 0x60, |
2837 0x4e, 0x4a, 0x2c, 0x62, | 2911 0x4e, 0x4a, 0x2c, 0x62, |
2838 0x60, 0x06, 0x08, 0xa0, | 2912 0x60, 0x06, 0x08, 0xa0, |
2839 0xb4, 0xfc, 0x7c, 0x80, | 2913 0xb4, 0xfc, 0x7c, 0x80, |
(...skipping 14 matching lines...) Expand all Loading... | |
2854 0x4a, 0x04, 0xe5, 0x0b, | 2928 0x4a, 0x04, 0xe5, 0x0b, |
2855 0x66, 0x80, 0x00, 0x4a, | 2929 0x66, 0x80, 0x00, 0x4a, |
2856 0xcb, 0xcf, 0x07, 0x08, | 2930 0xcb, 0xcf, 0x07, 0x08, |
2857 0x20, 0x10, 0x95, 0x96, | 2931 0x20, 0x10, 0x95, 0x96, |
2858 0x9f, 0x0f, 0xa2, 0x00, | 2932 0x9f, 0x0f, 0xa2, 0x00, |
2859 0x02, 0x28, 0x29, 0xb1, | 2933 0x02, 0x28, 0x29, 0xb1, |
2860 0x08, 0x20, 0x80, 0x00, | 2934 0x08, 0x20, 0x80, 0x00, |
2861 0x00, 0x00, 0x00, 0xff, | 2935 0x00, 0x00, 0x00, 0xff, |
2862 0xff, | 2936 0xff, |
2863 }; | 2937 }; |
2938 #else | |
2939 const unsigned char kV2FrameData[] = { | |
2940 0x80, spdy_version_ch_, 0x00, 0x08, | |
2941 0x00, 0x00, 0x00, 0x2f, | |
2942 0x00, 0x00, 0x00, 0x01, | |
2943 0x00, 0x00, 0x38, 0xea, | |
2944 0xdf, 0xa2, 0x51, 0xb2, | |
2945 0x62, 0x60, 0x62, 0x60, | |
2946 0x4e, 0x4a, 0x2c, 0x62, | |
2947 0x60, 0x06, 0x08, 0xa0, | |
2948 0xb4, 0xfc, 0x7c, 0x80, | |
2949 0x00, 0x62, 0x60, 0x06, | |
2950 0x13, 0x00, 0x01, 0x94, | |
2951 0x94, 0x58, 0x04, 0x10, | |
2952 0x40, 0x00, 0x00, 0x00, | |
2953 0x00, 0xff, 0xff, | |
2954 }; | |
2955 const unsigned char kV3FrameData[] = { | |
2956 0x80, spdy_version_ch_, 0x00, 0x08, | |
2957 0x00, 0x00, 0x00, 0x2c, | |
2958 0x00, 0x00, 0x00, 0x01, | |
2959 0x38, 0xea, 0xe3, 0xc6, | |
2960 0xa7, 0xc2, 0x02, 0xe5, | |
2961 0x0e, 0x50, 0xc2, 0x4b, | |
2962 0x4a, 0x04, 0xe5, 0x0b, | |
2963 0x66, 0x80, 0x00, 0x4a, | |
2964 0xcb, 0xcf, 0x07, 0x08, | |
2965 0x20, 0x24, 0x0a, 0x20, | |
2966 0x80, 0x92, 0x12, 0x8b, | |
2967 0x00, 0x02, 0x08, 0x00, | |
2968 0x00, 0x00, 0xff, 0xff, | |
2969 }; | |
2970 #endif //!defined(ZLIB_X86_SIMD) | |
2971 | |
2864 SpdyHeadersIR headers_ir(1); | 2972 SpdyHeadersIR headers_ir(1); |
2865 headers_ir.SetHeader("bar", "foo"); | 2973 headers_ir.SetHeader("bar", "foo"); |
2866 headers_ir.SetHeader("foo", "bar"); | 2974 headers_ir.SetHeader("foo", "bar"); |
2867 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2975 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2868 if (IsSpdy2()) { | 2976 if (IsSpdy2()) { |
2869 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2977 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2870 } else if (IsSpdy3()) { | 2978 } else if (IsSpdy3()) { |
2871 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2979 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2872 } else { | 2980 } else { |
2873 // Deflate compression doesn't apply to HPACK. | 2981 // Deflate compression doesn't apply to HPACK. |
(...skipping 2675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5549 TestSpdyVisitor visitor(spdy_version_); | 5657 TestSpdyVisitor visitor(spdy_version_); |
5550 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5658 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
5551 | 5659 |
5552 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5660 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
5553 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5661 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
5554 visitor.framer_.error_code()) | 5662 visitor.framer_.error_code()) |
5555 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5663 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
5556 } | 5664 } |
5557 | 5665 |
5558 } // namespace net | 5666 } // namespace net |
OLD | NEW |