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 3406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3417 } | 3417 } |
3418 | 3418 |
3419 TEST_P(SpdyFramerTest, CreateAltSvc) { | 3419 TEST_P(SpdyFramerTest, CreateAltSvc) { |
3420 if (spdy_version_ <= SPDY3) { | 3420 if (spdy_version_ <= SPDY3) { |
3421 return; | 3421 return; |
3422 } | 3422 } |
3423 | 3423 |
3424 SpdyFramer framer(spdy_version_); | 3424 SpdyFramer framer(spdy_version_); |
3425 | 3425 |
3426 const char kDescription[] = "ALTSVC frame"; | 3426 const char kDescription[] = "ALTSVC frame"; |
3427 const unsigned char kType = static_cast<unsigned char>( | 3427 const char kType = static_cast<unsigned char>( |
3428 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | 3428 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
3429 const unsigned char kFrameData[] = { | 3429 const unsigned char kFrameData[] = { |
3430 0x00, 0x00, 0x17, kType, 0x00, | 3430 0x00, 0x00, 0x1d, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, |
3431 0x00, 0x00, 0x00, 0x03, | 3431 0x06, 'o', 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', |
3432 0x00, 0x00, 0x00, 0x05, | 3432 '1', '=', '"', 'h', 'o', 's', 't', ':', '4', '4', |
3433 0x01, 0xbb, 0x00, 0x04, // Port = 443 | 3433 '3', '"', ';', ' ', 'm', 'a', '=', '5', |
3434 'p', 'i', 'd', '1', // Protocol-ID | |
3435 0x04, 'h', 'o', 's', | |
3436 't', 'o', 'r', 'i', | |
3437 'g', 'i', 'n', | |
3438 }; | 3434 }; |
3439 SpdyAltSvcIR altsvc_ir(3); | 3435 SpdyAltSvcIR altsvc_ir(3); |
3440 altsvc_ir.set_max_age(5); | 3436 altsvc_ir.set_max_age(5); |
3441 altsvc_ir.set_port(443); | 3437 altsvc_ir.set_port(443); |
3442 altsvc_ir.set_protocol_id("pid1"); | 3438 altsvc_ir.set_protocol_id("pid1"); |
3443 altsvc_ir.set_host("host"); | 3439 altsvc_ir.set_host("host"); |
3444 altsvc_ir.set_origin("origin"); | 3440 altsvc_ir.set_origin("origin"); |
3445 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 3441 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
3446 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 3442 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
3447 } | 3443 } |
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4701 EXPECT_EQ(14u, framer.GetSynStreamMinimumSize()); | 4697 EXPECT_EQ(14u, framer.GetSynStreamMinimumSize()); |
4702 EXPECT_EQ(9u, framer.GetSynReplyMinimumSize()); | 4698 EXPECT_EQ(9u, framer.GetSynReplyMinimumSize()); |
4703 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); | 4699 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize()); |
4704 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); | 4700 EXPECT_EQ(9u, framer.GetSettingsMinimumSize()); |
4705 EXPECT_EQ(17u, framer.GetPingSize()); | 4701 EXPECT_EQ(17u, framer.GetPingSize()); |
4706 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); | 4702 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize()); |
4707 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); | 4703 EXPECT_EQ(9u, framer.GetHeadersMinimumSize()); |
4708 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); | 4704 EXPECT_EQ(13u, framer.GetWindowUpdateSize()); |
4709 EXPECT_EQ(9u, framer.GetBlockedSize()); | 4705 EXPECT_EQ(9u, framer.GetBlockedSize()); |
4710 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); | 4706 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize()); |
4711 EXPECT_EQ(18u, framer.GetAltSvcMinimumSize()); | 4707 EXPECT_EQ(11u, framer.GetAltSvcMinimumSize()); |
4712 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); | 4708 EXPECT_EQ(9u, framer.GetFrameMinimumSize()); |
4713 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); | 4709 EXPECT_EQ(16393u, framer.GetFrameMaximumSize()); |
4714 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); | 4710 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload()); |
4715 } else { | 4711 } else { |
4716 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); | 4712 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); |
4717 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); | 4713 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); |
4718 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); | 4714 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); |
4719 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); | 4715 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); |
4720 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); | 4716 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); |
4721 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); | 4717 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); |
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5705 StringPiece("h1"), | 5701 StringPiece("h1"), |
5706 StringPiece("o1"))); | 5702 StringPiece("o1"))); |
5707 | 5703 |
5708 SpdyAltSvcIR altsvc_ir(1); | 5704 SpdyAltSvcIR altsvc_ir(1); |
5709 altsvc_ir.set_max_age(10); | 5705 altsvc_ir.set_max_age(10); |
5710 altsvc_ir.set_port(443); | 5706 altsvc_ir.set_port(443); |
5711 altsvc_ir.set_protocol_id("pid"); | 5707 altsvc_ir.set_protocol_id("pid"); |
5712 altsvc_ir.set_host("h1"); | 5708 altsvc_ir.set_host("h1"); |
5713 altsvc_ir.set_origin("o1"); | 5709 altsvc_ir.set_origin("o1"); |
5714 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5710 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5715 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + | 5711 framer.ProcessInput(frame->data(), frame->size()); |
5716 altsvc_ir.protocol_id().length() + | |
5717 altsvc_ir.host().length() + | |
5718 altsvc_ir.origin().length()); | |
5719 | 5712 |
5720 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5713 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5721 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5714 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5722 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5715 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5723 } | 5716 } |
5724 | 5717 |
5725 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { | 5718 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
5726 if (spdy_version_ <= SPDY3) { | 5719 if (spdy_version_ <= SPDY3) { |
5727 return; | 5720 return; |
5728 } | 5721 } |
5729 | 5722 |
5730 const SpdyStreamId kStreamId = 1; | 5723 const SpdyStreamId kStreamId = 1; |
5731 | 5724 |
5732 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5725 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5733 SpdyFramer framer(spdy_version_); | 5726 SpdyFramer framer(spdy_version_); |
5734 framer.set_visitor(&visitor); | 5727 framer.set_visitor(&visitor); |
5735 | 5728 |
5736 EXPECT_CALL(visitor, OnAltSvc(kStreamId, | 5729 EXPECT_CALL(visitor, |
5737 10, | 5730 OnAltSvc(kStreamId, 10, 443, StringPiece("p\"=i:d"), |
5738 443, | 5731 StringPiece("h_\\o\"st"), StringPiece("o_r|g!n"))); |
5739 StringPiece("pid"), | |
5740 StringPiece("h1"), | |
5741 StringPiece(""))); | |
5742 | 5732 |
5743 SpdyAltSvcIR altsvc_ir(1); | 5733 SpdyAltSvcIR altsvc_ir(1); |
5744 altsvc_ir.set_max_age(10); | 5734 altsvc_ir.set_max_age(10); |
5745 altsvc_ir.set_port(443); | 5735 altsvc_ir.set_port(443); |
5746 altsvc_ir.set_protocol_id("pid"); | 5736 altsvc_ir.set_protocol_id("p\"=i:d"); |
5747 altsvc_ir.set_host("h1"); | 5737 altsvc_ir.set_host("h_\\o\"st"); |
| 5738 altsvc_ir.set_origin("o_r|g!n"); |
5748 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5739 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5749 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + | 5740 framer.ProcessInput(frame->data(), frame->size()); |
5750 altsvc_ir.protocol_id().length() + | |
5751 altsvc_ir.host().length()); | |
5752 | 5741 |
5753 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5742 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5754 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5743 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5755 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5744 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5756 } | 5745 } |
5757 | 5746 |
5758 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { | 5747 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { |
5759 if (spdy_version_ <= SPDY3) { | 5748 if (spdy_version_ <= SPDY3) { |
5760 return; | 5749 return; |
5761 } | 5750 } |
5762 | 5751 |
5763 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5752 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5764 SpdyFramer framer(spdy_version_); | 5753 SpdyFramer framer(spdy_version_); |
5765 framer.set_visitor(&visitor); | 5754 framer.set_visitor(&visitor); |
5766 | 5755 |
5767 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 5756 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
5768 | 5757 |
5769 SpdyAltSvcIR altsvc_ir(1); | 5758 SpdyAltSvcIR altsvc_ir(1); |
5770 altsvc_ir.set_max_age(10); | 5759 altsvc_ir.set_max_age(10); |
5771 altsvc_ir.set_port(443); | 5760 altsvc_ir.set_port(443); |
5772 altsvc_ir.set_host("h1"); | 5761 altsvc_ir.set_host("h1"); |
5773 altsvc_ir.set_origin("o1"); | 5762 altsvc_ir.set_origin("o1"); |
5774 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5763 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5775 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + | 5764 framer.ProcessInput(frame->data(), frame->size()); |
5776 altsvc_ir.protocol_id().length() + | |
5777 altsvc_ir.host().length()); | |
5778 | 5765 |
5779 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5766 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
5780 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 5767 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
5781 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5768 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5782 } | 5769 } |
5783 | 5770 |
5784 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { | 5771 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
5785 if (spdy_version_ <= SPDY3) { | 5772 if (spdy_version_ <= SPDY3) { |
5786 return; | 5773 return; |
5787 } | 5774 } |
5788 | 5775 |
5789 const unsigned char kType = static_cast<unsigned char>( | 5776 const SpdyStreamId kStreamId = 1; |
5790 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | |
5791 { | |
5792 TestSpdyVisitor visitor(spdy_version_); | |
5793 SpdyFramer framer(spdy_version_); | |
5794 framer.set_visitor(&visitor); | |
5795 | 5777 |
5796 const unsigned char kFrameDataLargePIDLen[] = { | 5778 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5797 0x00, 0x00, 0x17, kType, 0x00, | 5779 SpdyFramer framer(spdy_version_); |
5798 0x00, 0x00, 0x00, 0x03, | 5780 framer.set_visitor(&visitor); |
5799 0x00, 0x00, 0x00, 0x05, | |
5800 0x01, 0xbb, 0x00, 0x05, // Port = 443 | |
5801 'p', 'i', 'd', '1', // Protocol-ID | |
5802 0x04, 'h', 'o', 's', | |
5803 't', 'o', 'r', 'i', | |
5804 'g', 'i', 'n', | |
5805 }; | |
5806 | 5781 |
5807 visitor.SimulateInFramer(kFrameDataLargePIDLen, | 5782 EXPECT_CALL(visitor, OnAltSvc(kStreamId, 10, 443, StringPiece("pid"), |
5808 sizeof(kFrameDataLargePIDLen)); | 5783 StringPiece("h1"), StringPiece(""))); |
5809 EXPECT_EQ(1, visitor.error_count_); | |
5810 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | |
5811 visitor.framer_.error_code()); | |
5812 } | |
5813 | 5784 |
5814 { | 5785 SpdyAltSvcIR altsvc_ir(1); |
5815 TestSpdyVisitor visitor(spdy_version_); | 5786 altsvc_ir.set_max_age(10); |
5816 SpdyFramer framer(spdy_version_); | 5787 altsvc_ir.set_port(443); |
5817 framer.set_visitor(&visitor); | 5788 altsvc_ir.set_protocol_id("pid"); |
5818 const unsigned char kFrameDataPIDLenLargerThanFrame[] = { | 5789 altsvc_ir.set_host("h1"); |
5819 0x00, 0x00, 0x17, kType, 0x00, | 5790 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5820 0x00, 0x00, 0x00, 0x03, | 5791 framer.ProcessInput(frame->data(), frame->size()); |
5821 0x00, 0x00, 0x00, 0x05, | |
5822 0x01, 0xbb, 0x00, 0x99, // Port = 443 | |
5823 'p', 'i', 'd', '1', // Protocol-ID | |
5824 0x04, 'h', 'o', 's', | |
5825 't', 'o', 'r', 'i', | |
5826 'g', 'i', 'n', | |
5827 }; | |
5828 | 5792 |
5829 visitor.SimulateInFramer(kFrameDataPIDLenLargerThanFrame, | 5793 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5830 sizeof(kFrameDataPIDLenLargerThanFrame)); | 5794 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5831 EXPECT_EQ(1, visitor.error_count_); | 5795 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5832 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | |
5833 visitor.framer_.error_code()); | |
5834 } | |
5835 | |
5836 { | |
5837 TestSpdyVisitor visitor(spdy_version_); | |
5838 SpdyFramer framer(spdy_version_); | |
5839 framer.set_visitor(&visitor); | |
5840 | |
5841 const unsigned char kFrameDataLargeHostLen[] = { | |
5842 0x00, 0x00, 0x17, kType, 0x00, | |
5843 0x00, 0x00, 0x00, 0x03, | |
5844 0x00, 0x00, 0x00, 0x05, | |
5845 0x01, 0xbb, 0x00, 0x04, // Port = 443 | |
5846 'p', 'i', 'd', '1', // Protocol-ID | |
5847 0x0f, 'h', 'o', 's', | |
5848 't', 'o', 'r', 'i', | |
5849 'g', 'i', 'n', | |
5850 }; | |
5851 | |
5852 visitor.SimulateInFramer(kFrameDataLargeHostLen, | |
5853 sizeof(kFrameDataLargeHostLen)); | |
5854 EXPECT_EQ(1, visitor.error_count_); | |
5855 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | |
5856 visitor.framer_.error_code()); | |
5857 } | |
5858 | |
5859 { | |
5860 TestSpdyVisitor visitor(spdy_version_); | |
5861 SpdyFramer framer(spdy_version_); | |
5862 framer.set_visitor(&visitor); | |
5863 const unsigned char kFrameDataSmallPIDLen[] = { | |
5864 0x00, 0x00, 0x17, kType, 0x00, | |
5865 0x00, 0x00, 0x00, 0x03, | |
5866 0x00, 0x00, 0x00, 0x05, | |
5867 0x01, 0xbb, 0x00, 0x01, // Port = 443 | |
5868 'p', 'i', 'd', '1', // Protocol-ID | |
5869 0x04, 'h', 'o', 's', | |
5870 't', 'o', 'r', 'i', | |
5871 'g', 'i', 'n', | |
5872 }; | |
5873 | |
5874 visitor.SimulateInFramer(kFrameDataSmallPIDLen, | |
5875 sizeof(kFrameDataSmallPIDLen)); | |
5876 EXPECT_EQ(1, visitor.error_count_); | |
5877 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | |
5878 visitor.framer_.error_code()); | |
5879 } | |
5880 } | 5796 } |
5881 | 5797 |
5882 // Tests handling of ALTSVC frames delivered in small chunks. | 5798 // Tests handling of ALTSVC frames delivered in small chunks. |
5883 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 5799 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
5884 if (spdy_version_ <= SPDY3) { | 5800 if (spdy_version_ <= SPDY3) { |
5885 return; | 5801 return; |
5886 } | 5802 } |
| 5803 |
5887 SpdyFramer framer(spdy_version_); | 5804 SpdyFramer framer(spdy_version_); |
5888 SpdyAltSvcIR altsvc_ir(1); | 5805 SpdyAltSvcIR altsvc_ir(1); |
5889 altsvc_ir.set_max_age(20); | 5806 altsvc_ir.set_max_age(20); |
5890 altsvc_ir.set_port(443); | 5807 altsvc_ir.set_port(443); |
5891 altsvc_ir.set_protocol_id("protocolid"); | 5808 altsvc_ir.set_protocol_id("protocolid"); |
5892 altsvc_ir.set_host("hostname"); | 5809 altsvc_ir.set_host("hostname"); |
5893 | 5810 |
5894 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); | 5811 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); |
5895 TestSpdyVisitor visitor(spdy_version_); | 5812 TestSpdyVisitor visitor(spdy_version_); |
5896 visitor.use_compression_ = false; | 5813 visitor.use_compression_ = false; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5983 TestSpdyVisitor visitor(spdy_version_); | 5900 TestSpdyVisitor visitor(spdy_version_); |
5984 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5901 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
5985 | 5902 |
5986 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5903 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
5987 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5904 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
5988 visitor.framer_.error_code()) | 5905 visitor.framer_.error_code()) |
5989 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5906 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
5990 } | 5907 } |
5991 | 5908 |
5992 } // namespace net | 5909 } // namespace net |
OLD | NEW |