Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: net/spdy/spdy_framer_test.cc

Issue 2558243002: Add Http2FrameDecoderAdapter. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_framer_decoder_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_framer.h" 5 #include "net/spdy/spdy_framer.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 reader.ReadUInt8(&serialized_type); 606 reader.ReadUInt8(&serialized_type);
607 SpdyFrameType type = SpdyConstants::ParseFrameType(serialized_type); 607 SpdyFrameType type = SpdyConstants::ParseFrameType(serialized_type);
608 DCHECK_EQ(HEADERS, type); 608 DCHECK_EQ(HEADERS, type);
609 uint8_t flags; 609 uint8_t flags;
610 reader.ReadUInt8(&flags); 610 reader.ReadUInt8(&flags);
611 611
612 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(), 612 return StringPiece(frame.data() + framer.GetHeadersMinimumSize(),
613 frame.size() - framer.GetHeadersMinimumSize()); 613 frame.size() - framer.GetHeadersMinimumSize());
614 } 614 }
615 615
616 enum DecoderChoice { DECODER_SELF, DECODER_NESTED }; 616 enum DecoderChoice { DECODER_SELF, DECODER_NESTED, DECODER_HTTP2 };
617 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_2 }; 617 enum HpackChoice { HPACK_DECODER_1, HPACK_DECODER_2 };
618 618
619 class SpdyFramerTest 619 class SpdyFramerTest
620 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> { 620 : public ::testing::TestWithParam<std::tuple<DecoderChoice, HpackChoice>> {
621 protected: 621 protected:
622 void SetUp() override { 622 void SetUp() override {
623 auto param = GetParam(); 623 auto param = GetParam();
624 switch (std::get<0>(param)) { 624 switch (std::get<0>(param)) {
625 case DECODER_SELF: 625 case DECODER_SELF:
626 FLAGS_use_nested_spdy_framer_decoder = false; 626 FLAGS_use_nested_spdy_framer_decoder = false;
627 FLAGS_use_http2_frame_decoder_adapter = false;
627 break; 628 break;
628 case DECODER_NESTED: 629 case DECODER_NESTED:
629 FLAGS_use_nested_spdy_framer_decoder = true; 630 FLAGS_use_nested_spdy_framer_decoder = true;
631 FLAGS_use_http2_frame_decoder_adapter = false;
632 break;
633 case DECODER_HTTP2:
634 FLAGS_use_nested_spdy_framer_decoder = false;
635 FLAGS_use_http2_frame_decoder_adapter = true;
630 break; 636 break;
631 } 637 }
632 switch (std::get<1>(param)) { 638 switch (std::get<1>(param)) {
633 case HPACK_DECODER_1: 639 case HPACK_DECODER_1:
634 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false; 640 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = false;
635 break; 641 break;
636 case HPACK_DECODER_2: 642 case HPACK_DECODER_2:
637 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = true; 643 FLAGS_chromium_http2_flag_spdy_use_hpack_decoder2 = true;
638 break; 644 break;
639 } 645 }
(...skipping 14 matching lines...) Expand all
654 const SpdySerializedFrame& actual_frame) { 660 const SpdySerializedFrame& actual_frame) {
655 CompareCharArraysWithHexError( 661 CompareCharArraysWithHexError(
656 description, 662 description,
657 reinterpret_cast<const unsigned char*>(expected_frame.data()), 663 reinterpret_cast<const unsigned char*>(expected_frame.data()),
658 expected_frame.size(), 664 expected_frame.size(),
659 reinterpret_cast<const unsigned char*>(actual_frame.data()), 665 reinterpret_cast<const unsigned char*>(actual_frame.data()),
660 actual_frame.size()); 666 actual_frame.size());
661 } 667 }
662 }; 668 };
663 669
664 INSTANTIATE_TEST_CASE_P( 670 INSTANTIATE_TEST_CASE_P(SpdyFramerTests,
665 SpdyFramerTests, 671 SpdyFramerTest,
666 SpdyFramerTest, 672 ::testing::Combine(::testing::Values(DECODER_SELF,
667 ::testing::Combine(::testing::Values(DECODER_SELF, DECODER_NESTED), 673 DECODER_NESTED,
668 ::testing::Values(HPACK_DECODER_1, HPACK_DECODER_2))); 674 DECODER_HTTP2),
675 ::testing::Values(HPACK_DECODER_1,
676 HPACK_DECODER_2)));
669 677
670 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. 678 // Test that we can encode and decode a SpdyHeaderBlock in serialized form.
671 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { 679 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) {
672 SpdyFramer framer; 680 SpdyFramer framer;
673 framer.set_enable_compression(false); 681 framer.set_enable_compression(false);
674 682
675 // Encode the header block into a Headers frame. 683 // Encode the header block into a Headers frame.
676 SpdyHeadersIR headers(1); 684 SpdyHeadersIR headers(1);
677 headers.SetHeader("alpha", "beta"); 685 headers.SetHeader("alpha", "beta");
678 headers.SetHeader("gamma", "charlie"); 686 headers.SetHeader("gamma", "charlie");
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 // signal SPDY_INVALID_STREAM_ID. 1134 // signal SPDY_INVALID_STREAM_ID.
1127 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) { 1135 TEST_P(SpdyFramerTest, PushPromiseWithPromisedStreamIdZero) {
1128 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 1136 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
1129 SpdyFramer framer; 1137 SpdyFramer framer;
1130 framer.set_visitor(&visitor); 1138 framer.set_visitor(&visitor);
1131 1139
1132 SpdyPushPromiseIR push_promise(3, 0); 1140 SpdyPushPromiseIR push_promise(3, 0);
1133 push_promise.SetHeader("alpha", "beta"); 1141 push_promise.SetHeader("alpha", "beta");
1134 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise)); 1142 SpdySerializedFrame frame(framer.SerializePushPromise(push_promise));
1135 1143
1136 // We shouldn't have to read the whole frame before we signal an error.
1137 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); 1144 EXPECT_CALL(visitor, OnError(testing::Eq(&framer)));
1138 EXPECT_GT(frame.size(), framer.ProcessInput(frame.data(), frame.size())); 1145 framer.ProcessInput(frame.data(), frame.size());
1139 EXPECT_TRUE(framer.HasError()); 1146 EXPECT_TRUE(framer.HasError());
1140 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) 1147 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code())
1141 << SpdyFramer::ErrorCodeToString(framer.error_code()); 1148 << SpdyFramer::ErrorCodeToString(framer.error_code());
1142 } 1149 }
1143 1150
1144 TEST_P(SpdyFramerTest, DuplicateHeader) { 1151 TEST_P(SpdyFramerTest, DuplicateHeader) {
1145 SpdyFramer framer; 1152 SpdyFramer framer;
1146 // Frame builder with plentiful buffer size. 1153 // Frame builder with plentiful buffer size.
1147 SpdyFrameBuilder frame(1024); 1154 SpdyFrameBuilder frame(1024);
1148 frame.BeginNewFrame(framer, HEADERS, 0, 3); 1155 frame.BeginNewFrame(framer, HEADERS, 0, 3);
(...skipping 1638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 framer.GetFrameHeaderSize()); 2794 framer.GetFrameHeaderSize());
2788 // Zero-len settings frames are permitted as of HTTP/2. 2795 // Zero-len settings frames are permitted as of HTTP/2.
2789 EXPECT_EQ(0, visitor.error_count_); 2796 EXPECT_EQ(0, visitor.error_count_);
2790 } 2797 }
2791 2798
2792 // Tests handling of SETTINGS frames with invalid length. 2799 // Tests handling of SETTINGS frames with invalid length.
2793 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { 2800 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) {
2794 SpdyFramer framer; 2801 SpdyFramer framer;
2795 SpdySettingsIR settings_ir; 2802 SpdySettingsIR settings_ir;
2796 2803
2797 // Add a setting to pad the frame so that we don't get a buffer overflow when 2804 // Add settings to more than fill the frame so that we don't get a buffer
2798 // calling SimulateInFramer() below. 2805 // overflow when calling SimulateInFramer() below. These settings must be
2806 // distinct parameters because SpdySettingsIR has a map for settings, and will
2807 // collapse multiple copies of the same parameter.
2799 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false, 2808 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, false, false,
2800 0x00000002); 2809 0x00000002);
2810 settings_ir.AddSetting(SETTINGS_MAX_CONCURRENT_STREAMS, false, false,
2811 0x00000002);
2801 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir)); 2812 SpdySerializedFrame control_frame(framer.SerializeSettings(settings_ir));
2802 const size_t kNewLength = 14; 2813 const size_t kNewLength = 8;
2803 SetFrameLength(&control_frame, kNewLength); 2814 SetFrameLength(&control_frame, kNewLength);
2804 TestSpdyVisitor visitor; 2815 TestSpdyVisitor visitor;
2805 visitor.use_compression_ = false; 2816 visitor.use_compression_ = false;
2806 visitor.SimulateInFramer( 2817 visitor.SimulateInFramer(
2807 reinterpret_cast<unsigned char*>(control_frame.data()), 2818 reinterpret_cast<unsigned char*>(control_frame.data()),
2808 framer.GetFrameHeaderSize() + kNewLength); 2819 framer.GetFrameHeaderSize() + kNewLength);
2809 // Should generate an error, since its not possible to have a 2820 // Should generate an error, since its not possible to have a
2810 // settings frame of length kNewLength. 2821 // settings frame of length kNewLength.
2811 EXPECT_EQ(1, visitor.error_count_); 2822 EXPECT_EQ(1, visitor.error_count_);
2812 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE, 2823 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_SIZE,
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after
4366 4377
4367 EXPECT_EQ(1, visitor->data_frame_count_); 4378 EXPECT_EQ(1, visitor->data_frame_count_);
4368 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_)); 4379 EXPECT_EQ(strlen(four_score), static_cast<unsigned>(visitor->data_bytes_));
4369 EXPECT_EQ(0, visitor->headers_frame_count_); 4380 EXPECT_EQ(0, visitor->headers_frame_count_);
4370 } 4381 }
4371 } 4382 }
4372 4383
4373 } // namespace test 4384 } // namespace test
4374 4385
4375 } // namespace net 4386 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer_decoder_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698