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

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

Issue 357513003: Stop using SpdySynStreamIR for SPDY 4. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: WebSocket test fix. Created 6 years, 6 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_network_transaction_unittest.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 <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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. 666 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4.
667 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, 667 INSTANTIATE_TEST_CASE_P(SpdyFramerTests,
668 SpdyFramerTest, 668 SpdyFramerTest,
669 ::testing::Values(SPDY2, SPDY3, SPDY4)); 669 ::testing::Values(SPDY2, SPDY3, SPDY4));
670 670
671 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. 671 // Test that we can encode and decode a SpdyHeaderBlock in serialized form.
672 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { 672 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) {
673 SpdyFramer framer(spdy_version_); 673 SpdyFramer framer(spdy_version_);
674 framer.set_enable_compression(false); 674 framer.set_enable_compression(false);
675 675
676 // Encode the header block into a SynStream frame. 676 // Encode the header block into a Headers frame.
677 SpdySynStreamIR syn_stream(1); 677 SpdyHeadersIR headers(1);
678 syn_stream.set_priority(1); 678 headers.set_priority(1);
679 syn_stream.SetHeader("alpha", "beta"); 679 headers.SetHeader("alpha", "beta");
680 syn_stream.SetHeader("gamma", "charlie"); 680 headers.SetHeader("gamma", "charlie");
681 syn_stream.SetHeader("cookie", "key1=value1; key2=value2"); 681 headers.SetHeader("cookie", "key1=value1; key2=value2");
682 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 682 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers));
683 EXPECT_TRUE(frame.get() != NULL); 683 EXPECT_TRUE(frame.get() != NULL);
684 684
685 TestSpdyVisitor visitor(spdy_version_); 685 TestSpdyVisitor visitor(spdy_version_);
686 visitor.use_compression_ = false; 686 visitor.use_compression_ = false;
687 visitor.SimulateInFramer( 687 visitor.SimulateInFramer(
688 reinterpret_cast<unsigned char*>(frame->data()), 688 reinterpret_cast<unsigned char*>(frame->data()),
689 frame->size()); 689 frame->size());
690 690
691 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); 691 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_);
692 EXPECT_TRUE(CompareHeaderBlocks(&syn_stream.name_value_block(), 692 EXPECT_TRUE(CompareHeaderBlocks(&headers.name_value_block(),
693 &visitor.headers_)); 693 &visitor.headers_));
694 } 694 }
695 695
696 // Test that if there's not a full frame, we fail to parse it. 696 // Test that if there's not a full frame, we fail to parse it.
697 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { 697 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) {
698 SpdyFramer framer(spdy_version_); 698 SpdyFramer framer(spdy_version_);
699 framer.set_enable_compression(false); 699 framer.set_enable_compression(false);
700 700
701 // Encode the header block into a SynStream frame. 701 // Encode the header block into a Headers frame.
702 SpdySynStreamIR syn_stream(1); 702 SpdyHeadersIR headers(1);
703 syn_stream.set_priority(1); 703 headers.set_priority(1);
704 syn_stream.SetHeader("alpha", "beta"); 704 headers.SetHeader("alpha", "beta");
705 syn_stream.SetHeader("gamma", "charlie"); 705 headers.SetHeader("gamma", "charlie");
706 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 706 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers));
707 EXPECT_TRUE(frame.get() != NULL); 707 EXPECT_TRUE(frame.get() != NULL);
708 708
709 TestSpdyVisitor visitor(spdy_version_); 709 TestSpdyVisitor visitor(spdy_version_);
710 visitor.use_compression_ = false; 710 visitor.use_compression_ = false;
711 visitor.SimulateInFramer( 711 visitor.SimulateInFramer(
712 reinterpret_cast<unsigned char*>(frame->data()), 712 reinterpret_cast<unsigned char*>(frame->data()),
713 frame->size() - 2); 713 frame->size() - 2);
714 714
715 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); 715 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_);
716 EXPECT_EQ(0u, visitor.headers_.size()); 716 EXPECT_EQ(0u, visitor.headers_.size());
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 // Expect frames 3 to be the same as a uncompressed frame created 990 // Expect frames 3 to be the same as a uncompressed frame created
991 // from scratch. 991 // from scratch.
992 framer.set_enable_compression(false); 992 framer.set_enable_compression(false);
993 scoped_ptr<SpdyFrame> uncompressed_frame( 993 scoped_ptr<SpdyFrame> uncompressed_frame(
994 framer.SerializeSynStream(syn_stream)); 994 framer.SerializeSynStream(syn_stream));
995 CompareFrames("Uncompressed SYN_STREAM", *frame3, *uncompressed_frame); 995 CompareFrames("Uncompressed SYN_STREAM", *frame3, *uncompressed_frame);
996 } 996 }
997 997
998 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { 998 TEST_P(SpdyFramerTest, CompressEmptyHeaders) {
999 // See crbug.com/172383 999 // See crbug.com/172383
1000 SpdySynStreamIR syn_stream(1); 1000 SpdyHeadersIR headers(1);
1001 syn_stream.SetHeader("server", "SpdyServer 1.0"); 1001 headers.SetHeader("server", "SpdyServer 1.0");
1002 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); 1002 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST");
1003 syn_stream.SetHeader("status", "200"); 1003 headers.SetHeader("status", "200");
1004 syn_stream.SetHeader("version", "HTTP/1.1"); 1004 headers.SetHeader("version", "HTTP/1.1");
1005 syn_stream.SetHeader("content-type", "text/html"); 1005 headers.SetHeader("content-type", "text/html");
1006 syn_stream.SetHeader("content-length", "12"); 1006 headers.SetHeader("content-length", "12");
1007 syn_stream.SetHeader("x-empty-header", ""); 1007 headers.SetHeader("x-empty-header", "");
1008 1008
1009 SpdyFramer framer(spdy_version_); 1009 SpdyFramer framer(spdy_version_);
1010 framer.set_enable_compression(true); 1010 framer.set_enable_compression(true);
1011 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); 1011 scoped_ptr<SpdyFrame> frame1(framer.SerializeHeaders(headers));
1012 } 1012 }
1013 1013
1014 TEST_P(SpdyFramerTest, Basic) { 1014 TEST_P(SpdyFramerTest, Basic) {
1015 const unsigned char kV2Input[] = { 1015 const unsigned char kV2Input[] = {
1016 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 1016 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1
1017 0x00, 0x00, 0x00, 0x14, 1017 0x00, 0x00, 0x00, 0x14,
1018 0x00, 0x00, 0x00, 0x01, 1018 0x00, 0x00, 0x00, 0x01,
1019 0x00, 0x00, 0x00, 0x00, 1019 0x00, 0x00, 0x00, 0x00,
1020 0x00, 0x00, 0x00, 0x01, 1020 0x00, 0x00, 0x00, 0x01,
1021 0x00, 0x02, 'h', 'h', 1021 0x00, 0x02, 'h', 'h',
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 decompressed_headers.clear(); 1443 decompressed_headers.clear();
1444 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), 1444 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(),
1445 serialized_headers.size(), 1445 serialized_headers.size(),
1446 &decompressed_headers)); 1446 &decompressed_headers));
1447 EXPECT_EQ(3u, decompressed_headers.size()); 1447 EXPECT_EQ(3u, decompressed_headers.size());
1448 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); 1448 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]);
1449 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); 1449 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]);
1450 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); 1450 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]);
1451 } 1451 }
1452 1452
1453 // Verify we don't leak when we leave streams unclosed
1454 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressors) {
1455 SpdyFramer send_framer(spdy_version_);
1456
1457 send_framer.set_enable_compression(true);
1458
1459 const char kHeader1[] = "header1";
1460 const char kHeader2[] = "header2";
1461 const char kValue1[] = "value1";
1462 const char kValue2[] = "value2";
1463
1464 SpdySynStreamIR syn_stream(1);
1465 syn_stream.SetHeader(kHeader1, kValue1);
1466 syn_stream.SetHeader(kHeader2, kValue2);
1467 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream));
1468 EXPECT_TRUE(syn_frame.get() != NULL);
1469
1470 StringPiece bytes = "this is a test test test test test!";
1471 SpdyDataIR data_ir(1, bytes);
1472 data_ir.set_fin(true);
1473 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir));
1474 EXPECT_TRUE(send_frame.get() != NULL);
1475
1476 // Run the inputs through the framer.
1477 TestSpdyVisitor visitor(spdy_version_);
1478 visitor.use_compression_ = true;
1479 const unsigned char* data;
1480 data = reinterpret_cast<const unsigned char*>(syn_frame->data());
1481 visitor.SimulateInFramer(data, syn_frame->size());
1482 data = reinterpret_cast<const unsigned char*>(send_frame->data());
1483 visitor.SimulateInFramer(data, send_frame->size());
1484
1485 EXPECT_EQ(0, visitor.error_count_);
1486 EXPECT_EQ(1, visitor.syn_frame_count_);
1487 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
1488 EXPECT_EQ(0, visitor.headers_frame_count_);
1489 EXPECT_EQ(bytes.size(), static_cast<unsigned>(visitor.data_bytes_));
1490 EXPECT_EQ(0, visitor.fin_frame_count_);
1491 EXPECT_EQ(0, visitor.fin_flag_count_);
1492 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
1493 EXPECT_EQ(1, visitor.data_frame_count_);
1494 }
1495
1496 // Verify we can decompress the stream even if handed over to the 1453 // Verify we can decompress the stream even if handed over to the
1497 // framer 1 byte at a time. 1454 // framer 1 byte at a time.
1498 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { 1455 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) {
1499 SpdyFramer send_framer(spdy_version_); 1456 SpdyFramer send_framer(spdy_version_);
1500 1457
1501 send_framer.set_enable_compression(true); 1458 send_framer.set_enable_compression(true);
1502 1459
1503 const char kHeader1[] = "header1"; 1460 const char kHeader1[] = "header1";
1504 const char kHeader2[] = "header2"; 1461 const char kHeader2[] = "header2";
1505 const char kValue1[] = "value1"; 1462 const char kValue1[] = "value1";
1506 const char kValue2[] = "value2"; 1463 const char kValue2[] = "value2";
1507 1464
1508 SpdySynStreamIR syn_stream(1); 1465 SpdyHeadersIR headers(1);
1509 syn_stream.SetHeader(kHeader1, kValue1); 1466 headers.SetHeader(kHeader1, kValue1);
1510 syn_stream.SetHeader(kHeader2, kValue2); 1467 headers.SetHeader(kHeader2, kValue2);
1511 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); 1468 scoped_ptr<SpdyFrame> headers_frame(send_framer.SerializeHeaders(headers));
1512 EXPECT_TRUE(syn_frame.get() != NULL); 1469 EXPECT_TRUE(headers_frame.get() != NULL);
1513 1470
1514 const char bytes[] = "this is a test test test test test!"; 1471 const char bytes[] = "this is a test test test test test!";
1515 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); 1472 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes)));
1516 data_ir.set_fin(true); 1473 data_ir.set_fin(true);
1517 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); 1474 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir));
1518 EXPECT_TRUE(send_frame.get() != NULL); 1475 EXPECT_TRUE(send_frame.get() != NULL);
1519 1476
1520 // Run the inputs through the framer. 1477 // Run the inputs through the framer.
1521 TestSpdyVisitor visitor(spdy_version_); 1478 TestSpdyVisitor visitor(spdy_version_);
1522 visitor.use_compression_ = true; 1479 visitor.use_compression_ = true;
1523 const unsigned char* data; 1480 const unsigned char* data;
1524 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); 1481 data = reinterpret_cast<const unsigned char*>(headers_frame->data());
1525 for (size_t idx = 0; idx < syn_frame->size(); ++idx) { 1482 for (size_t idx = 0; idx < headers_frame->size(); ++idx) {
1526 visitor.SimulateInFramer(data + idx, 1); 1483 visitor.SimulateInFramer(data + idx, 1);
1527 ASSERT_EQ(0, visitor.error_count_); 1484 ASSERT_EQ(0, visitor.error_count_);
1528 } 1485 }
1529 data = reinterpret_cast<const unsigned char*>(send_frame->data()); 1486 data = reinterpret_cast<const unsigned char*>(send_frame->data());
1530 for (size_t idx = 0; idx < send_frame->size(); ++idx) { 1487 for (size_t idx = 0; idx < send_frame->size(); ++idx) {
1531 visitor.SimulateInFramer(data + idx, 1); 1488 visitor.SimulateInFramer(data + idx, 1);
1532 ASSERT_EQ(0, visitor.error_count_); 1489 ASSERT_EQ(0, visitor.error_count_);
1533 } 1490 }
1534 1491
1535 EXPECT_EQ(0, visitor.error_count_); 1492 EXPECT_EQ(0, visitor.error_count_);
1536 EXPECT_EQ(1, visitor.syn_frame_count_); 1493 EXPECT_EQ(0, visitor.syn_frame_count_);
1537 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 1494 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
1538 EXPECT_EQ(0, visitor.headers_frame_count_); 1495 EXPECT_EQ(1, visitor.headers_frame_count_);
1539 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); 1496 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_));
1540 EXPECT_EQ(0, visitor.fin_frame_count_); 1497 EXPECT_EQ(0, visitor.fin_frame_count_);
1541 EXPECT_EQ(0, visitor.fin_flag_count_); 1498 EXPECT_EQ(0, visitor.fin_flag_count_);
1542 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); 1499 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
1543 EXPECT_EQ(1, visitor.data_frame_count_); 1500 EXPECT_EQ(1, visitor.data_frame_count_);
1544 } 1501 }
1545 1502
1546 TEST_P(SpdyFramerTest, WindowUpdateFrame) { 1503 TEST_P(SpdyFramerTest, WindowUpdateFrame) {
1547 SpdyFramer framer(spdy_version_); 1504 SpdyFramer framer(spdy_version_);
1548 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( 1505 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate(
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1866 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); 1823 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize);
1867 1824
1868 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); 1825 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size()));
1869 data_ir.set_fin(true); 1826 data_ir.set_fin(true);
1870 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1827 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1871 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); 1828 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize);
1872 } 1829 }
1873 } 1830 }
1874 1831
1875 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 1832 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) {
1833 if (!IsSpdy2() && !IsSpdy3()) {
1834 // SYN_STREAM unsupported in SPDY>3
1835 return;
1836 }
1876 SpdyFramer framer(spdy_version_); 1837 SpdyFramer framer(spdy_version_);
1877 framer.set_enable_compression(false); 1838 framer.set_enable_compression(false);
1878 1839
1879 { 1840 {
1880 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; 1841 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN";
1881 1842
1882 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; 1843 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0;
1883 const unsigned char kV2FrameData[] = { 1844 const unsigned char kV2FrameData[] = {
1884 0x80, spdy_version_ch_, 0x00, 0x01, 1845 0x80, spdy_version_ch_, 0x00, 0x01,
1885 0x00, 0x00, 0x00, 0x20, 1846 0x00, 0x00, 0x00, 0x20,
(...skipping 14 matching lines...) Expand all
1900 kPri, 0x00, 0x00, 0x00, 1861 kPri, 0x00, 0x00, 0x00,
1901 0x00, 0x02, 0x00, 0x00, 1862 0x00, 0x02, 0x00, 0x00,
1902 0x00, 0x03, 'b', 'a', 1863 0x00, 0x03, 'b', 'a',
1903 'r', 0x00, 0x00, 0x00, 1864 'r', 0x00, 0x00, 0x00,
1904 0x03, 'f', 'o', 'o', 1865 0x03, 'f', 'o', 'o',
1905 0x00, 0x00, 0x00, 0x03, 1866 0x00, 0x00, 0x00, 0x03,
1906 'f', 'o', 'o', 0x00, 1867 'f', 'o', 'o', 0x00,
1907 0x00, 0x00, 0x03, 'b', 1868 0x00, 0x00, 0x03, 'b',
1908 'a', 'r' 1869 'a', 'r'
1909 }; 1870 };
1910 const unsigned char kV4FrameData[] = {
1911 0x00, 0x17, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS
1912 0x00, 0x00, 0x00, 0x01, // Stream 1
1913 0x00, 0x00, 0x00, 0x00, // Non-exclusive dependency 0. Weight 0.
1914 0x00, 0x00, 0x03, 0x62,
1915 0x61, 0x72, 0x03, 0x66,
1916 0x6f, 0x6f, 0x00, 0x03,
1917 0x66, 0x6f, 0x6f, 0x03,
1918 0x62, 0x61, 0x72,
1919 };
1920 SpdySynStreamIR syn_stream(1); 1871 SpdySynStreamIR syn_stream(1);
1921 syn_stream.set_priority(framer.GetLowestPriority()); 1872 syn_stream.set_priority(framer.GetLowestPriority());
1922 syn_stream.SetHeader("bar", "foo"); 1873 syn_stream.SetHeader("bar", "foo");
1923 syn_stream.SetHeader("foo", "bar"); 1874 syn_stream.SetHeader("foo", "bar");
1924 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1875 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
1925 if (IsSpdy2()) { 1876 if (IsSpdy2()) {
1926 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 1877 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
1927 } else if (IsSpdy3()) { 1878 } else if (IsSpdy3()) {
1928 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1879 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1929 } else { 1880 } else {
1930 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1881 LOG(FATAL) << "Unsupported version in test.";
1931 } 1882 }
1932 } 1883 }
1933 1884
1934 { 1885 {
1935 const char kDescription[] = 1886 const char kDescription[] =
1936 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " 1887 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, "
1937 "max stream ID"; 1888 "max stream ID";
1938 1889
1939 const unsigned char kV2FrameData[] = { 1890 const unsigned char kV2FrameData[] = {
1940 0x80, spdy_version_ch_, 0x00, 0x01, 1891 0x80, spdy_version_ch_, 0x00, 0x01,
(...skipping 14 matching lines...) Expand all
1955 0x7f, 0xff, 0xff, 0xff, 1906 0x7f, 0xff, 0xff, 0xff,
1956 0x00, 0x00, 0x00, 0x00, 1907 0x00, 0x00, 0x00, 0x00,
1957 0x00, 0x02, 0x00, 0x00, 1908 0x00, 0x02, 0x00, 0x00,
1958 0x00, 0x00, 0x00, 0x00, 1909 0x00, 0x00, 0x00, 0x00,
1959 0x00, 0x03, 'f', 'o', 1910 0x00, 0x03, 'f', 'o',
1960 'o', 0x00, 0x00, 0x00, 1911 'o', 0x00, 0x00, 0x00,
1961 0x03, 'f', 'o', 'o', 1912 0x03, 'f', 'o', 'o',
1962 0x00, 0x00, 0x00, 0x03, 1913 0x00, 0x00, 0x00, 0x03,
1963 'b', 'a', 'r' 1914 'b', 'a', 'r'
1964 }; 1915 };
1965 const unsigned char kV4FrameData[] = {
1966 0x00, 0x14, 0x01, 0x25, // HEADERS: PRIORITY | FIN | END_HEADERS
1967 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff
1968 0x00, 0x00, 0x00, 0x00, // Non-exclusive dependency 0. Weight 255.
1969 0xff, 0x00, 0x00, 0x03,
1970 0x66, 0x6f, 0x6f, 0x00,
1971 0x03, 0x66, 0x6f, 0x6f,
1972 0x03, 0x62, 0x61, 0x72,
1973 };
1974 SpdySynStreamIR syn_stream(0x7fffffff); 1916 SpdySynStreamIR syn_stream(0x7fffffff);
1975 syn_stream.set_associated_to_stream_id(0x7fffffff); 1917 syn_stream.set_associated_to_stream_id(0x7fffffff);
1976 syn_stream.set_priority(framer.GetHighestPriority()); 1918 syn_stream.set_priority(framer.GetHighestPriority());
1977 syn_stream.set_fin(true); 1919 syn_stream.set_fin(true);
1978 syn_stream.SetHeader("", "foo"); 1920 syn_stream.SetHeader("", "foo");
1979 syn_stream.SetHeader("foo", "bar"); 1921 syn_stream.SetHeader("foo", "bar");
1980 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1922 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
1981 if (IsSpdy2()) { 1923 if (IsSpdy2()) {
1982 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 1924 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
1983 } else if (IsSpdy3()) { 1925 } else if (IsSpdy3()) {
1984 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1926 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1985 } else { 1927 } else {
1986 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1928 LOG(FATAL) << "Unsupported version in test.";
1987 } 1929 }
1988 } 1930 }
1989 1931
1990 { 1932 {
1991 const char kDescription[] = 1933 const char kDescription[] =
1992 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " 1934 "SYN_STREAM frame with a 0-length header val, high pri, FIN, "
1993 "max stream ID"; 1935 "max stream ID";
1994 1936
1995 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20; 1937 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20;
1996 const unsigned char kV2FrameData[] = { 1938 const unsigned char kV2FrameData[] = {
(...skipping 15 matching lines...) Expand all
2012 0x7f, 0xff, 0xff, 0xff, 1954 0x7f, 0xff, 0xff, 0xff,
2013 kPri, 0x00, 0x00, 0x00, 1955 kPri, 0x00, 0x00, 0x00,
2014 0x00, 0x02, 0x00, 0x00, 1956 0x00, 0x02, 0x00, 0x00,
2015 0x00, 0x03, 'b', 'a', 1957 0x00, 0x03, 'b', 'a',
2016 'r', 0x00, 0x00, 0x00, 1958 'r', 0x00, 0x00, 0x00,
2017 0x03, 'f', 'o', 'o', 1959 0x03, 'f', 'o', 'o',
2018 0x00, 0x00, 0x00, 0x03, 1960 0x00, 0x00, 0x00, 0x03,
2019 'f', 'o', 'o', 0x00, 1961 'f', 'o', 'o', 0x00,
2020 0x00, 0x00, 0x00 1962 0x00, 0x00, 0x00
2021 }; 1963 };
2022 const unsigned char kV4FrameData[] = {
2023 0x00, 0x14, 0x01, 0x25, // HEADERS: PRIORITY | FIN | END_HEADERS
2024 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff
2025 0x00, 0x00, 0x00, 0x00, // Non-exclusive dependency 0. Weight 219.
2026 0xdb, 0x00, 0x03, 0x62,
2027 0x61, 0x72, 0x03, 0x66,
2028 0x6f, 0x6f, 0x00, 0x03,
2029 0x66, 0x6f, 0x6f, 0x00,
2030 };
2031 SpdySynStreamIR syn_stream(0x7fffffff); 1964 SpdySynStreamIR syn_stream(0x7fffffff);
2032 syn_stream.set_associated_to_stream_id(0x7fffffff); 1965 syn_stream.set_associated_to_stream_id(0x7fffffff);
2033 syn_stream.set_priority(1); 1966 syn_stream.set_priority(1);
2034 syn_stream.set_fin(true); 1967 syn_stream.set_fin(true);
2035 syn_stream.SetHeader("bar", "foo"); 1968 syn_stream.SetHeader("bar", "foo");
2036 syn_stream.SetHeader("foo", ""); 1969 syn_stream.SetHeader("foo", "");
2037 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 1970 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
2038 if (IsSpdy2()) { 1971 if (IsSpdy2()) {
2039 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 1972 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2040 } else if (IsSpdy3()) { 1973 } else if (IsSpdy3()) {
2041 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1974 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2042 } else { 1975 } else {
2043 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1976 LOG(FATAL) << "Unsupported version in test.";
2044 } 1977 }
2045 } 1978 }
2046 } 1979 }
2047 1980
2048 // TODO(phajdan.jr): Clean up after we no longer need 1981 // TODO(phajdan.jr): Clean up after we no longer need
2049 // to workaround http://crbug.com/139744. 1982 // to workaround http://crbug.com/139744.
2050 #if !defined(USE_SYSTEM_ZLIB) 1983 #if !defined(USE_SYSTEM_ZLIB)
2051 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { 1984 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) {
1985 if (!IsSpdy2() && !IsSpdy3()) {
1986 // SYN_STREAM not supported for SPDY>3
1987 return;
1988 }
2052 SpdyFramer framer(spdy_version_); 1989 SpdyFramer framer(spdy_version_);
2053 framer.set_enable_compression(true); 1990 framer.set_enable_compression(true);
2054 1991
2055 { 1992 {
2056 const char kDescription[] = 1993 const char kDescription[] =
2057 "SYN_STREAM frame, low pri, no FIN"; 1994 "SYN_STREAM frame, low pri, no FIN";
2058 1995
2059 const SpdyPriority priority = IsSpdy2() ? 2 : 4; 1996 const SpdyPriority priority = IsSpdy2() ? 2 : 4;
2060 const unsigned char kV2FrameData[] = { 1997 const unsigned char kV2FrameData[] = {
2061 0x80, spdy_version_ch_, 0x00, 0x01, 1998 0x80, spdy_version_ch_, 0x00, 0x01,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 SpdySynStreamIR syn_stream(1); 2033 SpdySynStreamIR syn_stream(1);
2097 syn_stream.set_priority(priority); 2034 syn_stream.set_priority(priority);
2098 syn_stream.SetHeader("bar", "foo"); 2035 syn_stream.SetHeader("bar", "foo");
2099 syn_stream.SetHeader("foo", "bar"); 2036 syn_stream.SetHeader("foo", "bar");
2100 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 2037 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
2101 if (IsSpdy2()) { 2038 if (IsSpdy2()) {
2102 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2039 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2103 } else if (IsSpdy3()) { 2040 } else if (IsSpdy3()) {
2104 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2041 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2105 } else { 2042 } else {
2106 // Deflate compression doesn't apply to HPACK. 2043 LOG(FATAL) << "Unsupported version in test.";
2107 } 2044 }
2108 } 2045 }
2109 } 2046 }
2110 #endif // !defined(USE_SYSTEM_ZLIB) 2047 #endif // !defined(USE_SYSTEM_ZLIB)
2111 2048
2112 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { 2049 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) {
2113 if (spdy_version_ > SPDY3) { 2050 if (spdy_version_ > SPDY3) {
2051 // SYN_REPLY unsupported in SPDY>3
2114 return; 2052 return;
2115 } 2053 }
2116 SpdyFramer framer(spdy_version_); 2054 SpdyFramer framer(spdy_version_);
2117 framer.set_enable_compression(false); 2055 framer.set_enable_compression(false);
2118 2056
2119 { 2057 {
2120 const char kDescription[] = "SYN_REPLY frame, no FIN"; 2058 const char kDescription[] = "SYN_REPLY frame, no FIN";
2121 2059
2122 const unsigned char kV2FrameData[] = { 2060 const unsigned char kV2FrameData[] = {
2123 0x80, spdy_version_ch_, 0x00, 0x02, 2061 0x80, spdy_version_ch_, 0x00, 0x02,
(...skipping 12 matching lines...) Expand all
2136 0x00, 0x00, 0x00, 0x01, 2074 0x00, 0x00, 0x00, 0x01,
2137 0x00, 0x00, 0x00, 0x02, 2075 0x00, 0x00, 0x00, 0x02,
2138 0x00, 0x00, 0x00, 0x03, 2076 0x00, 0x00, 0x00, 0x03,
2139 'b', 'a', 'r', 0x00, 2077 'b', 'a', 'r', 0x00,
2140 0x00, 0x00, 0x03, 'f', 2078 0x00, 0x00, 0x03, 'f',
2141 'o', 'o', 0x00, 0x00, 2079 'o', 'o', 0x00, 0x00,
2142 0x00, 0x03, 'f', 'o', 2080 0x00, 0x03, 'f', 'o',
2143 'o', 0x00, 0x00, 0x00, 2081 'o', 0x00, 0x00, 0x00,
2144 0x03, 'b', 'a', 'r' 2082 0x03, 'b', 'a', 'r'
2145 }; 2083 };
2146 const unsigned char kV4FrameData[] = {
2147 0x00, 0x12, 0x01, 0x04, // HEADER: END_HEADERS
2148 0x00, 0x00, 0x00, 0x01, // Stream 1
2149 0x00, 0x03, 0x62, 0x61, // @.ba
2150 0x72, 0x03, 0x66, 0x6f, // r.fo
2151 0x6f, 0x00, 0x03, 0x66, // o@.f
2152 0x6f, 0x6f, 0x03, 0x62, // oo.b
2153 0x61, 0x72, // ar
2154 };
2155 SpdySynReplyIR syn_reply(1); 2084 SpdySynReplyIR syn_reply(1);
2156 syn_reply.SetHeader("bar", "foo"); 2085 syn_reply.SetHeader("bar", "foo");
2157 syn_reply.SetHeader("foo", "bar"); 2086 syn_reply.SetHeader("foo", "bar");
2158 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2087 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2159 if (IsSpdy2()) { 2088 if (IsSpdy2()) {
2160 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2089 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2161 } else if (IsSpdy3()) { 2090 } else if (IsSpdy3()) {
2162 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2091 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2163 } else { 2092 } else {
2164 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2093 LOG(FATAL) << "Unsupported version in test.";
2165 } 2094 }
2166 } 2095 }
2167 2096
2168 { 2097 {
2169 const char kDescription[] = 2098 const char kDescription[] =
2170 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; 2099 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID";
2171 2100
2172 const unsigned char kV2FrameData[] = { 2101 const unsigned char kV2FrameData[] = {
2173 0x80, spdy_version_ch_, 0x00, 0x02, 2102 0x80, spdy_version_ch_, 0x00, 0x02,
2174 0x01, 0x00, 0x00, 0x19, 2103 0x01, 0x00, 0x00, 0x19,
(...skipping 11 matching lines...) Expand all
2186 0x7f, 0xff, 0xff, 0xff, 2115 0x7f, 0xff, 0xff, 0xff,
2187 0x00, 0x00, 0x00, 0x02, 2116 0x00, 0x00, 0x00, 0x02,
2188 0x00, 0x00, 0x00, 0x00, 2117 0x00, 0x00, 0x00, 0x00,
2189 0x00, 0x00, 0x00, 0x03, 2118 0x00, 0x00, 0x00, 0x03,
2190 'f', 'o', 'o', 0x00, 2119 'f', 'o', 'o', 0x00,
2191 0x00, 0x00, 0x03, 'f', 2120 0x00, 0x00, 0x03, 'f',
2192 'o', 'o', 0x00, 0x00, 2121 'o', 'o', 0x00, 0x00,
2193 0x00, 0x03, 'b', 'a', 2122 0x00, 0x03, 'b', 'a',
2194 'r' 2123 'r'
2195 }; 2124 };
2196 const unsigned char kV4FrameData[] = {
2197 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS
2198 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff
2199 0x00, 0x00, 0x03, 0x66, // @..f
2200 0x6f, 0x6f, 0x00, 0x03, // oo@.
2201 0x66, 0x6f, 0x6f, 0x03, // foo.
2202 0x62, 0x61, 0x72, // bar
2203 };
2204 SpdySynReplyIR syn_reply(0x7fffffff); 2125 SpdySynReplyIR syn_reply(0x7fffffff);
2205 syn_reply.set_fin(true); 2126 syn_reply.set_fin(true);
2206 syn_reply.SetHeader("", "foo"); 2127 syn_reply.SetHeader("", "foo");
2207 syn_reply.SetHeader("foo", "bar"); 2128 syn_reply.SetHeader("foo", "bar");
2208 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2129 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2209 if (IsSpdy2()) { 2130 if (IsSpdy2()) {
2210 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2131 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2211 } else if (IsSpdy3()) { 2132 } else if (IsSpdy3()) {
2212 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2133 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2213 } else { 2134 } else {
2214 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2135 LOG(FATAL) << "Unsupported version in test.";
2215 } 2136 }
2216 } 2137 }
2217 2138
2218 { 2139 {
2219 const char kDescription[] = 2140 const char kDescription[] =
2220 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; 2141 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID";
2221 2142
2222 const unsigned char kV2FrameData[] = { 2143 const unsigned char kV2FrameData[] = {
2223 0x80, spdy_version_ch_, 0x00, 0x02, 2144 0x80, spdy_version_ch_, 0x00, 0x02,
2224 0x01, 0x00, 0x00, 0x19, 2145 0x01, 0x00, 0x00, 0x19,
(...skipping 11 matching lines...) Expand all
2236 0x7f, 0xff, 0xff, 0xff, 2157 0x7f, 0xff, 0xff, 0xff,
2237 0x00, 0x00, 0x00, 0x02, 2158 0x00, 0x00, 0x00, 0x02,
2238 0x00, 0x00, 0x00, 0x03, 2159 0x00, 0x00, 0x00, 0x03,
2239 'b', 'a', 'r', 0x00, 2160 'b', 'a', 'r', 0x00,
2240 0x00, 0x00, 0x03, 'f', 2161 0x00, 0x00, 0x03, 'f',
2241 'o', 'o', 0x00, 0x00, 2162 'o', 'o', 0x00, 0x00,
2242 0x00, 0x03, 'f', 'o', 2163 0x00, 0x03, 'f', 'o',
2243 'o', 0x00, 0x00, 0x00, 2164 'o', 0x00, 0x00, 0x00,
2244 0x00 2165 0x00
2245 }; 2166 };
2246 const unsigned char kV4FrameData[] = {
2247 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS
2248 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff
2249 0x00, 0x03, 0x62, 0x61, // @.ba
2250 0x72, 0x03, 0x66, 0x6f, // r.fo
2251 0x6f, 0x00, 0x03, 0x66, // o@.f
2252 0x6f, 0x6f, 0x00, // oo.
2253 };
2254 SpdySynReplyIR syn_reply(0x7fffffff); 2167 SpdySynReplyIR syn_reply(0x7fffffff);
2255 syn_reply.set_fin(true); 2168 syn_reply.set_fin(true);
2256 syn_reply.SetHeader("bar", "foo"); 2169 syn_reply.SetHeader("bar", "foo");
2257 syn_reply.SetHeader("foo", ""); 2170 syn_reply.SetHeader("foo", "");
2258 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2171 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2259 if (IsSpdy2()) { 2172 if (IsSpdy2()) {
2260 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2173 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2261 } else if (IsSpdy3()) { 2174 } else if (IsSpdy3()) {
2262 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2175 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2263 } else { 2176 } else {
2264 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2177 LOG(FATAL) << "Unsupported version in test.";
2265 } 2178 }
2266 } 2179 }
2267 } 2180 }
2268 2181
2269 // TODO(phajdan.jr): Clean up after we no longer need 2182 // TODO(phajdan.jr): Clean up after we no longer need
2270 // to workaround http://crbug.com/139744. 2183 // to workaround http://crbug.com/139744.
2271 #if !defined(USE_SYSTEM_ZLIB) 2184 #if !defined(USE_SYSTEM_ZLIB)
2272 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { 2185 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) {
2273 if (spdy_version_ > SPDY3) { 2186 if (spdy_version_ > SPDY3) {
2187 // SYN_REPLY unsupported in SPDY>3
2274 return; 2188 return;
2275 } 2189 }
2276 SpdyFramer framer(spdy_version_); 2190 SpdyFramer framer(spdy_version_);
2277 framer.set_enable_compression(true); 2191 framer.set_enable_compression(true);
2278 2192
2279 { 2193 {
2280 const char kDescription[] = "SYN_REPLY frame, no FIN"; 2194 const char kDescription[] = "SYN_REPLY frame, no FIN";
2281 2195
2282 const unsigned char kV2FrameData[] = { 2196 const unsigned char kV2FrameData[] = {
2283 0x80, spdy_version_ch_, 0x00, 0x02, 2197 0x80, spdy_version_ch_, 0x00, 0x02,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 }; 2229 };
2316 SpdySynReplyIR syn_reply(1); 2230 SpdySynReplyIR syn_reply(1);
2317 syn_reply.SetHeader("bar", "foo"); 2231 syn_reply.SetHeader("bar", "foo");
2318 syn_reply.SetHeader("foo", "bar"); 2232 syn_reply.SetHeader("foo", "bar");
2319 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); 2233 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply));
2320 if (IsSpdy2()) { 2234 if (IsSpdy2()) {
2321 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2235 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2322 } else if (IsSpdy3()) { 2236 } else if (IsSpdy3()) {
2323 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2237 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2324 } else { 2238 } else {
2325 // Deflate compression doesn't apply to HPACK. 2239 LOG(FATAL) << "Unsupported version in test.";
2326 } 2240 }
2327 } 2241 }
2328 } 2242 }
2329 #endif // !defined(USE_SYSTEM_ZLIB) 2243 #endif // !defined(USE_SYSTEM_ZLIB)
2330 2244
2331 TEST_P(SpdyFramerTest, CreateRstStream) { 2245 TEST_P(SpdyFramerTest, CreateRstStream) {
2332 SpdyFramer framer(spdy_version_); 2246 SpdyFramer framer(spdy_version_);
2333 2247
2334 { 2248 {
2335 const char kDescription[] = "RST_STREAM frame"; 2249 const char kDescription[] = "RST_STREAM frame";
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2804 headers_ir.SetHeader("foo", ""); 2718 headers_ir.SetHeader("foo", "");
2805 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2719 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2806 if (IsSpdy2()) { 2720 if (IsSpdy2()) {
2807 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2721 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2808 } else if (IsSpdy3()) { 2722 } else if (IsSpdy3()) {
2809 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2723 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2810 } else { 2724 } else {
2811 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2725 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2812 } 2726 }
2813 } 2727 }
2728
2729 {
2730 const char kDescription[] =
2731 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri";
2732
2733 const unsigned char kV4FrameData[] = {
2734 0x00, 0x14, 0x01, 0x25, // Headers: FIN | END_HEADERS | PRIORITY
2735 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff
2736 0x00, 0x00, 0x00, 0x00, // parent stream
2737 0xdb, // weight
2738 0x00, 0x03, 0x62, 0x61, // @.ba
2739 0x72, 0x03, 0x66, 0x6f, // r.fo
2740 0x6f, 0x00, 0x03, 0x66, // o@.f
2741 0x6f, 0x6f, 0x00, // oo.
2742 };
2743 SpdyHeadersIR headers_ir(0x7fffffff);
2744 headers_ir.set_fin(true);
2745 headers_ir.set_priority(1);
2746 headers_ir.set_has_priority(true);
2747 headers_ir.SetHeader("bar", "foo");
2748 headers_ir.SetHeader("foo", "");
2749 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2750 if (IsSpdy2() || IsSpdy3()) {
2751 // HEADERS with priority not supported.
2752 } else {
2753 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2754 }
2755 }
2814 } 2756 }
2815 2757
2816 // TODO(phajdan.jr): Clean up after we no longer need 2758 // TODO(phajdan.jr): Clean up after we no longer need
2817 // to workaround http://crbug.com/139744. 2759 // to workaround http://crbug.com/139744.
2818 #if !defined(USE_SYSTEM_ZLIB) 2760 #if !defined(USE_SYSTEM_ZLIB)
2819 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { 2761 TEST_P(SpdyFramerTest, CreateHeadersCompressed) {
2820 SpdyFramer framer(spdy_version_); 2762 SpdyFramer framer(spdy_version_);
2821 framer.set_enable_compression(true); 2763 framer.set_enable_compression(true);
2822 2764
2823 { 2765 {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
3053 0x00, 0x00, 0x00, 0x02, // Stream ID = 2 2995 0x00, 0x00, 0x00, 0x02, // Stream ID = 2
3054 0x80, 0x00, 0x00, 0x01, // Exclusive dependency, parent stream ID = 1 2996 0x80, 0x00, 0x00, 0x01, // Exclusive dependency, parent stream ID = 1
3055 0x10, // Weight = 16 2997 0x10, // Weight = 16
3056 }; 2998 };
3057 SpdyPriorityIR priority_ir(2, 1, 16, true); 2999 SpdyPriorityIR priority_ir(2, 1, 16, true);
3058 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(priority_ir)); 3000 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(priority_ir));
3059 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 3001 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3060 } 3002 }
3061 3003
3062 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { 3004 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) {
3005 if (spdy_version_ > SPDY3) {
3006 // SYN_STREAM not supported in SPDY>3
3007 return;
3008 }
3063 SpdyFramer framer(spdy_version_); 3009 SpdyFramer framer(spdy_version_);
3064 SpdySynStreamIR syn_stream(1); 3010 SpdySynStreamIR syn_stream(1);
3065 syn_stream.set_priority(1); 3011 syn_stream.set_priority(1);
3066 syn_stream.SetHeader("aa", "vv"); 3012 syn_stream.SetHeader("aa", "vv");
3067 syn_stream.SetHeader("bb", "ww"); 3013 syn_stream.SetHeader("bb", "ww");
3068 SpdyHeaderBlock headers = syn_stream.name_value_block(); 3014 SpdyHeaderBlock headers = syn_stream.name_value_block();
3069 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); 3015 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream));
3070 EXPECT_TRUE(control_frame.get() != NULL); 3016 EXPECT_TRUE(control_frame.get() != NULL);
3071 TestSpdyVisitor visitor(spdy_version_); 3017 TestSpdyVisitor visitor(spdy_version_);
3072 visitor.use_compression_ = true; 3018 visitor.use_compression_ = true;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
3288 // Check that the framer stops delivering header data chunks once the visitor 3234 // Check that the framer stops delivering header data chunks once the visitor
3289 // declares it doesn't want any more. This is important to guard against 3235 // declares it doesn't want any more. This is important to guard against
3290 // "zip bomb" types of attacks. 3236 // "zip bomb" types of attacks.
3291 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { 3237 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) {
3292 const size_t kHeaderBufferChunks = 4; 3238 const size_t kHeaderBufferChunks = 4;
3293 const size_t kHeaderBufferSize = 3239 const size_t kHeaderBufferSize =
3294 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; 3240 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks;
3295 const size_t kBigValueSize = kHeaderBufferSize * 2; 3241 const size_t kBigValueSize = kHeaderBufferSize * 2;
3296 string big_value(kBigValueSize, 'x'); 3242 string big_value(kBigValueSize, 'x');
3297 SpdyFramer framer(spdy_version_); 3243 SpdyFramer framer(spdy_version_);
3298 SpdySynStreamIR syn_stream(1); 3244 SpdyHeadersIR headers(1);
3299 syn_stream.set_priority(1); 3245 headers.set_priority(1);
3300 syn_stream.set_fin(true); 3246 headers.set_fin(true);
3301 syn_stream.SetHeader("aa", big_value); 3247 headers.SetHeader("aa", big_value);
3302 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); 3248 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers));
3303 EXPECT_TRUE(control_frame.get() != NULL); 3249 EXPECT_TRUE(control_frame.get() != NULL);
3304 TestSpdyVisitor visitor(spdy_version_); 3250 TestSpdyVisitor visitor(spdy_version_);
3305 visitor.set_header_buffer_size(kHeaderBufferSize); 3251 visitor.set_header_buffer_size(kHeaderBufferSize);
3306 visitor.use_compression_ = true; 3252 visitor.use_compression_ = true;
3307 visitor.SimulateInFramer( 3253 visitor.SimulateInFramer(
3308 reinterpret_cast<unsigned char*>(control_frame->data()), 3254 reinterpret_cast<unsigned char*>(control_frame->data()),
3309 control_frame->size()); 3255 control_frame->size());
3310 EXPECT_FALSE(visitor.header_buffer_valid_); 3256 EXPECT_FALSE(visitor.header_buffer_valid_);
3311 EXPECT_EQ(1, visitor.error_count_); 3257 EXPECT_EQ(1, visitor.error_count_);
3312 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, 3258 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE,
(...skipping 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after
4496 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4442 << SpdyFramer::ErrorCodeToString(framer.error_code());
4497 } else { 4443 } else {
4498 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4444 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4499 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4445 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4500 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4446 << SpdyFramer::ErrorCodeToString(framer.error_code());
4501 } 4447 }
4502 } 4448 }
4503 } 4449 }
4504 4450
4505 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { 4451 TEST_P(SpdyFramerTest, SynStreamFrameFlags) {
4452 if (!IsSpdy2() && !IsSpdy3()) {
4453 // SYN_STREAM not supported in SPDY>3
4454 return;
4455 }
4506 for (int flags = 0; flags < 256; ++flags) { 4456 for (int flags = 0; flags < 256; ++flags) {
4507 SCOPED_TRACE(testing::Message() << "Flags " << flags); 4457 SCOPED_TRACE(testing::Message() << "Flags " << flags);
4508 4458
4509 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4459 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
4510 testing::StrictMock<test::MockDebugVisitor> debug_visitor; 4460 testing::StrictMock<test::MockDebugVisitor> debug_visitor;
4511 SpdyFramer framer(spdy_version_); 4461 SpdyFramer framer(spdy_version_);
4512 framer.set_visitor(&visitor); 4462 framer.set_visitor(&visitor);
4513 framer.set_debug_visitor(&debug_visitor); 4463 framer.set_debug_visitor(&debug_visitor);
4514 4464
4515 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _)); 4465 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _));
4516 4466
4517 SpdySynStreamIR syn_stream(8); 4467 SpdySynStreamIR syn_stream(8);
4518 syn_stream.set_associated_to_stream_id(3); 4468 syn_stream.set_associated_to_stream_id(3);
4519 syn_stream.set_priority(1); 4469 syn_stream.set_priority(1);
4520 syn_stream.SetHeader("foo", "bar"); 4470 syn_stream.SetHeader("foo", "bar");
4521 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); 4471 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream));
4522 int set_flags = flags; 4472 int set_flags = flags;
4523 if (IsSpdy4()) {
4524 // PRIORITY required for SYN_STREAM simulation.
4525 set_flags |= HEADERS_FLAG_PRIORITY;
4526
4527 // TODO(jgraettinger): Add padding to SynStreamIR, and implement framing.
4528 set_flags &= ~HEADERS_FLAG_PAD_LOW;
4529 set_flags &= ~HEADERS_FLAG_PAD_HIGH;
4530 }
4531 SetFrameFlags(frame.get(), set_flags, spdy_version_); 4473 SetFrameFlags(frame.get(), set_flags, spdy_version_);
4532 4474
4533 if (!IsSpdy4() && 4475 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) {
4534 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) {
4535 EXPECT_CALL(visitor, OnError(_));
4536 } else if (IsSpdy4() &&
4537 flags & ~(CONTROL_FLAG_FIN |
4538 HEADERS_FLAG_PRIORITY |
4539 HEADERS_FLAG_END_HEADERS |
4540 HEADERS_FLAG_END_SEGMENT |
4541 HEADERS_FLAG_PAD_LOW |
4542 HEADERS_FLAG_PAD_HIGH)) {
4543 EXPECT_CALL(visitor, OnError(_)); 4476 EXPECT_CALL(visitor, OnError(_));
4544 } else { 4477 } else {
4545 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); 4478 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _));
4546 if (IsSpdy4()) { 4479 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN,
4547 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, 4480 flags & CONTROL_FLAG_UNIDIRECTIONAL));
4548 false));
4549 } else {
4550 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN,
4551 flags & CONTROL_FLAG_UNIDIRECTIONAL));
4552 }
4553 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) 4481 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _))
4554 .WillRepeatedly(testing::Return(true)); 4482 .WillRepeatedly(testing::Return(true));
4555 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || 4483 if (flags & DATA_FLAG_FIN) {
4556 flags & HEADERS_FLAG_END_HEADERS)) {
4557 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); 4484 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true));
4558 } else { 4485 } else {
4559 // Do not close the stream if we are expecting a CONTINUATION frame. 4486 // Do not close the stream if we are expecting a CONTINUATION frame.
4560 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); 4487 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0);
4561 } 4488 }
4562 } 4489 }
4563 4490
4564 framer.ProcessInput(frame->data(), frame->size()); 4491 framer.ProcessInput(frame->data(), frame->size());
4565 if (!IsSpdy4() && 4492 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) {
4566 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) {
4567 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); 4493 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state());
4568 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, 4494 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS,
4569 framer.error_code()) 4495 framer.error_code())
4570 << SpdyFramer::ErrorCodeToString(framer.error_code());
4571 } else if (IsSpdy4() &&
4572 flags & ~(CONTROL_FLAG_FIN |
4573 HEADERS_FLAG_PRIORITY |
4574 HEADERS_FLAG_END_HEADERS |
4575 HEADERS_FLAG_END_SEGMENT |
4576 HEADERS_FLAG_PAD_LOW |
4577 HEADERS_FLAG_PAD_HIGH)) {
4578 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state());
4579 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS,
4580 framer.error_code())
4581 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4496 << SpdyFramer::ErrorCodeToString(framer.error_code());
4582 } else { 4497 } else {
4583 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4498 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4584 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4499 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4585 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4500 << SpdyFramer::ErrorCodeToString(framer.error_code());
4586 } 4501 }
4587 } 4502 }
4588 } 4503 }
4589 4504
4590 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { 4505 TEST_P(SpdyFramerTest, SynReplyFrameFlags) {
4591 if (IsSpdy4()) { 4506 if (!IsSpdy2() && !IsSpdy3()) {
4592 // Covered by HEADERS case. 4507 // SYN_REPLY not supported in SPDY>3
4593 return; 4508 return;
4594 } 4509 }
4595 for (int flags = 0; flags < 256; ++flags) { 4510 for (int flags = 0; flags < 256; ++flags) {
4596 SCOPED_TRACE(testing::Message() << "Flags " << flags); 4511 SCOPED_TRACE(testing::Message() << "Flags " << flags);
4597 4512
4598 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4513 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
4599 SpdyFramer framer(spdy_version_); 4514 SpdyFramer framer(spdy_version_);
4600 framer.set_visitor(&visitor); 4515 framer.set_visitor(&visitor);
4601 4516
4602 SpdySynReplyIR syn_reply(37); 4517 SpdySynReplyIR syn_reply(37);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
4771 } else { 4686 } else {
4772 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4687 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4773 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4688 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4774 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4689 << SpdyFramer::ErrorCodeToString(framer.error_code());
4775 } 4690 }
4776 } 4691 }
4777 } 4692 }
4778 4693
4779 TEST_P(SpdyFramerTest, HeadersFrameFlags) { 4694 TEST_P(SpdyFramerTest, HeadersFrameFlags) {
4780 for (int flags = 0; flags < 256; ++flags) { 4695 for (int flags = 0; flags < 256; ++flags) {
4781 if (IsSpdy4() && flags & HEADERS_FLAG_PRIORITY) {
4782 // Covered by SYN_STREAM case.
4783 continue;
4784 }
4785 SCOPED_TRACE(testing::Message() << "Flags " << flags); 4696 SCOPED_TRACE(testing::Message() << "Flags " << flags);
4786 4697
4787 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4698 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
4788 SpdyFramer framer(spdy_version_); 4699 SpdyFramer framer(spdy_version_);
4789 framer.set_visitor(&visitor); 4700 framer.set_visitor(&visitor);
4790 4701
4791 SpdyHeadersIR headers_ir(57); 4702 SpdyHeadersIR headers_ir(57);
4703 if (IsSpdy4() && (flags & HEADERS_FLAG_PRIORITY)) {
4704 headers_ir.set_priority(3);
4705 headers_ir.set_has_priority(true);
4706 }
4792 headers_ir.SetHeader("foo", "bar"); 4707 headers_ir.SetHeader("foo", "bar");
4793 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 4708 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
4794 int set_flags = flags; 4709 int set_flags = flags;
4795 if (IsSpdy4()) { 4710 if (IsSpdy4()) {
4796 // TODO(jgraettinger): Add padding to SpdyHeadersIR, 4711 // TODO(jgraettinger): Add padding to SpdyHeadersIR,
4797 // and implement framing. 4712 // and implement framing.
4798 set_flags &= ~HEADERS_FLAG_PAD_LOW; 4713 set_flags &= ~HEADERS_FLAG_PAD_LOW;
4799 set_flags &= ~HEADERS_FLAG_PAD_HIGH; 4714 set_flags &= ~HEADERS_FLAG_PAD_HIGH;
4800 } 4715 }
4801 SetFrameFlags(frame.get(), set_flags, spdy_version_); 4716 SetFrameFlags(frame.get(), set_flags, spdy_version_);
4802 4717
4803 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { 4718 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) {
4804 EXPECT_CALL(visitor, OnError(_)); 4719 EXPECT_CALL(visitor, OnError(_));
4805 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | 4720 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN |
4806 HEADERS_FLAG_END_HEADERS | 4721 HEADERS_FLAG_END_HEADERS |
4807 HEADERS_FLAG_END_SEGMENT | 4722 HEADERS_FLAG_END_SEGMENT |
4808 HEADERS_FLAG_PAD_LOW | 4723 HEADERS_FLAG_PAD_LOW |
4809 HEADERS_FLAG_PAD_HIGH)) { 4724 HEADERS_FLAG_PAD_HIGH |
4725 HEADERS_FLAG_PRIORITY)) {
4810 EXPECT_CALL(visitor, OnError(_)); 4726 EXPECT_CALL(visitor, OnError(_));
4811 } else { 4727 } else {
4812 EXPECT_CALL(visitor, OnHeaders(57, 4728 if (spdy_version_ > SPDY3 && flags & HEADERS_FLAG_PRIORITY) {
4813 flags & CONTROL_FLAG_FIN, 4729 EXPECT_CALL(visitor, OnSynStream(57, // stream id
4814 (flags & HEADERS_FLAG_END_HEADERS) || 4730 0, // associated stream id
4815 !IsSpdy4())); 4731 3, // priority
4732 flags & CONTROL_FLAG_FIN,
4733 false)); // unidirectional
4734 } else {
4735 EXPECT_CALL(visitor, OnHeaders(57,
4736 flags & CONTROL_FLAG_FIN,
4737 (flags & HEADERS_FLAG_END_HEADERS) ||
4738 !IsSpdy4()));
4739 }
4816 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) 4740 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _))
4817 .WillRepeatedly(testing::Return(true)); 4741 .WillRepeatedly(testing::Return(true));
4818 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || 4742 if (flags & DATA_FLAG_FIN && (!IsSpdy4() ||
4819 flags & HEADERS_FLAG_END_HEADERS)) { 4743 flags & HEADERS_FLAG_END_HEADERS)) {
4820 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); 4744 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true));
4821 } else { 4745 } else {
4822 // Do not close the stream if we are expecting a CONTINUATION frame. 4746 // Do not close the stream if we are expecting a CONTINUATION frame.
4823 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); 4747 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0);
4824 } 4748 }
4825 } 4749 }
4826 4750
4827 framer.ProcessInput(frame->data(), frame->size()); 4751 framer.ProcessInput(frame->data(), frame->size());
4828 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { 4752 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) {
4829 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); 4753 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state());
4830 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, 4754 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS,
4831 framer.error_code()) 4755 framer.error_code())
4832 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4756 << SpdyFramer::ErrorCodeToString(framer.error_code());
4833 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | 4757 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN |
4834 HEADERS_FLAG_END_HEADERS | 4758 HEADERS_FLAG_END_HEADERS |
4835 HEADERS_FLAG_END_SEGMENT | 4759 HEADERS_FLAG_END_SEGMENT |
4836 HEADERS_FLAG_PAD_LOW | 4760 HEADERS_FLAG_PAD_LOW |
4837 HEADERS_FLAG_PAD_HIGH)) { 4761 HEADERS_FLAG_PAD_HIGH |
4762 HEADERS_FLAG_PRIORITY)) {
4838 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); 4763 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state());
4839 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, 4764 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS,
4840 framer.error_code()) 4765 framer.error_code())
4841 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4766 << SpdyFramer::ErrorCodeToString(framer.error_code());
4842 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { 4767 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) {
4843 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4768 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
4844 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 4769 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
4845 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4770 << SpdyFramer::ErrorCodeToString(framer.error_code());
4846 } else { 4771 } else {
4847 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 4772 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
5033 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4958 << SpdyFramer::ErrorCodeToString(framer.error_code());
5034 } 4959 }
5035 } 4960 }
5036 } 4961 }
5037 4962
5038 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) 4963 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags)
5039 4964
5040 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) 4965 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags)
5041 4966
5042 TEST_P(SpdyFramerTest, EmptySynStream) { 4967 TEST_P(SpdyFramerTest, EmptySynStream) {
4968 if (!IsSpdy2() && !IsSpdy3()) {
4969 // SYN_STREAM not supported in SPDY>3.
4970 return;
4971 }
5043 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 4972 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5044 testing::StrictMock<test::MockDebugVisitor> debug_visitor; 4973 testing::StrictMock<test::MockDebugVisitor> debug_visitor;
5045 SpdyFramer framer(spdy_version_); 4974 SpdyFramer framer(spdy_version_);
5046 framer.set_visitor(&visitor); 4975 framer.set_visitor(&visitor);
5047 framer.set_debug_visitor(&debug_visitor); 4976 framer.set_debug_visitor(&debug_visitor);
5048 4977
5049 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); 4978 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _));
5050 4979
5051 SpdySynStreamIR syn_stream(1); 4980 SpdySynStreamIR syn_stream(1);
5052 syn_stream.set_priority(1); 4981 syn_stream.set_priority(1);
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
5481 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); 5410 EXPECT_EQ(4u, framer.MapWeightToPriority(109));
5482 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); 5411 EXPECT_EQ(4u, framer.MapWeightToPriority(74));
5483 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); 5412 EXPECT_EQ(5u, framer.MapWeightToPriority(73));
5484 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); 5413 EXPECT_EQ(5u, framer.MapWeightToPriority(37));
5485 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); 5414 EXPECT_EQ(6u, framer.MapWeightToPriority(36));
5486 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); 5415 EXPECT_EQ(6u, framer.MapWeightToPriority(1));
5487 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); 5416 EXPECT_EQ(7u, framer.MapWeightToPriority(0));
5488 } 5417 }
5489 5418
5490 } // namespace net 5419 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698