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 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3494 if (spdy_version_ <= SPDY3) { | 3494 if (spdy_version_ <= SPDY3) { |
3495 return; | 3495 return; |
3496 } | 3496 } |
3497 | 3497 |
3498 SpdyFramer framer(spdy_version_); | 3498 SpdyFramer framer(spdy_version_); |
3499 | 3499 |
3500 const char kDescription[] = "ALTSVC frame"; | 3500 const char kDescription[] = "ALTSVC frame"; |
3501 const char kType = static_cast<unsigned char>( | 3501 const char kType = static_cast<unsigned char>( |
3502 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); | 3502 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
3503 const unsigned char kFrameData[] = { | 3503 const unsigned char kFrameData[] = { |
3504 0x00, 0x00, 0x51, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', | 3504 0x00, 0x00, 0x53, kType, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 'o', |
3505 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', | 3505 'r', 'i', 'g', 'i', 'n', 'p', 'i', 'd', '1', '=', '"', 'h', |
3506 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', | 3506 'o', 's', 't', ':', '4', '4', '3', '"', ';', ' ', 'm', 'a', |
3507 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', | 3507 '=', '5', ',', 'p', '%', '2', '2', '%', '3', 'D', 'i', '%', |
3508 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', | 3508 '3', 'A', 'd', '=', '"', 'h', '_', '\\', '\\', 'o', '\\', '"', |
3509 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'v', '=', '2', | 3509 's', 't', ':', '1', '2', '3', '"', ';', ' ', 'm', 'a', '=', |
3510 '4', ';', ' ', 'm', 'a', '=', '4', '2', ';', ' ', 'p', '=', | 3510 '4', '2', ';', ' ', 'p', '=', '"', '0', '.', '2', '0', '"', |
3511 '"', '0', '.', '2', '0', '"'}; | 3511 ';', ' ', 'v', '=', '"', '2', '4', '"'}; |
3512 SpdyAltSvcIR altsvc_ir(3); | 3512 SpdyAltSvcIR altsvc_ir(3); |
3513 altsvc_ir.set_origin("origin"); | 3513 altsvc_ir.set_origin("origin"); |
3514 altsvc_ir.add_altsvc( | |
3515 SpdyAltSvcWireFormat::AlternativeService("pid1", "host", 443, 0, 5, 1.0)); | |
3516 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( | 3514 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
3517 "p\"=i:d", "h_\\o\"st", 123, 24, 42, 0.2)); | 3515 "pid1", "host", 443, 5, 1.0, SpdyAltSvcWireFormat::VersionVector{})); |
| 3516 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
| 3517 "p\"=i:d", "h_\\o\"st", 123, 42, 0.2, |
| 3518 SpdyAltSvcWireFormat::VersionVector{24})); |
3518 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 3519 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
3519 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 3520 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
3520 } | 3521 } |
3521 | 3522 |
3522 TEST_P(SpdyFramerTest, CreatePriority) { | 3523 TEST_P(SpdyFramerTest, CreatePriority) { |
3523 if (spdy_version_ <= SPDY3) { | 3524 if (spdy_version_ <= SPDY3) { |
3524 return; | 3525 return; |
3525 } | 3526 } |
3526 | 3527 |
3527 SpdyFramer framer(spdy_version_); | 3528 SpdyFramer framer(spdy_version_); |
(...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5765 if (spdy_version_ <= SPDY3) { | 5766 if (spdy_version_ <= SPDY3) { |
5766 return; | 5767 return; |
5767 } | 5768 } |
5768 | 5769 |
5769 const SpdyStreamId kStreamId = 1; | 5770 const SpdyStreamId kStreamId = 1; |
5770 | 5771 |
5771 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5772 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5772 SpdyFramer framer(spdy_version_); | 5773 SpdyFramer framer(spdy_version_); |
5773 framer.set_visitor(&visitor); | 5774 framer.set_visitor(&visitor); |
5774 | 5775 |
5775 SpdyAltSvcWireFormat::AlternativeService altsvc1("pid1", "host", 443, 0, 5, | 5776 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
5776 1.0); | 5777 "pid1", "host", 443, 5, 1.0, SpdyAltSvcWireFormat::VersionVector()); |
5777 SpdyAltSvcWireFormat::AlternativeService altsvc2("p\"=i:d", "h_\\o\"st", 123, | 5778 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
5778 24, 42, 0.2); | 5779 "p\"=i:d", "h_\\o\"st", 123, 42, 0.2, |
| 5780 SpdyAltSvcWireFormat::VersionVector{24}); |
5779 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 5781 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
5780 altsvc_vector.push_back(altsvc1); | 5782 altsvc_vector.push_back(altsvc1); |
5781 altsvc_vector.push_back(altsvc2); | 5783 altsvc_vector.push_back(altsvc2); |
5782 EXPECT_CALL(visitor, | 5784 EXPECT_CALL(visitor, |
5783 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); | 5785 OnAltSvc(kStreamId, StringPiece("o_r|g!n"), altsvc_vector)); |
5784 | 5786 |
5785 SpdyAltSvcIR altsvc_ir(1); | 5787 SpdyAltSvcIR altsvc_ir(1); |
5786 altsvc_ir.set_origin("o_r|g!n"); | 5788 altsvc_ir.set_origin("o_r|g!n"); |
5787 altsvc_ir.add_altsvc(altsvc1); | 5789 altsvc_ir.add_altsvc(altsvc1); |
5788 altsvc_ir.add_altsvc(altsvc2); | 5790 altsvc_ir.add_altsvc(altsvc2); |
5789 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5791 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5790 framer.ProcessInput(frame->data(), frame->size()); | 5792 framer.ProcessInput(frame->data(), frame->size()); |
5791 | 5793 |
5792 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 5794 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5793 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5795 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5794 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5796 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5795 } | 5797 } |
5796 | 5798 |
5797 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { | 5799 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
5798 if (spdy_version_ <= SPDY3) { | 5800 if (spdy_version_ <= SPDY3) { |
5799 return; | 5801 return; |
5800 } | 5802 } |
5801 | 5803 |
5802 const SpdyStreamId kStreamId = 1; | 5804 const SpdyStreamId kStreamId = 1; |
5803 | 5805 |
5804 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5806 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5805 SpdyFramer framer(spdy_version_); | 5807 SpdyFramer framer(spdy_version_); |
5806 framer.set_visitor(&visitor); | 5808 framer.set_visitor(&visitor); |
5807 | 5809 |
5808 SpdyAltSvcWireFormat::AlternativeService altsvc1("pid1", "host", 443, 0, 5, | 5810 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
5809 1.0); | 5811 "pid1", "host", 443, 5, 1.0, SpdyAltSvcWireFormat::VersionVector()); |
5810 SpdyAltSvcWireFormat::AlternativeService altsvc2("p\"=i:d", "h_\\o\"st", 123, | 5812 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
5811 24, 42, 0.2); | 5813 "p\"=i:d", "h_\\o\"st", 123, 42, 0.2, |
| 5814 SpdyAltSvcWireFormat::VersionVector{24}); |
5812 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 5815 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
5813 altsvc_vector.push_back(altsvc1); | 5816 altsvc_vector.push_back(altsvc1); |
5814 altsvc_vector.push_back(altsvc2); | 5817 altsvc_vector.push_back(altsvc2); |
5815 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); | 5818 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece(""), altsvc_vector)); |
5816 | 5819 |
5817 SpdyAltSvcIR altsvc_ir(1); | 5820 SpdyAltSvcIR altsvc_ir(1); |
5818 altsvc_ir.add_altsvc(altsvc1); | 5821 altsvc_ir.add_altsvc(altsvc1); |
5819 altsvc_ir.add_altsvc(altsvc2); | 5822 altsvc_ir.add_altsvc(altsvc2); |
5820 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5823 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5821 framer.ProcessInput(frame->data(), frame->size()); | 5824 framer.ProcessInput(frame->data(), frame->size()); |
5822 | 5825 |
5823 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 5826 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5824 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5827 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5825 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5828 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5826 } | 5829 } |
5827 | 5830 |
5828 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { | 5831 TEST_P(SpdyFramerTest, OnAltSvcEmptyProtocolId) { |
5829 if (spdy_version_ <= SPDY3) { | 5832 if (spdy_version_ <= SPDY3) { |
5830 return; | 5833 return; |
5831 } | 5834 } |
5832 | 5835 |
5833 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5836 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5834 SpdyFramer framer(spdy_version_); | 5837 SpdyFramer framer(spdy_version_); |
5835 framer.set_visitor(&visitor); | 5838 framer.set_visitor(&visitor); |
5836 | 5839 |
5837 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 5840 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
5838 | 5841 |
5839 SpdyAltSvcIR altsvc_ir(1); | 5842 SpdyAltSvcIR altsvc_ir(1); |
5840 altsvc_ir.set_origin("o1"); | 5843 altsvc_ir.set_origin("o1"); |
5841 altsvc_ir.add_altsvc( | 5844 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
5842 SpdyAltSvcWireFormat::AlternativeService("pid1", "host", 443, 0, 5, 1.0)); | 5845 "pid1", "host", 443, 5, 1.0, SpdyAltSvcWireFormat::VersionVector())); |
5843 altsvc_ir.add_altsvc( | 5846 altsvc_ir.add_altsvc(SpdyAltSvcWireFormat::AlternativeService( |
5844 SpdyAltSvcWireFormat::AlternativeService("", "h1", 443, 0, 10, 1.0)); | 5847 "", "h1", 443, 10, 1.0, SpdyAltSvcWireFormat::VersionVector())); |
5845 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5848 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5846 framer.ProcessInput(frame->data(), frame->size()); | 5849 framer.ProcessInput(frame->data(), frame->size()); |
5847 | 5850 |
5848 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5851 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
5849 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 5852 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
5850 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5853 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5851 } | 5854 } |
5852 | 5855 |
5853 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { | 5856 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
5854 if (spdy_version_ <= SPDY3) { | 5857 if (spdy_version_ <= SPDY3) { |
5855 return; | 5858 return; |
5856 } | 5859 } |
5857 | 5860 |
5858 const SpdyStreamId kStreamId = 1; | 5861 const SpdyStreamId kStreamId = 1; |
5859 | 5862 |
5860 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5863 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
5861 SpdyFramer framer(spdy_version_); | 5864 SpdyFramer framer(spdy_version_); |
5862 framer.set_visitor(&visitor); | 5865 framer.set_visitor(&visitor); |
5863 | 5866 |
5864 SpdyAltSvcWireFormat::AlternativeService altsvc("pid", "h1", 443, 0, 10, 1.0); | 5867 SpdyAltSvcWireFormat::AlternativeService altsvc( |
| 5868 "pid", "h1", 443, 10, 1.0, SpdyAltSvcWireFormat::VersionVector()); |
5865 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; | 5869 SpdyAltSvcWireFormat::AlternativeServiceVector altsvc_vector; |
5866 altsvc_vector.push_back(altsvc); | 5870 altsvc_vector.push_back(altsvc); |
5867 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); | 5871 EXPECT_CALL(visitor, OnAltSvc(kStreamId, StringPiece("o1"), altsvc_vector)); |
5868 | 5872 |
5869 SpdyAltSvcIR altsvc_ir(1); | 5873 SpdyAltSvcIR altsvc_ir(1); |
5870 altsvc_ir.set_origin("o1"); | 5874 altsvc_ir.set_origin("o1"); |
5871 altsvc_ir.add_altsvc(altsvc); | 5875 altsvc_ir.add_altsvc(altsvc); |
5872 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 5876 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
5873 framer.ProcessInput(frame->data(), frame->size()); | 5877 framer.ProcessInput(frame->data(), frame->size()); |
5874 | 5878 |
5875 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); | 5879 EXPECT_EQ(SpdyFramer::SPDY_READY_FOR_FRAME, framer.state()); |
5876 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5880 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5877 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5881 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5878 } | 5882 } |
5879 | 5883 |
5880 // Tests handling of ALTSVC frames delivered in small chunks. | 5884 // Tests handling of ALTSVC frames delivered in small chunks. |
5881 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { | 5885 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
5882 if (spdy_version_ <= SPDY3) { | 5886 if (spdy_version_ <= SPDY3) { |
5883 return; | 5887 return; |
5884 } | 5888 } |
5885 | 5889 |
5886 SpdyFramer framer(spdy_version_); | 5890 SpdyFramer framer(spdy_version_); |
5887 SpdyAltSvcIR altsvc_ir(1); | 5891 SpdyAltSvcIR altsvc_ir(1); |
5888 SpdyAltSvcWireFormat::AlternativeService altsvc1("pid1", "host", 443, 0, 5, | 5892 SpdyAltSvcWireFormat::AlternativeService altsvc1( |
5889 1.0); | 5893 "pid1", "host", 443, 5, 1.0, SpdyAltSvcWireFormat::VersionVector()); |
5890 SpdyAltSvcWireFormat::AlternativeService altsvc2("p\"=i:d", "h_\\o\"st", 123, | 5894 SpdyAltSvcWireFormat::AlternativeService altsvc2( |
5891 24, 42, 0.2); | 5895 "p\"=i:d", "h_\\o\"st", 123, 42, 0.2, |
| 5896 SpdyAltSvcWireFormat::VersionVector{24}); |
5892 altsvc_ir.add_altsvc(altsvc1); | 5897 altsvc_ir.add_altsvc(altsvc1); |
5893 altsvc_ir.add_altsvc(altsvc2); | 5898 altsvc_ir.add_altsvc(altsvc2); |
5894 | 5899 |
5895 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); | 5900 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); |
5896 TestSpdyVisitor visitor(spdy_version_); | 5901 TestSpdyVisitor visitor(spdy_version_); |
5897 visitor.use_compression_ = false; | 5902 visitor.use_compression_ = false; |
5898 | 5903 |
5899 // Read data in small chunks. | 5904 // Read data in small chunks. |
5900 size_t framed_data = 0; | 5905 size_t framed_data = 0; |
5901 size_t unframed_data = control_frame->size(); | 5906 size_t unframed_data = control_frame->size(); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6114 | 6119 |
6115 EXPECT_EQ(1, visitor->data_frame_count_); | 6120 EXPECT_EQ(1, visitor->data_frame_count_); |
6116 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); | 6121 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); |
6117 EXPECT_EQ(0, visitor->headers_frame_count_); | 6122 EXPECT_EQ(0, visitor->headers_frame_count_); |
6118 } | 6123 } |
6119 } | 6124 } |
6120 | 6125 |
6121 } // namespace test | 6126 } // namespace test |
6122 | 6127 |
6123 } // namespace net | 6128 } // namespace net |
OLD | NEW |