Chromium Code Reviews| 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" |
| 11 #include "net/spdy/hpack_output_stream.h" | 11 #include "net/spdy/hpack_output_stream.h" |
| 12 #include "net/spdy/mock_spdy_framer_visitor.h" | 12 #include "net/spdy/mock_spdy_framer_visitor.h" |
| 13 #include "net/spdy/spdy_frame_builder.h" | 13 #include "net/spdy/spdy_frame_builder.h" |
| 14 #include "net/spdy/spdy_frame_reader.h" | 14 #include "net/spdy/spdy_frame_reader.h" |
| 15 #include "net/spdy/spdy_framer.h" | 15 #include "net/spdy/spdy_framer.h" |
| 16 #include "net/spdy/spdy_protocol.h" | 16 #include "net/spdy/spdy_protocol.h" |
| 17 #include "net/spdy/spdy_test_utils.h" | 17 #include "net/spdy/spdy_test_utils.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
| 20 | 20 |
| 21 using base::StringPiece; | |
| 22 using std::string; | |
| 23 using std::max; | |
| 24 using std::min; | |
| 25 using std::numeric_limits; | |
| 26 using testing::ElementsAre; | |
| 27 using testing::Pair; | |
|
Peter Kasting
2014/11/25 22:51:00
Most of the changes in this file are from removing
| |
| 28 using testing::_; | 21 using testing::_; |
| 29 | 22 |
| 30 namespace net { | 23 namespace net { |
| 31 | 24 |
| 32 namespace test { | 25 namespace test { |
| 33 | 26 |
| 34 static const size_t kMaxDecompressedSize = 1024; | 27 static const size_t kMaxDecompressedSize = 1024; |
| 35 | 28 |
| 36 class MockDebugVisitor : public SpdyFramerDebugVisitorInterface { | 29 class MockDebugVisitor : public SpdyFramerDebugVisitorInterface { |
| 37 public: | 30 public: |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 framer_.set_visitor(this); | 464 framer_.set_visitor(this); |
| 472 size_t input_remaining = size; | 465 size_t input_remaining = size; |
| 473 const char* input_ptr = reinterpret_cast<const char*>(input); | 466 const char* input_ptr = reinterpret_cast<const char*>(input); |
| 474 while (input_remaining > 0 && | 467 while (input_remaining > 0 && |
| 475 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { | 468 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { |
| 476 // To make the tests more interesting, we feed random (amd small) chunks | 469 // To make the tests more interesting, we feed random (amd small) chunks |
| 477 // into the framer. This simulates getting strange-sized reads from | 470 // into the framer. This simulates getting strange-sized reads from |
| 478 // the socket. | 471 // the socket. |
| 479 const size_t kMaxReadSize = 32; | 472 const size_t kMaxReadSize = 32; |
| 480 size_t bytes_read = | 473 size_t bytes_read = |
| 481 (rand() % min(input_remaining, kMaxReadSize)) + 1; | 474 (rand() % std::min(input_remaining, kMaxReadSize)) + 1; |
| 482 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); | 475 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); |
| 483 input_remaining -= bytes_processed; | 476 input_remaining -= bytes_processed; |
| 484 input_ptr += bytes_processed; | 477 input_ptr += bytes_processed; |
| 485 } | 478 } |
| 486 } | 479 } |
| 487 | 480 |
| 488 void InitHeaderStreaming(SpdyFrameType header_control_type, | 481 void InitHeaderStreaming(SpdyFrameType header_control_type, |
| 489 SpdyStreamId stream_id) { | 482 SpdyStreamId stream_id) { |
| 490 if (!SpdyConstants::IsValidFrameType(framer_.protocol_version(), | 483 if (!SpdyConstants::IsValidFrameType(framer_.protocol_version(), |
| 491 SpdyConstants::SerializeFrameType(framer_.protocol_version(), | 484 SpdyConstants::SerializeFrameType(framer_.protocol_version(), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 615 namespace net { | 608 namespace net { |
| 616 | 609 |
| 617 class SpdyFramerTest : public ::testing::TestWithParam<SpdyMajorVersion> { | 610 class SpdyFramerTest : public ::testing::TestWithParam<SpdyMajorVersion> { |
| 618 protected: | 611 protected: |
| 619 void SetUp() override { | 612 void SetUp() override { |
| 620 spdy_version_ = GetParam(); | 613 spdy_version_ = GetParam(); |
| 621 spdy_version_ch_ = static_cast<unsigned char>( | 614 spdy_version_ch_ = static_cast<unsigned char>( |
| 622 SpdyConstants::SerializeMajorVersion(spdy_version_)); | 615 SpdyConstants::SerializeMajorVersion(spdy_version_)); |
| 623 } | 616 } |
| 624 | 617 |
| 625 void CompareFrame(const string& description, | 618 void CompareFrame(const std::string& description, |
| 626 const SpdyFrame& actual_frame, | 619 const SpdyFrame& actual_frame, |
| 627 const unsigned char* expected, | 620 const unsigned char* expected, |
| 628 const int expected_len) { | 621 const int expected_len) { |
| 629 const unsigned char* actual = | 622 const unsigned char* actual = |
| 630 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 623 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 631 CompareCharArraysWithHexError( | 624 CompareCharArraysWithHexError( |
| 632 description, actual, actual_frame.size(), expected, expected_len); | 625 description, actual, actual_frame.size(), expected, expected_len); |
| 633 } | 626 } |
| 634 | 627 |
| 635 void CompareFrames(const string& description, | 628 void CompareFrames(const std::string& description, |
| 636 const SpdyFrame& expected_frame, | 629 const SpdyFrame& expected_frame, |
| 637 const SpdyFrame& actual_frame) { | 630 const SpdyFrame& actual_frame) { |
| 638 CompareCharArraysWithHexError( | 631 CompareCharArraysWithHexError( |
| 639 description, | 632 description, |
| 640 reinterpret_cast<const unsigned char*>(expected_frame.data()), | 633 reinterpret_cast<const unsigned char*>(expected_frame.data()), |
| 641 expected_frame.size(), | 634 expected_frame.size(), |
| 642 reinterpret_cast<const unsigned char*>(actual_frame.data()), | 635 reinterpret_cast<const unsigned char*>(actual_frame.data()), |
| 643 actual_frame.size()); | 636 actual_frame.size()); |
| 644 } | 637 } |
| 645 | 638 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 frame.WriteUInt16(0); // Priority. | 906 frame.WriteUInt16(0); // Priority. |
| 914 } else { | 907 } else { |
| 915 frame.BeginNewFrame(framer, | 908 frame.BeginNewFrame(framer, |
| 916 HEADERS, | 909 HEADERS, |
| 917 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, | 910 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, |
| 918 3); | 911 3); |
| 919 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. | 912 frame.WriteUInt32(0); // Priority exclusivity and dependent stream. |
| 920 frame.WriteUInt8(255); // Priority weight. | 913 frame.WriteUInt8(255); // Priority weight. |
| 921 } | 914 } |
| 922 | 915 |
| 923 string value("value1\0value2", 13); | 916 std::string value("value1\0value2", 13); |
| 924 if (IsSpdy2()) { | 917 if (IsSpdy2()) { |
| 925 frame.WriteUInt16(1); // Number of headers. | 918 frame.WriteUInt16(1); // Number of headers. |
| 926 frame.WriteString("name"); | 919 frame.WriteString("name"); |
| 927 frame.WriteString(value); | 920 frame.WriteString(value); |
| 928 } else if (spdy_version_ > SPDY3) { | 921 } else if (spdy_version_ > SPDY3) { |
| 929 // TODO(jgraettinger): If this pattern appears again, move to test class. | 922 // TODO(jgraettinger): If this pattern appears again, move to test class. |
| 930 std::map<string, string> header_set; | 923 std::map<std::string, std::string> header_set; |
| 931 header_set["name"] = value; | 924 header_set["name"] = value; |
| 932 string buffer; | 925 std::string buffer; |
| 933 HpackEncoder encoder(ObtainHpackHuffmanTable()); | 926 HpackEncoder encoder(ObtainHpackHuffmanTable()); |
| 934 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); | 927 encoder.EncodeHeaderSetWithoutCompression(header_set, &buffer); |
| 935 frame.WriteBytes(&buffer[0], buffer.size()); | 928 frame.WriteBytes(&buffer[0], buffer.size()); |
| 936 } else { | 929 } else { |
| 937 frame.WriteUInt32(1); // Number of headers. | 930 frame.WriteUInt32(1); // Number of headers. |
| 938 frame.WriteStringPiece32("name"); | 931 frame.WriteStringPiece32("name"); |
| 939 frame.WriteStringPiece32(value); | 932 frame.WriteStringPiece32(value); |
| 940 } | 933 } |
| 941 // write the length | 934 // write the length |
| 942 frame.RewriteLength(framer); | 935 frame.RewriteLength(framer); |
| 943 | 936 |
| 944 framer.set_enable_compression(false); | 937 framer.set_enable_compression(false); |
| 945 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 938 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 946 | 939 |
| 947 TestSpdyVisitor visitor(spdy_version_); | 940 TestSpdyVisitor visitor(spdy_version_); |
| 948 visitor.use_compression_ = false; | 941 visitor.use_compression_ = false; |
| 949 visitor.SimulateInFramer( | 942 visitor.SimulateInFramer( |
| 950 reinterpret_cast<unsigned char*>(control_frame->data()), | 943 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 951 control_frame->size()); | 944 control_frame->size()); |
| 952 | 945 |
| 953 EXPECT_THAT(visitor.headers_, ElementsAre( | 946 EXPECT_THAT(visitor.headers_, |
| 954 Pair("name", value))); | 947 testing::ElementsAre(testing::Pair("name", value))); |
| 955 } | 948 } |
| 956 | 949 |
| 957 TEST_P(SpdyFramerTest, BasicCompression) { | 950 TEST_P(SpdyFramerTest, BasicCompression) { |
| 958 if (spdy_version_ > SPDY3) { | 951 if (spdy_version_ > SPDY3) { |
| 959 // Deflate compression doesn't apply to HPACK. | 952 // Deflate compression doesn't apply to HPACK. |
| 960 return; | 953 return; |
| 961 } | 954 } |
| 962 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); | 955 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); |
| 963 SpdyFramer framer(spdy_version_); | 956 SpdyFramer framer(spdy_version_); |
| 964 framer.set_debug_visitor(visitor.get()); | 957 framer.set_debug_visitor(visitor.get()); |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1865 CompareFrame( | 1858 CompareFrame( |
| 1866 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1859 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1867 } | 1860 } |
| 1868 } | 1861 } |
| 1869 | 1862 |
| 1870 if (!IsSpdy4()) { | 1863 if (!IsSpdy4()) { |
| 1871 // This test does not apply to SPDY 4 because the max frame size is smaller | 1864 // This test does not apply to SPDY 4 because the max frame size is smaller |
| 1872 // than 4MB. | 1865 // than 4MB. |
| 1873 const char kDescription[] = "Large data frame"; | 1866 const char kDescription[] = "Large data frame"; |
| 1874 const int kDataSize = 4 * 1024 * 1024; // 4 MB | 1867 const int kDataSize = 4 * 1024 * 1024; // 4 MB |
| 1875 const string kData(kDataSize, 'A'); | 1868 const std::string kData(kDataSize, 'A'); |
| 1876 const unsigned char kFrameHeader[] = { | 1869 const unsigned char kFrameHeader[] = { |
| 1877 0x00, 0x00, 0x00, 0x01, | 1870 0x00, 0x00, 0x00, 0x01, |
| 1878 0x01, 0x40, 0x00, 0x00, | 1871 0x01, 0x40, 0x00, 0x00, |
| 1879 }; | 1872 }; |
| 1880 | 1873 |
| 1881 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; | 1874 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; |
| 1882 scoped_ptr<unsigned char[]> expected_frame_data( | 1875 scoped_ptr<unsigned char[]> expected_frame_data( |
| 1883 new unsigned char[kFrameSize]); | 1876 new unsigned char[kFrameSize]); |
| 1884 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); | 1877 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); |
| 1885 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | 1878 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); |
| (...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3356 0x2a, 0x78, 0x78, 0x78, // Stream 42, xxx | 3349 0x2a, 0x78, 0x78, 0x78, // Stream 42, xxx |
| 3357 0x78, 0x78, 0x78, 0x78, // xxxx | 3350 0x78, 0x78, 0x78, 0x78, // xxxx |
| 3358 0x78, 0x78, 0x78, 0x78, // xxxx | 3351 0x78, 0x78, 0x78, 0x78, // xxxx |
| 3359 0x78, 0x78, 0x78, 0x78, // xxxx | 3352 0x78, 0x78, 0x78, 0x78, // xxxx |
| 3360 0x78, 0x78, 0x78, 0x78, // xxxx | 3353 0x78, 0x78, 0x78, 0x78, // xxxx |
| 3361 0x78, 0x78, | 3354 0x78, 0x78, |
| 3362 }; | 3355 }; |
| 3363 | 3356 |
| 3364 SpdyPushPromiseIR push_promise(42, 57); | 3357 SpdyPushPromiseIR push_promise(42, 57); |
| 3365 push_promise.set_padding_len(1); | 3358 push_promise.set_padding_len(1); |
| 3366 string big_value(TestSpdyVisitor::sent_control_frame_max_size(), 'x'); | 3359 std::string big_value(TestSpdyVisitor::sent_control_frame_max_size(), 'x'); |
| 3367 push_promise.SetHeader("xxx", big_value); | 3360 push_promise.SetHeader("xxx", big_value); |
| 3368 scoped_ptr<SpdySerializedFrame> frame( | 3361 scoped_ptr<SpdySerializedFrame> frame( |
| 3369 framer.SerializePushPromise(push_promise)); | 3362 framer.SerializePushPromise(push_promise)); |
| 3370 | 3363 |
| 3371 // The entire frame should look like below: | 3364 // The entire frame should look like below: |
| 3372 // Name Length in Byte | 3365 // Name Length in Byte |
| 3373 // ------------------------------------------- Begin of PUSH_PROMISE frame | 3366 // ------------------------------------------- Begin of PUSH_PROMISE frame |
| 3374 // PUSH_PROMISE header 9 | 3367 // PUSH_PROMISE header 9 |
| 3375 // Pad length field 1 | 3368 // Pad length field 1 |
| 3376 // Promised stream 4 | 3369 // Promised stream 4 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3566 SpdyFramer framer(spdy_version_); | 3559 SpdyFramer framer(spdy_version_); |
| 3567 framer.set_enable_compression(false); | 3560 framer.set_enable_compression(false); |
| 3568 SpdySynStreamIR syn_stream(1); | 3561 SpdySynStreamIR syn_stream(1); |
| 3569 syn_stream.set_priority(1); | 3562 syn_stream.set_priority(1); |
| 3570 syn_stream.SetHeader("aa", ""); | 3563 syn_stream.SetHeader("aa", ""); |
| 3571 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3564 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
| 3572 const size_t kBigValueSize = | 3565 const size_t kBigValueSize = |
| 3573 TestSpdyVisitor::sent_control_frame_max_size() - control_frame->size(); | 3566 TestSpdyVisitor::sent_control_frame_max_size() - control_frame->size(); |
| 3574 | 3567 |
| 3575 // Create a frame at exactly that size. | 3568 // Create a frame at exactly that size. |
| 3576 string big_value(kBigValueSize, 'x'); | 3569 std::string big_value(kBigValueSize, 'x'); |
| 3577 syn_stream.SetHeader("aa", big_value); | 3570 syn_stream.SetHeader("aa", big_value); |
| 3578 control_frame.reset(framer.SerializeSynStream(syn_stream)); | 3571 control_frame.reset(framer.SerializeSynStream(syn_stream)); |
| 3579 EXPECT_TRUE(control_frame.get() != NULL); | 3572 EXPECT_TRUE(control_frame.get() != NULL); |
| 3580 EXPECT_EQ(TestSpdyVisitor::sent_control_frame_max_size(), | 3573 EXPECT_EQ(TestSpdyVisitor::sent_control_frame_max_size(), |
| 3581 control_frame->size()); | 3574 control_frame->size()); |
| 3582 | 3575 |
| 3583 TestSpdyVisitor visitor(spdy_version_); | 3576 TestSpdyVisitor visitor(spdy_version_); |
| 3584 visitor.SimulateInFramer( | 3577 visitor.SimulateInFramer( |
| 3585 reinterpret_cast<unsigned char*>(control_frame->data()), | 3578 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3586 control_frame->size()); | 3579 control_frame->size()); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 3606 framer.set_enable_compression(false); | 3599 framer.set_enable_compression(false); |
| 3607 SpdySynStreamIR syn_stream(1); | 3600 SpdySynStreamIR syn_stream(1); |
| 3608 syn_stream.SetHeader("aa", ""); | 3601 syn_stream.SetHeader("aa", ""); |
| 3609 syn_stream.set_priority(1); | 3602 syn_stream.set_priority(1); |
| 3610 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3603 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
| 3611 const size_t kBigValueSize = | 3604 const size_t kBigValueSize = |
| 3612 SpdyConstants::GetFrameMaximumSize(spdy_version_) - | 3605 SpdyConstants::GetFrameMaximumSize(spdy_version_) - |
| 3613 control_frame->size() + 1; | 3606 control_frame->size() + 1; |
| 3614 | 3607 |
| 3615 // Create a frame at exatly that size. | 3608 // Create a frame at exatly that size. |
| 3616 string big_value(kBigValueSize, 'x'); | 3609 std::string big_value(kBigValueSize, 'x'); |
| 3617 syn_stream.SetHeader("aa", big_value); | 3610 syn_stream.SetHeader("aa", big_value); |
| 3618 // Upstream branches here and wraps SPDY4 with EXPECT_DEBUG_DFATAL. We | 3611 // Upstream branches here and wraps SPDY4 with EXPECT_DEBUG_DFATAL. We |
| 3619 // neither support that in Chromium, nor do we use the same DFATAL (see | 3612 // neither support that in Chromium, nor do we use the same DFATAL (see |
| 3620 // SpdyFrameBuilder::WriteFramePrefix()). | 3613 // SpdyFrameBuilder::WriteFramePrefix()). |
| 3621 control_frame.reset(framer.SerializeSynStream(syn_stream)); | 3614 control_frame.reset(framer.SerializeSynStream(syn_stream)); |
| 3622 | 3615 |
| 3623 EXPECT_TRUE(control_frame.get() != NULL); | 3616 EXPECT_TRUE(control_frame.get() != NULL); |
| 3624 EXPECT_EQ(SpdyConstants::GetFrameMaximumSize(spdy_version_) + 1, | 3617 EXPECT_EQ(SpdyConstants::GetFrameMaximumSize(spdy_version_) + 1, |
| 3625 control_frame->size()); | 3618 control_frame->size()); |
| 3626 | 3619 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 3642 return; | 3635 return; |
| 3643 } | 3636 } |
| 3644 SpdyFramer framer(spdy_version_); | 3637 SpdyFramer framer(spdy_version_); |
| 3645 framer.set_enable_compression(false); | 3638 framer.set_enable_compression(false); |
| 3646 SpdyHeadersIR headers(1); | 3639 SpdyHeadersIR headers(1); |
| 3647 headers.set_padding_len(256); | 3640 headers.set_padding_len(256); |
| 3648 | 3641 |
| 3649 // Exact payload length will change with HPACK, but this should be long | 3642 // Exact payload length will change with HPACK, but this should be long |
| 3650 // enough to cause an overflow. | 3643 // enough to cause an overflow. |
| 3651 const size_t kBigValueSize = kControlFrameSizeLimit; | 3644 const size_t kBigValueSize = kControlFrameSizeLimit; |
| 3652 string big_value(kBigValueSize, 'x'); | 3645 std::string big_value(kBigValueSize, 'x'); |
| 3653 headers.SetHeader("aa", big_value); | 3646 headers.SetHeader("aa", big_value); |
| 3654 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); | 3647 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); |
| 3655 EXPECT_TRUE(control_frame.get() != NULL); | 3648 EXPECT_TRUE(control_frame.get() != NULL); |
| 3656 EXPECT_GT(control_frame->size(), | 3649 EXPECT_GT(control_frame->size(), |
| 3657 TestSpdyVisitor::sent_control_frame_max_size()); | 3650 TestSpdyVisitor::sent_control_frame_max_size()); |
| 3658 | 3651 |
| 3659 TestSpdyVisitor visitor(spdy_version_); | 3652 TestSpdyVisitor visitor(spdy_version_); |
| 3660 visitor.SimulateInFramer( | 3653 visitor.SimulateInFramer( |
| 3661 reinterpret_cast<unsigned char*>(control_frame->data()), | 3654 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3662 control_frame->size()); | 3655 control_frame->size()); |
| 3663 EXPECT_TRUE(visitor.header_buffer_valid_); | 3656 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 3664 EXPECT_EQ(0, visitor.error_count_); | 3657 EXPECT_EQ(0, visitor.error_count_); |
| 3665 EXPECT_EQ(1, visitor.headers_frame_count_); | 3658 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3666 EXPECT_EQ(16, visitor.continuation_count_); | 3659 EXPECT_EQ(16, visitor.continuation_count_); |
| 3667 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3660 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3668 } | 3661 } |
| 3669 | 3662 |
| 3670 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 3663 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
| 3671 if (spdy_version_ <= SPDY3) { | 3664 if (spdy_version_ <= SPDY3) { |
| 3672 return; | 3665 return; |
| 3673 } | 3666 } |
| 3674 SpdyFramer framer(spdy_version_); | 3667 SpdyFramer framer(spdy_version_); |
| 3675 framer.set_enable_compression(false); | 3668 framer.set_enable_compression(false); |
| 3676 SpdyPushPromiseIR push_promise(1, 2); | 3669 SpdyPushPromiseIR push_promise(1, 2); |
| 3677 push_promise.set_padding_len(256); | 3670 push_promise.set_padding_len(256); |
| 3678 | 3671 |
| 3679 // Exact payload length will change with HPACK, but this should be long | 3672 // Exact payload length will change with HPACK, but this should be long |
| 3680 // enough to cause an overflow. | 3673 // enough to cause an overflow. |
| 3681 const size_t kBigValueSize = kControlFrameSizeLimit; | 3674 const size_t kBigValueSize = kControlFrameSizeLimit; |
| 3682 string big_value(kBigValueSize, 'x'); | 3675 std::string big_value(kBigValueSize, 'x'); |
| 3683 push_promise.SetHeader("aa", big_value); | 3676 push_promise.SetHeader("aa", big_value); |
| 3684 scoped_ptr<SpdyFrame> control_frame( | 3677 scoped_ptr<SpdyFrame> control_frame( |
| 3685 framer.SerializePushPromise(push_promise)); | 3678 framer.SerializePushPromise(push_promise)); |
| 3686 EXPECT_TRUE(control_frame.get() != NULL); | 3679 EXPECT_TRUE(control_frame.get() != NULL); |
| 3687 EXPECT_GT(control_frame->size(), | 3680 EXPECT_GT(control_frame->size(), |
| 3688 TestSpdyVisitor::sent_control_frame_max_size()); | 3681 TestSpdyVisitor::sent_control_frame_max_size()); |
| 3689 | 3682 |
| 3690 TestSpdyVisitor visitor(spdy_version_); | 3683 TestSpdyVisitor visitor(spdy_version_); |
| 3691 visitor.SimulateInFramer( | 3684 visitor.SimulateInFramer( |
| 3692 reinterpret_cast<unsigned char*>(control_frame->data()), | 3685 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3693 control_frame->size()); | 3686 control_frame->size()); |
| 3694 EXPECT_TRUE(visitor.header_buffer_valid_); | 3687 EXPECT_TRUE(visitor.header_buffer_valid_); |
| 3695 EXPECT_EQ(0, visitor.error_count_); | 3688 EXPECT_EQ(0, visitor.error_count_); |
| 3696 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 3689 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
| 3697 EXPECT_EQ(16, visitor.continuation_count_); | 3690 EXPECT_EQ(16, visitor.continuation_count_); |
| 3698 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3691 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3699 } | 3692 } |
| 3700 | 3693 |
| 3701 // Check that the framer stops delivering header data chunks once the visitor | 3694 // Check that the framer stops delivering header data chunks once the visitor |
| 3702 // declares it doesn't want any more. This is important to guard against | 3695 // declares it doesn't want any more. This is important to guard against |
| 3703 // "zip bomb" types of attacks. | 3696 // "zip bomb" types of attacks. |
| 3704 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { | 3697 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { |
| 3705 const size_t kHeaderBufferChunks = 4; | 3698 const size_t kHeaderBufferChunks = 4; |
| 3706 const size_t kHeaderBufferSize = | 3699 const size_t kHeaderBufferSize = |
| 3707 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 3700 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
| 3708 const size_t kBigValueSize = kHeaderBufferSize * 2; | 3701 const size_t kBigValueSize = kHeaderBufferSize * 2; |
| 3709 string big_value(kBigValueSize, 'x'); | 3702 std::string big_value(kBigValueSize, 'x'); |
| 3710 SpdyFramer framer(spdy_version_); | 3703 SpdyFramer framer(spdy_version_); |
| 3711 SpdyHeadersIR headers(1); | 3704 SpdyHeadersIR headers(1); |
| 3712 headers.set_priority(1); | 3705 headers.set_priority(1); |
| 3713 headers.set_fin(true); | 3706 headers.set_fin(true); |
| 3714 headers.SetHeader("aa", big_value); | 3707 headers.SetHeader("aa", big_value); |
| 3715 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); | 3708 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); |
| 3716 EXPECT_TRUE(control_frame.get() != NULL); | 3709 EXPECT_TRUE(control_frame.get() != NULL); |
| 3717 TestSpdyVisitor visitor(spdy_version_); | 3710 TestSpdyVisitor visitor(spdy_version_); |
| 3718 visitor.set_header_buffer_size(kHeaderBufferSize); | 3711 visitor.set_header_buffer_size(kHeaderBufferSize); |
| 3719 visitor.use_compression_ = true; | 3712 visitor.use_compression_ = true; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3763 EXPECT_EQ(1, visitor.error_count_); | 3756 EXPECT_EQ(1, visitor.error_count_); |
| 3764 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()) | 3757 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()) |
| 3765 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3758 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3766 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3759 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3767 } | 3760 } |
| 3768 | 3761 |
| 3769 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { | 3762 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 3770 SpdyFramer framer(spdy_version_); | 3763 SpdyFramer framer(spdy_version_); |
| 3771 // Create a GoAway frame that has a few extra bytes at the end. | 3764 // Create a GoAway frame that has a few extra bytes at the end. |
| 3772 // We create enough overhead to overflow the framer's control frame buffer. | 3765 // We create enough overhead to overflow the framer's control frame buffer. |
| 3773 ASSERT_GE(250u, SpdyFramer::kControlFrameBufferSize); | 3766 ASSERT_LE(SpdyFramer::kControlFrameBufferSize, 250u); |
| 3774 const unsigned char length = 1 + SpdyFramer::kControlFrameBufferSize; | 3767 const size_t length = SpdyFramer::kControlFrameBufferSize + 1; |
| 3775 const unsigned char kV3FrameData[] = { // Also applies for V2. | 3768 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 3776 0x80, spdy_version_ch_, 0x00, 0x07, | 3769 0x80, spdy_version_ch_, 0x00, 0x07, |
| 3777 0x00, 0x00, 0x00, length, | 3770 0x00, 0x00, 0x00, static_cast<unsigned char>(length + 1), |
|
Bence
2014/12/01 18:18:38
Why do you add 1 here?
Peter Kasting
2014/12/02 02:13:55
Bug from a modified previous version of rewriting
Bence
2014/12/02 14:58:44
FYI I tried many different values here locally and
| |
| 3778 0x00, 0x00, 0x00, 0x00, // Stream ID | 3771 0x00, 0x00, 0x00, 0x00, // Stream ID |
| 3779 0x00, 0x00, 0x00, 0x00, // Status | 3772 0x00, 0x00, 0x00, 0x00, // Status |
| 3780 }; | 3773 }; |
| 3781 | 3774 |
| 3782 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length, | 3775 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length, |
| 3783 // since it may carry opaque data. Verify that minimal length is tested. | 3776 // since it may carry opaque data. Verify that minimal length is tested. |
| 3784 const unsigned char less_than_min_length = | 3777 ASSERT_GT(framer.GetGoAwayMinimumSize(), framer.GetControlFrameHeaderSize()); |
| 3778 const size_t less_than_min_length = | |
| 3785 framer.GetGoAwayMinimumSize() - framer.GetControlFrameHeaderSize() - 1; | 3779 framer.GetGoAwayMinimumSize() - framer.GetControlFrameHeaderSize() - 1; |
| 3780 ASSERT_LE(less_than_min_length, std::numeric_limits<unsigned char>::max()); | |
| 3786 const unsigned char kV4FrameData[] = { | 3781 const unsigned char kV4FrameData[] = { |
| 3787 0x00, 0x00, static_cast<uint8>(less_than_min_length), 0x07, | 3782 0x00, 0x00, static_cast<unsigned char>(less_than_min_length), 0x07, |
| 3788 0x00, 0x00, 0x00, 0x00, | 3783 0x00, 0x00, 0x00, 0x00, |
| 3789 0x00, 0x00, 0x00, 0x00, // Stream Id | 3784 0x00, 0x00, 0x00, 0x00, // Stream Id |
| 3790 0x00, 0x00, 0x00, 0x00, // Status | 3785 0x00, 0x00, 0x00, 0x00, // Status |
| 3791 0x00, | 3786 0x00, |
| 3792 }; | 3787 }; |
| 3793 const size_t pad_length = | 3788 const size_t pad_length = |
| 3794 length + framer.GetControlFrameHeaderSize() - | 3789 length + framer.GetControlFrameHeaderSize() - |
| 3795 (IsSpdy4() ? sizeof(kV4FrameData) : sizeof(kV3FrameData)); | 3790 (IsSpdy4() ? sizeof(kV4FrameData) : sizeof(kV3FrameData)); |
| 3796 string pad('A', pad_length); | 3791 std::string pad(pad_length, 'A'); |
|
Peter Kasting
2014/11/25 22:51:00
This was an outright error! It worries me that th
| |
| 3797 TestSpdyVisitor visitor(spdy_version_); | 3792 TestSpdyVisitor visitor(spdy_version_); |
| 3798 | 3793 |
| 3799 if (IsSpdy4()) { | 3794 if (IsSpdy4()) { |
| 3800 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3795 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
| 3801 } else { | 3796 } else { |
| 3802 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3797 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 3803 } | 3798 } |
| 3804 visitor.SimulateInFramer( | 3799 visitor.SimulateInFramer( |
| 3805 reinterpret_cast<const unsigned char*>(pad.c_str()), | 3800 reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 3806 pad.length()); | 3801 pad.length()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3886 EXPECT_EQ(3, visitor.setting_count_); | 3881 EXPECT_EQ(3, visitor.setting_count_); |
| 3887 if (spdy_version_ > SPDY3) { | 3882 if (spdy_version_ > SPDY3) { |
| 3888 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3883 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3889 } | 3884 } |
| 3890 | 3885 |
| 3891 // Read data in small chunks. | 3886 // Read data in small chunks. |
| 3892 size_t framed_data = 0; | 3887 size_t framed_data = 0; |
| 3893 size_t unframed_data = control_frame->size(); | 3888 size_t unframed_data = control_frame->size(); |
| 3894 size_t kReadChunkSize = 5; // Read five bytes at a time. | 3889 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 3895 while (unframed_data > 0) { | 3890 while (unframed_data > 0) { |
| 3896 size_t to_read = min(kReadChunkSize, unframed_data); | 3891 size_t to_read = std::min(kReadChunkSize, unframed_data); |
| 3897 visitor.SimulateInFramer( | 3892 visitor.SimulateInFramer( |
| 3898 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), | 3893 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), |
| 3899 to_read); | 3894 to_read); |
| 3900 unframed_data -= to_read; | 3895 unframed_data -= to_read; |
| 3901 framed_data += to_read; | 3896 framed_data += to_read; |
| 3902 } | 3897 } |
| 3903 EXPECT_EQ(0, visitor.error_count_); | 3898 EXPECT_EQ(0, visitor.error_count_); |
| 3904 EXPECT_EQ(3 * 2, visitor.setting_count_); | 3899 EXPECT_EQ(3 * 2, visitor.setting_count_); |
| 3905 if (spdy_version_ > SPDY3) { | 3900 if (spdy_version_ > SPDY3) { |
| 3906 EXPECT_EQ(2, visitor.settings_ack_sent_); | 3901 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4209 0x0C, 'a', 'n', 'o', | 4204 0x0C, 'a', 'n', 'o', |
| 4210 't', 'h', 'e', 'r', | 4205 't', 'h', 'e', 'r', |
| 4211 ' ', 'c', 'e', 'r', | 4206 ' ', 'c', 'e', 'r', |
| 4212 't', 0x00, 0x00, 0x00, | 4207 't', 0x00, 0x00, 0x00, |
| 4213 0x0A, 'f', 'i', 'n', | 4208 0x0A, 'f', 'i', 'n', |
| 4214 'a', 'l', ' ', 'c', | 4209 'a', 'l', ' ', 'c', |
| 4215 'e', 'r', 't', | 4210 'e', 'r', 't', |
| 4216 }; | 4211 }; |
| 4217 TestSpdyVisitor visitor(spdy_version_); | 4212 TestSpdyVisitor visitor(spdy_version_); |
| 4218 visitor.use_compression_ = false; | 4213 visitor.use_compression_ = false; |
| 4219 string multiple_frame_data(reinterpret_cast<const char*>(kV3FrameData), | 4214 std::string multiple_frame_data(reinterpret_cast<const char*>(kV3FrameData), |
| 4220 arraysize(kV3FrameData)); | 4215 arraysize(kV3FrameData)); |
| 4221 scoped_ptr<SpdyFrame> control_frame( | 4216 scoped_ptr<SpdyFrame> control_frame( |
| 4222 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 4217 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 4223 multiple_frame_data.append(string(control_frame->data(), | 4218 multiple_frame_data.append(std::string(control_frame->data(), |
| 4224 control_frame->size())); | 4219 control_frame->size())); |
| 4225 visitor.SimulateInFramer( | 4220 visitor.SimulateInFramer( |
| 4226 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), | 4221 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), |
| 4227 multiple_frame_data.length()); | 4222 multiple_frame_data.length()); |
| 4228 EXPECT_EQ(0, visitor.error_count_); | 4223 EXPECT_EQ(0, visitor.error_count_); |
| 4229 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 4224 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 4230 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 4225 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
| 4231 } | 4226 } |
| 4232 | 4227 |
| 4233 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { | 4228 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
| 4234 if (spdy_version_ <= SPDY3) { | 4229 if (spdy_version_ <= SPDY3) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4287 | 4282 |
| 4288 TestSpdyVisitor visitor(spdy_version_); | 4283 TestSpdyVisitor visitor(spdy_version_); |
| 4289 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 4284 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4290 | 4285 |
| 4291 EXPECT_EQ(0, visitor.error_count_); | 4286 EXPECT_EQ(0, visitor.error_count_); |
| 4292 EXPECT_EQ(1, visitor.headers_frame_count_); | 4287 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 4293 EXPECT_EQ(2, visitor.continuation_count_); | 4288 EXPECT_EQ(2, visitor.continuation_count_); |
| 4294 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 4289 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 4295 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 4290 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 4296 | 4291 |
| 4297 EXPECT_THAT(visitor.headers_, ElementsAre( | 4292 EXPECT_THAT(visitor.headers_, |
| 4298 Pair("cookie", "foo=bar; baz=bing; "), | 4293 testing::ElementsAre( |
| 4299 Pair("name", "value"))); | 4294 testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 4295 testing::Pair("name", "value"))); | |
| 4300 } | 4296 } |
| 4301 | 4297 |
| 4302 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { | 4298 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { |
| 4303 if (spdy_version_ <= SPDY3) { | 4299 if (spdy_version_ <= SPDY3) { |
| 4304 return; | 4300 return; |
| 4305 } | 4301 } |
| 4306 | 4302 |
| 4307 const unsigned char kInput[] = { | 4303 const unsigned char kInput[] = { |
| 4308 0x00, 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN | 4304 0x00, 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN |
| 4309 0x00, 0x00, 0x00, 0x01, // Stream 1 | 4305 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 4333 TestSpdyVisitor visitor(spdy_version_); | 4329 TestSpdyVisitor visitor(spdy_version_); |
| 4334 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 4330 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4335 | 4331 |
| 4336 EXPECT_EQ(0, visitor.error_count_); | 4332 EXPECT_EQ(0, visitor.error_count_); |
| 4337 EXPECT_EQ(1, visitor.headers_frame_count_); | 4333 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 4338 EXPECT_EQ(2, visitor.continuation_count_); | 4334 EXPECT_EQ(2, visitor.continuation_count_); |
| 4339 EXPECT_EQ(1, visitor.fin_flag_count_); | 4335 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 4340 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 4336 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 4341 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 4337 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 4342 | 4338 |
| 4343 EXPECT_THAT(visitor.headers_, ElementsAre( | 4339 EXPECT_THAT(visitor.headers_, |
| 4344 Pair("cookie", "foo=bar; baz=bing; "), | 4340 testing::ElementsAre( |
| 4345 Pair("name", "value"))); | 4341 testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 4342 testing::Pair("name", "value"))); | |
| 4346 } | 4343 } |
| 4347 | 4344 |
| 4348 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 4345 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 4349 if (spdy_version_ <= SPDY3) { | 4346 if (spdy_version_ <= SPDY3) { |
| 4350 return; | 4347 return; |
| 4351 } | 4348 } |
| 4352 | 4349 |
| 4353 const unsigned char kInput[] = { | 4350 const unsigned char kInput[] = { |
| 4354 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE | 4351 0x00, 0x00, 0x17, 0x05, // PUSH_PROMISE |
| 4355 0x08, 0x00, 0x00, 0x00, // PADDED | 4352 0x08, 0x00, 0x00, 0x00, // PADDED |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 4382 TestSpdyVisitor visitor(spdy_version_); | 4379 TestSpdyVisitor visitor(spdy_version_); |
| 4383 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 4380 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4384 | 4381 |
| 4385 EXPECT_EQ(0, visitor.error_count_); | 4382 EXPECT_EQ(0, visitor.error_count_); |
| 4386 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 4383 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
| 4387 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 4384 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
| 4388 EXPECT_EQ(2, visitor.continuation_count_); | 4385 EXPECT_EQ(2, visitor.continuation_count_); |
| 4389 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 4386 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 4390 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 4387 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 4391 | 4388 |
| 4392 EXPECT_THAT(visitor.headers_, ElementsAre( | 4389 EXPECT_THAT(visitor.headers_, |
| 4393 Pair("cookie", "foo=bar; baz=bing; "), | 4390 testing::ElementsAre( |
| 4394 Pair("name", "value"))); | 4391 testing::Pair("cookie", "foo=bar; baz=bing; "), |
| 4392 testing::Pair("name", "value"))); | |
| 4395 } | 4393 } |
| 4396 | 4394 |
| 4397 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { | 4395 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { |
| 4398 if (spdy_version_ <= SPDY3) { | 4396 if (spdy_version_ <= SPDY3) { |
| 4399 return; | 4397 return; |
| 4400 } | 4398 } |
| 4401 | 4399 |
| 4402 const unsigned char kInput[] = { | 4400 const unsigned char kInput[] = { |
| 4403 0x00, 0x00, 0x10, 0x01, 0x00, // HEADERS | 4401 0x00, 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 4404 0x00, 0x00, 0x00, 0x01, // Stream 1 | 4402 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4563 }; | 4561 }; |
| 4564 | 4562 |
| 4565 TestSpdyVisitor visitor(spdy_version_); | 4563 TestSpdyVisitor visitor(spdy_version_); |
| 4566 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 4564 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4567 | 4565 |
| 4568 // TODO(jgraettinger): Verify END_SEGMENT when support is added. | 4566 // TODO(jgraettinger): Verify END_SEGMENT when support is added. |
| 4569 EXPECT_EQ(0, visitor.error_count_); | 4567 EXPECT_EQ(0, visitor.error_count_); |
| 4570 EXPECT_EQ(1, visitor.headers_frame_count_); | 4568 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 4571 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 4569 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 4572 | 4570 |
| 4573 EXPECT_THAT(visitor.headers_, ElementsAre( | 4571 EXPECT_THAT(visitor.headers_, |
| 4574 Pair("cookie", "foo=bar"))); | 4572 testing::ElementsAre(testing::Pair("cookie", "foo=bar"))); |
| 4575 } | 4573 } |
| 4576 | 4574 |
| 4577 TEST_P(SpdyFramerTest, ReadGarbage) { | 4575 TEST_P(SpdyFramerTest, ReadGarbage) { |
| 4578 SpdyFramer framer(spdy_version_); | 4576 SpdyFramer framer(spdy_version_); |
| 4579 unsigned char garbage_frame[256]; | 4577 unsigned char garbage_frame[256]; |
| 4580 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 4578 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 4581 TestSpdyVisitor visitor(spdy_version_); | 4579 TestSpdyVisitor visitor(spdy_version_); |
| 4582 visitor.use_compression_ = false; | 4580 visitor.use_compression_ = false; |
| 4583 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 4581 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 4584 EXPECT_EQ(1, visitor.error_count_); | 4582 EXPECT_EQ(1, visitor.error_count_); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4853 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) | 4851 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) |
| 4854 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4852 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4855 } | 4853 } |
| 4856 } | 4854 } |
| 4857 | 4855 |
| 4858 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { | 4856 TEST_P(SpdyFramerTest, DataFrameFlagsV2V3) { |
| 4859 if (spdy_version_ > SPDY3) { | 4857 if (spdy_version_ > SPDY3) { |
| 4860 return; | 4858 return; |
| 4861 } | 4859 } |
| 4862 | 4860 |
| 4863 for (int flags = 0; flags < 256; ++flags) { | 4861 uint8 flags = 0; |
| 4862 do { | |
| 4864 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4863 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4865 | 4864 |
| 4866 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4865 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4867 SpdyFramer framer(spdy_version_); | 4866 SpdyFramer framer(spdy_version_); |
| 4868 framer.set_visitor(&visitor); | 4867 framer.set_visitor(&visitor); |
| 4869 | 4868 |
| 4870 SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 4869 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 4871 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 4870 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 4872 SetFrameFlags(frame.get(), flags, spdy_version_); | 4871 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4873 | 4872 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 4885 if (flags & ~DATA_FLAG_FIN) { | 4884 if (flags & ~DATA_FLAG_FIN) { |
| 4886 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4885 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4887 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 4886 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, |
| 4888 framer.error_code()) | 4887 framer.error_code()) |
| 4889 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4888 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4890 } else { | 4889 } else { |
| 4891 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4890 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4892 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4891 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4893 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4892 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4894 } | 4893 } |
| 4895 } | 4894 } while (++flags != 0); |
| 4896 } | 4895 } |
| 4897 | 4896 |
| 4898 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 4897 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
| 4899 if (spdy_version_ <= SPDY3) { | 4898 if (spdy_version_ <= SPDY3) { |
| 4900 return; | 4899 return; |
| 4901 } | 4900 } |
| 4902 | 4901 |
| 4903 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | | 4902 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | |
| 4904 DATA_FLAG_PADDED; | 4903 DATA_FLAG_PADDED; |
| 4905 | 4904 |
| 4906 for (int flags = 0; flags < 256; ++flags) { | 4905 uint8 flags = 0; |
| 4906 do { | |
| 4907 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4907 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4908 | 4908 |
| 4909 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4909 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4910 SpdyFramer framer(spdy_version_); | 4910 SpdyFramer framer(spdy_version_); |
| 4911 framer.set_visitor(&visitor); | 4911 framer.set_visitor(&visitor); |
| 4912 | 4912 |
| 4913 SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 4913 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 4914 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 4914 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 4915 SetFrameFlags(frame.get(), flags, spdy_version_); | 4915 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4916 | 4916 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4933 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PADDED)) { | 4933 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PADDED)) { |
| 4934 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4934 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4935 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 4935 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, |
| 4936 framer.error_code()) | 4936 framer.error_code()) |
| 4937 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4937 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4938 } else { | 4938 } else { |
| 4939 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4939 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4940 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4940 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4941 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4941 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4942 } | 4942 } |
| 4943 } | 4943 } while (++flags != 0); |
| 4944 } | 4944 } |
| 4945 | 4945 |
| 4946 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { | 4946 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { |
| 4947 if (!IsSpdy2() && !IsSpdy3()) { | 4947 if (!IsSpdy2() && !IsSpdy3()) { |
| 4948 // SYN_STREAM not supported in SPDY>3 | 4948 // SYN_STREAM not supported in SPDY>3 |
| 4949 return; | 4949 return; |
| 4950 } | 4950 } |
| 4951 for (int flags = 0; flags < 256; ++flags) { | 4951 uint8 flags = 0; |
| 4952 do { | |
| 4952 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4953 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4953 | 4954 |
| 4954 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4955 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4955 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4956 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
| 4956 SpdyFramer framer(spdy_version_); | 4957 SpdyFramer framer(spdy_version_); |
| 4957 framer.set_visitor(&visitor); | 4958 framer.set_visitor(&visitor); |
| 4958 framer.set_debug_visitor(&debug_visitor); | 4959 framer.set_debug_visitor(&debug_visitor); |
| 4959 | 4960 |
| 4960 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _)); | 4961 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _)); |
| 4961 | 4962 |
| 4962 SpdySynStreamIR syn_stream(8); | 4963 SpdySynStreamIR syn_stream(8); |
| 4963 syn_stream.set_associated_to_stream_id(3); | 4964 syn_stream.set_associated_to_stream_id(3); |
| 4964 syn_stream.set_priority(1); | 4965 syn_stream.set_priority(1); |
| 4965 syn_stream.SetHeader("foo", "bar"); | 4966 syn_stream.SetHeader("foo", "bar"); |
| 4966 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 4967 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 4967 int set_flags = flags; | 4968 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4968 SetFrameFlags(frame.get(), set_flags, spdy_version_); | |
| 4969 | 4969 |
| 4970 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 4970 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
| 4971 EXPECT_CALL(visitor, OnError(_)); | 4971 EXPECT_CALL(visitor, OnError(_)); |
| 4972 } else { | 4972 } else { |
| 4973 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); | 4973 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); |
| 4974 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, | 4974 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, |
| 4975 flags & CONTROL_FLAG_UNIDIRECTIONAL)); | 4975 flags & CONTROL_FLAG_UNIDIRECTIONAL)); |
| 4976 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) | 4976 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) |
| 4977 .WillRepeatedly(testing::Return(true)); | 4977 .WillRepeatedly(testing::Return(true)); |
| 4978 if (flags & DATA_FLAG_FIN) { | 4978 if (flags & DATA_FLAG_FIN) { |
| 4979 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4979 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
| 4980 } else { | 4980 } else { |
| 4981 // Do not close the stream if we are expecting a CONTINUATION frame. | 4981 // Do not close the stream if we are expecting a CONTINUATION frame. |
| 4982 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 4982 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
| 4983 } | 4983 } |
| 4984 } | 4984 } |
| 4985 | 4985 |
| 4986 framer.ProcessInput(frame->data(), frame->size()); | 4986 framer.ProcessInput(frame->data(), frame->size()); |
| 4987 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 4987 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
| 4988 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4988 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4989 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4989 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4990 framer.error_code()) | 4990 framer.error_code()) |
| 4991 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4991 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4992 } else { | 4992 } else { |
| 4993 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4993 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4994 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4994 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4995 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4995 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4996 } | 4996 } |
| 4997 } | 4997 } while (++flags != 0); |
| 4998 } | 4998 } |
| 4999 | 4999 |
| 5000 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { | 5000 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { |
| 5001 if (!IsSpdy2() && !IsSpdy3()) { | 5001 if (!IsSpdy2() && !IsSpdy3()) { |
| 5002 // SYN_REPLY not supported in SPDY>3 | 5002 // SYN_REPLY not supported in SPDY>3 |
| 5003 return; | 5003 return; |
| 5004 } | 5004 } |
| 5005 for (int flags = 0; flags < 256; ++flags) { | 5005 uint8 flags = 0; |
| 5006 do { | |
| 5006 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5007 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5007 | 5008 |
| 5008 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5009 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5009 SpdyFramer framer(spdy_version_); | 5010 SpdyFramer framer(spdy_version_); |
| 5010 framer.set_visitor(&visitor); | 5011 framer.set_visitor(&visitor); |
| 5011 | 5012 |
| 5012 SpdySynReplyIR syn_reply(37); | 5013 SpdySynReplyIR syn_reply(37); |
| 5013 syn_reply.SetHeader("foo", "bar"); | 5014 syn_reply.SetHeader("foo", "bar"); |
| 5014 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 5015 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
| 5015 SetFrameFlags(frame.get(), flags, spdy_version_); | 5016 SetFrameFlags(frame.get(), flags, spdy_version_); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 5029 if (flags & ~CONTROL_FLAG_FIN) { | 5030 if (flags & ~CONTROL_FLAG_FIN) { |
| 5030 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5031 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5031 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5032 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5032 framer.error_code()) | 5033 framer.error_code()) |
| 5033 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5034 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5034 } else { | 5035 } else { |
| 5035 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5036 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5036 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5037 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5037 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5038 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5038 } | 5039 } |
| 5039 } | 5040 } while (++flags != 0); |
| 5040 } | 5041 } |
| 5041 | 5042 |
| 5042 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { | 5043 TEST_P(SpdyFramerTest, RstStreamFrameFlags) { |
| 5043 for (int flags = 0; flags < 256; ++flags) { | 5044 uint8 flags = 0; |
| 5045 do { | |
| 5044 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5046 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5045 | 5047 |
| 5046 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5048 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5047 SpdyFramer framer(spdy_version_); | 5049 SpdyFramer framer(spdy_version_); |
| 5048 framer.set_visitor(&visitor); | 5050 framer.set_visitor(&visitor); |
| 5049 | 5051 |
| 5050 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL, ""); | 5052 SpdyRstStreamIR rst_stream(13, RST_STREAM_CANCEL, ""); |
| 5051 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 5053 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 5052 SetFrameFlags(frame.get(), flags, spdy_version_); | 5054 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 5053 | 5055 |
| 5054 if (flags != 0) { | 5056 if (flags != 0) { |
| 5055 EXPECT_CALL(visitor, OnError(_)); | 5057 EXPECT_CALL(visitor, OnError(_)); |
| 5056 } else { | 5058 } else { |
| 5057 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); | 5059 EXPECT_CALL(visitor, OnRstStream(13, RST_STREAM_CANCEL)); |
| 5058 } | 5060 } |
| 5059 | 5061 |
| 5060 framer.ProcessInput(frame->data(), frame->size()); | 5062 framer.ProcessInput(frame->data(), frame->size()); |
| 5061 if (flags != 0) { | 5063 if (flags != 0) { |
| 5062 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5064 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5063 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5065 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5064 framer.error_code()) | 5066 framer.error_code()) |
| 5065 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5067 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5066 } else { | 5068 } else { |
| 5067 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5069 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5068 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5070 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5069 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5071 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5070 } | 5072 } |
| 5071 } | 5073 } while (++flags != 0); |
| 5072 } | 5074 } |
| 5073 | 5075 |
| 5074 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { | 5076 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { |
| 5075 if (spdy_version_ > SPDY3) { return; } | 5077 if (spdy_version_ > SPDY3) { return; } |
| 5076 for (int flags = 0; flags < 256; ++flags) { | 5078 uint8 flags = 0; |
| 5079 do { | |
| 5077 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5080 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5078 | 5081 |
| 5079 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5082 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5080 SpdyFramer framer(spdy_version_); | 5083 SpdyFramer framer(spdy_version_); |
| 5081 framer.set_visitor(&visitor); | 5084 framer.set_visitor(&visitor); |
| 5082 | 5085 |
| 5083 SpdySettingsIR settings_ir; | 5086 SpdySettingsIR settings_ir; |
| 5084 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, | 5087 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, |
| 5085 false, | 5088 false, |
| 5086 false, | 5089 false, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 5102 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { | 5105 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { |
| 5103 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5106 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5104 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5107 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5105 framer.error_code()) | 5108 framer.error_code()) |
| 5106 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5109 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5107 } else { | 5110 } else { |
| 5108 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5111 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5109 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5112 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5110 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5113 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5111 } | 5114 } |
| 5112 } | 5115 } while (++flags != 0); |
| 5113 } | 5116 } |
| 5114 | 5117 |
| 5115 TEST_P(SpdyFramerTest, SettingsFrameFlags) { | 5118 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
| 5116 if (spdy_version_ <= SPDY3) { return; } | 5119 if (spdy_version_ <= SPDY3) { return; } |
| 5117 for (int flags = 0; flags < 256; ++flags) { | 5120 uint8 flags = 0; |
| 5121 do { | |
| 5118 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5122 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5119 | 5123 |
| 5120 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5124 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5121 SpdyFramer framer(spdy_version_); | 5125 SpdyFramer framer(spdy_version_); |
| 5122 framer.set_visitor(&visitor); | 5126 framer.set_visitor(&visitor); |
| 5123 | 5127 |
| 5124 SpdySettingsIR settings_ir; | 5128 SpdySettingsIR settings_ir; |
| 5125 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); | 5129 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); |
| 5126 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 5130 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| 5127 SetFrameFlags(frame.get(), flags, spdy_version_); | 5131 SetFrameFlags(frame.get(), flags, spdy_version_); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 5144 // The frame is invalid because ACK frames should have no payload. | 5148 // The frame is invalid because ACK frames should have no payload. |
| 5145 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5149 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5146 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5150 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5147 framer.error_code()) | 5151 framer.error_code()) |
| 5148 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5152 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5149 } else { | 5153 } else { |
| 5150 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5154 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5151 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5155 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5152 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5156 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5153 } | 5157 } |
| 5154 } | 5158 } while (++flags != 0); |
| 5155 } | 5159 } |
| 5156 | 5160 |
| 5157 TEST_P(SpdyFramerTest, GoawayFrameFlags) { | 5161 TEST_P(SpdyFramerTest, GoawayFrameFlags) { |
| 5158 for (int flags = 0; flags < 256; ++flags) { | 5162 uint8 flags = 0; |
| 5163 do { | |
| 5159 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5164 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5160 | 5165 |
| 5161 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5166 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5162 SpdyFramer framer(spdy_version_); | 5167 SpdyFramer framer(spdy_version_); |
| 5163 framer.set_visitor(&visitor); | 5168 framer.set_visitor(&visitor); |
| 5164 | 5169 |
| 5165 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); | 5170 SpdyGoAwayIR goaway_ir(97, GOAWAY_OK, "test"); |
| 5166 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); | 5171 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); |
| 5167 SetFrameFlags(frame.get(), flags, spdy_version_); | 5172 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 5168 | 5173 |
| 5169 if (flags != 0) { | 5174 if (flags != 0) { |
| 5170 EXPECT_CALL(visitor, OnError(_)); | 5175 EXPECT_CALL(visitor, OnError(_)); |
| 5171 } else { | 5176 } else { |
| 5172 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); | 5177 EXPECT_CALL(visitor, OnGoAway(97, GOAWAY_OK)); |
| 5173 } | 5178 } |
| 5174 | 5179 |
| 5175 framer.ProcessInput(frame->data(), frame->size()); | 5180 framer.ProcessInput(frame->data(), frame->size()); |
| 5176 if (flags != 0) { | 5181 if (flags != 0) { |
| 5177 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5182 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5178 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5183 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5179 framer.error_code()) | 5184 framer.error_code()) |
| 5180 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5185 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5181 } else { | 5186 } else { |
| 5182 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5187 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5183 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5188 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5184 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5189 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5185 } | 5190 } |
| 5186 } | 5191 } while (++flags != 0); |
| 5187 } | 5192 } |
| 5188 | 5193 |
| 5189 TEST_P(SpdyFramerTest, HeadersFrameFlags) { | 5194 TEST_P(SpdyFramerTest, HeadersFrameFlags) { |
| 5190 for (int flags = 0; flags < 256; ++flags) { | 5195 uint8 flags = 0; |
| 5196 do { | |
| 5191 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5197 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5192 | 5198 |
| 5193 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5199 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5194 SpdyFramer framer(spdy_version_); | 5200 SpdyFramer framer(spdy_version_); |
| 5195 framer.set_visitor(&visitor); | 5201 framer.set_visitor(&visitor); |
| 5196 | 5202 |
| 5197 SpdyHeadersIR headers_ir(57); | 5203 SpdyHeadersIR headers_ir(57); |
| 5198 if (IsSpdy4() && (flags & HEADERS_FLAG_PRIORITY)) { | 5204 if (IsSpdy4() && (flags & HEADERS_FLAG_PRIORITY)) { |
| 5199 headers_ir.set_priority(3); | 5205 headers_ir.set_priority(3); |
| 5200 headers_ir.set_has_priority(true); | 5206 headers_ir.set_has_priority(true); |
| 5201 } | 5207 } |
| 5202 headers_ir.SetHeader("foo", "bar"); | 5208 headers_ir.SetHeader("foo", "bar"); |
| 5203 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 5209 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 5204 int set_flags = flags; | 5210 uint8 set_flags = flags; |
| 5205 if (IsSpdy4()) { | 5211 if (IsSpdy4()) { |
| 5206 // TODO(jgraettinger): Add padding to SpdyHeadersIR, | 5212 // TODO(jgraettinger): Add padding to SpdyHeadersIR, |
| 5207 // and implement framing. | 5213 // and implement framing. |
| 5208 set_flags &= ~HEADERS_FLAG_PADDED; | 5214 set_flags &= ~HEADERS_FLAG_PADDED; |
| 5209 } | 5215 } |
| 5210 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 5216 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
| 5211 | 5217 |
| 5212 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 5218 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
| 5213 EXPECT_CALL(visitor, OnError(_)); | 5219 EXPECT_CALL(visitor, OnError(_)); |
| 5214 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 5220 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5259 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5265 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5260 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { | 5266 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { |
| 5261 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5267 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5262 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5268 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5263 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5269 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5264 } else { | 5270 } else { |
| 5265 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5271 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5266 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5272 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5267 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5273 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5268 } | 5274 } |
| 5269 } | 5275 } while (++flags != 0); |
| 5270 } | 5276 } |
| 5271 | 5277 |
| 5272 TEST_P(SpdyFramerTest, PingFrameFlags) { | 5278 TEST_P(SpdyFramerTest, PingFrameFlags) { |
| 5273 for (int flags = 0; flags < 256; ++flags) { | 5279 uint8 flags = 0; |
| 5280 do { | |
| 5274 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5281 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5275 | 5282 |
| 5276 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5283 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5277 SpdyFramer framer(spdy_version_); | 5284 SpdyFramer framer(spdy_version_); |
| 5278 framer.set_visitor(&visitor); | 5285 framer.set_visitor(&visitor); |
| 5279 | 5286 |
| 5280 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); | 5287 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); |
| 5281 SetFrameFlags(frame.get(), flags, spdy_version_); | 5288 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 5282 | 5289 |
| 5283 if (spdy_version_ > SPDY3 && | 5290 if (spdy_version_ > SPDY3 && |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 5294 flags == 0) { | 5301 flags == 0) { |
| 5295 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5302 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5296 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5303 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5297 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5304 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5298 } else { | 5305 } else { |
| 5299 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5306 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5300 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5307 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5301 framer.error_code()) | 5308 framer.error_code()) |
| 5302 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5309 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5303 } | 5310 } |
| 5304 } | 5311 } while (++flags != 0); |
| 5305 } | 5312 } |
| 5306 | 5313 |
| 5307 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { | 5314 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { |
| 5308 for (int flags = 0; flags < 256; ++flags) { | 5315 uint8 flags = 0; |
| 5316 do { | |
| 5309 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5317 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5310 | 5318 |
| 5311 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5319 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5312 SpdyFramer framer(spdy_version_); | 5320 SpdyFramer framer(spdy_version_); |
| 5313 framer.set_visitor(&visitor); | 5321 framer.set_visitor(&visitor); |
| 5314 | 5322 |
| 5315 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 5323 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( |
| 5316 SpdyWindowUpdateIR(4, 1024))); | 5324 SpdyWindowUpdateIR(4, 1024))); |
| 5317 SetFrameFlags(frame.get(), flags, spdy_version_); | 5325 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 5318 | 5326 |
| 5319 if (flags != 0) { | 5327 if (flags != 0) { |
| 5320 EXPECT_CALL(visitor, OnError(_)); | 5328 EXPECT_CALL(visitor, OnError(_)); |
| 5321 } else { | 5329 } else { |
| 5322 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 5330 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
| 5323 } | 5331 } |
| 5324 | 5332 |
| 5325 framer.ProcessInput(frame->data(), frame->size()); | 5333 framer.ProcessInput(frame->data(), frame->size()); |
| 5326 if (flags != 0) { | 5334 if (flags != 0) { |
| 5327 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5335 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5328 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5336 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5329 framer.error_code()) | 5337 framer.error_code()) |
| 5330 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5338 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5331 } else { | 5339 } else { |
| 5332 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5340 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5333 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5341 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5334 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5342 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5335 } | 5343 } |
| 5336 } | 5344 } while (++flags != 0); |
| 5337 } | 5345 } |
| 5338 | 5346 |
| 5339 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { | 5347 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { |
| 5340 if (spdy_version_ <= SPDY3) { | 5348 if (spdy_version_ <= SPDY3) { |
| 5341 return; | 5349 return; |
| 5342 } | 5350 } |
| 5343 | 5351 |
| 5344 for (int flags = 0; flags < 256; ++flags) { | 5352 uint8 flags = 0; |
| 5353 do { | |
| 5345 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5354 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5346 | 5355 |
| 5347 testing::StrictMock<net::test::MockSpdyFramerVisitor> visitor; | 5356 testing::StrictMock<net::test::MockSpdyFramerVisitor> visitor; |
| 5348 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 5357 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
| 5349 SpdyFramer framer(spdy_version_); | 5358 SpdyFramer framer(spdy_version_); |
| 5350 framer.set_visitor(&visitor); | 5359 framer.set_visitor(&visitor); |
| 5351 framer.set_debug_visitor(&debug_visitor); | 5360 framer.set_debug_visitor(&debug_visitor); |
| 5352 | 5361 |
| 5353 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); | 5362 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); |
| 5354 | 5363 |
| 5355 SpdyPushPromiseIR push_promise(42, 57); | 5364 SpdyPushPromiseIR push_promise(42, 57); |
| 5356 push_promise.SetHeader("foo", "bar"); | 5365 push_promise.SetHeader("foo", "bar"); |
| 5357 scoped_ptr<SpdySerializedFrame> frame( | 5366 scoped_ptr<SpdySerializedFrame> frame( |
| 5358 framer.SerializePushPromise(push_promise)); | 5367 framer.SerializePushPromise(push_promise)); |
| 5359 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, | 5368 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
| 5360 // and implement framing. | 5369 // and implement framing. |
| 5361 int set_flags = flags & ~HEADERS_FLAG_PADDED; | 5370 SetFrameFlags(frame.get(), flags & ~HEADERS_FLAG_PADDED, spdy_version_); |
| 5362 SetFrameFlags(frame.get(), set_flags, spdy_version_); | |
| 5363 | 5371 |
| 5364 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { | 5372 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { |
| 5365 EXPECT_CALL(visitor, OnError(_)); | 5373 EXPECT_CALL(visitor, OnError(_)); |
| 5366 } else { | 5374 } else { |
| 5367 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); | 5375 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); |
| 5368 EXPECT_CALL(visitor, OnPushPromise(42, 57, | 5376 EXPECT_CALL(visitor, OnPushPromise(42, 57, |
| 5369 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); | 5377 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); |
| 5370 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 5378 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
| 5371 .WillRepeatedly(testing::Return(true)); | 5379 .WillRepeatedly(testing::Return(true)); |
| 5372 } | 5380 } |
| 5373 | 5381 |
| 5374 framer.ProcessInput(frame->data(), frame->size()); | 5382 framer.ProcessInput(frame->data(), frame->size()); |
| 5375 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { | 5383 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { |
| 5376 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5384 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5377 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5385 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5378 framer.error_code()) | 5386 framer.error_code()) |
| 5379 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5387 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5380 } else { | 5388 } else { |
| 5381 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5389 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5382 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5390 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5383 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5391 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5384 } | 5392 } |
| 5385 } | 5393 } while (++flags != 0); |
| 5386 } | 5394 } |
| 5387 | 5395 |
| 5388 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { | 5396 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { |
| 5389 if (spdy_version_ <= SPDY3) { | 5397 if (spdy_version_ <= SPDY3) { |
| 5390 return; | 5398 return; |
| 5391 } | 5399 } |
| 5392 | 5400 |
| 5393 for (int flags = 0; flags < 256; ++flags) { | 5401 uint8 flags = 0; |
| 5402 do { | |
| 5394 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 5403 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 5395 | 5404 |
| 5396 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5405 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5397 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 5406 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
| 5398 SpdyFramer framer(spdy_version_); | 5407 SpdyFramer framer(spdy_version_); |
| 5399 framer.set_visitor(&visitor); | 5408 framer.set_visitor(&visitor); |
| 5400 framer.set_debug_visitor(&debug_visitor); | 5409 framer.set_debug_visitor(&debug_visitor); |
| 5401 | 5410 |
| 5402 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); | 5411 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); |
| 5403 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); | 5412 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 5431 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 5440 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
| 5432 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 5441 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 5433 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 5442 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 5434 framer.error_code()) | 5443 framer.error_code()) |
| 5435 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5444 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5436 } else { | 5445 } else { |
| 5437 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5446 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5438 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5447 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5439 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5448 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5440 } | 5449 } |
| 5441 } | 5450 } while (++flags != 0); |
| 5442 } | 5451 } |
| 5443 | 5452 |
| 5444 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) | 5453 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
| 5445 | 5454 |
| 5446 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) | 5455 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) |
| 5447 | 5456 |
| 5448 TEST_P(SpdyFramerTest, EmptySynStream) { | 5457 TEST_P(SpdyFramerTest, EmptySynStream) { |
| 5449 if (!IsSpdy2() && !IsSpdy3()) { | 5458 if (!IsSpdy2() && !IsSpdy3()) { |
| 5450 // SYN_STREAM not supported in SPDY>3. | 5459 // SYN_STREAM not supported in SPDY>3. |
| 5451 return; | 5460 return; |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5835 | 5844 |
| 5836 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); | 5845 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); |
| 5837 TestSpdyVisitor visitor(spdy_version_); | 5846 TestSpdyVisitor visitor(spdy_version_); |
| 5838 visitor.use_compression_ = false; | 5847 visitor.use_compression_ = false; |
| 5839 | 5848 |
| 5840 // Read data in small chunks. | 5849 // Read data in small chunks. |
| 5841 size_t framed_data = 0; | 5850 size_t framed_data = 0; |
| 5842 size_t unframed_data = control_frame->size(); | 5851 size_t unframed_data = control_frame->size(); |
| 5843 size_t kReadChunkSize = 5; // Read five bytes at a time. | 5852 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 5844 while (unframed_data > 0) { | 5853 while (unframed_data > 0) { |
| 5845 size_t to_read = min(kReadChunkSize, unframed_data); | 5854 size_t to_read = std::min(kReadChunkSize, unframed_data); |
| 5846 visitor.SimulateInFramer( | 5855 visitor.SimulateInFramer( |
| 5847 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), | 5856 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), |
| 5848 to_read); | 5857 to_read); |
| 5849 unframed_data -= to_read; | 5858 unframed_data -= to_read; |
| 5850 framed_data += to_read; | 5859 framed_data += to_read; |
| 5851 } | 5860 } |
| 5852 EXPECT_EQ(0, visitor.error_count_); | 5861 EXPECT_EQ(0, visitor.error_count_); |
| 5853 EXPECT_EQ(1, visitor.altsvc_count_); | 5862 EXPECT_EQ(1, visitor.altsvc_count_); |
| 5854 EXPECT_EQ(20u, visitor.test_altsvc_ir_.max_age()); | 5863 EXPECT_EQ(20u, visitor.test_altsvc_ir_.max_age()); |
| 5855 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); | 5864 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5925 TestSpdyVisitor visitor(spdy_version_); | 5934 TestSpdyVisitor visitor(spdy_version_); |
| 5926 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 5935 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 5927 | 5936 |
| 5928 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); | 5937 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 5929 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 5938 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5930 visitor.framer_.error_code()) | 5939 visitor.framer_.error_code()) |
| 5931 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | 5940 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 5932 } | 5941 } |
| 5933 | 5942 |
| 5934 } // namespace net | 5943 } // namespace net |
| OLD | NEW |