| 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 #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 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1607 if (IsSpdy4()) { | 1607 if (IsSpdy4()) { |
| 1608 CompareFrame( | 1608 CompareFrame( |
| 1609 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1609 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1610 } else { | 1610 } else { |
| 1611 CompareFrame( | 1611 CompareFrame( |
| 1612 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1612 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1613 } | 1613 } |
| 1614 | 1614 |
| 1615 SpdyDataIR data_header_ir(1); | 1615 SpdyDataIR data_header_ir(1); |
| 1616 data_header_ir.SetDataShallow(base::StringPiece(bytes, strlen(bytes))); | 1616 data_header_ir.SetDataShallow(base::StringPiece(bytes, strlen(bytes))); |
| 1617 frame.reset(framer.SerializeDataFrameHeader(data_header_ir)); | 1617 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField( |
| 1618 data_header_ir)); |
| 1618 CompareCharArraysWithHexError( | 1619 CompareCharArraysWithHexError( |
| 1619 kDescription, | 1620 kDescription, |
| 1620 reinterpret_cast<const unsigned char*>(frame->data()), | 1621 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1621 framer.GetDataFrameMinimumSize(), | 1622 framer.GetDataFrameMinimumSize(), |
| 1622 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1623 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1623 framer.GetDataFrameMinimumSize()); | 1624 framer.GetDataFrameMinimumSize()); |
| 1624 } | 1625 } |
| 1625 | 1626 |
| 1626 { | 1627 { |
| 1627 const char kDescription[] = "'hello' data frame with padding, no FIN"; | 1628 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
| 1628 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1629 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1629 0x00, 0x00, 0x00, 0x01, | 1630 0x00, 0x00, 0x00, 0x01, |
| 1630 0x00, 0x00, 0x00, 0x05, | 1631 0x00, 0x00, 0x00, 0x05, |
| 1632 'h', 'e', 'l', 'l', |
| 1633 'o' |
| 1634 }; |
| 1635 |
| 1636 const unsigned char kV4FrameData[] = { |
| 1637 0x01, 0x0b, 0x00, 0x30, // Length = 267. PAD_HIGH and PAD_LOW set. |
| 1638 0x00, 0x00, 0x00, 0x01, |
| 1639 0x01, 0x04, // Pad Low and Pad High fields. |
| 1640 'h', 'e', 'l', 'l', // Data |
| 1641 'o', |
| 1642 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). |
| 1643 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1644 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1645 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1646 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1647 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1648 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1649 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1650 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1651 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1652 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1653 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1654 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1655 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1656 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1657 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1658 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1659 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1660 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1661 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1662 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1663 }; |
| 1664 const char bytes[] = "hello"; |
| 1665 |
| 1666 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1667 // 260 zeros and the pad low/high fields make the overall padding to be 262 |
| 1668 // bytes. |
| 1669 data_ir.set_padding_len(262); |
| 1670 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1671 if (IsSpdy4()) { |
| 1672 CompareFrame( |
| 1673 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1674 } else { |
| 1675 CompareFrame( |
| 1676 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1677 } |
| 1678 |
| 1679 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1680 CompareCharArraysWithHexError( |
| 1681 kDescription, |
| 1682 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1683 framer.GetDataFrameMinimumSize(), |
| 1684 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1685 framer.GetDataFrameMinimumSize()); |
| 1686 } |
| 1687 |
| 1688 { |
| 1689 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
| 1690 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1691 0x00, 0x00, 0x00, 0x01, |
| 1692 0x00, 0x00, 0x00, 0x05, |
| 1631 'h', 'e', 'l', 'l', | 1693 'h', 'e', 'l', 'l', |
| 1632 'o' | 1694 'o' |
| 1633 }; | 1695 }; |
| 1634 | 1696 |
| 1635 const unsigned char kV4FrameData[] = { | 1697 const unsigned char kV4FrameData[] = { |
| 1636 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. | 1698 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. |
| 1637 0x00, 0x00, 0x00, 0x01, | 1699 0x00, 0x00, 0x00, 0x01, |
| 1638 0x07, // Pad Low field. | 1700 0x07, // Pad Low field. |
| 1639 'h', 'e', 'l', 'l', // Data | 1701 'h', 'e', 'l', 'l', // Data |
| 1640 'o', | 1702 'o', |
| 1641 '0', '0', '0', '0', // Padding | 1703 '0', '0', '0', '0', // Padding |
| 1642 '0', '0', '0' | 1704 '0', '0', '0' |
| 1643 }; | 1705 }; |
| 1644 const char bytes[] = "hello"; | 1706 const char bytes[] = "hello"; |
| 1645 | 1707 |
| 1646 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1708 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1647 // 7 zeros and the pad low field make the overal padding to be 8 bytes. | 1709 // 7 zeros and the pad low field make the overall padding to be 8 bytes. |
| 1648 data_ir.set_padding_len(8); | 1710 data_ir.set_padding_len(8); |
| 1649 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1711 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1650 if (IsSpdy4()) { | 1712 if (IsSpdy4()) { |
| 1651 CompareFrame( | 1713 CompareFrame( |
| 1652 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1714 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1653 } else { | 1715 } else { |
| 1654 CompareFrame( | 1716 CompareFrame( |
| 1655 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1717 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1656 } | 1718 } |
| 1719 |
| 1720 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1721 CompareCharArraysWithHexError( |
| 1722 kDescription, |
| 1723 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1724 framer.GetDataFrameMinimumSize(), |
| 1725 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1726 framer.GetDataFrameMinimumSize()); |
| 1657 } | 1727 } |
| 1658 | 1728 |
| 1659 { | 1729 { |
| 1660 const char kDescription[] = "Data frame with negative data byte, no FIN"; | 1730 const char kDescription[] = "Data frame with negative data byte, no FIN"; |
| 1661 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1731 const unsigned char kV3FrameData[] = { // Also applies for V2. |
| 1662 0x00, 0x00, 0x00, 0x01, | 1732 0x00, 0x00, 0x00, 0x01, |
| 1663 0x00, 0x00, 0x00, 0x01, | 1733 0x00, 0x00, 0x00, 0x01, |
| 1664 0xff | 1734 0xff |
| 1665 }; | 1735 }; |
| 1666 const unsigned char kV4FrameData[] = { | 1736 const unsigned char kV4FrameData[] = { |
| (...skipping 2855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4522 for (int flags = 0; flags < 256; ++flags) { | 4592 for (int flags = 0; flags < 256; ++flags) { |
| 4523 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4593 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4524 | 4594 |
| 4525 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4595 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4526 SpdyFramer framer(spdy_version_); | 4596 SpdyFramer framer(spdy_version_); |
| 4527 framer.set_visitor(&visitor); | 4597 framer.set_visitor(&visitor); |
| 4528 | 4598 |
| 4529 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); | 4599 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); |
| 4530 SetFrameFlags(frame.get(), flags, spdy_version_); | 4600 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4531 | 4601 |
| 4532 if (spdy_version_ >= SPDY4 && | 4602 if (spdy_version_ > SPDY3 && |
| 4533 flags == PING_FLAG_ACK) { | 4603 flags == PING_FLAG_ACK) { |
| 4534 EXPECT_CALL(visitor, OnPing(42, true)); | 4604 EXPECT_CALL(visitor, OnPing(42, true)); |
| 4535 } else if (flags == 0) { | 4605 } else if (flags == 0) { |
| 4536 EXPECT_CALL(visitor, OnPing(42, false)); | 4606 EXPECT_CALL(visitor, OnPing(42, false)); |
| 4537 } else { | 4607 } else { |
| 4538 EXPECT_CALL(visitor, OnError(_)); | 4608 EXPECT_CALL(visitor, OnError(_)); |
| 4539 } | 4609 } |
| 4540 | 4610 |
| 4541 framer.ProcessInput(frame->data(), frame->size()); | 4611 framer.ProcessInput(frame->data(), frame->size()); |
| 4542 if ((spdy_version_ >= SPDY4 && flags == PING_FLAG_ACK) || | 4612 if ((spdy_version_ > SPDY3 && flags == PING_FLAG_ACK) || |
| 4543 flags == 0) { | 4613 flags == 0) { |
| 4544 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4614 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4545 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4615 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4546 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4616 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4547 } else { | 4617 } else { |
| 4548 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4618 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4549 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4619 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4550 framer.error_code()) | 4620 framer.error_code()) |
| 4551 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4621 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4552 } | 4622 } |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4843 SpdyBlockedIR blocked_ir(0); | 4913 SpdyBlockedIR blocked_ir(0); |
| 4844 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 4914 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 4845 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 4915 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
| 4846 | 4916 |
| 4847 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4917 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4848 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4918 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4849 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4919 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4850 } | 4920 } |
| 4851 | 4921 |
| 4852 } // namespace net | 4922 } // namespace net |
| OLD | NEW |