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 1997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2008 SpdyFramer framer(spdy_version_); | 2008 SpdyFramer framer(spdy_version_); |
2009 | 2009 |
2010 { | 2010 { |
2011 const char kDescription[] = "RST_STREAM frame"; | 2011 const char kDescription[] = "RST_STREAM frame"; |
2012 const unsigned char kFrameData[] = { | 2012 const unsigned char kFrameData[] = { |
2013 0x80, spdy_version_, 0x00, 0x03, | 2013 0x80, spdy_version_, 0x00, 0x03, |
2014 0x00, 0x00, 0x00, 0x08, | 2014 0x00, 0x00, 0x00, 0x08, |
2015 0x00, 0x00, 0x00, 0x01, | 2015 0x00, 0x00, 0x00, 0x01, |
2016 0x00, 0x00, 0x00, 0x01, | 2016 0x00, 0x00, 0x00, 0x01, |
2017 }; | 2017 }; |
2018 scoped_ptr<SpdyRstStreamControlFrame> frame( | 2018 scoped_ptr<SpdyFrame> frame( |
2019 framer.CreateRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 2019 framer.CreateRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
2020 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2020 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
2021 } | 2021 } |
2022 | 2022 |
2023 { | 2023 { |
2024 const char kDescription[] = "RST_STREAM frame with max stream ID"; | 2024 const char kDescription[] = "RST_STREAM frame with max stream ID"; |
2025 const unsigned char kFrameData[] = { | 2025 const unsigned char kFrameData[] = { |
2026 0x80, spdy_version_, 0x00, 0x03, | 2026 0x80, spdy_version_, 0x00, 0x03, |
2027 0x00, 0x00, 0x00, 0x08, | 2027 0x00, 0x00, 0x00, 0x08, |
2028 0x7f, 0xff, 0xff, 0xff, | 2028 0x7f, 0xff, 0xff, 0xff, |
(...skipping 1523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 const uint32 kFlags = 0x01; | 3552 const uint32 kFlags = 0x01; |
3553 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); | 3553 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304); |
3554 | 3554 |
3555 SettingsFlagsAndId id_and_flags = | 3555 SettingsFlagsAndId id_and_flags = |
3556 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 3556 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
3557 EXPECT_EQ(kId, id_and_flags.id()); | 3557 EXPECT_EQ(kId, id_and_flags.id()); |
3558 EXPECT_EQ(kFlags, id_and_flags.flags()); | 3558 EXPECT_EQ(kFlags, id_and_flags.flags()); |
3559 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 3559 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
3560 } | 3560 } |
3561 | 3561 |
| 3562 // Test handling of a RST_STREAM with out-of-bounds status codes. |
| 3563 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
| 3564 DCHECK_GE(0xff, RST_STREAM_NUM_STATUS_CODES); |
| 3565 |
| 3566 const unsigned char kRstStreamInvalid[] = { |
| 3567 0x80, spdy_version_, 0x00, 0x03, |
| 3568 0x00, 0x00, 0x00, 0x08, |
| 3569 0x00, 0x00, 0x00, 0x01, |
| 3570 0x00, 0x00, 0x00, RST_STREAM_INVALID |
| 3571 }; |
| 3572 |
| 3573 const unsigned char kRstStreamNumStatusCodes[] = { |
| 3574 0x80, spdy_version_, 0x00, 0x03, |
| 3575 0x00, 0x00, 0x00, 0x08, |
| 3576 0x00, 0x00, 0x00, 0x01, |
| 3577 0x00, 0x00, 0x00, RST_STREAM_NUM_STATUS_CODES |
| 3578 }; |
| 3579 |
| 3580 testing::StrictMock<net::test::MockVisitor> visitor; |
| 3581 SpdyFramer framer(spdy_version_); |
| 3582 framer.set_visitor(&visitor); |
| 3583 |
| 3584 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 3585 framer.ProcessInput(reinterpret_cast<const char*>(kRstStreamInvalid), |
| 3586 arraysize(kRstStreamInvalid)); |
| 3587 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 3588 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()); |
| 3589 |
| 3590 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 3591 framer.ProcessInput(reinterpret_cast<const char*>(kRstStreamNumStatusCodes), |
| 3592 arraysize(kRstStreamNumStatusCodes)); |
| 3593 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 3594 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()); |
| 3595 } |
| 3596 |
3562 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 3597 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
3563 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { | 3598 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
3564 const unsigned char kV2FrameData[] = { | 3599 const unsigned char kV2FrameData[] = { |
3565 0x80, spdy_version_, 0x00, 0x07, | 3600 0x80, spdy_version_, 0x00, 0x07, |
3566 0x00, 0x00, 0x00, 0x04, | 3601 0x00, 0x00, 0x00, 0x04, |
3567 0xff, 0xff, 0xff, 0xff, | 3602 0xff, 0xff, 0xff, 0xff, |
3568 }; | 3603 }; |
3569 const unsigned char kV3FrameData[] = { | 3604 const unsigned char kV3FrameData[] = { |
3570 0x80, spdy_version_, 0x00, 0x07, | 3605 0x80, spdy_version_, 0x00, 0x07, |
3571 0x00, 0x00, 0x00, 0x08, | 3606 0x00, 0x00, 0x00, 0x08, |
(...skipping 11 matching lines...) Expand all Loading... |
3583 arraysize(kV2FrameData)); | 3618 arraysize(kV2FrameData)); |
3584 } else { | 3619 } else { |
3585 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), | 3620 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData), |
3586 arraysize(kV3FrameData)); | 3621 arraysize(kV3FrameData)); |
3587 } | 3622 } |
3588 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 3623 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
3589 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()); | 3624 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()); |
3590 } | 3625 } |
3591 | 3626 |
3592 } // namespace net | 3627 } // namespace net |
OLD | NEW |