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

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

Issue 141953004: SPDY cleanup: remove credential slot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix inadvertent rebase on upstream branches. Created 6 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | 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 <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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } else { 109 } else {
110 // Done. 110 // Done.
111 finished_ = true; 111 finished_ = true;
112 } 112 }
113 return true; 113 return true;
114 } 114 }
115 115
116 virtual void OnSynStream(SpdyStreamId stream_id, 116 virtual void OnSynStream(SpdyStreamId stream_id,
117 SpdyStreamId associated_stream_id, 117 SpdyStreamId associated_stream_id,
118 SpdyPriority priority, 118 SpdyPriority priority,
119 uint8 slot,
120 bool fin, 119 bool fin,
121 bool unidirectional) OVERRIDE { 120 bool unidirectional) OVERRIDE {
122 SpdyFramer framer(version_); 121 SpdyFramer framer(version_);
123 framer.set_enable_compression(false); 122 framer.set_enable_compression(false);
124 SpdySynStreamIR syn_stream(stream_id); 123 SpdySynStreamIR syn_stream(stream_id);
125 syn_stream.set_associated_to_stream_id(associated_stream_id); 124 syn_stream.set_associated_to_stream_id(associated_stream_id);
126 syn_stream.set_priority(priority); 125 syn_stream.set_priority(priority);
127 syn_stream.set_slot(slot);
128 syn_stream.set_fin(fin); 126 syn_stream.set_fin(fin);
129 syn_stream.set_unidirectional(unidirectional); 127 syn_stream.set_unidirectional(unidirectional);
130 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 128 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
131 ResetBuffer(); 129 ResetBuffer();
132 memcpy(buffer_.get(), frame->data(), framer.GetSynStreamMinimumSize()); 130 memcpy(buffer_.get(), frame->data(), framer.GetSynStreamMinimumSize());
133 size_ += framer.GetSynStreamMinimumSize(); 131 size_ += framer.GetSynStreamMinimumSize();
134 } 132 }
135 133
136 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE { 134 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE {
137 SpdyFramer framer(version_); 135 SpdyFramer framer(version_);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return false; 300 return false;
303 } 301 }
304 memcpy(header_buffer_.get() + header_buffer_length_, header_data, len); 302 memcpy(header_buffer_.get() + header_buffer_length_, header_data, len);
305 header_buffer_length_ += len; 303 header_buffer_length_ += len;
306 return true; 304 return true;
307 } 305 }
308 306
309 virtual void OnSynStream(SpdyStreamId stream_id, 307 virtual void OnSynStream(SpdyStreamId stream_id,
310 SpdyStreamId associated_stream_id, 308 SpdyStreamId associated_stream_id,
311 SpdyPriority priority, 309 SpdyPriority priority,
312 uint8 credential_slot,
313 bool fin, 310 bool fin,
314 bool unidirectional) OVERRIDE { 311 bool unidirectional) OVERRIDE {
315 syn_frame_count_++; 312 syn_frame_count_++;
316 InitHeaderStreaming(SYN_STREAM, stream_id); 313 InitHeaderStreaming(SYN_STREAM, stream_id);
317 if (fin) { 314 if (fin) {
318 fin_flag_count_++; 315 fin_flag_count_++;
319 } 316 }
320 } 317 }
321 318
322 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE { 319 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 EXPECT_TRUE(frame.get() != NULL); 606 EXPECT_TRUE(frame.get() != NULL);
610 607
611 base::StringPiece serialized_headers = 608 base::StringPiece serialized_headers =
612 GetSerializedHeaders(frame.get(), framer); 609 GetSerializedHeaders(frame.get(), framer);
613 SpdyHeaderBlock new_headers; 610 SpdyHeaderBlock new_headers;
614 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), 611 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(),
615 serialized_headers.size() - 2, 612 serialized_headers.size() - 2,
616 &new_headers)); 613 &new_headers));
617 } 614 }
618 615
619 TEST_P(SpdyFramerTest, OutOfOrderHeaders) {
620 SpdyFramer framer(spdy_version_);
621 framer.set_enable_compression(false);
622
623 // Frame builder with plentiful buffer size.
624 SpdyFrameBuilder frame(1024);
625 if (spdy_version_ < 4) {
626 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE);
627 frame.WriteUInt32(3); // stream_id
628 } else {
629 frame.WriteFramePrefix(framer, SYN_STREAM, CONTROL_FLAG_NONE, 3);
630 }
631
632 frame.WriteUInt32(0); // Associated stream id
633 frame.WriteUInt16(0); // Priority.
634
635 if (IsSpdy2()) {
636 frame.WriteUInt16(2); // Number of headers.
637 frame.WriteString("gamma");
638 frame.WriteString("gamma");
639 frame.WriteString("alpha");
640 frame.WriteString("alpha");
641 } else {
642 frame.WriteUInt32(2); // Number of headers.
643 frame.WriteStringPiece32("gamma");
644 frame.WriteStringPiece32("gamma");
645 frame.WriteStringPiece32("alpha");
646 frame.WriteStringPiece32("alpha");
647 }
648 // write the length
649 frame.RewriteLength(framer);
650
651 SpdyHeaderBlock new_headers;
652 scoped_ptr<SpdyFrame> control_frame(frame.take());
653 base::StringPiece serialized_headers =
654 GetSerializedHeaders(control_frame.get(), framer);
655 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(),
656 serialized_headers.size(),
657 &new_headers));
658 }
659
660 // Test that if we receive a SYN_STREAM with stream ID zero, we signal an error
661 // (but don't crash).
662 TEST_P(SpdyFramerTest, SynStreamWithStreamIdZero) {
663 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
664 SpdyFramer framer(spdy_version_);
665 framer.set_visitor(&visitor);
666
667 SpdySynStreamIR syn_stream(0);
668 syn_stream.set_priority(1);
669 syn_stream.SetHeader("alpha", "beta");
670 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
671 ASSERT_TRUE(frame.get() != NULL);
672
673 // We shouldn't have to read the whole frame before we signal an error.
674 EXPECT_CALL(visitor, OnError(testing::Eq(&framer)));
675 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size()));
676 EXPECT_TRUE(framer.HasError());
677 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code())
678 << SpdyFramer::ErrorCodeToString(framer.error_code());
679 }
680
681 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error 616 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error
682 // (but don't crash). 617 // (but don't crash).
683 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { 618 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) {
684 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 619 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
685 SpdyFramer framer(spdy_version_); 620 SpdyFramer framer(spdy_version_);
686 framer.set_visitor(&visitor); 621 framer.set_visitor(&visitor);
687 622
688 SpdySynReplyIR syn_reply(0); 623 SpdySynReplyIR syn_reply(0);
689 syn_reply.SetHeader("alpha", "beta"); 624 syn_reply.SetHeader("alpha", "beta");
690 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeSynReply(syn_reply)); 625 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeSynReply(syn_reply));
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1614 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1680 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); 1615 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize);
1681 } 1616 }
1682 } 1617 }
1683 1618
1684 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 1619 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) {
1685 SpdyFramer framer(spdy_version_); 1620 SpdyFramer framer(spdy_version_);
1686 framer.set_enable_compression(false); 1621 framer.set_enable_compression(false);
1687 1622
1688 { 1623 {
1689 const char kDescription[] = "SYN_STREAM frame, lowest pri, slot 2, no FIN"; 1624 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN";
1690 1625
1691 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; 1626 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0;
1692 const unsigned char kCre = IsSpdy2() ? 0 : 2;
1693 const unsigned char kV2FrameData[] = { 1627 const unsigned char kV2FrameData[] = {
1694 0x80, spdy_version_ch_, 0x00, 0x01, 1628 0x80, spdy_version_ch_, 0x00, 0x01,
1695 0x00, 0x00, 0x00, 0x20, 1629 0x00, 0x00, 0x00, 0x20,
1696 0x00, 0x00, 0x00, 0x01, 1630 0x00, 0x00, 0x00, 0x01,
1697 0x00, 0x00, 0x00, 0x00, 1631 0x00, 0x00, 0x00, 0x00,
1698 kPri, 0x00, 0x00, 0x02, 1632 kPri, 0x00, 0x00, 0x02,
1699 0x00, 0x03, 'b', 'a', 1633 0x00, 0x03, 'b', 'a',
1700 'r', 0x00, 0x03, 'f', 1634 'r', 0x00, 0x03, 'f',
1701 'o', 'o', 0x00, 0x03, 1635 'o', 'o', 0x00, 0x03,
1702 'f', 'o', 'o', 0x00, 1636 'f', 'o', 'o', 0x00,
1703 0x03, 'b', 'a', 'r' 1637 0x03, 'b', 'a', 'r'
1704 }; 1638 };
1705 const unsigned char kV3FrameData[] = { 1639 const unsigned char kV3FrameData[] = {
1706 0x80, spdy_version_ch_, 0x00, 0x01, 1640 0x80, spdy_version_ch_, 0x00, 0x01,
1707 0x00, 0x00, 0x00, 0x2a, 1641 0x00, 0x00, 0x00, 0x2a,
1708 0x00, 0x00, 0x00, 0x01, 1642 0x00, 0x00, 0x00, 0x01,
1709 0x00, 0x00, 0x00, 0x00, 1643 0x00, 0x00, 0x00, 0x00,
1710 kPri, kCre, 0x00, 0x00, 1644 kPri, 0x00, 0x00, 0x00,
1711 0x00, 0x02, 0x00, 0x00, 1645 0x00, 0x02, 0x00, 0x00,
1712 0x00, 0x03, 'b', 'a', 1646 0x00, 0x03, 'b', 'a',
1713 'r', 0x00, 0x00, 0x00, 1647 'r', 0x00, 0x00, 0x00,
1714 0x03, 'f', 'o', 'o', 1648 0x03, 'f', 'o', 'o',
1715 0x00, 0x00, 0x00, 0x03, 1649 0x00, 0x00, 0x00, 0x03,
1716 'f', 'o', 'o', 0x00, 1650 'f', 'o', 'o', 0x00,
1717 0x00, 0x00, 0x03, 'b', 1651 0x00, 0x00, 0x03, 'b',
1718 'a', 'r' 1652 'a', 'r'
1719 }; 1653 };
1720 const unsigned char kV4FrameData[] = { 1654 const unsigned char kV4FrameData[] = {
1721 0x00, 0x2c, 0x08, 0x08, 1655 0x00, 0x2c, 0x08, 0x08,
1722 0x00, 0x00, 0x00, 0x01, 1656 0x00, 0x00, 0x00, 0x01,
1723 0x00, 0x00, 0x00, 0x07, 1657 0x00, 0x00, 0x00, 0x07,
1724 0x00, 0x00, 0x00, 0x02, 1658 0x00, 0x00, 0x00, 0x02,
1725 0x00, 0x00, 0x00, 0x03, 1659 0x00, 0x00, 0x00, 0x03,
1726 'b', 'a', 'r', 0x00, 1660 'b', 'a', 'r', 0x00,
1727 0x00, 0x00, 0x03, 'f', 1661 0x00, 0x00, 0x03, 'f',
1728 'o', 'o', 0x00, 0x00, 1662 'o', 'o', 0x00, 0x00,
1729 0x00, 0x03, 'f', 'o', 1663 0x00, 0x03, 'f', 'o',
1730 'o', 0x00, 0x00, 0x00, 1664 'o', 0x00, 0x00, 0x00,
1731 0x03, 'b', 'a', 'r' 1665 0x03, 'b', 'a', 'r'
1732 }; 1666 };
1733 SpdySynStreamIR syn_stream(1); 1667 SpdySynStreamIR syn_stream(1);
1734 syn_stream.set_priority(framer.GetLowestPriority()); 1668 syn_stream.set_priority(framer.GetLowestPriority());
1735 syn_stream.set_slot(kCre);
1736 syn_stream.SetHeader("bar", "foo"); 1669 syn_stream.SetHeader("bar", "foo");
1737 syn_stream.SetHeader("foo", "bar"); 1670 syn_stream.SetHeader("foo", "bar");
1738 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1671 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
1739 if (IsSpdy2()) { 1672 if (IsSpdy2()) {
1740 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 1673 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
1741 } else if (IsSpdy3()) { 1674 } else if (IsSpdy3()) {
1742 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1675 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1743 } else { 1676 } else {
1744 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1677 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1745 } 1678 }
(...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after
3724 3657
3725 if (!IsSpdy4() && 3658 if (!IsSpdy4() &&
3726 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { 3659 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) {
3727 EXPECT_CALL(visitor, OnError(_)); 3660 EXPECT_CALL(visitor, OnError(_));
3728 } else if (IsSpdy4() && 3661 } else if (IsSpdy4() &&
3729 flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY)) { 3662 flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY)) {
3730 EXPECT_CALL(visitor, OnError(_)); 3663 EXPECT_CALL(visitor, OnError(_));
3731 } else { 3664 } else {
3732 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); 3665 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _));
3733 if (IsSpdy4()) { 3666 if (IsSpdy4()) {
3734 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, 0, flags & CONTROL_FLAG_FIN, 3667 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN,
3735 false)); 3668 false));
3736 } else { 3669 } else {
3737 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, 0, flags & CONTROL_FLAG_FIN, 3670 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN,
3738 flags & CONTROL_FLAG_UNIDIRECTIONAL)); 3671 flags & CONTROL_FLAG_UNIDIRECTIONAL));
3739 } 3672 }
3740 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) 3673 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _))
3741 .WillRepeatedly(testing::Return(true)); 3674 .WillRepeatedly(testing::Return(true));
3742 if (flags & DATA_FLAG_FIN) { 3675 if (flags & DATA_FLAG_FIN) {
3743 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); 3676 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true));
3744 } 3677 }
3745 } 3678 }
3746 3679
3747 framer.ProcessInput(frame->data(), frame->size()); 3680 framer.ProcessInput(frame->data(), frame->size());
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
4079 framer.GetSynStreamMinimumSize(), 4012 framer.GetSynStreamMinimumSize(),
4080 spdy_version_); 4013 spdy_version_);
4081 } else { 4014 } else {
4082 SetFrameLength( 4015 SetFrameLength(
4083 frame.get(), 4016 frame.get(),
4084 framer.GetSynStreamMinimumSize() - framer.GetControlFrameHeaderSize(), 4017 framer.GetSynStreamMinimumSize() - framer.GetControlFrameHeaderSize(),
4085 spdy_version_); 4018 spdy_version_);
4086 } 4019 }
4087 4020
4088 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(1, SYN_STREAM, _)); 4021 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(1, SYN_STREAM, _));
4089 EXPECT_CALL(visitor, OnSynStream(1, 0, 1, 0, false, false)); 4022 EXPECT_CALL(visitor, OnSynStream(1, 0, 1, false, false));
4090 EXPECT_CALL(visitor, OnControlFrameHeaderData(1, NULL, 0)); 4023 EXPECT_CALL(visitor, OnControlFrameHeaderData(1, NULL, 0));
4091 4024
4092 framer.ProcessInput(frame->data(), framer.GetSynStreamMinimumSize()); 4025 framer.ProcessInput(frame->data(), framer.GetSynStreamMinimumSize());
4093 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4026 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4094 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4027 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4095 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4028 << SpdyFramer::ErrorCodeToString(framer.error_code());
4096 } 4029 }
4097 4030
4098 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { 4031 TEST_P(SpdyFramerTest, SettingsFlagsAndId) {
4099 const uint32 kId = 0x020304; 4032 const uint32 kId = 0x020304;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
4222 SpdyBlockedIR blocked_ir(0); 4155 SpdyBlockedIR blocked_ir(0);
4223 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); 4156 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir));
4224 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); 4157 framer.ProcessInput(frame->data(), framer.GetBlockedSize());
4225 4158
4226 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4159 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4227 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4160 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4228 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4161 << SpdyFramer::ErrorCodeToString(framer.error_code());
4229 } 4162 }
4230 4163
4231 } // namespace net 4164 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698