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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 reinterpret_cast<unsigned char*>(frame->data()), | 684 reinterpret_cast<unsigned char*>(frame->data()), |
685 frame->size() - 2); | 685 frame->size() - 2); |
686 | 686 |
687 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 687 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
688 EXPECT_EQ(0u, visitor.headers_.size()); | 688 EXPECT_EQ(0u, visitor.headers_.size()); |
689 } | 689 } |
690 | 690 |
691 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error | 691 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error |
692 // (but don't crash). | 692 // (but don't crash). |
693 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { | 693 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { |
| 694 if (spdy_version_ > SPDY3) { |
| 695 return; |
| 696 } |
694 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 697 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
695 SpdyFramer framer(spdy_version_); | 698 SpdyFramer framer(spdy_version_); |
696 framer.set_visitor(&visitor); | 699 framer.set_visitor(&visitor); |
697 | 700 |
698 SpdySynReplyIR syn_reply(0); | 701 SpdySynReplyIR syn_reply(0); |
699 syn_reply.SetHeader("alpha", "beta"); | 702 syn_reply.SetHeader("alpha", "beta"); |
700 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeSynReply(syn_reply)); | 703 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeSynReply(syn_reply)); |
701 ASSERT_TRUE(frame.get() != NULL); | 704 ASSERT_TRUE(frame.get() != NULL); |
702 | 705 |
703 // We shouldn't have to read the whole frame before we signal an error. | 706 // We shouldn't have to read the whole frame before we signal an error. |
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2072 } else if (IsSpdy3()) { | 2075 } else if (IsSpdy3()) { |
2073 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2076 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2074 } else { | 2077 } else { |
2075 // Deflate compression doesn't apply to HPACK. | 2078 // Deflate compression doesn't apply to HPACK. |
2076 } | 2079 } |
2077 } | 2080 } |
2078 } | 2081 } |
2079 #endif // !defined(USE_SYSTEM_ZLIB) | 2082 #endif // !defined(USE_SYSTEM_ZLIB) |
2080 | 2083 |
2081 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | 2084 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
| 2085 if (spdy_version_ > SPDY3) { |
| 2086 return; |
| 2087 } |
2082 SpdyFramer framer(spdy_version_); | 2088 SpdyFramer framer(spdy_version_); |
2083 framer.set_enable_compression(false); | 2089 framer.set_enable_compression(false); |
2084 | 2090 |
2085 { | 2091 { |
2086 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 2092 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2087 | 2093 |
2088 const unsigned char kV2FrameData[] = { | 2094 const unsigned char kV2FrameData[] = { |
2089 0x80, spdy_version_ch_, 0x00, 0x02, | 2095 0x80, spdy_version_ch_, 0x00, 0x02, |
2090 0x00, 0x00, 0x00, 0x1C, | 2096 0x00, 0x00, 0x00, 0x1C, |
2091 0x00, 0x00, 0x00, 0x01, | 2097 0x00, 0x00, 0x00, 0x01, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 } else { | 2235 } else { |
2230 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2236 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2231 } | 2237 } |
2232 } | 2238 } |
2233 } | 2239 } |
2234 | 2240 |
2235 // TODO(phajdan.jr): Clean up after we no longer need | 2241 // TODO(phajdan.jr): Clean up after we no longer need |
2236 // to workaround http://crbug.com/139744. | 2242 // to workaround http://crbug.com/139744. |
2237 #if !defined(USE_SYSTEM_ZLIB) | 2243 #if !defined(USE_SYSTEM_ZLIB) |
2238 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { | 2244 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { |
| 2245 if (spdy_version_ > SPDY3) { |
| 2246 return; |
| 2247 } |
2239 SpdyFramer framer(spdy_version_); | 2248 SpdyFramer framer(spdy_version_); |
2240 framer.set_enable_compression(true); | 2249 framer.set_enable_compression(true); |
2241 | 2250 |
2242 { | 2251 { |
2243 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 2252 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2244 | 2253 |
2245 const unsigned char kV2FrameData[] = { | 2254 const unsigned char kV2FrameData[] = { |
2246 0x80, spdy_version_ch_, 0x00, 0x02, | 2255 0x80, spdy_version_ch_, 0x00, 0x02, |
2247 0x00, 0x00, 0x00, 0x32, | 2256 0x00, 0x00, 0x00, 0x32, |
2248 0x00, 0x00, 0x00, 0x01, | 2257 0x00, 0x00, 0x00, 0x01, |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3013 TestSpdyVisitor visitor(spdy_version_); | 3022 TestSpdyVisitor visitor(spdy_version_); |
3014 visitor.use_compression_ = true; | 3023 visitor.use_compression_ = true; |
3015 visitor.SimulateInFramer( | 3024 visitor.SimulateInFramer( |
3016 reinterpret_cast<unsigned char*>(control_frame->data()), | 3025 reinterpret_cast<unsigned char*>(control_frame->data()), |
3017 control_frame->size()); | 3026 control_frame->size()); |
3018 EXPECT_EQ(1, visitor.syn_frame_count_); | 3027 EXPECT_EQ(1, visitor.syn_frame_count_); |
3019 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3028 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
3020 } | 3029 } |
3021 | 3030 |
3022 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { | 3031 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { |
| 3032 if (spdy_version_ > SPDY3) { |
| 3033 return; |
| 3034 } |
3023 SpdyFramer framer(spdy_version_); | 3035 SpdyFramer framer(spdy_version_); |
3024 SpdySynReplyIR syn_reply(1); | 3036 SpdySynReplyIR syn_reply(1); |
3025 syn_reply.SetHeader("alpha", "beta"); | 3037 syn_reply.SetHeader("alpha", "beta"); |
3026 syn_reply.SetHeader("gamma", "delta"); | 3038 syn_reply.SetHeader("gamma", "delta"); |
3027 SpdyHeaderBlock headers = syn_reply.name_value_block(); | 3039 SpdyHeaderBlock headers = syn_reply.name_value_block(); |
3028 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynReply(syn_reply)); | 3040 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynReply(syn_reply)); |
3029 EXPECT_TRUE(control_frame.get() != NULL); | 3041 EXPECT_TRUE(control_frame.get() != NULL); |
3030 TestSpdyVisitor visitor(spdy_version_); | 3042 TestSpdyVisitor visitor(spdy_version_); |
3031 visitor.use_compression_ = true; | 3043 visitor.use_compression_ = true; |
3032 visitor.SimulateInFramer( | 3044 visitor.SimulateInFramer( |
(...skipping 2390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5423 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); | 5435 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); |
5424 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); | 5436 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); |
5425 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); | 5437 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); |
5426 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); | 5438 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); |
5427 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); | 5439 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); |
5428 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); | 5440 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); |
5429 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); | 5441 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); |
5430 } | 5442 } |
5431 | 5443 |
5432 } // namespace net | 5444 } // namespace net |
OLD | NEW |