| 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 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 0x80, spdy_version_, 0x00, 0x07, | 2161 0x80, spdy_version_, 0x00, 0x07, |
| 2162 0x00, 0x00, 0x00, 0x04, | 2162 0x00, 0x00, 0x00, 0x04, |
| 2163 0x00, 0x00, 0x00, 0x00, | 2163 0x00, 0x00, 0x00, 0x00, |
| 2164 }; | 2164 }; |
| 2165 const unsigned char kV3FrameData[] = { | 2165 const unsigned char kV3FrameData[] = { |
| 2166 0x80, spdy_version_, 0x00, 0x07, | 2166 0x80, spdy_version_, 0x00, 0x07, |
| 2167 0x00, 0x00, 0x00, 0x08, | 2167 0x00, 0x00, 0x00, 0x08, |
| 2168 0x00, 0x00, 0x00, 0x00, | 2168 0x00, 0x00, 0x00, 0x00, |
| 2169 0x00, 0x00, 0x00, 0x00, | 2169 0x00, 0x00, 0x00, 0x00, |
| 2170 }; | 2170 }; |
| 2171 scoped_ptr<SpdyGoAwayControlFrame> frame(framer.CreateGoAway(0, GOAWAY_OK)); | 2171 scoped_ptr<SpdyFrame> frame(framer.CreateGoAway(0, GOAWAY_OK)); |
| 2172 CompareFrame(kDescription, | 2172 CompareFrame(kDescription, |
| 2173 *frame, | 2173 *frame, |
| 2174 IsSpdy2() ? kV2FrameData : kV3FrameData, | 2174 IsSpdy2() ? kV2FrameData : kV3FrameData, |
| 2175 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData)); | 2175 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData)); |
| 2176 } | 2176 } |
| 2177 | 2177 |
| 2178 { | 2178 { |
| 2179 const char kDescription[] = "GOAWAY frame with max stream ID, status"; | 2179 const char kDescription[] = "GOAWAY frame with max stream ID, status"; |
| 2180 const unsigned char kV2FrameData[] = { | 2180 const unsigned char kV2FrameData[] = { |
| 2181 0x80, spdy_version_, 0x00, 0x07, | 2181 0x80, spdy_version_, 0x00, 0x07, |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2459 control_frame->length() + SpdyControlFrame::kHeaderSize); | 2459 control_frame->length() + SpdyControlFrame::kHeaderSize); |
| 2460 EXPECT_EQ(1, visitor.syn_frame_count_); | 2460 EXPECT_EQ(1, visitor.syn_frame_count_); |
| 2461 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 2461 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 2462 } | 2462 } |
| 2463 | 2463 |
| 2464 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { | 2464 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { |
| 2465 SpdyHeaderBlock headers; | 2465 SpdyHeaderBlock headers; |
| 2466 headers["alpha"] = "beta"; | 2466 headers["alpha"] = "beta"; |
| 2467 headers["gamma"] = "delta"; | 2467 headers["gamma"] = "delta"; |
| 2468 SpdyFramer framer(spdy_version_); | 2468 SpdyFramer framer(spdy_version_); |
| 2469 scoped_ptr<SpdySynReplyControlFrame> control_frame( | 2469 scoped_ptr<SpdyFrame> control_frame( |
| 2470 framer.CreateSynReply(1, // stream_id | 2470 framer.CreateSynReply(1, // stream_id |
| 2471 CONTROL_FLAG_NONE, | 2471 CONTROL_FLAG_NONE, |
| 2472 true, // compress | 2472 true, // compress |
| 2473 &headers)); | 2473 &headers)); |
| 2474 EXPECT_TRUE(control_frame.get() != NULL); | 2474 EXPECT_TRUE(control_frame.get() != NULL); |
| 2475 TestSpdyVisitor visitor(spdy_version_); | 2475 TestSpdyVisitor visitor(spdy_version_); |
| 2476 visitor.use_compression_ = true; | 2476 visitor.use_compression_ = true; |
| 2477 visitor.SimulateInFramer( | 2477 visitor.SimulateInFramer( |
| 2478 reinterpret_cast<unsigned char*>(control_frame->data()), | 2478 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 2479 control_frame->length() + SpdyControlFrame::kHeaderSize); | 2479 control_frame->length() + SpdyControlFrame::kHeaderSize); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2673 reinterpret_cast<unsigned char*>(control_frame->data()), | 2673 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 2674 control_frame->length() + SpdyControlFrame::kHeaderSize); | 2674 control_frame->length() + SpdyControlFrame::kHeaderSize); |
| 2675 EXPECT_EQ(1, visitor.error_count_); | 2675 EXPECT_EQ(1, visitor.error_count_); |
| 2676 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()); | 2676 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()); |
| 2677 EXPECT_EQ(0u, visitor.header_buffer_length_); | 2677 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 2678 } | 2678 } |
| 2679 | 2679 |
| 2680 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { | 2680 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 2681 // Create a GoAway frame that has a few extra bytes at the end. | 2681 // Create a GoAway frame that has a few extra bytes at the end. |
| 2682 // We create enough overhead to overflow the framer's control frame buffer. | 2682 // We create enough overhead to overflow the framer's control frame buffer. |
| 2683 size_t overhead = SpdyFramer::kControlFrameBufferSize; | 2683 ASSERT_GE(254u, SpdyFramer::kControlFrameBufferSize); |
| 2684 const unsigned char length = 1 + SpdyFramer::kControlFrameBufferSize; |
| 2685 const unsigned char kV2FrameData[] = { |
| 2686 0x80, spdy_version_, 0x00, 0x07, |
| 2687 0x00, 0x00, 0x00, length, |
| 2688 0x00, 0x00, 0x00, 0x00, |
| 2689 }; |
| 2690 const unsigned char kV3FrameData[] = { |
| 2691 0x80, spdy_version_, 0x00, 0x07, |
| 2692 0x00, 0x00, 0x00, length, |
| 2693 0x00, 0x00, 0x00, 0x00, |
| 2694 0x00, 0x00, 0x00, 0x00, |
| 2695 }; |
| 2684 SpdyFramer framer(spdy_version_); | 2696 SpdyFramer framer(spdy_version_); |
| 2685 scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1, GOAWAY_OK)); | 2697 const size_t pad_length = length + SpdyFrame::kHeaderSize - |
| 2686 goaway->set_length(goaway->length() + overhead); | 2698 (IsSpdy2() ? sizeof(kV2FrameData) : sizeof(kV3FrameData)); |
| 2687 string pad('A', overhead); | 2699 string pad('A', pad_length); |
| 2688 TestSpdyVisitor visitor(spdy_version_); | 2700 TestSpdyVisitor visitor(spdy_version_); |
| 2689 | 2701 |
| 2690 visitor.SimulateInFramer( | 2702 if (IsSpdy2()) { |
| 2691 reinterpret_cast<unsigned char*>(goaway->data()), | 2703 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
| 2692 goaway->length() - overhead + SpdyControlFrame::kHeaderSize); | 2704 } else { |
| 2705 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 2706 } |
| 2693 visitor.SimulateInFramer( | 2707 visitor.SimulateInFramer( |
| 2694 reinterpret_cast<const unsigned char*>(pad.c_str()), | 2708 reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 2695 overhead); | 2709 pad.length()); |
| 2696 | 2710 |
| 2697 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2711 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
| 2698 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 2712 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 2699 visitor.framer_.error_code()); | 2713 visitor.framer_.error_code()); |
| 2700 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. | 2714 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. |
| 2701 } | 2715 } |
| 2702 | 2716 |
| 2703 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 2717 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 2704 SpdyFramer framer(spdy_version_); | 2718 SpdyFramer framer(spdy_version_); |
| 2705 SettingsMap settings; | 2719 SettingsMap settings; |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3535 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); | 3549 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); |
| 3536 | 3550 |
| 3537 SettingsFlagsAndId id_and_flags = | 3551 SettingsFlagsAndId id_and_flags = |
| 3538 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 3552 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
| 3539 EXPECT_EQ(kId, id_and_flags.id()); | 3553 EXPECT_EQ(kId, id_and_flags.id()); |
| 3540 EXPECT_EQ(kFlags, id_and_flags.flags()); | 3554 EXPECT_EQ(kFlags, id_and_flags.flags()); |
| 3541 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 3555 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
| 3542 } | 3556 } |
| 3543 | 3557 |
| 3544 } // namespace net | 3558 } // namespace net |
| OLD | NEW |