| 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 "net/spdy/spdy_framer.h" | 5 #include "net/spdy/spdy_framer.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1681 { | 1681 { |
| 1682 const char kDescription[] = "Basic SETTINGS frame"; | 1682 const char kDescription[] = "Basic SETTINGS frame"; |
| 1683 // These end up seemingly out of order because of the way that our internal | 1683 // These end up seemingly out of order because of the way that our internal |
| 1684 // ordering for settings_ir works. HTTP2 has no requirement on ordering on | 1684 // ordering for settings_ir works. HTTP2 has no requirement on ordering on |
| 1685 // the wire. | 1685 // the wire. |
| 1686 const unsigned char kH2FrameData[] = { | 1686 const unsigned char kH2FrameData[] = { |
| 1687 0x00, 0x00, 0x18, // Length: 24 | 1687 0x00, 0x00, 0x18, // Length: 24 |
| 1688 0x04, // Type: SETTINGS | 1688 0x04, // Type: SETTINGS |
| 1689 0x00, // Flags: none | 1689 0x00, // Flags: none |
| 1690 0x00, 0x00, 0x00, 0x00, // Stream: 0 | 1690 0x00, 0x00, 0x00, 0x00, // Stream: 0 |
| 1691 0x00, 0x01, // Param: HEADER_TABLE_SIZE |
| 1692 0x00, 0x00, 0x00, 0x05, // Value: 5 |
| 1693 0x00, 0x02, // Param: ENABLE_PUSH |
| 1694 0x00, 0x00, 0x00, 0x06, // Value: 6 |
| 1691 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS | 1695 0x00, 0x03, // Param: MAX_CONCURRENT_STREAMS |
| 1692 0x00, 0x00, 0x00, 0x07, // Value: 7 | 1696 0x00, 0x00, 0x00, 0x07, // Value: 7 |
| 1693 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE | 1697 0x00, 0x04, // Param: INITIAL_WINDOW_SIZE |
| 1694 0x00, 0x00, 0x00, 0x08, // Value: 8 | 1698 0x00, 0x00, 0x00, 0x08, // Value: 8 |
| 1695 0x00, 0x01, // Param: HEADER_TABLE_SIZE | |
| 1696 0x00, 0x00, 0x00, 0x05, // Value: 5 | |
| 1697 0x00, 0x02, // Param: ENABLE_PUSH | |
| 1698 0x00, 0x00, 0x00, 0x06, // Value: 6 | |
| 1699 }; | 1699 }; |
| 1700 | 1700 |
| 1701 SpdySettingsIR settings_ir; | 1701 SpdySettingsIR settings_ir; |
| 1702 settings_ir.AddSetting(SpdyConstants::ParseSettingId(1), | 1702 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, |
| 1703 false, // persist | 1703 false, // persist |
| 1704 false, // persisted | 1704 false, // persisted |
| 1705 5); | 1705 5); |
| 1706 settings_ir.AddSetting(SpdyConstants::ParseSettingId(2), | 1706 settings_ir.AddSetting(SETTINGS_ENABLE_PUSH, |
| 1707 false, // persist | 1707 false, // persist |
| 1708 false, // persisted | 1708 false, // persisted |
| 1709 6); | 1709 6); |
| 1710 settings_ir.AddSetting(SpdyConstants::ParseSettingId(3), | 1710 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, |
| 1711 false, // persist | 1711 false, // persist |
| 1712 false, // persisted | 1712 false, // persisted |
| 1713 7); | 1713 7); |
| 1714 settings_ir.AddSetting(SpdyConstants::ParseSettingId(4), | 1714 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, |
| 1715 false, // persist | 1715 false, // persist |
| 1716 false, // persisted | 1716 false, // persisted |
| 1717 8); | 1717 8); |
| 1718 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); | 1718 SpdySerializedFrame frame(framer.SerializeSettings(settings_ir)); |
| 1719 | 1719 |
| 1720 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); | 1720 CompareFrame(kDescription, frame, kH2FrameData, arraysize(kH2FrameData)); |
| 1721 } | 1721 } |
| 1722 | 1722 |
| 1723 { | 1723 { |
| 1724 const char kDescription[] = "Empty SETTINGS frame"; | 1724 const char kDescription[] = "Empty SETTINGS frame"; |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2779 EXPECT_EQ(1, visitor.error_count_); | 2779 EXPECT_EQ(1, visitor.error_count_); |
| 2780 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, | 2780 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, |
| 2781 visitor.framer_.error_code()) | 2781 visitor.framer_.error_code()) |
| 2782 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 2782 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 2783 } | 2783 } |
| 2784 | 2784 |
| 2785 // Tests handling of SETTINGS frames larger than the frame buffer size. | 2785 // Tests handling of SETTINGS frames larger than the frame buffer size. |
| 2786 TEST_F(SpdyFramerTest, ReadLargeSettingsFrame) { | 2786 TEST_F(SpdyFramerTest, ReadLargeSettingsFrame) { |
| 2787 SpdyFramer framer; | 2787 SpdyFramer framer; |
| 2788 SpdySettingsIR settings_ir; | 2788 SpdySettingsIR settings_ir; |
| 2789 settings_ir.AddSetting(SpdyConstants::ParseSettingId(1), | 2789 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, |
| 2790 false, // persist | 2790 false, // persist |
| 2791 false, // persisted | 2791 false, // persisted |
| 2792 5); | 2792 5); |
| 2793 settings_ir.AddSetting(SpdyConstants::ParseSettingId(2), | 2793 settings_ir.AddSetting(SETTINGS_ENABLE_PUSH, |
| 2794 false, // persist | 2794 false, // persist |
| 2795 false, // persisted | 2795 false, // persisted |
| 2796 6); | 2796 6); |
| 2797 settings_ir.AddSetting(SpdyConstants::ParseSettingId(3), | 2797 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, |
| 2798 false, // persist | 2798 false, // persist |
| 2799 false, // persisted | 2799 false, // persisted |
| 2800 7); | 2800 7); |
| 2801 | 2801 |
| 2802 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 2802 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 2803 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); | 2803 EXPECT_LT(SpdyFramerPeer::ControlFrameBufferSize(), control_frame.size()); |
| 2804 TestSpdyVisitor visitor; | 2804 TestSpdyVisitor visitor; |
| 2805 visitor.use_compression_ = false; | 2805 visitor.use_compression_ = false; |
| 2806 | 2806 |
| 2807 // Read all at once. | 2807 // Read all at once. |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3362 | 3362 |
| 3363 // Simulate the case where the stream id validation checks out. | 3363 // Simulate the case where the stream id validation checks out. |
| 3364 visitor.on_unknown_frame_result_ = true; | 3364 visitor.on_unknown_frame_result_ = true; |
| 3365 visitor.use_compression_ = false; | 3365 visitor.use_compression_ = false; |
| 3366 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); | 3366 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame)); |
| 3367 EXPECT_EQ(0, visitor.error_count_); | 3367 EXPECT_EQ(0, visitor.error_count_); |
| 3368 | 3368 |
| 3369 // Follow it up with a valid control frame to make sure we handle | 3369 // Follow it up with a valid control frame to make sure we handle |
| 3370 // subsequent frames correctly. | 3370 // subsequent frames correctly. |
| 3371 SpdySettingsIR settings_ir; | 3371 SpdySettingsIR settings_ir; |
| 3372 settings_ir.AddSetting(SpdyConstants::ParseSettingId(1), | 3372 settings_ir.AddSetting(SETTINGS_HEADER_TABLE_SIZE, |
| 3373 false, // persist | 3373 false, // persist |
| 3374 false, // persisted | 3374 false, // persisted |
| 3375 10); | 3375 10); |
| 3376 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); | 3376 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); |
| 3377 visitor.SimulateInFramer( | 3377 visitor.SimulateInFramer( |
| 3378 reinterpret_cast<unsigned char*>(control_frame.data()), | 3378 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 3379 control_frame.size()); | 3379 control_frame.size()); |
| 3380 EXPECT_EQ(0, visitor.error_count_); | 3380 EXPECT_EQ(0, visitor.error_count_); |
| 3381 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); | 3381 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_)); |
| 3382 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); | 3382 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_)); |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4334 | 4334 |
| 4335 EXPECT_EQ(1, visitor->data_frame_count_); | 4335 EXPECT_EQ(1, visitor->data_frame_count_); |
| 4336 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 4336 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
| 4337 EXPECT_EQ(0, visitor->headers_frame_count_); | 4337 EXPECT_EQ(0, visitor->headers_frame_count_); |
| 4338 } | 4338 } |
| 4339 } | 4339 } |
| 4340 | 4340 |
| 4341 } // namespace test | 4341 } // namespace test |
| 4342 | 4342 |
| 4343 } // namespace net | 4343 } // namespace net |
| OLD | NEW |