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

Side by Side Diff: net/quic/quic_framer_test.cc

Issue 15074007: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix for windows Created 7 years, 7 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/quic/quic_framer.cc ('k') | net/quic/quic_http_stream_test.cc » ('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 <map> 6 #include <map>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 } 565 }
566 566
567 TEST_F(QuicFramerTest, PacketHeaderWithVersionFlag) { 567 TEST_F(QuicFramerTest, PacketHeaderWithVersionFlag) {
568 unsigned char packet[] = { 568 unsigned char packet[] = {
569 // guid 569 // guid
570 0x10, 0x32, 0x54, 0x76, 570 0x10, 0x32, 0x54, 0x76,
571 0x98, 0xBA, 0xDC, 0xFE, 571 0x98, 0xBA, 0xDC, 0xFE,
572 // public flags (version) 572 // public flags (version)
573 0x01, 573 0x01,
574 // version tag 574 // version tag
575 'Q', '0', '0', '1', 575 'Q', '0', '0', '2',
576 // packet sequence number 576 // packet sequence number
577 0xBC, 0x9A, 0x78, 0x56, 577 0xBC, 0x9A, 0x78, 0x56,
578 0x34, 0x12, 578 0x34, 0x12,
579 // private flags 579 // private flags
580 0x00, 580 0x00,
581 // first fec protected packet offset 581 // first fec protected packet offset
582 0xFF, 582 0xFF,
583 }; 583 };
584 584
585 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 585 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 } 810 }
811 811
812 TEST_F(QuicFramerTest, StreamFrameWithVersion) { 812 TEST_F(QuicFramerTest, StreamFrameWithVersion) {
813 unsigned char packet[] = { 813 unsigned char packet[] = {
814 // guid 814 // guid
815 0x10, 0x32, 0x54, 0x76, 815 0x10, 0x32, 0x54, 0x76,
816 0x98, 0xBA, 0xDC, 0xFE, 816 0x98, 0xBA, 0xDC, 0xFE,
817 // public flags (version) 817 // public flags (version)
818 0x01, 818 0x01,
819 // version tag 819 // version tag
820 'Q', '0', '0', '1', 820 'Q', '0', '0', '2',
821 // packet sequence number 821 // packet sequence number
822 0xBC, 0x9A, 0x78, 0x56, 822 0xBC, 0x9A, 0x78, 0x56,
823 0x34, 0x12, 823 0x34, 0x12,
824 // private flags 824 // private flags
825 0x00, 825 0x00,
826 // first fec protected packet offset 826 // first fec protected packet offset
827 0xFF, 827 0xFF,
828 828
829 // frame type (stream frame) 829 // frame type (stream frame)
830 0x01, 830 0x01,
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 visitor_.public_reset_packet_->nonce_proof); 1601 visitor_.public_reset_packet_->nonce_proof);
1602 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 1602 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1603 visitor_.public_reset_packet_->rejected_sequence_number); 1603 visitor_.public_reset_packet_->rejected_sequence_number);
1604 1604
1605 // Now test framing boundaries 1605 // Now test framing boundaries
1606 for (size_t i = 0; i < GetPublicResetPacketSize(); ++i) { 1606 for (size_t i = 0; i < GetPublicResetPacketSize(); ++i) {
1607 string expected_error; 1607 string expected_error;
1608 DLOG(INFO) << "iteration: " << i; 1608 DLOG(INFO) << "iteration: " << i;
1609 if (i < kPublicFlagsOffset) { 1609 if (i < kPublicFlagsOffset) {
1610 expected_error = "Unable to read GUID."; 1610 expected_error = "Unable to read GUID.";
1611 CheckProcessingFails(packet, i, expected_error,
1612 QUIC_INVALID_PACKET_HEADER);
1611 } else if (i < kPublicResetPacketNonceProofOffset) { 1613 } else if (i < kPublicResetPacketNonceProofOffset) {
1612 expected_error = "Unable to read public flags."; 1614 expected_error = "Unable to read public flags.";
1615 CheckProcessingFails(packet, i, expected_error,
1616 QUIC_INVALID_PACKET_HEADER);
1613 } else if (i < kPublicResetPacketRejectedSequenceNumberOffset) { 1617 } else if (i < kPublicResetPacketRejectedSequenceNumberOffset) {
1614 expected_error = "Unable to read nonce proof."; 1618 expected_error = "Unable to read nonce proof.";
1619 CheckProcessingFails(packet, i, expected_error,
1620 QUIC_INVALID_PUBLIC_RST_PACKET);
1615 } else { 1621 } else {
1616 expected_error = "Unable to read rejected sequence number."; 1622 expected_error = "Unable to read rejected sequence number.";
1623 CheckProcessingFails(packet, i, expected_error,
1624 QUIC_INVALID_PUBLIC_RST_PACKET);
1617 } 1625 }
1618 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
1619 } 1626 }
1620 } 1627 }
1621 1628
1622 TEST_F(QuicFramerTest, VersionNegotiationPacket) { 1629 TEST_F(QuicFramerTest, VersionNegotiationPacket) {
1623 unsigned char packet[] = { 1630 unsigned char packet[] = {
1624 0x10, 0x32, 0x54, 0x76, 1631 0x10, 0x32, 0x54, 0x76,
1625 0x98, 0xBA, 0xDC, 0xFE, 1632 0x98, 0xBA, 0xDC, 0xFE,
1626 // public flags (version) 1633 // public flags (version)
1627 0x01, 1634 0x01,
1628 // version tag 1635 // version tag
1629 'Q', '0', '0', '1', 1636 'Q', '0', '0', '2',
1630 'Q', '2', '.', '0', 1637 'Q', '2', '.', '0',
1631 }; 1638 };
1632 1639
1633 QuicFramerPeer::SetIsServer(&framer_, false); 1640 QuicFramerPeer::SetIsServer(&framer_, false);
1634 1641
1635 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1642 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1636 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1643 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1637 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 1644 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
1638 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); 1645 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
1639 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); 1646 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 QuicFrames frames; 1825 QuicFrames frames;
1819 frames.push_back(QuicFrame(&stream_frame)); 1826 frames.push_back(QuicFrame(&stream_frame));
1820 1827
1821 unsigned char packet[] = { 1828 unsigned char packet[] = {
1822 // guid 1829 // guid
1823 0x10, 0x32, 0x54, 0x76, 1830 0x10, 0x32, 0x54, 0x76,
1824 0x98, 0xBA, 0xDC, 0xFE, 1831 0x98, 0xBA, 0xDC, 0xFE,
1825 // public flags (version) 1832 // public flags (version)
1826 0x01, 1833 0x01,
1827 // version tag 1834 // version tag
1828 'Q', '0', '0', '1', 1835 'Q', '0', '0', '2',
1829 // packet sequence number 1836 // packet sequence number
1830 0xBC, 0x9A, 0x78, 0x56, 1837 0xBC, 0x9A, 0x78, 0x56,
1831 0x34, 0x12, 1838 0x34, 0x12,
1832 // private flags (entropy) 1839 // private flags (entropy)
1833 0x02, 1840 0x02,
1834 // first fec protected packet offset 1841 // first fec protected packet offset
1835 0xFF, 1842 0xFF,
1836 1843
1837 // frame type (stream frame) 1844 // frame type (stream frame)
1838 0x01, 1845 0x01,
(...skipping 27 matching lines...) Expand all
1866 header.guid = GG_UINT64_C(0xFEDCBA9876543210); 1873 header.guid = GG_UINT64_C(0xFEDCBA9876543210);
1867 header.reset_flag = false; 1874 header.reset_flag = false;
1868 header.version_flag = true; 1875 header.version_flag = true;
1869 1876
1870 unsigned char packet[] = { 1877 unsigned char packet[] = {
1871 0x10, 0x32, 0x54, 0x76, 1878 0x10, 0x32, 0x54, 0x76,
1872 0x98, 0xBA, 0xDC, 0xFE, 1879 0x98, 0xBA, 0xDC, 0xFE,
1873 // public flags (version) 1880 // public flags (version)
1874 0x01, 1881 0x01,
1875 // version tag 1882 // version tag
1876 'Q', '0', '0', '1', 1883 'Q', '0', '0', '2',
1877 'Q', '2', '.', '0', 1884 'Q', '2', '.', '0',
1878 }; 1885 };
1879 1886
1880 const int kQuicVersion2 = MakeQuicTag('Q', '2', '.', '0'); 1887 const int kQuicVersion2 = MakeQuicTag('Q', '2', '.', '0');
1881 QuicTagVector versions; 1888 QuicTagVector versions;
1882 versions.push_back(kQuicVersion1); 1889 versions.push_back(kQuicVersion1);
1883 versions.push_back(kQuicVersion2); 1890 versions.push_back(kQuicVersion2);
1884 scoped_ptr<QuicEncryptedPacket> data( 1891 scoped_ptr<QuicEncryptedPacket> data(
1885 framer_.ConstructVersionNegotiationPacket(header, versions)); 1892 framer_.ConstructVersionNegotiationPacket(header, versions));
1886 1893
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
2794 EXPECT_CALL(visitor, OnPacketHeader(_)); 2801 EXPECT_CALL(visitor, OnPacketHeader(_));
2795 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); 2802 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
2796 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); 2803 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
2797 EXPECT_CALL(visitor, OnPacketComplete()); 2804 EXPECT_CALL(visitor, OnPacketComplete());
2798 2805
2799 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2806 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2800 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2807 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2801 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2808 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2802 } 2809 }
2803 2810
2811 TEST_F(QuicFramerTest, ConnectionCloseWithInvalidAck) {
2812 unsigned char packet[] = {
2813 // guid
2814 0x10, 0x32, 0x54, 0x76,
2815 0x98, 0xBA, 0xDC, 0xFE,
2816 // public flags
2817 0x00,
2818 // packet sequence number
2819 0xBC, 0x9A, 0x78, 0x56,
2820 0x34, 0x12,
2821 // private flags
2822 0x00,
2823 // first fec protected packet offset
2824 0xFF,
2825
2826 // frame type (connection close frame)
2827 0x05,
2828 // error code
2829 0x11, 0x00, 0x00, 0x00,
2830 // error details length
2831 0x0d, 0x00,
2832 // error details
2833 'b', 'e', 'c', 'a',
2834 'u', 's', 'e', ' ',
2835 'I', ' ', 'c', 'a',
2836 'n',
2837
2838 // Ack frame.
2839 // entropy hash of sent packets till least awaiting - 1.
2840 0xE0,
2841 // least packet sequence number awaiting an ack
2842 0xA0, 0x9A, 0x78, 0x56,
2843 0x34, 0x12,
2844 // entropy hash of all received packets.
2845 0x43,
2846 // largest observed packet sequence number
2847 0xBF, 0x9A, 0x78, 0x56,
2848 0x34, 0x12,
2849 // Infinite delta time.
2850 0xFF, 0xFF, 0xFF, 0xFF,
2851 // num missing packets
2852 0x01,
2853 // missing packet
2854 0xBE, 0x9A, 0x78, 0x56,
2855 0x34, 0x12,
2856 };
2857
2858 MockFramerVisitor visitor;
2859 framer_.set_visitor(&visitor);
2860 EXPECT_CALL(visitor, OnPacket());
2861 EXPECT_CALL(visitor, OnPacketHeader(_));
2862 EXPECT_CALL(visitor, OnAckFrame(_)).WillOnce(Return(false));
2863 EXPECT_CALL(visitor, OnConnectionCloseFrame(_)).Times(0);
2864 EXPECT_CALL(visitor, OnPacketComplete());
2865
2866 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2867 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2868 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2869 }
2870
2804 } // namespace test 2871 } // namespace test
2805 } // namespace net 2872 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698