| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 return true; | 352 return true; |
| 353 } | 353 } |
| 354 | 354 |
| 355 virtual void OnSetting(SpdySettingsIds id, | 355 virtual void OnSetting(SpdySettingsIds id, |
| 356 uint8 flags, | 356 uint8 flags, |
| 357 uint32 value) OVERRIDE { | 357 uint32 value) OVERRIDE { |
| 358 ++setting_count_; | 358 ++setting_count_; |
| 359 } | 359 } |
| 360 | 360 |
| 361 virtual void OnSettingsAck() OVERRIDE { | 361 virtual void OnSettingsAck() OVERRIDE { |
| 362 DCHECK_GE(4, framer_.protocol_version()); | 362 DCHECK_LT(SPDY3, framer_.protocol_version()); |
| 363 ++settings_ack_received_; | 363 ++settings_ack_received_; |
| 364 } | 364 } |
| 365 | 365 |
| 366 virtual void OnSettingsEnd() OVERRIDE { | 366 virtual void OnSettingsEnd() OVERRIDE { |
| 367 if (framer_.protocol_version() < 4) { return; } | 367 if (framer_.protocol_version() <= SPDY3) { return; } |
| 368 ++settings_ack_sent_; | 368 ++settings_ack_sent_; |
| 369 } | 369 } |
| 370 | 370 |
| 371 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE { | 371 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE { |
| 372 DLOG(FATAL); | 372 DLOG(FATAL); |
| 373 } | 373 } |
| 374 | 374 |
| 375 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 375 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 376 SpdyGoAwayStatus status) OVERRIDE { | 376 SpdyGoAwayStatus status) OVERRIDE { |
| 377 ++goaway_count_; | 377 ++goaway_count_; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 using net::test::SpdyFramerTestUtil; | 545 using net::test::SpdyFramerTestUtil; |
| 546 using net::test::TestSpdyVisitor; | 546 using net::test::TestSpdyVisitor; |
| 547 using net::test::GetSerializedHeaders; | 547 using net::test::GetSerializedHeaders; |
| 548 | 548 |
| 549 namespace net { | 549 namespace net { |
| 550 | 550 |
| 551 class SpdyFramerTest : public ::testing::TestWithParam<SpdyMajorVersion> { | 551 class SpdyFramerTest : public ::testing::TestWithParam<SpdyMajorVersion> { |
| 552 protected: | 552 protected: |
| 553 virtual void SetUp() { | 553 virtual void SetUp() { |
| 554 spdy_version_ = GetParam(); | 554 spdy_version_ = GetParam(); |
| 555 spdy_version_ch_ = static_cast<unsigned char>(spdy_version_); | 555 spdy_version_ch_ = static_cast<unsigned char>( |
| 556 SpdyConstants::SerializeMajorVersion(spdy_version_)); |
| 556 } | 557 } |
| 557 | 558 |
| 558 void CompareFrame(const string& description, | 559 void CompareFrame(const string& description, |
| 559 const SpdyFrame& actual_frame, | 560 const SpdyFrame& actual_frame, |
| 560 const unsigned char* expected, | 561 const unsigned char* expected, |
| 561 const int expected_len) { | 562 const int expected_len) { |
| 562 const unsigned char* actual = | 563 const unsigned char* actual = |
| 563 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 564 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 564 CompareCharArraysWithHexError( | 565 CompareCharArraysWithHexError( |
| 565 description, actual, actual_frame.size(), expected, expected_len); | 566 description, actual, actual_frame.size(), expected, expected_len); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 779 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 779 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 780 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 780 EXPECT_TRUE(framer.HasError()); | 781 EXPECT_TRUE(framer.HasError()); |
| 781 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 782 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 782 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 783 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 783 } | 784 } |
| 784 | 785 |
| 785 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an | 786 // Test that if we receive a PUSH_PROMISE with stream ID zero, we signal an |
| 786 // error (but don't crash). | 787 // error (but don't crash). |
| 787 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { | 788 TEST_P(SpdyFramerTest, PushPromiseWithStreamIdZero) { |
| 788 if (spdy_version_ < SPDY4) { | 789 if (spdy_version_ <= SPDY3) { |
| 789 return; | 790 return; |
| 790 } | 791 } |
| 791 | 792 |
| 792 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 793 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 793 SpdyFramer framer(spdy_version_); | 794 SpdyFramer framer(spdy_version_); |
| 794 framer.set_visitor(&visitor); | 795 framer.set_visitor(&visitor); |
| 795 | 796 |
| 796 SpdyPushPromiseIR push_promise(0, 4); | 797 SpdyPushPromiseIR push_promise(0, 4); |
| 797 push_promise.SetHeader("alpha", "beta"); | 798 push_promise.SetHeader("alpha", "beta"); |
| 798 scoped_ptr<SpdySerializedFrame> frame( | 799 scoped_ptr<SpdySerializedFrame> frame( |
| 799 framer.SerializePushPromise(push_promise)); | 800 framer.SerializePushPromise(push_promise)); |
| 800 ASSERT_TRUE(frame.get() != NULL); | 801 ASSERT_TRUE(frame.get() != NULL); |
| 801 | 802 |
| 802 // We shouldn't have to read the whole frame before we signal an error. | 803 // We shouldn't have to read the whole frame before we signal an error. |
| 803 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 804 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 804 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 805 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 805 EXPECT_TRUE(framer.HasError()); | 806 EXPECT_TRUE(framer.HasError()); |
| 806 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 807 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 807 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 808 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 808 } | 809 } |
| 809 | 810 |
| 810 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we | 811 // Test that if we receive a PUSH_PROMISE with promised stream ID zero, we |
| 811 // signal an error (but don't crash). | 812 // signal an error (but don't crash). |
| 812 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { | 813 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { |
| 813 if (spdy_version_ < SPDY4) { | 814 if (spdy_version_ <= SPDY3) { |
| 814 return; | 815 return; |
| 815 } | 816 } |
| 816 | 817 |
| 817 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 818 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 818 SpdyFramer framer(spdy_version_); | 819 SpdyFramer framer(spdy_version_); |
| 819 framer.set_visitor(&visitor); | 820 framer.set_visitor(&visitor); |
| 820 | 821 |
| 821 SpdyPushPromiseIR push_promise(3, 0); | 822 SpdyPushPromiseIR push_promise(3, 0); |
| 822 push_promise.SetHeader("alpha", "beta"); | 823 push_promise.SetHeader("alpha", "beta"); |
| 823 scoped_ptr<SpdySerializedFrame> frame( | 824 scoped_ptr<SpdySerializedFrame> frame( |
| 824 framer.SerializePushPromise(push_promise)); | 825 framer.SerializePushPromise(push_promise)); |
| 825 ASSERT_TRUE(frame.get() != NULL); | 826 ASSERT_TRUE(frame.get() != NULL); |
| 826 | 827 |
| 827 // We shouldn't have to read the whole frame before we signal an error. | 828 // We shouldn't have to read the whole frame before we signal an error. |
| 828 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 829 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 829 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 830 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 830 EXPECT_TRUE(framer.HasError()); | 831 EXPECT_TRUE(framer.HasError()); |
| 831 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 832 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 832 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 833 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 833 } | 834 } |
| 834 | 835 |
| 835 TEST_P(SpdyFramerTest, DuplicateHeader) { | 836 TEST_P(SpdyFramerTest, DuplicateHeader) { |
| 836 if (spdy_version_ >= 4) { | 837 if (spdy_version_ > SPDY3) { |
| 837 // TODO(jgraettinger): Punting on this because we haven't determined | 838 // TODO(jgraettinger): Punting on this because we haven't determined |
| 838 // whether duplicate HPACK headers other than Cookie are an error. | 839 // whether duplicate HPACK headers other than Cookie are an error. |
| 839 // If they are, this will need to be updated to use HpackOutputStream. | 840 // If they are, this will need to be updated to use HpackOutputStream. |
| 840 return; | 841 return; |
| 841 } | 842 } |
| 842 SpdyFramer framer(spdy_version_); | 843 SpdyFramer framer(spdy_version_); |
| 843 // Frame builder with plentiful buffer size. | 844 // Frame builder with plentiful buffer size. |
| 844 SpdyFrameBuilder frame(1024, spdy_version_); | 845 SpdyFrameBuilder frame(1024, spdy_version_); |
| 845 if (spdy_version_ < 4) { | 846 if (spdy_version_ <= SPDY3) { |
| 846 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 847 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); |
| 847 frame.WriteUInt32(3); // stream_id | 848 frame.WriteUInt32(3); // stream_id |
| 848 frame.WriteUInt32(0); // associated stream id | 849 frame.WriteUInt32(0); // associated stream id |
| 849 frame.WriteUInt16(0); // Priority. | 850 frame.WriteUInt16(0); // Priority. |
| 850 } else { | 851 } else { |
| 851 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); | 852 frame.BeginNewFrame(framer, HEADERS, HEADERS_FLAG_PRIORITY, 3); |
| 852 frame.WriteUInt32(framer.GetHighestPriority()); | 853 frame.WriteUInt32(framer.GetHighestPriority()); |
| 853 } | 854 } |
| 854 | 855 |
| 855 if (IsSpdy2()) { | 856 if (IsSpdy2()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 876 // This should fail because duplicate headers are verboten by the spec. | 877 // This should fail because duplicate headers are verboten by the spec. |
| 877 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 878 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
| 878 serialized_headers.size(), | 879 serialized_headers.size(), |
| 879 &new_headers)); | 880 &new_headers)); |
| 880 } | 881 } |
| 881 | 882 |
| 882 TEST_P(SpdyFramerTest, MultiValueHeader) { | 883 TEST_P(SpdyFramerTest, MultiValueHeader) { |
| 883 SpdyFramer framer(spdy_version_); | 884 SpdyFramer framer(spdy_version_); |
| 884 // Frame builder with plentiful buffer size. | 885 // Frame builder with plentiful buffer size. |
| 885 SpdyFrameBuilder frame(1024, spdy_version_); | 886 SpdyFrameBuilder frame(1024, spdy_version_); |
| 886 if (spdy_version_ < 4) { | 887 if (spdy_version_ <= SPDY3) { |
| 887 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 888 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); |
| 888 frame.WriteUInt32(3); // stream_id | 889 frame.WriteUInt32(3); // stream_id |
| 889 frame.WriteUInt32(0); // associated stream id | 890 frame.WriteUInt32(0); // associated stream id |
| 890 frame.WriteUInt16(0); // Priority. | 891 frame.WriteUInt16(0); // Priority. |
| 891 } else { | 892 } else { |
| 892 frame.BeginNewFrame(framer, | 893 frame.BeginNewFrame(framer, |
| 893 HEADERS, | 894 HEADERS, |
| 894 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, | 895 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, |
| 895 3); | 896 3); |
| 896 frame.WriteUInt32(framer.GetHighestPriority()); | 897 frame.WriteUInt32(framer.GetHighestPriority()); |
| 897 } | 898 } |
| 898 | 899 |
| 899 string value("value1\0value2", 13); | 900 string value("value1\0value2", 13); |
| 900 if (IsSpdy2()) { | 901 if (IsSpdy2()) { |
| 901 frame.WriteUInt16(1); // Number of headers. | 902 frame.WriteUInt16(1); // Number of headers. |
| 902 frame.WriteString("name"); | 903 frame.WriteString("name"); |
| 903 frame.WriteString(value); | 904 frame.WriteString(value); |
| 904 } else if (spdy_version_ >= 4) { | 905 } else if (spdy_version_ > SPDY3) { |
| 905 HpackOutputStream output_stream(1024); | 906 HpackOutputStream output_stream(1024); |
| 906 output_stream.AppendLiteralHeaderNoIndexingWithName("name", value); | 907 output_stream.AppendLiteralHeaderNoIndexingWithName("name", value); |
| 907 string buffer; | 908 string buffer; |
| 908 output_stream.TakeString(&buffer); | 909 output_stream.TakeString(&buffer); |
| 909 frame.WriteBytes(&buffer[0], buffer.size()); | 910 frame.WriteBytes(&buffer[0], buffer.size()); |
| 910 } else { | 911 } else { |
| 911 frame.WriteUInt32(1); // Number of headers. | 912 frame.WriteUInt32(1); // Number of headers. |
| 912 frame.WriteStringPiece32("name"); | 913 frame.WriteStringPiece32("name"); |
| 913 frame.WriteStringPiece32(value); | 914 frame.WriteStringPiece32(value); |
| 914 } | 915 } |
| 915 // write the length | 916 // write the length |
| 916 frame.RewriteLength(framer); | 917 frame.RewriteLength(framer); |
| 917 | 918 |
| 918 framer.set_enable_compression(false); | 919 framer.set_enable_compression(false); |
| 919 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 920 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 920 | 921 |
| 921 TestSpdyVisitor visitor(spdy_version_); | 922 TestSpdyVisitor visitor(spdy_version_); |
| 922 visitor.use_compression_ = false; | 923 visitor.use_compression_ = false; |
| 923 visitor.SimulateInFramer( | 924 visitor.SimulateInFramer( |
| 924 reinterpret_cast<unsigned char*>(control_frame->data()), | 925 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 925 control_frame->size()); | 926 control_frame->size()); |
| 926 | 927 |
| 927 EXPECT_THAT(visitor.headers_, ElementsAre( | 928 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 928 Pair("name", value))); | 929 Pair("name", value))); |
| 929 } | 930 } |
| 930 | 931 |
| 931 TEST_P(SpdyFramerTest, BasicCompression) { | 932 TEST_P(SpdyFramerTest, BasicCompression) { |
| 932 if (spdy_version_ >= 4) { | 933 if (spdy_version_ > SPDY3) { |
| 933 // Deflate compression doesn't apply to HPACK. | 934 // Deflate compression doesn't apply to HPACK. |
| 934 return; | 935 return; |
| 935 } | 936 } |
| 936 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); | 937 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); |
| 937 SpdyFramer framer(spdy_version_); | 938 SpdyFramer framer(spdy_version_); |
| 938 framer.set_debug_visitor(visitor.get()); | 939 framer.set_debug_visitor(visitor.get()); |
| 939 SpdySynStreamIR syn_stream(1); | 940 SpdySynStreamIR syn_stream(1); |
| 940 syn_stream.set_priority(1); | 941 syn_stream.set_priority(1); |
| 941 syn_stream.SetHeader("server", "SpdyServer 1.0"); | 942 syn_stream.SetHeader("server", "SpdyServer 1.0"); |
| 942 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 943 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1397 EXPECT_EQ(0, visitor.headers_frame_count_); | 1398 EXPECT_EQ(0, visitor.headers_frame_count_); |
| 1398 } | 1399 } |
| 1399 EXPECT_EQ(0, visitor.data_bytes_); | 1400 EXPECT_EQ(0, visitor.data_bytes_); |
| 1400 EXPECT_EQ(0, visitor.fin_frame_count_); | 1401 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1401 EXPECT_EQ(1, visitor.fin_flag_count_); | 1402 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 1402 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1403 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1403 EXPECT_EQ(0, visitor.data_frame_count_); | 1404 EXPECT_EQ(0, visitor.data_frame_count_); |
| 1404 } | 1405 } |
| 1405 | 1406 |
| 1406 TEST_P(SpdyFramerTest, HeaderCompression) { | 1407 TEST_P(SpdyFramerTest, HeaderCompression) { |
| 1407 if (spdy_version_ >= 4) { | 1408 if (spdy_version_ > SPDY3) { |
| 1408 // Deflate compression doesn't apply to HPACK. | 1409 // Deflate compression doesn't apply to HPACK. |
| 1409 return; | 1410 return; |
| 1410 } | 1411 } |
| 1411 SpdyFramer send_framer(spdy_version_); | 1412 SpdyFramer send_framer(spdy_version_); |
| 1412 SpdyFramer recv_framer(spdy_version_); | 1413 SpdyFramer recv_framer(spdy_version_); |
| 1413 | 1414 |
| 1414 send_framer.set_enable_compression(true); | 1415 send_framer.set_enable_compression(true); |
| 1415 recv_framer.set_enable_compression(true); | 1416 recv_framer.set_enable_compression(true); |
| 1416 | 1417 |
| 1417 const char kHeader1[] = "header1"; | 1418 const char kHeader1[] = "header1"; |
| (...skipping 1686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3104 // produced by rand(), so adding, removing or running single tests | 3105 // produced by rand(), so adding, removing or running single tests |
| 3105 // alters this value. The best we can do is assert that it happens | 3106 // alters this value. The best we can do is assert that it happens |
| 3106 // at least twice. | 3107 // at least twice. |
| 3107 EXPECT_LE(2, visitor.control_frame_header_data_count_); | 3108 EXPECT_LE(2, visitor.control_frame_header_data_count_); |
| 3108 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3109 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3109 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3110 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 3110 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3111 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 3111 } | 3112 } |
| 3112 | 3113 |
| 3113 TEST_P(SpdyFramerTest, ControlFrameAtMaxSizeLimit) { | 3114 TEST_P(SpdyFramerTest, ControlFrameAtMaxSizeLimit) { |
| 3114 if (spdy_version_ >= 4) { | 3115 if (spdy_version_ > SPDY3) { |
| 3115 // TODO(jgraettinger): This test setup doesn't work with HPACK. | 3116 // TODO(jgraettinger): This test setup doesn't work with HPACK. |
| 3116 return; | 3117 return; |
| 3117 } | 3118 } |
| 3118 // First find the size of the header value in order to just reach the control | 3119 // First find the size of the header value in order to just reach the control |
| 3119 // frame max size. | 3120 // frame max size. |
| 3120 SpdyFramer framer(spdy_version_); | 3121 SpdyFramer framer(spdy_version_); |
| 3121 framer.set_enable_compression(false); | 3122 framer.set_enable_compression(false); |
| 3122 SpdySynStreamIR syn_stream(1); | 3123 SpdySynStreamIR syn_stream(1); |
| 3123 syn_stream.set_priority(1); | 3124 syn_stream.set_priority(1); |
| 3124 syn_stream.SetHeader("aa", ""); | 3125 syn_stream.SetHeader("aa", ""); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3139 control_frame->size()); | 3140 control_frame->size()); |
| 3140 EXPECT_TRUE(visitor.header_buffer_valid_); | 3141 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 3141 EXPECT_EQ(0, visitor.error_count_); | 3142 EXPECT_EQ(0, visitor.error_count_); |
| 3142 EXPECT_EQ(1, visitor.syn_frame_count_); | 3143 EXPECT_EQ(1, visitor.syn_frame_count_); |
| 3143 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3144 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3144 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3145 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3145 EXPECT_LT(kBigValueSize, visitor.header_buffer_length_); | 3146 EXPECT_LT(kBigValueSize, visitor.header_buffer_length_); |
| 3146 } | 3147 } |
| 3147 | 3148 |
| 3148 TEST_P(SpdyFramerTest, ControlFrameTooLarge) { | 3149 TEST_P(SpdyFramerTest, ControlFrameTooLarge) { |
| 3149 if (spdy_version_ >= 4) { | 3150 if (spdy_version_ > SPDY3) { |
| 3150 // TODO(jgraettinger): This test setup doesn't work with HPACK. | 3151 // TODO(jgraettinger): This test setup doesn't work with HPACK. |
| 3151 return; | 3152 return; |
| 3152 } | 3153 } |
| 3153 // First find the size of the header value in order to just reach the control | 3154 // First find the size of the header value in order to just reach the control |
| 3154 // frame max size. | 3155 // frame max size. |
| 3155 SpdyFramer framer(spdy_version_); | 3156 SpdyFramer framer(spdy_version_); |
| 3156 framer.set_enable_compression(false); | 3157 framer.set_enable_compression(false); |
| 3157 SpdySynStreamIR syn_stream(1); | 3158 SpdySynStreamIR syn_stream(1); |
| 3158 syn_stream.SetHeader("aa", ""); | 3159 syn_stream.SetHeader("aa", ""); |
| 3159 syn_stream.set_priority(1); | 3160 syn_stream.set_priority(1); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3280 // at least kHeaderBufferChunks + 1. | 3281 // at least kHeaderBufferChunks + 1. |
| 3281 EXPECT_LE(kHeaderBufferChunks + 1, | 3282 EXPECT_LE(kHeaderBufferChunks + 1, |
| 3282 static_cast<unsigned>(visitor.control_frame_header_data_count_)); | 3283 static_cast<unsigned>(visitor.control_frame_header_data_count_)); |
| 3283 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 3284 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 3284 | 3285 |
| 3285 // The framer should not have sent half-close to the visitor. | 3286 // The framer should not have sent half-close to the visitor. |
| 3286 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3287 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3287 } | 3288 } |
| 3288 | 3289 |
| 3289 TEST_P(SpdyFramerTest, DecompressCorruptHeaderBlock) { | 3290 TEST_P(SpdyFramerTest, DecompressCorruptHeaderBlock) { |
| 3290 if (spdy_version_ >= 4) { | 3291 if (spdy_version_ > SPDY3) { |
| 3291 // Deflate compression doesn't apply to HPACK. | 3292 // Deflate compression doesn't apply to HPACK. |
| 3292 return; | 3293 return; |
| 3293 } | 3294 } |
| 3294 SpdyFramer framer(spdy_version_); | 3295 SpdyFramer framer(spdy_version_); |
| 3295 framer.set_enable_compression(false); | 3296 framer.set_enable_compression(false); |
| 3296 // Construct a SYN_STREAM control frame without compressing the header block, | 3297 // Construct a SYN_STREAM control frame without compressing the header block, |
| 3297 // and have the framer try to decompress it. This will cause the framer to | 3298 // and have the framer try to decompress it. This will cause the framer to |
| 3298 // deal with a decompression error. | 3299 // deal with a decompression error. |
| 3299 SpdySynStreamIR syn_stream(1); | 3300 SpdySynStreamIR syn_stream(1); |
| 3300 syn_stream.set_priority(1); | 3301 syn_stream.set_priority(1); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3359 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 3360 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 3360 SpdyFramer framer(spdy_version_); | 3361 SpdyFramer framer(spdy_version_); |
| 3361 SpdySettingsIR settings_ir; | 3362 SpdySettingsIR settings_ir; |
| 3362 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); | 3363 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); |
| 3363 SetFrameLength(control_frame.get(), 0, spdy_version_); | 3364 SetFrameLength(control_frame.get(), 0, spdy_version_); |
| 3364 TestSpdyVisitor visitor(spdy_version_); | 3365 TestSpdyVisitor visitor(spdy_version_); |
| 3365 visitor.use_compression_ = false; | 3366 visitor.use_compression_ = false; |
| 3366 visitor.SimulateInFramer( | 3367 visitor.SimulateInFramer( |
| 3367 reinterpret_cast<unsigned char*>(control_frame->data()), | 3368 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3368 framer.GetControlFrameHeaderSize()); | 3369 framer.GetControlFrameHeaderSize()); |
| 3369 if (spdy_version_ < 4) { | 3370 if (spdy_version_ <= SPDY3) { |
| 3370 // Should generate an error, since zero-len settings frames are unsupported. | 3371 // Should generate an error, since zero-len settings frames are unsupported. |
| 3371 EXPECT_EQ(1, visitor.error_count_); | 3372 EXPECT_EQ(1, visitor.error_count_); |
| 3372 } else { | 3373 } else { |
| 3373 // Zero-len settings frames are permitted as of SPDY 4. | 3374 // Zero-len settings frames are permitted as of SPDY 4. |
| 3374 EXPECT_EQ(0, visitor.error_count_); | 3375 EXPECT_EQ(0, visitor.error_count_); |
| 3375 } | 3376 } |
| 3376 } | 3377 } |
| 3377 | 3378 |
| 3378 // Tests handling of SETTINGS frames with invalid length. | 3379 // Tests handling of SETTINGS frames with invalid length. |
| 3379 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 3380 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3421 control_frame->size()); | 3422 control_frame->size()); |
| 3422 TestSpdyVisitor visitor(spdy_version_); | 3423 TestSpdyVisitor visitor(spdy_version_); |
| 3423 visitor.use_compression_ = false; | 3424 visitor.use_compression_ = false; |
| 3424 | 3425 |
| 3425 // Read all at once. | 3426 // Read all at once. |
| 3426 visitor.SimulateInFramer( | 3427 visitor.SimulateInFramer( |
| 3427 reinterpret_cast<unsigned char*>(control_frame->data()), | 3428 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3428 control_frame->size()); | 3429 control_frame->size()); |
| 3429 EXPECT_EQ(0, visitor.error_count_); | 3430 EXPECT_EQ(0, visitor.error_count_); |
| 3430 EXPECT_EQ(3, visitor.setting_count_); | 3431 EXPECT_EQ(3, visitor.setting_count_); |
| 3431 if (spdy_version_ >= 4) { | 3432 if (spdy_version_ > SPDY3) { |
| 3432 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3433 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3433 } | 3434 } |
| 3434 | 3435 |
| 3435 // Read data in small chunks. | 3436 // Read data in small chunks. |
| 3436 size_t framed_data = 0; | 3437 size_t framed_data = 0; |
| 3437 size_t unframed_data = control_frame->size(); | 3438 size_t unframed_data = control_frame->size(); |
| 3438 size_t kReadChunkSize = 5; // Read five bytes at a time. | 3439 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 3439 while (unframed_data > 0) { | 3440 while (unframed_data > 0) { |
| 3440 size_t to_read = min(kReadChunkSize, unframed_data); | 3441 size_t to_read = min(kReadChunkSize, unframed_data); |
| 3441 visitor.SimulateInFramer( | 3442 visitor.SimulateInFramer( |
| 3442 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), | 3443 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), |
| 3443 to_read); | 3444 to_read); |
| 3444 unframed_data -= to_read; | 3445 unframed_data -= to_read; |
| 3445 framed_data += to_read; | 3446 framed_data += to_read; |
| 3446 } | 3447 } |
| 3447 EXPECT_EQ(0, visitor.error_count_); | 3448 EXPECT_EQ(0, visitor.error_count_); |
| 3448 EXPECT_EQ(3 * 2, visitor.setting_count_); | 3449 EXPECT_EQ(3 * 2, visitor.setting_count_); |
| 3449 if (spdy_version_ >= 4) { | 3450 if (spdy_version_ > SPDY3) { |
| 3450 EXPECT_EQ(2, visitor.settings_ack_sent_); | 3451 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| 3451 } | 3452 } |
| 3452 } | 3453 } |
| 3453 | 3454 |
| 3454 // Tests handling of SETTINGS frame with duplicate entries. | 3455 // Tests handling of SETTINGS frame with duplicate entries. |
| 3455 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { | 3456 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 3456 SpdyFramer framer(spdy_version_); | 3457 SpdyFramer framer(spdy_version_); |
| 3457 | 3458 |
| 3458 const unsigned char kV2FrameData[] = { | 3459 const unsigned char kV2FrameData[] = { |
| 3459 0x80, spdy_version_ch_, 0x00, 0x04, | 3460 0x80, spdy_version_ch_, 0x00, 0x04, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3562 EXPECT_EQ(1, visitor.error_count_); | 3563 EXPECT_EQ(1, visitor.error_count_); |
| 3563 } else { | 3564 } else { |
| 3564 // In SPDY 4+, settings are allowed in any order. | 3565 // In SPDY 4+, settings are allowed in any order. |
| 3565 EXPECT_EQ(3, visitor.setting_count_); | 3566 EXPECT_EQ(3, visitor.setting_count_); |
| 3566 EXPECT_EQ(0, visitor.error_count_); | 3567 EXPECT_EQ(0, visitor.error_count_); |
| 3567 // EXPECT_EQ(1, visitor.settings_ack_count_); | 3568 // EXPECT_EQ(1, visitor.settings_ack_count_); |
| 3568 } | 3569 } |
| 3569 } | 3570 } |
| 3570 | 3571 |
| 3571 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { | 3572 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 3572 if (spdy_version_ < 4) { | 3573 if (spdy_version_ <= SPDY3) { |
| 3573 return; | 3574 return; |
| 3574 } | 3575 } |
| 3575 SpdyFramer framer(spdy_version_); | 3576 SpdyFramer framer(spdy_version_); |
| 3576 | 3577 |
| 3577 const unsigned char kFrameData[] = { | 3578 const unsigned char kFrameData[] = { |
| 3578 0x00, 0x00, 0x04, 0x01, | 3579 0x00, 0x00, 0x04, 0x01, |
| 3579 0x00, 0x00, 0x00, 0x00, | 3580 0x00, 0x00, 0x00, 0x00, |
| 3580 }; | 3581 }; |
| 3581 | 3582 |
| 3582 TestSpdyVisitor visitor(spdy_version_); | 3583 TestSpdyVisitor visitor(spdy_version_); |
| 3583 visitor.use_compression_ = false; | 3584 visitor.use_compression_ = false; |
| 3584 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 3585 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 3585 | 3586 |
| 3586 EXPECT_EQ(0, visitor.error_count_); | 3587 EXPECT_EQ(0, visitor.error_count_); |
| 3587 EXPECT_EQ(0, visitor.setting_count_); | 3588 EXPECT_EQ(0, visitor.setting_count_); |
| 3588 EXPECT_EQ(1, visitor.settings_ack_received_); | 3589 EXPECT_EQ(1, visitor.settings_ack_received_); |
| 3589 } | 3590 } |
| 3590 | 3591 |
| 3591 | 3592 |
| 3592 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 3593 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
| 3593 if (spdy_version_ < 4) { | 3594 if (spdy_version_ <= SPDY3) { |
| 3594 return; | 3595 return; |
| 3595 } | 3596 } |
| 3596 | 3597 |
| 3597 const int kPaddingLen = 512; // So we get two bytes for padding length field. | 3598 const int kPaddingLen = 512; // So we get two bytes for padding length field. |
| 3598 const char data_payload[] = "hello"; | 3599 const char data_payload[] = "hello"; |
| 3599 | 3600 |
| 3600 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3601 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3601 SpdyFramer framer(spdy_version_); | 3602 SpdyFramer framer(spdy_version_); |
| 3602 framer.set_visitor(&visitor); | 3603 framer.set_visitor(&visitor); |
| 3603 | 3604 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3756 | 3757 |
| 3757 SpdyContinuationIR continuation(42); | 3758 SpdyContinuationIR continuation(42); |
| 3758 continuation.SetHeader("bar", "foo"); | 3759 continuation.SetHeader("bar", "foo"); |
| 3759 continuation.SetHeader("foo", "bar"); | 3760 continuation.SetHeader("foo", "bar"); |
| 3760 scoped_ptr<SpdySerializedFrame> frame( | 3761 scoped_ptr<SpdySerializedFrame> frame( |
| 3761 framer.SerializeContinuation(continuation)); | 3762 framer.SerializeContinuation(continuation)); |
| 3762 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 3763 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 3763 } | 3764 } |
| 3764 | 3765 |
| 3765 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { | 3766 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
| 3766 if (spdy_version_ < 4) { | 3767 if (spdy_version_ <= SPDY3) { |
| 3767 return; | 3768 return; |
| 3768 } | 3769 } |
| 3769 | 3770 |
| 3770 SpdyFramer framer(spdy_version_); | 3771 SpdyFramer framer(spdy_version_); |
| 3771 SpdyPushPromiseIR push_promise(42, 57); | 3772 SpdyPushPromiseIR push_promise(42, 57); |
| 3772 push_promise.SetHeader("foo", "bar"); | 3773 push_promise.SetHeader("foo", "bar"); |
| 3773 push_promise.SetHeader("bar", "foofoo"); | 3774 push_promise.SetHeader("bar", "foofoo"); |
| 3774 SpdyHeaderBlock headers = push_promise.name_value_block(); | 3775 SpdyHeaderBlock headers = push_promise.name_value_block(); |
| 3775 scoped_ptr<SpdySerializedFrame> frame( | 3776 scoped_ptr<SpdySerializedFrame> frame( |
| 3776 framer.SerializePushPromise(push_promise)); | 3777 framer.SerializePushPromise(push_promise)); |
| 3777 EXPECT_TRUE(frame.get() != NULL); | 3778 EXPECT_TRUE(frame.get() != NULL); |
| 3778 TestSpdyVisitor visitor(spdy_version_); | 3779 TestSpdyVisitor visitor(spdy_version_); |
| 3779 visitor.use_compression_ = true; | 3780 visitor.use_compression_ = true; |
| 3780 visitor.SimulateInFramer( | 3781 visitor.SimulateInFramer( |
| 3781 reinterpret_cast<unsigned char*>(frame->data()), | 3782 reinterpret_cast<unsigned char*>(frame->data()), |
| 3782 frame->size()); | 3783 frame->size()); |
| 3783 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3784 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3784 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3785 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3785 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3786 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 3786 } | 3787 } |
| 3787 | 3788 |
| 3788 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3789 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3789 if (spdy_version_ < 4) { | 3790 if (spdy_version_ <= SPDY3) { |
| 3790 return; | 3791 return; |
| 3791 } | 3792 } |
| 3792 | 3793 |
| 3793 const unsigned char kInput[] = { | 3794 const unsigned char kInput[] = { |
| 3794 0x00, 0x10, 0x01, 0x00, // HEADERS | 3795 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3795 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3796 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3796 0x40, 0x06, 0x43, 0x6f, | 3797 0x40, 0x06, 0x43, 0x6f, |
| 3797 0x6f, 0x6b, 0x69, 0x65, | 3798 0x6f, 0x6b, 0x69, 0x65, |
| 3798 0x07, 0x66, 0x6f, 0x6f, | 3799 0x07, 0x66, 0x6f, 0x6f, |
| 3799 0x3d, 0x62, 0x61, 0x72, | 3800 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3824 EXPECT_EQ(2, visitor.continuation_count_); | 3825 EXPECT_EQ(2, visitor.continuation_count_); |
| 3825 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3826 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3826 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3827 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3827 | 3828 |
| 3828 EXPECT_THAT(visitor.headers_, ElementsAre( | 3829 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3829 Pair("cookie", "foo=bar; baz=bing; "), | 3830 Pair("cookie", "foo=bar; baz=bing; "), |
| 3830 Pair("name", "value"))); | 3831 Pair("name", "value"))); |
| 3831 } | 3832 } |
| 3832 | 3833 |
| 3833 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { | 3834 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { |
| 3834 if (spdy_version_ < 4) { | 3835 if (spdy_version_ <= SPDY3) { |
| 3835 return; | 3836 return; |
| 3836 } | 3837 } |
| 3837 | 3838 |
| 3838 const unsigned char kInput[] = { | 3839 const unsigned char kInput[] = { |
| 3839 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN | 3840 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN |
| 3840 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3841 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3841 0x40, 0x06, 0x43, 0x6f, | 3842 0x40, 0x06, 0x43, 0x6f, |
| 3842 0x6f, 0x6b, 0x69, 0x65, | 3843 0x6f, 0x6b, 0x69, 0x65, |
| 3843 0x07, 0x66, 0x6f, 0x6f, | 3844 0x07, 0x66, 0x6f, 0x6f, |
| 3844 0x3d, 0x62, 0x61, 0x72, | 3845 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 3870 EXPECT_EQ(1, visitor.fin_flag_count_); | 3871 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3871 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3872 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3872 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3873 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 3873 | 3874 |
| 3874 EXPECT_THAT(visitor.headers_, ElementsAre( | 3875 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3875 Pair("cookie", "foo=bar; baz=bing; "), | 3876 Pair("cookie", "foo=bar; baz=bing; "), |
| 3876 Pair("name", "value"))); | 3877 Pair("name", "value"))); |
| 3877 } | 3878 } |
| 3878 | 3879 |
| 3879 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3880 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 3880 if (spdy_version_ < 4) { | 3881 if (spdy_version_ <= SPDY3) { |
| 3881 return; | 3882 return; |
| 3882 } | 3883 } |
| 3883 | 3884 |
| 3884 const unsigned char kInput[] = { | 3885 const unsigned char kInput[] = { |
| 3885 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE | 3886 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE |
| 3886 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3887 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3887 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3888 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
| 3888 0x40, 0x06, 0x43, 0x6f, | 3889 0x40, 0x06, 0x43, 0x6f, |
| 3889 0x6f, 0x6b, 0x69, 0x65, | 3890 0x6f, 0x6b, 0x69, 0x65, |
| 3890 0x07, 0x66, 0x6f, 0x6f, | 3891 0x07, 0x66, 0x6f, 0x6f, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3917 EXPECT_EQ(2, visitor.continuation_count_); | 3918 EXPECT_EQ(2, visitor.continuation_count_); |
| 3918 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3919 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3919 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3920 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3920 | 3921 |
| 3921 EXPECT_THAT(visitor.headers_, ElementsAre( | 3922 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 3922 Pair("cookie", "foo=bar; baz=bing; "), | 3923 Pair("cookie", "foo=bar; baz=bing; "), |
| 3923 Pair("name", "value"))); | 3924 Pair("name", "value"))); |
| 3924 } | 3925 } |
| 3925 | 3926 |
| 3926 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { | 3927 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { |
| 3927 if (spdy_version_ < 4) { | 3928 if (spdy_version_ <= SPDY3) { |
| 3928 return; | 3929 return; |
| 3929 } | 3930 } |
| 3930 | 3931 |
| 3931 const unsigned char kInput[] = { | 3932 const unsigned char kInput[] = { |
| 3932 0x00, 0x10, 0x01, 0x00, // HEADERS | 3933 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3933 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3934 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3934 0x40, 0x06, 0x43, 0x6f, | 3935 0x40, 0x06, 0x43, 0x6f, |
| 3935 0x6f, 0x6b, 0x69, 0x65, | 3936 0x6f, 0x6b, 0x69, 0x65, |
| 3936 0x07, 0x66, 0x6f, 0x6f, | 3937 0x07, 0x66, 0x6f, 0x6f, |
| 3937 0x3d, 0x62, 0x61, 0x72, | 3938 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 3953 EXPECT_EQ(1, visitor.error_count_); | 3954 EXPECT_EQ(1, visitor.error_count_); |
| 3954 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 3955 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 3955 visitor.framer_.error_code()) | 3956 visitor.framer_.error_code()) |
| 3956 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3957 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3957 EXPECT_EQ(1, visitor.headers_frame_count_); | 3958 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3958 EXPECT_EQ(0, visitor.continuation_count_); | 3959 EXPECT_EQ(0, visitor.continuation_count_); |
| 3959 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3960 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3960 } | 3961 } |
| 3961 | 3962 |
| 3962 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3963 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { |
| 3963 if (spdy_version_ < 4) { | 3964 if (spdy_version_ <= SPDY3) { |
| 3964 return; | 3965 return; |
| 3965 } | 3966 } |
| 3966 | 3967 |
| 3967 const unsigned char kInput[] = { | 3968 const unsigned char kInput[] = { |
| 3968 0x00, 0x10, 0x09, 0x00, // CONTINUATION | 3969 0x00, 0x10, 0x09, 0x00, // CONTINUATION |
| 3969 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3970 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3970 0x40, 0x06, 0x43, 0x6f, | 3971 0x40, 0x06, 0x43, 0x6f, |
| 3971 0x6f, 0x6b, 0x69, 0x65, | 3972 0x6f, 0x6b, 0x69, 0x65, |
| 3972 0x07, 0x66, 0x6f, 0x6f, | 3973 0x07, 0x66, 0x6f, 0x6f, |
| 3973 0x3d, 0x62, 0x61, 0x72, | 3974 0x3d, 0x62, 0x61, 0x72, |
| 3974 }; | 3975 }; |
| 3975 | 3976 |
| 3976 SpdyFramer framer(spdy_version_); | 3977 SpdyFramer framer(spdy_version_); |
| 3977 TestSpdyVisitor visitor(spdy_version_); | 3978 TestSpdyVisitor visitor(spdy_version_); |
| 3978 framer.set_visitor(&visitor); | 3979 framer.set_visitor(&visitor); |
| 3979 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3980 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3980 | 3981 |
| 3981 EXPECT_EQ(1, visitor.error_count_); | 3982 EXPECT_EQ(1, visitor.error_count_); |
| 3982 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 3983 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, |
| 3983 visitor.framer_.error_code()) | 3984 visitor.framer_.error_code()) |
| 3984 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3985 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3985 EXPECT_EQ(0, visitor.continuation_count_); | 3986 EXPECT_EQ(0, visitor.continuation_count_); |
| 3986 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3987 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3987 } | 3988 } |
| 3988 | 3989 |
| 3989 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { | 3990 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { |
| 3990 if (spdy_version_ < 4) { | 3991 if (spdy_version_ <= SPDY3) { |
| 3991 return; | 3992 return; |
| 3992 } | 3993 } |
| 3993 | 3994 |
| 3994 const unsigned char kInput[] = { | 3995 const unsigned char kInput[] = { |
| 3995 0x00, 0x10, 0x01, 0x00, // HEADERS | 3996 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3996 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3997 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3997 0x40, 0x06, 0x43, 0x6f, | 3998 0x40, 0x06, 0x43, 0x6f, |
| 3998 0x6f, 0x6b, 0x69, 0x65, | 3999 0x6f, 0x6b, 0x69, 0x65, |
| 3999 0x07, 0x66, 0x6f, 0x6f, | 4000 0x07, 0x66, 0x6f, 0x6f, |
| 4000 0x3d, 0x62, 0x61, 0x72, | 4001 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4013 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 4014 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, |
| 4014 visitor.framer_.error_code()) | 4015 visitor.framer_.error_code()) |
| 4015 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4016 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4016 EXPECT_EQ(1, visitor.headers_frame_count_); | 4017 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 4017 EXPECT_EQ(0, visitor.continuation_count_); | 4018 EXPECT_EQ(0, visitor.continuation_count_); |
| 4018 EXPECT_EQ(0u, visitor.header_buffer_length_); | 4019 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 4019 EXPECT_EQ(0, visitor.data_frame_count_); | 4020 EXPECT_EQ(0, visitor.data_frame_count_); |
| 4020 } | 4021 } |
| 4021 | 4022 |
| 4022 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { | 4023 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { |
| 4023 if (spdy_version_ < 4) { | 4024 if (spdy_version_ <= SPDY3) { |
| 4024 return; | 4025 return; |
| 4025 } | 4026 } |
| 4026 | 4027 |
| 4027 const unsigned char kInput[] = { | 4028 const unsigned char kInput[] = { |
| 4028 0x00, 0x10, 0x01, 0x00, // HEADERS | 4029 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 4029 0x00, 0x00, 0x00, 0x01, // Stream 1 | 4030 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4030 0x40, 0x06, 0x43, 0x6f, | 4031 0x40, 0x06, 0x43, 0x6f, |
| 4031 0x6f, 0x6b, 0x69, 0x65, | 4032 0x6f, 0x6b, 0x69, 0x65, |
| 4032 0x07, 0x66, 0x6f, 0x6f, | 4033 0x07, 0x66, 0x6f, 0x6f, |
| 4033 0x3d, 0x62, 0x61, 0x72, | 4034 0x3d, 0x62, 0x61, 0x72, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4270 EXPECT_CALL(visitor, OnError(_)); | 4271 EXPECT_CALL(visitor, OnError(_)); |
| 4271 framer.ProcessInput("HTTP/1.0", 8); | 4272 framer.ProcessInput("HTTP/1.0", 8); |
| 4272 EXPECT_TRUE(framer.probable_http_response()); | 4273 EXPECT_TRUE(framer.probable_http_response()); |
| 4273 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4274 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4274 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) | 4275 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) |
| 4275 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4276 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4276 } | 4277 } |
| 4277 } | 4278 } |
| 4278 | 4279 |
| 4279 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { | 4280 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { |
| 4280 if (spdy_version_ >= 4) { | 4281 if (spdy_version_ > SPDY3) { |
| 4281 return; | 4282 return; |
| 4282 } | 4283 } |
| 4283 | 4284 |
| 4284 for (int flags = 0; flags < 256; ++flags) { | 4285 for (int flags = 0; flags < 256; ++flags) { |
| 4285 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4286 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4286 | 4287 |
| 4287 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4288 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4288 SpdyFramer framer(spdy_version_); | 4289 SpdyFramer framer(spdy_version_); |
| 4289 framer.set_visitor(&visitor); | 4290 framer.set_visitor(&visitor); |
| 4290 | 4291 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4310 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4311 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4311 } else { | 4312 } else { |
| 4312 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4313 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4313 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4314 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4314 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4315 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4315 } | 4316 } |
| 4316 } | 4317 } |
| 4317 } | 4318 } |
| 4318 | 4319 |
| 4319 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 4320 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
| 4320 if (spdy_version_ < 4) { | 4321 if (spdy_version_ <= SPDY3) { |
| 4321 return; | 4322 return; |
| 4322 } | 4323 } |
| 4323 | 4324 |
| 4324 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | | 4325 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | |
| 4325 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; | 4326 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; |
| 4326 | 4327 |
| 4327 for (int flags = 0; flags < 256; ++flags) { | 4328 for (int flags = 0; flags < 256; ++flags) { |
| 4328 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4329 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4329 | 4330 |
| 4330 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4331 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4508 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4509 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4509 } else { | 4510 } else { |
| 4510 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4511 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4511 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4512 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4512 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4513 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4513 } | 4514 } |
| 4514 } | 4515 } |
| 4515 } | 4516 } |
| 4516 | 4517 |
| 4517 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { | 4518 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { |
| 4518 if (spdy_version_ >= 4) { return; } | 4519 if (spdy_version_ > SPDY3) { return; } |
| 4519 for (int flags = 0; flags < 256; ++flags) { | 4520 for (int flags = 0; flags < 256; ++flags) { |
| 4520 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4521 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4521 | 4522 |
| 4522 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4523 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4523 SpdyFramer framer(spdy_version_); | 4524 SpdyFramer framer(spdy_version_); |
| 4524 framer.set_visitor(&visitor); | 4525 framer.set_visitor(&visitor); |
| 4525 | 4526 |
| 4526 SpdySettingsIR settings_ir; | 4527 SpdySettingsIR settings_ir; |
| 4527 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, | 4528 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, |
| 4528 false, | 4529 false, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4549 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4550 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4550 } else { | 4551 } else { |
| 4551 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4552 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4552 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4553 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4553 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4554 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4554 } | 4555 } |
| 4555 } | 4556 } |
| 4556 } | 4557 } |
| 4557 | 4558 |
| 4558 TEST_P(SpdyFramerTest, SettingsFrameFlags) { | 4559 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
| 4559 if (spdy_version_ < 4) { return; } | 4560 if (spdy_version_ <= SPDY3) { return; } |
| 4560 for (int flags = 0; flags < 256; ++flags) { | 4561 for (int flags = 0; flags < 256; ++flags) { |
| 4561 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4562 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4562 | 4563 |
| 4563 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4564 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4564 SpdyFramer framer(spdy_version_); | 4565 SpdyFramer framer(spdy_version_); |
| 4565 framer.set_visitor(&visitor); | 4566 framer.set_visitor(&visitor); |
| 4566 | 4567 |
| 4567 SpdySettingsIR settings_ir; | 4568 SpdySettingsIR settings_ir; |
| 4568 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); | 4569 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); |
| 4569 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 4570 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5027 SpdyBlockedIR blocked_ir(0); | 5028 SpdyBlockedIR blocked_ir(0); |
| 5028 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 5029 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 5029 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 5030 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
| 5030 | 5031 |
| 5031 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5032 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5032 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5033 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5033 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5034 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5034 } | 5035 } |
| 5035 | 5036 |
| 5036 } // namespace net | 5037 } // namespace net |
| OLD | NEW |