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 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2032 if (!IsSpdy2() && !IsSpdy3()) { | 2032 if (!IsSpdy2() && !IsSpdy3()) { |
2033 // SYN_STREAM not supported for SPDY>3 | 2033 // SYN_STREAM not supported for SPDY>3 |
2034 return; | 2034 return; |
2035 } | 2035 } |
2036 SpdyFramer framer(spdy_version_); | 2036 SpdyFramer framer(spdy_version_); |
2037 framer.set_enable_compression(true); | 2037 framer.set_enable_compression(true); |
2038 | 2038 |
2039 { | 2039 { |
2040 const char kDescription[] = | 2040 const char kDescription[] = |
2041 "SYN_STREAM frame, low pri, no FIN"; | 2041 "SYN_STREAM frame, low pri, no FIN"; |
| 2042 |
2042 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | 2043 const SpdyPriority priority = IsSpdy2() ? 2 : 4; |
2043 | |
2044 const unsigned char kV2FrameData[] = { | 2044 const unsigned char kV2FrameData[] = { |
2045 0x80, spdy_version_ch_, 0x00, 0x01, | 2045 0x80, spdy_version_ch_, 0x00, 0x01, |
2046 0x00, 0x00, 0x00, 0x36, | 2046 0x00, 0x00, 0x00, 0x36, |
2047 0x00, 0x00, 0x00, 0x01, | 2047 0x00, 0x00, 0x00, 0x01, |
2048 0x00, 0x00, 0x00, 0x00, | 2048 0x00, 0x00, 0x00, 0x00, |
2049 0x80, 0x00, 0x38, 0xea, | 2049 0x80, 0x00, 0x38, 0xea, |
2050 0xdf, 0xa2, 0x51, 0xb2, | 2050 0xdf, 0xa2, 0x51, 0xb2, |
2051 0x62, 0x60, 0x62, 0x60, | 2051 0x62, 0x60, 0x62, 0x60, |
2052 0x4e, 0x4a, 0x2c, 0x62, | 2052 0x4e, 0x4a, 0x2c, 0x62, |
2053 0x60, 0x06, 0x08, 0xa0, | 2053 0x60, 0x06, 0x08, 0xa0, |
(...skipping 16 matching lines...) Expand all Loading... |
2070 0xC2, 0x4B, 0x4A, 0x04, | 2070 0xC2, 0x4B, 0x4A, 0x04, |
2071 0xE5, 0x0B, 0x66, 0x80, | 2071 0xE5, 0x0B, 0x66, 0x80, |
2072 0x00, 0x4A, 0xCB, 0xCF, | 2072 0x00, 0x4A, 0xCB, 0xCF, |
2073 0x07, 0x08, 0x20, 0x10, | 2073 0x07, 0x08, 0x20, 0x10, |
2074 0x95, 0x96, 0x9F, 0x0F, | 2074 0x95, 0x96, 0x9F, 0x0F, |
2075 0xA2, 0x00, 0x02, 0x28, | 2075 0xA2, 0x00, 0x02, 0x28, |
2076 0x29, 0xB1, 0x08, 0x20, | 2076 0x29, 0xB1, 0x08, 0x20, |
2077 0x80, 0x00, 0x00, 0x00, | 2077 0x80, 0x00, 0x00, 0x00, |
2078 0x00, 0xFF, 0xFF, | 2078 0x00, 0xFF, 0xFF, |
2079 }; | 2079 }; |
2080 const unsigned char kV2SIMDFrameData[] = { | |
2081 0x80, spdy_version_ch_, 0x00, 0x01, | |
2082 0x00, 0x00, 0x00, 0x33, | |
2083 0x00, 0x00, 0x00, 0x01, | |
2084 0x00, 0x00, 0x00, 0x00, | |
2085 0x80, 0x00, 0x38, 0xea, | |
2086 0xdf, 0xa2, 0x51, 0xb2, | |
2087 0x62, 0x60, 0x62, 0x60, | |
2088 0x4e, 0x4a, 0x2c, 0x62, | |
2089 0x60, 0x06, 0x08, 0xa0, | |
2090 0xb4, 0xfc, 0x7c, 0x80, | |
2091 0x00, 0x62, 0x60, 0x06, | |
2092 0x13, 0x00, 0x01, 0x94, | |
2093 0x94, 0x58, 0x04, 0x10, | |
2094 0x40, 0x00, 0x00, 0x00, | |
2095 0x00, 0xff, 0xff, | |
2096 }; | |
2097 const unsigned char kV3SIMDFrameData[] = { | |
2098 0x80, spdy_version_ch_, 0x00, 0x01, | |
2099 0x00, 0x00, 0x00, 0x32, | |
2100 0x00, 0x00, 0x00, 0x01, | |
2101 0x00, 0x00, 0x00, 0x00, | |
2102 0x80, 0x00, 0x38, 0xea, | |
2103 0xe3, 0xc6, 0xa7, 0xc2, | |
2104 0x02, 0xe5, 0x0e, 0x50, | |
2105 0xc2, 0x4b, 0x4a, 0x04, | |
2106 0xe5, 0x0b, 0x66, 0x80, | |
2107 0x00, 0x4a, 0xcb, 0xcf, | |
2108 0x07, 0x08, 0x20, 0x24, | |
2109 0x0a, 0x20, 0x80, 0x92, | |
2110 0x12, 0x8b, 0x00, 0x02, | |
2111 0x08, 0x00, 0x00, 0x00, | |
2112 0xff, 0xff, | |
2113 }; | |
2114 | |
2115 SpdySynStreamIR syn_stream(1); | 2080 SpdySynStreamIR syn_stream(1); |
2116 syn_stream.set_priority(priority); | 2081 syn_stream.set_priority(priority); |
2117 syn_stream.SetHeader("bar", "foo"); | 2082 syn_stream.SetHeader("bar", "foo"); |
2118 syn_stream.SetHeader("foo", "bar"); | 2083 syn_stream.SetHeader("foo", "bar"); |
2119 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 2084 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
2120 const unsigned char* frame_data = | |
2121 reinterpret_cast<const unsigned char*>(frame->data()); | |
2122 if (IsSpdy2()) { | 2085 if (IsSpdy2()) { |
2123 // Try comparing with SIMD version, if that fails, do a failing check | 2086 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2124 // with pretty printing against non-SIMD version | |
2125 if (memcmp(frame_data, | |
2126 kV2SIMDFrameData, | |
2127 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { | |
2128 CompareCharArraysWithHexError(kDescription, | |
2129 frame_data, | |
2130 frame->size(), | |
2131 kV2FrameData, | |
2132 arraysize(kV2FrameData)); | |
2133 } | |
2134 } else if (IsSpdy3()) { | 2087 } else if (IsSpdy3()) { |
2135 if (memcmp(frame_data, | 2088 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2136 kV3SIMDFrameData, | |
2137 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { | |
2138 CompareCharArraysWithHexError(kDescription, | |
2139 frame_data, | |
2140 frame->size(), | |
2141 kV3FrameData, | |
2142 arraysize(kV3FrameData)); | |
2143 } | |
2144 } else { | 2089 } else { |
2145 LOG(FATAL) << "Unsupported version in test."; | 2090 LOG(FATAL) << "Unsupported version in test."; |
2146 } | 2091 } |
2147 } | 2092 } |
2148 } | 2093 } |
2149 #endif // !defined(USE_SYSTEM_ZLIB) | 2094 #endif // !defined(USE_SYSTEM_ZLIB) |
2150 | 2095 |
2151 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | 2096 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
2152 if (spdy_version_ > SPDY3) { | 2097 if (spdy_version_ > SPDY3) { |
2153 // SYN_REPLY unsupported in SPDY>3 | 2098 // SYN_REPLY unsupported in SPDY>3 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2322 0x4a, 0x04, 0xe5, 0x0b, | 2267 0x4a, 0x04, 0xe5, 0x0b, |
2323 0x66, 0x80, 0x00, 0x4a, | 2268 0x66, 0x80, 0x00, 0x4a, |
2324 0xcb, 0xcf, 0x07, 0x08, | 2269 0xcb, 0xcf, 0x07, 0x08, |
2325 0x20, 0x10, 0x95, 0x96, | 2270 0x20, 0x10, 0x95, 0x96, |
2326 0x9f, 0x0f, 0xa2, 0x00, | 2271 0x9f, 0x0f, 0xa2, 0x00, |
2327 0x02, 0x28, 0x29, 0xb1, | 2272 0x02, 0x28, 0x29, 0xb1, |
2328 0x08, 0x20, 0x80, 0x00, | 2273 0x08, 0x20, 0x80, 0x00, |
2329 0x00, 0x00, 0x00, 0xff, | 2274 0x00, 0x00, 0x00, 0xff, |
2330 0xff, | 2275 0xff, |
2331 }; | 2276 }; |
2332 const unsigned char kV2SIMDFrameData[] = { | |
2333 0x80, spdy_version_ch_, 0x00, 0x02, | |
2334 0x00, 0x00, 0x00, 0x2f, | |
2335 0x00, 0x00, 0x00, 0x01, | |
2336 0x00, 0x00, 0x38, 0xea, | |
2337 0xdf, 0xa2, 0x51, 0xb2, | |
2338 0x62, 0x60, 0x62, 0x60, | |
2339 0x4e, 0x4a, 0x2c, 0x62, | |
2340 0x60, 0x06, 0x08, 0xa0, | |
2341 0xb4, 0xfc, 0x7c, 0x80, | |
2342 0x00, 0x62, 0x60, 0x06, | |
2343 0x13, 0x00, 0x01, 0x94, | |
2344 0x94, 0x58, 0x04, 0x10, | |
2345 0x40, 0x00, 0x00, 0x00, | |
2346 0x00, 0xff, 0xff, | |
2347 }; | |
2348 const unsigned char kV3SIMDFrameData[] = { | |
2349 0x80, spdy_version_ch_, 0x00, 0x02, | |
2350 0x00, 0x00, 0x00, 0x2c, | |
2351 0x00, 0x00, 0x00, 0x01, | |
2352 0x38, 0xea, 0xe3, 0xc6, | |
2353 0xa7, 0xc2, 0x02, 0xe5, | |
2354 0x0e, 0x50, 0xc2, 0x4b, | |
2355 0x4a, 0x04, 0xe5, 0x0b, | |
2356 0x66, 0x80, 0x00, 0x4a, | |
2357 0xcb, 0xcf, 0x07, 0x08, | |
2358 0x20, 0x24, 0x0a, 0x20, | |
2359 0x80, 0x92, 0x12, 0x8b, | |
2360 0x00, 0x02, 0x08, 0x00, | |
2361 0x00, 0x00, 0xff, 0xff, | |
2362 }; | |
2363 | |
2364 SpdySynReplyIR syn_reply(1); | 2277 SpdySynReplyIR syn_reply(1); |
2365 syn_reply.SetHeader("bar", "foo"); | 2278 syn_reply.SetHeader("bar", "foo"); |
2366 syn_reply.SetHeader("foo", "bar"); | 2279 syn_reply.SetHeader("foo", "bar"); |
2367 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2280 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2368 const unsigned char* frame_data = | |
2369 reinterpret_cast<const unsigned char*>(frame->data()); | |
2370 if (IsSpdy2()) { | 2281 if (IsSpdy2()) { |
2371 // Try comparing with SIMD version, if that fails, do a failing check | 2282 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2372 // with pretty printing against non-SIMD version | |
2373 if (memcmp(frame_data, | |
2374 kV2SIMDFrameData, | |
2375 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { | |
2376 CompareCharArraysWithHexError(kDescription, | |
2377 frame_data, | |
2378 frame->size(), | |
2379 kV2FrameData, | |
2380 arraysize(kV2FrameData)); | |
2381 } | |
2382 } else if (IsSpdy3()) { | 2283 } else if (IsSpdy3()) { |
2383 if (memcmp(frame_data, | 2284 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2384 kV3SIMDFrameData, | |
2385 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { | |
2386 CompareCharArraysWithHexError(kDescription, | |
2387 frame_data, | |
2388 frame->size(), | |
2389 kV3FrameData, | |
2390 arraysize(kV3FrameData)); | |
2391 } | |
2392 } else { | 2285 } else { |
2393 LOG(FATAL) << "Unsupported version in test."; | 2286 LOG(FATAL) << "Unsupported version in test."; |
2394 } | 2287 } |
2395 } | 2288 } |
2396 } | 2289 } |
2397 #endif // !defined(USE_SYSTEM_ZLIB) | 2290 #endif // !defined(USE_SYSTEM_ZLIB) |
2398 | 2291 |
2399 TEST_P(SpdyFramerTest, CreateRstStream) { | 2292 TEST_P(SpdyFramerTest, CreateRstStream) { |
2400 SpdyFramer framer(spdy_version_); | 2293 SpdyFramer framer(spdy_version_); |
2401 | 2294 |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2951 0x4a, 0x04, 0xe5, 0x0b, | 2844 0x4a, 0x04, 0xe5, 0x0b, |
2952 0x66, 0x80, 0x00, 0x4a, | 2845 0x66, 0x80, 0x00, 0x4a, |
2953 0xcb, 0xcf, 0x07, 0x08, | 2846 0xcb, 0xcf, 0x07, 0x08, |
2954 0x20, 0x10, 0x95, 0x96, | 2847 0x20, 0x10, 0x95, 0x96, |
2955 0x9f, 0x0f, 0xa2, 0x00, | 2848 0x9f, 0x0f, 0xa2, 0x00, |
2956 0x02, 0x28, 0x29, 0xb1, | 2849 0x02, 0x28, 0x29, 0xb1, |
2957 0x08, 0x20, 0x80, 0x00, | 2850 0x08, 0x20, 0x80, 0x00, |
2958 0x00, 0x00, 0x00, 0xff, | 2851 0x00, 0x00, 0x00, 0xff, |
2959 0xff, | 2852 0xff, |
2960 }; | 2853 }; |
2961 const unsigned char kV2SIMDFrameData[] = { | |
2962 0x80, spdy_version_ch_, 0x00, 0x08, | |
2963 0x00, 0x00, 0x00, 0x2f, | |
2964 0x00, 0x00, 0x00, 0x01, | |
2965 0x00, 0x00, 0x38, 0xea, | |
2966 0xdf, 0xa2, 0x51, 0xb2, | |
2967 0x62, 0x60, 0x62, 0x60, | |
2968 0x4e, 0x4a, 0x2c, 0x62, | |
2969 0x60, 0x06, 0x08, 0xa0, | |
2970 0xb4, 0xfc, 0x7c, 0x80, | |
2971 0x00, 0x62, 0x60, 0x06, | |
2972 0x13, 0x00, 0x01, 0x94, | |
2973 0x94, 0x58, 0x04, 0x10, | |
2974 0x40, 0x00, 0x00, 0x00, | |
2975 0x00, 0xff, 0xff, | |
2976 }; | |
2977 const unsigned char kV3SIMDFrameData[] = { | |
2978 0x80, spdy_version_ch_, 0x00, 0x08, | |
2979 0x00, 0x00, 0x00, 0x2c, | |
2980 0x00, 0x00, 0x00, 0x01, | |
2981 0x38, 0xea, 0xe3, 0xc6, | |
2982 0xa7, 0xc2, 0x02, 0xe5, | |
2983 0x0e, 0x50, 0xc2, 0x4b, | |
2984 0x4a, 0x04, 0xe5, 0x0b, | |
2985 0x66, 0x80, 0x00, 0x4a, | |
2986 0xcb, 0xcf, 0x07, 0x08, | |
2987 0x20, 0x24, 0x0a, 0x20, | |
2988 0x80, 0x92, 0x12, 0x8b, | |
2989 0x00, 0x02, 0x08, 0x00, | |
2990 0x00, 0x00, 0xff, 0xff, | |
2991 }; | |
2992 | |
2993 SpdyHeadersIR headers_ir(1); | 2854 SpdyHeadersIR headers_ir(1); |
2994 headers_ir.SetHeader("bar", "foo"); | 2855 headers_ir.SetHeader("bar", "foo"); |
2995 headers_ir.SetHeader("foo", "bar"); | 2856 headers_ir.SetHeader("foo", "bar"); |
2996 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2857 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2997 const unsigned char* frame_data = | |
2998 reinterpret_cast<const unsigned char*>(frame->data()); | |
2999 if (IsSpdy2()) { | 2858 if (IsSpdy2()) { |
3000 // Try comparing with SIMD version, if that fails, do a failing check | 2859 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
3001 // with pretty printing against non-SIMD version | |
3002 if (memcmp(frame_data, | |
3003 kV2SIMDFrameData, | |
3004 std::min(arraysize(kV2SIMDFrameData), frame->size())) != 0) { | |
3005 CompareCharArraysWithHexError(kDescription, | |
3006 frame_data, | |
3007 frame->size(), | |
3008 kV2FrameData, | |
3009 arraysize(kV2FrameData)); | |
3010 } | |
3011 } else if (IsSpdy3()) { | 2860 } else if (IsSpdy3()) { |
3012 if (memcmp(frame_data, | 2861 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
3013 kV3SIMDFrameData, | |
3014 std::min(arraysize(kV3SIMDFrameData), frame->size())) != 0) { | |
3015 CompareCharArraysWithHexError(kDescription, | |
3016 frame_data, | |
3017 frame->size(), | |
3018 kV3FrameData, | |
3019 arraysize(kV3FrameData)); | |
3020 } | |
3021 } else { | 2862 } else { |
3022 // Deflate compression doesn't apply to HPACK. | 2863 // Deflate compression doesn't apply to HPACK. |
3023 } | 2864 } |
3024 } | 2865 } |
3025 } | 2866 } |
3026 #endif // !defined(USE_SYSTEM_ZLIB) | 2867 #endif // !defined(USE_SYSTEM_ZLIB) |
3027 | 2868 |
3028 TEST_P(SpdyFramerTest, CreateWindowUpdate) { | 2869 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
3029 SpdyFramer framer(spdy_version_); | 2870 SpdyFramer framer(spdy_version_); |
3030 | 2871 |
(...skipping 2667 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5698 TestSpdyVisitor visitor(spdy_version_); | 5539 TestSpdyVisitor visitor(spdy_version_); |
5699 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5540 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
5700 | 5541 |
5701 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5542 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
5702 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5543 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
5703 visitor.framer_.error_code()) | 5544 visitor.framer_.error_code()) |
5704 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5545 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
5705 } | 5546 } |
5706 | 5547 |
5707 } // namespace net | 5548 } // namespace net |
OLD | NEW |