Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: net/spdy/spdy_framer_test.cc

Issue 243643002: Refactor RST_STREAM status code handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Expanded FRAME_TOO_LARGE/FRAME_SIZE_ERROR comment. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3915 matching lines...) Expand 10 before | Expand all | Expand 10 after
3926 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); 3926 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM));
3927 EXPECT_STREQ("UNSUPPORTED_VERSION", 3927 EXPECT_STREQ("UNSUPPORTED_VERSION",
3928 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); 3928 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION));
3929 EXPECT_STREQ("CANCEL", 3929 EXPECT_STREQ("CANCEL",
3930 SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); 3930 SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL));
3931 EXPECT_STREQ("INTERNAL_ERROR", 3931 EXPECT_STREQ("INTERNAL_ERROR",
3932 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); 3932 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR));
3933 EXPECT_STREQ("FLOW_CONTROL_ERROR", 3933 EXPECT_STREQ("FLOW_CONTROL_ERROR",
3934 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); 3934 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR));
3935 EXPECT_STREQ("UNKNOWN_STATUS", 3935 EXPECT_STREQ("UNKNOWN_STATUS",
3936 SpdyFramer::StatusCodeToString(RST_STREAM_NUM_STATUS_CODES)); 3936 SpdyFramer::StatusCodeToString(-1));
3937 } 3937 }
3938 3938
3939 TEST_P(SpdyFramerTest, FrameTypeToStringTest) { 3939 TEST_P(SpdyFramerTest, FrameTypeToStringTest) {
3940 EXPECT_STREQ("DATA", 3940 EXPECT_STREQ("DATA",
3941 SpdyFramer::FrameTypeToString(DATA)); 3941 SpdyFramer::FrameTypeToString(DATA));
3942 EXPECT_STREQ("SYN_STREAM", 3942 EXPECT_STREQ("SYN_STREAM",
3943 SpdyFramer::FrameTypeToString(SYN_STREAM)); 3943 SpdyFramer::FrameTypeToString(SYN_STREAM));
3944 EXPECT_STREQ("SYN_REPLY", 3944 EXPECT_STREQ("SYN_REPLY",
3945 SpdyFramer::FrameTypeToString(SYN_REPLY)); 3945 SpdyFramer::FrameTypeToString(SYN_REPLY));
3946 EXPECT_STREQ("RST_STREAM", 3946 EXPECT_STREQ("RST_STREAM",
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
4616 4616
4617 SettingsFlagsAndId id_and_flags = 4617 SettingsFlagsAndId id_and_flags =
4618 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); 4618 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat);
4619 EXPECT_EQ(kId, id_and_flags.id()); 4619 EXPECT_EQ(kId, id_and_flags.id());
4620 EXPECT_EQ(kFlags, id_and_flags.flags()); 4620 EXPECT_EQ(kFlags, id_and_flags.flags());
4621 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); 4621 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_));
4622 } 4622 }
4623 4623
4624 // Test handling of a RST_STREAM with out-of-bounds status codes. 4624 // Test handling of a RST_STREAM with out-of-bounds status codes.
4625 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { 4625 TEST_P(SpdyFramerTest, RstStreamStatusBounds) {
4626 DCHECK_GE(0xff, RST_STREAM_NUM_STATUS_CODES); 4626 const unsigned char kRstStreamStatusTooLow = 0x00;
4627 4627 const unsigned char kRstStreamStatusTooHigh = 0xff;
4628 const unsigned char kV3RstStreamInvalid[] = { 4628 const unsigned char kV3RstStreamInvalid[] = {
4629 0x80, spdy_version_ch_, 0x00, 0x03, 4629 0x80, spdy_version_ch_, 0x00, 0x03,
4630 0x00, 0x00, 0x00, 0x08, 4630 0x00, 0x00, 0x00, 0x08,
4631 0x00, 0x00, 0x00, 0x01, 4631 0x00, 0x00, 0x00, 0x01,
4632 0x00, 0x00, 0x00, RST_STREAM_INVALID 4632 0x00, 0x00, 0x00, kRstStreamStatusTooLow
4633 }; 4633 };
4634 const unsigned char kV4RstStreamInvalid[] = { 4634 const unsigned char kV4RstStreamInvalid[] = {
4635 0x00, 0x04, 0x03, 0x00, 4635 0x00, 0x04, 0x03, 0x00,
4636 0x00, 0x00, 0x00, 0x01, 4636 0x00, 0x00, 0x00, 0x01,
4637 0x00, 0x00, 0x00, RST_STREAM_INVALID 4637 0x00, 0x00, 0x00, kRstStreamStatusTooLow
4638 }; 4638 };
4639 4639
4640 const unsigned char kV3RstStreamNumStatusCodes[] = { 4640 const unsigned char kV3RstStreamNumStatusCodes[] = {
4641 0x80, spdy_version_ch_, 0x00, 0x03, 4641 0x80, spdy_version_ch_, 0x00, 0x03,
4642 0x00, 0x00, 0x00, 0x08, 4642 0x00, 0x00, 0x00, 0x08,
4643 0x00, 0x00, 0x00, 0x01, 4643 0x00, 0x00, 0x00, 0x01,
4644 0x00, 0x00, 0x00, RST_STREAM_NUM_STATUS_CODES 4644 0x00, 0x00, 0x00, kRstStreamStatusTooHigh
4645 }; 4645 };
4646 const unsigned char kV4RstStreamNumStatusCodes[] = { 4646 const unsigned char kV4RstStreamNumStatusCodes[] = {
4647 0x00, 0x04, 0x03, 0x00, 4647 0x00, 0x04, 0x03, 0x00,
4648 0x00, 0x00, 0x00, 0x01, 4648 0x00, 0x00, 0x00, 0x01,
4649 0x00, 0x00, 0x00, RST_STREAM_NUM_STATUS_CODES 4649 0x00, 0x00, 0x00, kRstStreamStatusTooHigh
4650 }; 4650 };
4651 4651
4652 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4652 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
4653 SpdyFramer framer(spdy_version_); 4653 SpdyFramer framer(spdy_version_);
4654 framer.set_visitor(&visitor); 4654 framer.set_visitor(&visitor);
4655 4655
4656 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); 4656 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID));
4657 if (IsSpdy4()) { 4657 if (IsSpdy4()) {
4658 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), 4658 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid),
4659 arraysize(kV4RstStreamInvalid)); 4659 arraysize(kV4RstStreamInvalid));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
4736 SpdyBlockedIR blocked_ir(0); 4736 SpdyBlockedIR blocked_ir(0);
4737 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); 4737 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir));
4738 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); 4738 framer.ProcessInput(frame->data(), framer.GetBlockedSize());
4739 4739
4740 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4740 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4741 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4741 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4742 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4742 << SpdyFramer::ErrorCodeToString(framer.error_code());
4743 } 4743 }
4744 4744
4745 } // namespace net 4745 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698