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 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 if (!IsSpdy2() && !IsSpdy3()) { | 2038 if (!IsSpdy2() && !IsSpdy3()) { |
2039 // SYN_STREAM not supported for SPDY>3 | 2039 // SYN_STREAM not supported for SPDY>3 |
2040 return; | 2040 return; |
2041 } | 2041 } |
2042 SpdyFramer framer(spdy_version_); | 2042 SpdyFramer framer(spdy_version_); |
2043 framer.set_enable_compression(true); | 2043 framer.set_enable_compression(true); |
2044 | 2044 |
2045 { | 2045 { |
2046 const char kDescription[] = | 2046 const char kDescription[] = |
2047 "SYN_STREAM frame, low pri, no FIN"; | 2047 "SYN_STREAM frame, low pri, no FIN"; |
| 2048 const SpdyPriority priority = IsSpdy2() ? 2 : 4; |
2048 | 2049 |
2049 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | |
2050 const unsigned char kV2FrameData[] = { | 2050 const unsigned char kV2FrameData[] = { |
2051 0x80, spdy_version_ch_, 0x00, 0x01, | 2051 0x80, spdy_version_ch_, 0x00, 0x01, |
2052 0x00, 0x00, 0x00, 0x36, | 2052 0x00, 0x00, 0x00, 0x36, |
2053 0x00, 0x00, 0x00, 0x01, | 2053 0x00, 0x00, 0x00, 0x01, |
2054 0x00, 0x00, 0x00, 0x00, | 2054 0x00, 0x00, 0x00, 0x00, |
2055 0x80, 0x00, 0x38, 0xea, | 2055 0x80, 0x00, 0x38, 0xea, |
2056 0xdf, 0xa2, 0x51, 0xb2, | 2056 0xdf, 0xa2, 0x51, 0xb2, |
2057 0x62, 0x60, 0x62, 0x60, | 2057 0x62, 0x60, 0x62, 0x60, |
2058 0x4e, 0x4a, 0x2c, 0x62, | 2058 0x4e, 0x4a, 0x2c, 0x62, |
2059 0x60, 0x06, 0x08, 0xa0, | 2059 0x60, 0x06, 0x08, 0xa0, |
(...skipping 16 matching lines...) Expand all Loading... |
2076 0xC2, 0x4B, 0x4A, 0x04, | 2076 0xC2, 0x4B, 0x4A, 0x04, |
2077 0xE5, 0x0B, 0x66, 0x80, | 2077 0xE5, 0x0B, 0x66, 0x80, |
2078 0x00, 0x4A, 0xCB, 0xCF, | 2078 0x00, 0x4A, 0xCB, 0xCF, |
2079 0x07, 0x08, 0x20, 0x10, | 2079 0x07, 0x08, 0x20, 0x10, |
2080 0x95, 0x96, 0x9F, 0x0F, | 2080 0x95, 0x96, 0x9F, 0x0F, |
2081 0xA2, 0x00, 0x02, 0x28, | 2081 0xA2, 0x00, 0x02, 0x28, |
2082 0x29, 0xB1, 0x08, 0x20, | 2082 0x29, 0xB1, 0x08, 0x20, |
2083 0x80, 0x00, 0x00, 0x00, | 2083 0x80, 0x00, 0x00, 0x00, |
2084 0x00, 0xFF, 0xFF, | 2084 0x00, 0xFF, 0xFF, |
2085 }; | 2085 }; |
| 2086 const unsigned char kV2SIMDFrameData[] = { |
| 2087 0x80, spdy_version_ch_, 0x00, 0x01, |
| 2088 0x00, 0x00, 0x00, 0x33, |
| 2089 0x00, 0x00, 0x00, 0x01, |
| 2090 0x00, 0x00, 0x00, 0x00, |
| 2091 0x80, 0x00, 0x38, 0xea, |
| 2092 0xdf, 0xa2, 0x51, 0xb2, |
| 2093 0x62, 0x60, 0x62, 0x60, |
| 2094 0x4e, 0x4a, 0x2c, 0x62, |
| 2095 0x60, 0x06, 0x08, 0xa0, |
| 2096 0xb4, 0xfc, 0x7c, 0x80, |
| 2097 0x00, 0x62, 0x60, 0x06, |
| 2098 0x13, 0x00, 0x01, 0x94, |
| 2099 0x94, 0x58, 0x04, 0x10, |
| 2100 0x40, 0x00, 0x00, 0x00, |
| 2101 0x00, 0xff, 0xff, |
| 2102 }; |
| 2103 const unsigned char kV3SIMDFrameData[] = { |
| 2104 0x80, spdy_version_ch_, 0x00, 0x01, |
| 2105 0x00, 0x00, 0x00, 0x32, |
| 2106 0x00, 0x00, 0x00, 0x01, |
| 2107 0x00, 0x00, 0x00, 0x00, |
| 2108 0x80, 0x00, 0x38, 0xea, |
| 2109 0xe3, 0xc6, 0xa7, 0xc2, |
| 2110 0x02, 0xe5, 0x0e, 0x50, |
| 2111 0xc2, 0x4b, 0x4a, 0x04, |
| 2112 0xe5, 0x0b, 0x66, 0x80, |
| 2113 0x00, 0x4a, 0xcb, 0xcf, |
| 2114 0x07, 0x08, 0x20, 0x24, |
| 2115 0x0a, 0x20, 0x80, 0x92, |
| 2116 0x12, 0x8b, 0x00, 0x02, |
| 2117 0x08, 0x00, 0x00, 0x00, |
| 2118 0xff, 0xff, |
| 2119 }; |
| 2120 |
2086 SpdySynStreamIR syn_stream(1); | 2121 SpdySynStreamIR syn_stream(1); |
2087 syn_stream.set_priority(priority); | 2122 syn_stream.set_priority(priority); |
2088 syn_stream.SetHeader("bar", "foo"); | 2123 syn_stream.SetHeader("bar", "foo"); |
2089 syn_stream.SetHeader("foo", "bar"); | 2124 syn_stream.SetHeader("foo", "bar"); |
2090 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 2125 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 2126 const unsigned char* frame_data = |
| 2127 reinterpret_cast<const unsigned char*>(frame->data()); |
2091 if (IsSpdy2()) { | 2128 if (IsSpdy2()) { |
2092 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2129 // Try comparing with SIMD version, if that fails, do a failing check |
| 2130 // with pretty printing against non-SIMD version |
| 2131 if (memcmp(frame_data, |
| 2132 kV2SIMDFrameData, |
| 2133 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { |
| 2134 CompareCharArraysWithHexError(kDescription, |
| 2135 frame_data, |
| 2136 frame->size(), |
| 2137 kV2FrameData, |
| 2138 arraysize(kV2FrameData)); |
| 2139 } |
2093 } else if (IsSpdy3()) { | 2140 } else if (IsSpdy3()) { |
2094 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2141 if (memcmp(frame_data, |
| 2142 kV3SIMDFrameData, |
| 2143 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { |
| 2144 CompareCharArraysWithHexError(kDescription, |
| 2145 frame_data, |
| 2146 frame->size(), |
| 2147 kV3FrameData, |
| 2148 arraysize(kV3FrameData)); |
| 2149 } |
2095 } else { | 2150 } else { |
2096 LOG(FATAL) << "Unsupported version in test."; | 2151 LOG(FATAL) << "Unsupported version in test."; |
2097 } | 2152 } |
2098 } | 2153 } |
2099 } | 2154 } |
2100 #endif // !defined(USE_SYSTEM_ZLIB) | 2155 #endif // !defined(USE_SYSTEM_ZLIB) |
2101 | 2156 |
2102 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | 2157 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
2103 if (spdy_version_ > SPDY3) { | 2158 if (spdy_version_ > SPDY3) { |
2104 // SYN_REPLY unsupported in SPDY>3 | 2159 // SYN_REPLY unsupported in SPDY>3 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 0x4a, 0x04, 0xe5, 0x0b, | 2328 0x4a, 0x04, 0xe5, 0x0b, |
2274 0x66, 0x80, 0x00, 0x4a, | 2329 0x66, 0x80, 0x00, 0x4a, |
2275 0xcb, 0xcf, 0x07, 0x08, | 2330 0xcb, 0xcf, 0x07, 0x08, |
2276 0x20, 0x10, 0x95, 0x96, | 2331 0x20, 0x10, 0x95, 0x96, |
2277 0x9f, 0x0f, 0xa2, 0x00, | 2332 0x9f, 0x0f, 0xa2, 0x00, |
2278 0x02, 0x28, 0x29, 0xb1, | 2333 0x02, 0x28, 0x29, 0xb1, |
2279 0x08, 0x20, 0x80, 0x00, | 2334 0x08, 0x20, 0x80, 0x00, |
2280 0x00, 0x00, 0x00, 0xff, | 2335 0x00, 0x00, 0x00, 0xff, |
2281 0xff, | 2336 0xff, |
2282 }; | 2337 }; |
| 2338 const unsigned char kV2SIMDFrameData[] = { |
| 2339 0x80, spdy_version_ch_, 0x00, 0x02, |
| 2340 0x00, 0x00, 0x00, 0x2f, |
| 2341 0x00, 0x00, 0x00, 0x01, |
| 2342 0x00, 0x00, 0x38, 0xea, |
| 2343 0xdf, 0xa2, 0x51, 0xb2, |
| 2344 0x62, 0x60, 0x62, 0x60, |
| 2345 0x4e, 0x4a, 0x2c, 0x62, |
| 2346 0x60, 0x06, 0x08, 0xa0, |
| 2347 0xb4, 0xfc, 0x7c, 0x80, |
| 2348 0x00, 0x62, 0x60, 0x06, |
| 2349 0x13, 0x00, 0x01, 0x94, |
| 2350 0x94, 0x58, 0x04, 0x10, |
| 2351 0x40, 0x00, 0x00, 0x00, |
| 2352 0x00, 0xff, 0xff, |
| 2353 }; |
| 2354 const unsigned char kV3SIMDFrameData[] = { |
| 2355 0x80, spdy_version_ch_, 0x00, 0x02, |
| 2356 0x00, 0x00, 0x00, 0x2c, |
| 2357 0x00, 0x00, 0x00, 0x01, |
| 2358 0x38, 0xea, 0xe3, 0xc6, |
| 2359 0xa7, 0xc2, 0x02, 0xe5, |
| 2360 0x0e, 0x50, 0xc2, 0x4b, |
| 2361 0x4a, 0x04, 0xe5, 0x0b, |
| 2362 0x66, 0x80, 0x00, 0x4a, |
| 2363 0xcb, 0xcf, 0x07, 0x08, |
| 2364 0x20, 0x24, 0x0a, 0x20, |
| 2365 0x80, 0x92, 0x12, 0x8b, |
| 2366 0x00, 0x02, 0x08, 0x00, |
| 2367 0x00, 0x00, 0xff, 0xff, |
| 2368 }; |
| 2369 |
2283 SpdySynReplyIR syn_reply(1); | 2370 SpdySynReplyIR syn_reply(1); |
2284 syn_reply.SetHeader("bar", "foo"); | 2371 syn_reply.SetHeader("bar", "foo"); |
2285 syn_reply.SetHeader("foo", "bar"); | 2372 syn_reply.SetHeader("foo", "bar"); |
2286 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2373 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
| 2374 const unsigned char* frame_data = |
| 2375 reinterpret_cast<const unsigned char*>(frame->data()); |
2287 if (IsSpdy2()) { | 2376 if (IsSpdy2()) { |
2288 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2377 // Try comparing with SIMD version, if that fails, do a failing check |
| 2378 // with pretty printing against non-SIMD version |
| 2379 if (memcmp(frame_data, |
| 2380 kV2SIMDFrameData, |
| 2381 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { |
| 2382 CompareCharArraysWithHexError(kDescription, |
| 2383 frame_data, |
| 2384 frame->size(), |
| 2385 kV2FrameData, |
| 2386 arraysize(kV2FrameData)); |
| 2387 } |
2289 } else if (IsSpdy3()) { | 2388 } else if (IsSpdy3()) { |
2290 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2389 if (memcmp(frame_data, |
| 2390 kV3SIMDFrameData, |
| 2391 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { |
| 2392 CompareCharArraysWithHexError(kDescription, |
| 2393 frame_data, |
| 2394 frame->size(), |
| 2395 kV3FrameData, |
| 2396 arraysize(kV3FrameData)); |
| 2397 } |
2291 } else { | 2398 } else { |
2292 LOG(FATAL) << "Unsupported version in test."; | 2399 LOG(FATAL) << "Unsupported version in test."; |
2293 } | 2400 } |
2294 } | 2401 } |
2295 } | 2402 } |
2296 #endif // !defined(USE_SYSTEM_ZLIB) | 2403 #endif // !defined(USE_SYSTEM_ZLIB) |
2297 | 2404 |
2298 TEST_P(SpdyFramerTest, CreateRstStream) { | 2405 TEST_P(SpdyFramerTest, CreateRstStream) { |
2299 SpdyFramer framer(spdy_version_); | 2406 SpdyFramer framer(spdy_version_); |
2300 | 2407 |
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2879 0x4a, 0x04, 0xe5, 0x0b, | 2986 0x4a, 0x04, 0xe5, 0x0b, |
2880 0x66, 0x80, 0x00, 0x4a, | 2987 0x66, 0x80, 0x00, 0x4a, |
2881 0xcb, 0xcf, 0x07, 0x08, | 2988 0xcb, 0xcf, 0x07, 0x08, |
2882 0x20, 0x10, 0x95, 0x96, | 2989 0x20, 0x10, 0x95, 0x96, |
2883 0x9f, 0x0f, 0xa2, 0x00, | 2990 0x9f, 0x0f, 0xa2, 0x00, |
2884 0x02, 0x28, 0x29, 0xb1, | 2991 0x02, 0x28, 0x29, 0xb1, |
2885 0x08, 0x20, 0x80, 0x00, | 2992 0x08, 0x20, 0x80, 0x00, |
2886 0x00, 0x00, 0x00, 0xff, | 2993 0x00, 0x00, 0x00, 0xff, |
2887 0xff, | 2994 0xff, |
2888 }; | 2995 }; |
| 2996 const unsigned char kV2SIMDFrameData[] = { |
| 2997 0x80, spdy_version_ch_, 0x00, 0x08, |
| 2998 0x00, 0x00, 0x00, 0x2f, |
| 2999 0x00, 0x00, 0x00, 0x01, |
| 3000 0x00, 0x00, 0x38, 0xea, |
| 3001 0xdf, 0xa2, 0x51, 0xb2, |
| 3002 0x62, 0x60, 0x62, 0x60, |
| 3003 0x4e, 0x4a, 0x2c, 0x62, |
| 3004 0x60, 0x06, 0x08, 0xa0, |
| 3005 0xb4, 0xfc, 0x7c, 0x80, |
| 3006 0x00, 0x62, 0x60, 0x06, |
| 3007 0x13, 0x00, 0x01, 0x94, |
| 3008 0x94, 0x58, 0x04, 0x10, |
| 3009 0x40, 0x00, 0x00, 0x00, |
| 3010 0x00, 0xff, 0xff, |
| 3011 }; |
| 3012 const unsigned char kV3SIMDFrameData[] = { |
| 3013 0x80, spdy_version_ch_, 0x00, 0x08, |
| 3014 0x00, 0x00, 0x00, 0x2c, |
| 3015 0x00, 0x00, 0x00, 0x01, |
| 3016 0x38, 0xea, 0xe3, 0xc6, |
| 3017 0xa7, 0xc2, 0x02, 0xe5, |
| 3018 0x0e, 0x50, 0xc2, 0x4b, |
| 3019 0x4a, 0x04, 0xe5, 0x0b, |
| 3020 0x66, 0x80, 0x00, 0x4a, |
| 3021 0xcb, 0xcf, 0x07, 0x08, |
| 3022 0x20, 0x24, 0x0a, 0x20, |
| 3023 0x80, 0x92, 0x12, 0x8b, |
| 3024 0x00, 0x02, 0x08, 0x00, |
| 3025 0x00, 0x00, 0xff, 0xff, |
| 3026 }; |
| 3027 |
2889 SpdyHeadersIR headers_ir(1); | 3028 SpdyHeadersIR headers_ir(1); |
2890 headers_ir.SetHeader("bar", "foo"); | 3029 headers_ir.SetHeader("bar", "foo"); |
2891 headers_ir.SetHeader("foo", "bar"); | 3030 headers_ir.SetHeader("foo", "bar"); |
2892 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 3031 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 3032 const unsigned char* frame_data = |
| 3033 reinterpret_cast<const unsigned char*>(frame->data()); |
2893 if (IsSpdy2()) { | 3034 if (IsSpdy2()) { |
2894 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 3035 // Try comparing with SIMD version, if that fails, do a failing check |
| 3036 // with pretty printing against non-SIMD version |
| 3037 if (memcmp(frame_data, |
| 3038 kV2SIMDFrameData, |
| 3039 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { |
| 3040 CompareCharArraysWithHexError(kDescription, |
| 3041 frame_data, |
| 3042 frame->size(), |
| 3043 kV2FrameData, |
| 3044 arraysize(kV2FrameData)); |
| 3045 } |
2895 } else if (IsSpdy3()) { | 3046 } else if (IsSpdy3()) { |
2896 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 3047 if (memcmp(frame_data, |
| 3048 kV3SIMDFrameData, |
| 3049 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { |
| 3050 CompareCharArraysWithHexError(kDescription, |
| 3051 frame_data, |
| 3052 frame->size(), |
| 3053 kV3FrameData, |
| 3054 arraysize(kV3FrameData)); |
| 3055 } |
2897 } else { | 3056 } else { |
2898 // Deflate compression doesn't apply to HPACK. | 3057 // Deflate compression doesn't apply to HPACK. |
2899 } | 3058 } |
2900 } | 3059 } |
2901 } | 3060 } |
2902 #endif // !defined(USE_SYSTEM_ZLIB) | 3061 #endif // !defined(USE_SYSTEM_ZLIB) |
2903 | 3062 |
2904 TEST_P(SpdyFramerTest, CreateWindowUpdate) { | 3063 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
2905 SpdyFramer framer(spdy_version_); | 3064 SpdyFramer framer(spdy_version_); |
2906 | 3065 |
(...skipping 2849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5756 TestSpdyVisitor visitor(spdy_version_); | 5915 TestSpdyVisitor visitor(spdy_version_); |
5757 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5916 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
5758 | 5917 |
5759 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5918 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
5760 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5919 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
5761 visitor.framer_.error_code()) | 5920 visitor.framer_.error_code()) |
5762 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5921 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
5763 } | 5922 } |
5764 | 5923 |
5765 } // namespace net | 5924 } // namespace net |
OLD | NEW |