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 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
10 #include "net/spdy/spdy_protocol.h" | 10 #include "net/spdy/spdy_protocol.h" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 SpdyCredential credential_; | 431 SpdyCredential credential_; |
432 }; | 432 }; |
433 | 433 |
434 } // namespace test | 434 } // namespace test |
435 | 435 |
436 using test::CompareCharArraysWithHexError; | 436 using test::CompareCharArraysWithHexError; |
437 using test::SpdyFramerTestUtil; | 437 using test::SpdyFramerTestUtil; |
438 using test::TestSpdyVisitor; | 438 using test::TestSpdyVisitor; |
439 | 439 |
440 TEST(SpdyFrameBuilderTest, WriteLimits) { | 440 TEST(SpdyFrameBuilderTest, WriteLimits) { |
441 SpdyFrameBuilder builder(kLengthMask + 4); | 441 SpdyFrameBuilder builder(1, DATA_FLAG_NONE, kLengthMask + 8); |
442 // length field should fail. | 442 // Data frame header is 8 bytes |
443 EXPECT_FALSE(builder.WriteBytes(reinterpret_cast<const void*>(0x1), | 443 EXPECT_EQ(8, builder.length()); |
444 kLengthMask + 1)); | |
445 EXPECT_EQ(0, builder.length()); | |
446 | |
447 // Writing a block of the maximum allowed size should succeed. | |
448 const std::string kLargeData(kLengthMask, 'A'); | 444 const std::string kLargeData(kLengthMask, 'A'); |
449 builder.WriteUInt32(kLengthMask); | 445 builder.WriteUInt32(kLengthMask); |
450 EXPECT_EQ(4, builder.length()); | 446 EXPECT_EQ(12, builder.length()); |
451 EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask)); | 447 EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask - 4)); |
452 EXPECT_EQ(4 + kLengthMask, static_cast<unsigned>(builder.length())); | 448 EXPECT_EQ(kLengthMask + 8, static_cast<unsigned>(builder.length())); |
453 } | 449 } |
454 | 450 |
455 enum SpdyFramerTestTypes { | 451 enum SpdyFramerTestTypes { |
456 SPDY2, | 452 SPDY2, |
457 SPDY3, | 453 SPDY3, |
458 }; | 454 }; |
459 | 455 |
460 class SpdyFramerTest | 456 class SpdyFramerTest |
461 : public ::testing::TestWithParam<SpdyFramerTestTypes> { | 457 : public ::testing::TestWithParam<SpdyFramerTestTypes> { |
462 protected: | 458 protected: |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 std::string serialized_headers(frame->header_block(), | 570 std::string serialized_headers(frame->header_block(), |
575 frame->header_block_len()); | 571 frame->header_block_len()); |
576 SpdyHeaderBlock new_headers; | 572 SpdyHeaderBlock new_headers; |
577 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 573 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
578 serialized_headers.size() - 2, | 574 serialized_headers.size() - 2, |
579 &new_headers)); | 575 &new_headers)); |
580 } | 576 } |
581 | 577 |
582 TEST_P(SpdyFramerTest, OutOfOrderHeaders) { | 578 TEST_P(SpdyFramerTest, OutOfOrderHeaders) { |
583 // Frame builder with plentiful buffer size. | 579 // Frame builder with plentiful buffer size. |
584 SpdyFrameBuilder frame(1024); | 580 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024); |
585 | 581 |
586 frame.WriteUInt16(kControlFlagMask | 1); | |
587 frame.WriteUInt16(SYN_STREAM); | |
588 frame.WriteUInt32(0); // Placeholder for the length. | |
589 frame.WriteUInt32(3); // stream_id | 582 frame.WriteUInt32(3); // stream_id |
590 frame.WriteUInt32(0); // Associated stream id | 583 frame.WriteUInt32(0); // Associated stream id |
591 frame.WriteUInt16(0); // Priority. | 584 frame.WriteUInt16(0); // Priority. |
592 | 585 |
593 if (IsSpdy2()) { | 586 if (IsSpdy2()) { |
594 frame.WriteUInt16(2); // Number of headers. | 587 frame.WriteUInt16(2); // Number of headers. |
595 frame.WriteString("gamma"); | 588 frame.WriteString("gamma"); |
596 frame.WriteString("gamma"); | 589 frame.WriteString("gamma"); |
597 frame.WriteString("alpha"); | 590 frame.WriteString("alpha"); |
598 frame.WriteString("alpha"); | 591 frame.WriteString("alpha"); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 EXPECT_EQ("another cert", credential.certs.front()); | 677 EXPECT_EQ("another cert", credential.certs.front()); |
685 credential.certs.erase(credential.certs.begin()); | 678 credential.certs.erase(credential.certs.begin()); |
686 EXPECT_EQ("final cert", credential.certs.front()); | 679 EXPECT_EQ("final cert", credential.certs.front()); |
687 credential.certs.erase(credential.certs.begin()); | 680 credential.certs.erase(credential.certs.begin()); |
688 EXPECT_TRUE(credential.certs.empty()); | 681 EXPECT_TRUE(credential.certs.empty()); |
689 } | 682 } |
690 } | 683 } |
691 | 684 |
692 TEST_P(SpdyFramerTest, DuplicateHeader) { | 685 TEST_P(SpdyFramerTest, DuplicateHeader) { |
693 // Frame builder with plentiful buffer size. | 686 // Frame builder with plentiful buffer size. |
694 SpdyFrameBuilder frame(1024); | 687 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024); |
695 | 688 |
696 frame.WriteUInt16(kControlFlagMask | 1); | |
697 frame.WriteUInt16(SYN_STREAM); | |
698 frame.WriteUInt32(0); // Placeholder for the length. | |
699 frame.WriteUInt32(3); // stream_id | 689 frame.WriteUInt32(3); // stream_id |
700 frame.WriteUInt32(0); // associated stream id | 690 frame.WriteUInt32(0); // associated stream id |
701 frame.WriteUInt16(0); // Priority. | 691 frame.WriteUInt16(0); // Priority. |
702 | 692 |
703 if (IsSpdy2()) { | 693 if (IsSpdy2()) { |
704 frame.WriteUInt16(2); // Number of headers. | 694 frame.WriteUInt16(2); // Number of headers. |
705 frame.WriteString("name"); | 695 frame.WriteString("name"); |
706 frame.WriteString("value1"); | 696 frame.WriteString("value1"); |
707 frame.WriteString("name"); | 697 frame.WriteString("name"); |
708 frame.WriteString("value2"); | 698 frame.WriteString("value2"); |
(...skipping 15 matching lines...) Expand all Loading... |
724 SpdyFramer framer(spdy_version_); | 714 SpdyFramer framer(spdy_version_); |
725 framer.set_enable_compression(false); | 715 framer.set_enable_compression(false); |
726 // This should fail because duplicate headers are verboten by the spec. | 716 // This should fail because duplicate headers are verboten by the spec. |
727 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 717 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
728 serialized_headers.size(), | 718 serialized_headers.size(), |
729 &new_headers)); | 719 &new_headers)); |
730 } | 720 } |
731 | 721 |
732 TEST_P(SpdyFramerTest, MultiValueHeader) { | 722 TEST_P(SpdyFramerTest, MultiValueHeader) { |
733 // Frame builder with plentiful buffer size. | 723 // Frame builder with plentiful buffer size. |
734 SpdyFrameBuilder frame(1024); | 724 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024); |
735 | 725 |
736 frame.WriteUInt16(kControlFlagMask | 1); | |
737 frame.WriteUInt16(SYN_STREAM); | |
738 frame.WriteUInt32(0); // Placeholder for the length. | |
739 frame.WriteUInt32(3); // stream_id | 726 frame.WriteUInt32(3); // stream_id |
740 frame.WriteUInt32(0); // associated stream id | 727 frame.WriteUInt32(0); // associated stream id |
741 frame.WriteUInt16(0); // Priority. | 728 frame.WriteUInt16(0); // Priority. |
742 | 729 |
743 std::string value("value1\0value2"); | 730 std::string value("value1\0value2"); |
744 if (IsSpdy2()) { | 731 if (IsSpdy2()) { |
745 frame.WriteUInt16(1); // Number of headers. | 732 frame.WriteUInt16(1); // Number of headers. |
746 frame.WriteString("name"); | 733 frame.WriteString("name"); |
747 frame.WriteString(value); | 734 frame.WriteString(value); |
748 } else { | 735 } else { |
(...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2697 htonl(IsSpdy2() ? 0x04030201 : 0x01020304); | 2684 htonl(IsSpdy2() ? 0x04030201 : 0x01020304); |
2698 | 2685 |
2699 SettingsFlagsAndId id_and_flags = | 2686 SettingsFlagsAndId id_and_flags = |
2700 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); | 2687 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
2701 EXPECT_EQ(kId, id_and_flags.id()); | 2688 EXPECT_EQ(kId, id_and_flags.id()); |
2702 EXPECT_EQ(kFlags, id_and_flags.flags()); | 2689 EXPECT_EQ(kFlags, id_and_flags.flags()); |
2703 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 2690 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
2704 } | 2691 } |
2705 | 2692 |
2706 } // namespace net | 2693 } // namespace net |
OLD | NEW |