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 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1569 { | 1569 { |
1570 const char kDescription[] = "'hello' data frame with more padding, no FIN"; | 1570 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
1571 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1571 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1572 0x00, 0x00, 0x00, 0x01, | 1572 0x00, 0x00, 0x00, 0x01, |
1573 0x00, 0x00, 0x00, 0x05, | 1573 0x00, 0x00, 0x00, 0x05, |
1574 'h', 'e', 'l', 'l', | 1574 'h', 'e', 'l', 'l', |
1575 'o' | 1575 'o' |
1576 }; | 1576 }; |
1577 | 1577 |
1578 const unsigned char kV4FrameData[] = { | 1578 const unsigned char kV4FrameData[] = { |
1579 0x01, 0x0b, 0x00, 0x18, // Length = 267. PAD_HIGH and PAD_LOW set. | 1579 0x00, 0xfd, 0x00, 0x08, // Length = 253. PADDED set. |
1580 0x00, 0x00, 0x00, 0x01, | 1580 0x00, 0x00, 0x00, 0x01, |
1581 0x01, 0x04, // Pad Low and Pad High fields. | 1581 0xf7, // Pad length field. |
1582 'h', 'e', 'l', 'l', // Data | 1582 'h', 'e', 'l', 'l', // Data |
1583 'o', | 1583 'o', |
1584 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). | 1584 // Padding of 247 zeros. |
1585 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1585 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1586 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1586 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1587 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1587 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1588 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | |
1589 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1588 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1590 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1589 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1591 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1590 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1592 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1591 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1593 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1592 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1594 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1593 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1595 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1594 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1596 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1595 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1597 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1596 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1598 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1597 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1599 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1598 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1600 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1599 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1601 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1600 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1602 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1601 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1603 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1602 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1604 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1603 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1605 }; | 1604 }; |
1606 const char bytes[] = "hello"; | 1605 const char bytes[] = "hello"; |
1607 | 1606 |
1608 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1607 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1609 // 260 zeros and the pad low/high fields make the overall padding to be 262 | 1608 // 247 zeros and the pad length field make the overall padding to be 248 |
1610 // bytes. | 1609 // bytes. |
1611 data_ir.set_padding_len(262); | 1610 data_ir.set_padding_len(248); |
1612 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1611 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1613 if (IsSpdy4()) { | 1612 if (IsSpdy4()) { |
1614 CompareFrame( | 1613 CompareFrame( |
1615 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1614 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
1616 } else { | 1615 } else { |
1617 CompareFrame( | 1616 CompareFrame( |
1618 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1617 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1619 } | 1618 } |
1620 | 1619 |
1621 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); | 1620 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
1622 CompareCharArraysWithHexError( | 1621 CompareCharArraysWithHexError( |
1623 kDescription, | 1622 kDescription, |
1624 reinterpret_cast<const unsigned char*>(frame->data()), | 1623 reinterpret_cast<const unsigned char*>(frame->data()), |
1625 framer.GetDataFrameMinimumSize(), | 1624 framer.GetDataFrameMinimumSize(), |
1626 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1625 IsSpdy4() ? kV4FrameData : kV3FrameData, |
1627 framer.GetDataFrameMinimumSize()); | 1626 framer.GetDataFrameMinimumSize()); |
1628 } | 1627 } |
1629 | 1628 |
1630 { | 1629 { |
1631 const char kDescription[] = "'hello' data frame with few padding, no FIN"; | 1630 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
1632 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1631 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1633 0x00, 0x00, 0x00, 0x01, | 1632 0x00, 0x00, 0x00, 0x01, |
1634 0x00, 0x00, 0x00, 0x05, | 1633 0x00, 0x00, 0x00, 0x05, |
1635 'h', 'e', 'l', 'l', | 1634 'h', 'e', 'l', 'l', |
1636 'o' | 1635 'o' |
1637 }; | 1636 }; |
1638 | 1637 |
1639 const unsigned char kV4FrameData[] = { | 1638 const unsigned char kV4FrameData[] = { |
1640 0x00, 0x0d, 0x00, 0x08, // Length = 13. PAD_LOW set. | 1639 0x00, 0x0d, 0x00, 0x08, // Length = 13. PADDED set. |
1641 0x00, 0x00, 0x00, 0x01, | 1640 0x00, 0x00, 0x00, 0x01, |
1642 0x07, // Pad Low field. | 1641 0x07, // Pad length field. |
1643 'h', 'e', 'l', 'l', // Data | 1642 'h', 'e', 'l', 'l', // Data |
1644 'o', | 1643 'o', |
1645 '0', '0', '0', '0', // Padding | 1644 '0', '0', '0', '0', // Padding |
1646 '0', '0', '0' | 1645 '0', '0', '0' |
1647 }; | 1646 }; |
1648 const char bytes[] = "hello"; | 1647 const char bytes[] = "hello"; |
1649 | 1648 |
1650 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1649 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1651 // 7 zeros and the pad low field make the overall padding to be 8 bytes. | 1650 // 7 zeros and the pad length field make the overall padding to be 8 bytes. |
1652 data_ir.set_padding_len(8); | 1651 data_ir.set_padding_len(8); |
1653 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1652 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1654 if (IsSpdy4()) { | 1653 if (IsSpdy4()) { |
1655 CompareFrame( | 1654 CompareFrame( |
1656 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1655 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
1657 } else { | 1656 } else { |
1658 CompareFrame( | 1657 CompareFrame( |
1659 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1658 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1660 } | 1659 } |
1661 } | 1660 } |
1662 | 1661 |
1663 { | 1662 { |
1664 const char kDescription[] = | 1663 const char kDescription[] = |
1665 "'hello' data frame with 1 byte padding, no FIN"; | 1664 "'hello' data frame with 1 byte padding, no FIN"; |
1666 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1665 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1667 0x00, 0x00, 0x00, 0x01, | 1666 0x00, 0x00, 0x00, 0x01, |
1668 0x00, 0x00, 0x00, 0x05, | 1667 0x00, 0x00, 0x00, 0x05, |
1669 'h', 'e', 'l', 'l', | 1668 'h', 'e', 'l', 'l', |
1670 'o' | 1669 'o' |
1671 }; | 1670 }; |
1672 | 1671 |
1673 const unsigned char kV4FrameData[] = { | 1672 const unsigned char kV4FrameData[] = { |
1674 0x00, 0x06, 0x00, 0x08, // Length = 6. PAD_LOW set. | 1673 0x00, 0x06, 0x00, 0x08, // Length = 6. PADDED set. |
1675 0x00, 0x00, 0x00, 0x01, | 1674 0x00, 0x00, 0x00, 0x01, |
1676 0x00, // Pad Low field. | 1675 0x00, // Pad length field. |
1677 'h', 'e', 'l', 'l', // Data | 1676 'h', 'e', 'l', 'l', // Data |
1678 'o', | 1677 'o', |
1679 }; | 1678 }; |
1680 const char bytes[] = "hello"; | 1679 const char bytes[] = "hello"; |
1681 | 1680 |
1682 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1681 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1683 // The pad low field itself is used for the 1-byte padding and no padding | 1682 // The pad length field itself is used for the 1-byte padding and no padding |
1684 // payload is needed. | 1683 // payload is needed. |
1685 data_ir.set_padding_len(1); | 1684 data_ir.set_padding_len(1); |
1686 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1685 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1687 if (IsSpdy4()) { | 1686 if (IsSpdy4()) { |
1688 CompareFrame( | 1687 CompareFrame( |
1689 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1688 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
1690 } else { | 1689 } else { |
1691 CompareFrame( | 1690 CompareFrame( |
1692 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1691 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1693 } | 1692 } |
(...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3569 | 3568 |
3570 TestSpdyVisitor visitor(spdy_version_); | 3569 TestSpdyVisitor visitor(spdy_version_); |
3571 visitor.use_compression_ = false; | 3570 visitor.use_compression_ = false; |
3572 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 3571 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
3573 | 3572 |
3574 EXPECT_EQ(0, visitor.error_count_); | 3573 EXPECT_EQ(0, visitor.error_count_); |
3575 EXPECT_EQ(0, visitor.setting_count_); | 3574 EXPECT_EQ(0, visitor.setting_count_); |
3576 EXPECT_EQ(1, visitor.settings_ack_received_); | 3575 EXPECT_EQ(1, visitor.settings_ack_received_); |
3577 } | 3576 } |
3578 | 3577 |
3579 | |
3580 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 3578 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
3581 if (spdy_version_ <= SPDY3) { | 3579 if (spdy_version_ <= SPDY3) { |
3582 return; | 3580 return; |
3583 } | 3581 } |
3584 | 3582 |
3585 const int kPaddingLen = 512; // So we get two bytes for padding length field. | 3583 const int kPaddingLen = 119; |
3586 const char data_payload[] = "hello"; | 3584 const char data_payload[] = "hello"; |
3587 | 3585 |
3588 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3586 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
3589 SpdyFramer framer(spdy_version_); | 3587 SpdyFramer framer(spdy_version_); |
3590 framer.set_visitor(&visitor); | 3588 framer.set_visitor(&visitor); |
3591 | 3589 |
3592 SpdyDataIR data_ir(1, StringPiece(data_payload, strlen(data_payload))); | 3590 SpdyDataIR data_ir(1, StringPiece(data_payload, strlen(data_payload))); |
3593 data_ir.set_padding_len(kPaddingLen); | 3591 data_ir.set_padding_len(kPaddingLen); |
3594 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 3592 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
3595 ASSERT_TRUE(frame.get() != NULL); | 3593 ASSERT_TRUE(frame.get() != NULL); |
3596 | 3594 |
3597 int bytes_consumed = 0; | 3595 int bytes_consumed = 0; |
3598 | 3596 |
3599 // Send the frame header. | 3597 // Send the frame header. |
3600 EXPECT_CALL(visitor, OnDataFrameHeader(1, | 3598 EXPECT_CALL(visitor, OnDataFrameHeader(1, |
3601 kPaddingLen + strlen(data_payload), | 3599 kPaddingLen + strlen(data_payload), |
3602 false)); | 3600 false)); |
3603 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); | 3601 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); |
3604 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); | 3602 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); |
3605 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3603 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3606 bytes_consumed += 8; | 3604 bytes_consumed += 8; |
3607 | 3605 |
3608 // Send the first byte of the padding length field. | 3606 // Send the padding length field. |
3609 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); | |
3610 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); | |
3611 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | |
3612 bytes_consumed += 1; | |
3613 | |
3614 // Send the second byte of the padding length field. | |
3615 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); | 3607 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); |
3616 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); | 3608 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); |
3617 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3609 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3618 bytes_consumed += 1; | 3610 bytes_consumed += 1; |
3619 | 3611 |
3620 // Send the first two bytes of the data payload. | 3612 // Send the first two bytes of the data payload, i.e., "he". |
3621 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 2, false)); | 3613 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 2, false)); |
3622 CHECK_EQ(2u, framer.ProcessInput(frame->data() + bytes_consumed, 2)); | 3614 CHECK_EQ(2u, framer.ProcessInput(frame->data() + bytes_consumed, 2)); |
3623 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); | 3615 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); |
3624 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3616 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3625 bytes_consumed += 2; | 3617 bytes_consumed += 2; |
3626 | 3618 |
3627 // Send the rest three bytes of the data payload. | 3619 // Send the rest three bytes of the data payload, i.e., "llo". |
3628 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 3, false)); | 3620 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 3, false)); |
3629 CHECK_EQ(3u, framer.ProcessInput(frame->data() + bytes_consumed, 3)); | 3621 CHECK_EQ(3u, framer.ProcessInput(frame->data() + bytes_consumed, 3)); |
3630 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); | 3622 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); |
3631 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3623 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3632 bytes_consumed += 3; | 3624 bytes_consumed += 3; |
3633 | 3625 |
3634 // Send the first 100 bytes of the padding payload. | 3626 // Send the first 100 bytes of the padding payload. |
3635 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 100, false)); | 3627 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 100, false)); |
3636 CHECK_EQ(100u, framer.ProcessInput(frame->data() + bytes_consumed, 100)); | 3628 CHECK_EQ(100u, framer.ProcessInput(frame->data() + bytes_consumed, 100)); |
3637 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); | 3629 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); |
3638 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3630 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3639 bytes_consumed += 100; | 3631 bytes_consumed += 100; |
3640 | 3632 |
3641 // Send rest of the padding payload. | 3633 // Send rest of the padding payload. |
3642 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 410, false)); | 3634 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 18, false)); |
3643 CHECK_EQ(410u, framer.ProcessInput(frame->data() + bytes_consumed, 410)); | 3635 CHECK_EQ(18u, framer.ProcessInput(frame->data() + bytes_consumed, 18)); |
3644 CHECK_EQ(framer.state(), SpdyFramer::SPDY_RESET); | 3636 CHECK_EQ(framer.state(), SpdyFramer::SPDY_RESET); |
3645 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3637 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3646 } | 3638 } |
3647 | 3639 |
3648 TEST_P(SpdyFramerTest, ReadWindowUpdate) { | 3640 TEST_P(SpdyFramerTest, ReadWindowUpdate) { |
3649 SpdyFramer framer(spdy_version_); | 3641 SpdyFramer framer(spdy_version_); |
3650 scoped_ptr<SpdyFrame> control_frame( | 3642 scoped_ptr<SpdyFrame> control_frame( |
3651 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 3643 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
3652 TestSpdyVisitor visitor(spdy_version_); | 3644 TestSpdyVisitor visitor(spdy_version_); |
3653 visitor.SimulateInFramer( | 3645 visitor.SimulateInFramer( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3772 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3764 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
3773 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3765 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
3774 } | 3766 } |
3775 | 3767 |
3776 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3768 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
3777 if (spdy_version_ <= SPDY3) { | 3769 if (spdy_version_ <= SPDY3) { |
3778 return; | 3770 return; |
3779 } | 3771 } |
3780 | 3772 |
3781 const unsigned char kInput[] = { | 3773 const unsigned char kInput[] = { |
3782 0x00, 0x14, 0x01, 0x08, // HEADERS: PAD_LOW | 3774 0x00, 0x14, 0x01, 0x08, // HEADERS: PADDED |
3783 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3775 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3784 0x03, // Padding of 3. | 3776 0x03, // Padding of 3. |
3785 0x00, 0x06, 0x63, 0x6f, | 3777 0x00, 0x06, 0x63, 0x6f, |
3786 0x6f, 0x6b, 0x69, 0x65, | 3778 0x6f, 0x6b, 0x69, 0x65, |
3787 0x07, 0x66, 0x6f, 0x6f, | 3779 0x07, 0x66, 0x6f, 0x6f, |
3788 0x3d, 0x62, 0x61, 0x72, | 3780 0x3d, 0x62, 0x61, 0x72, |
3789 0x00, 0x00, 0x00, | 3781 0x00, 0x00, 0x00, |
3790 | 3782 |
3791 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3783 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
3792 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3784 0x00, 0x00, 0x00, 0x01, // Stream 1 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3864 Pair("cookie", "foo=bar; baz=bing; "), | 3856 Pair("cookie", "foo=bar; baz=bing; "), |
3865 Pair("name", "value"))); | 3857 Pair("name", "value"))); |
3866 } | 3858 } |
3867 | 3859 |
3868 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3860 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
3869 if (spdy_version_ <= SPDY3) { | 3861 if (spdy_version_ <= SPDY3) { |
3870 return; | 3862 return; |
3871 } | 3863 } |
3872 | 3864 |
3873 const unsigned char kInput[] = { | 3865 const unsigned char kInput[] = { |
3874 0x00, 0x18, 0x05, 0x18, // PUSH_PROMISE: PAD_LOW & PAD_HIGH | 3866 0x00, 0x17, 0x05, 0x08, // PUSH_PROMISE: PADDED |
3875 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3867 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3876 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3868 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
3877 0x00, 0x02, // Padding of 2. | 3869 0x02, // Padding of 2. |
3878 0x00, 0x06, 0x63, 0x6f, | 3870 0x00, 0x06, 0x63, 0x6f, |
3879 0x6f, 0x6b, 0x69, 0x65, | 3871 0x6f, 0x6b, 0x69, 0x65, |
3880 0x07, 0x66, 0x6f, 0x6f, | 3872 0x07, 0x66, 0x6f, 0x6f, |
3881 0x3d, 0x62, 0x61, 0x72, | 3873 0x3d, 0x62, 0x61, 0x72, |
3882 0x00, 0x00, | 3874 0x00, 0x00, |
3883 | 3875 |
3884 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3876 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
3885 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3877 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3886 0x00, 0x06, 0x63, 0x6f, | 3878 0x00, 0x06, 0x63, 0x6f, |
3887 0x6f, 0x6b, 0x69, 0x65, | 3879 0x6f, 0x6b, 0x69, 0x65, |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4374 } | 4366 } |
4375 } | 4367 } |
4376 } | 4368 } |
4377 | 4369 |
4378 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 4370 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
4379 if (spdy_version_ <= SPDY3) { | 4371 if (spdy_version_ <= SPDY3) { |
4380 return; | 4372 return; |
4381 } | 4373 } |
4382 | 4374 |
4383 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | | 4375 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | |
4384 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; | 4376 DATA_FLAG_PADDED; |
4385 | 4377 |
4386 for (int flags = 0; flags < 256; ++flags) { | 4378 for (int flags = 0; flags < 256; ++flags) { |
4387 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4379 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4388 | 4380 |
4389 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4381 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4390 SpdyFramer framer(spdy_version_); | 4382 SpdyFramer framer(spdy_version_); |
4391 framer.set_visitor(&visitor); | 4383 framer.set_visitor(&visitor); |
4392 | 4384 |
4393 SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 4385 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
4394 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 4386 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
4395 SetFrameFlags(frame.get(), flags, spdy_version_); | 4387 SetFrameFlags(frame.get(), flags, spdy_version_); |
4396 | 4388 |
4397 if (flags & ~valid_data_flags) { | 4389 if (flags & ~valid_data_flags) { |
4398 EXPECT_CALL(visitor, OnError(_)); | 4390 EXPECT_CALL(visitor, OnError(_)); |
4399 } else { | 4391 } else { |
4400 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 4392 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
4401 if ((flags & DATA_FLAG_PAD_LOW) || (flags & DATA_FLAG_PAD_HIGH)) { | 4393 if (flags & DATA_FLAG_PADDED) { |
4402 // Expect Error since we don't set pad_high and pad_low in payload. | 4394 // Expect Error since we don't set padded in payload. |
4403 EXPECT_CALL(visitor, OnError(_)); | 4395 EXPECT_CALL(visitor, OnError(_)); |
4404 } else { | 4396 } else { |
4405 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); | 4397 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); |
4406 if (flags & DATA_FLAG_FIN) { | 4398 if (flags & DATA_FLAG_FIN) { |
4407 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4399 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
4408 } | 4400 } |
4409 } | 4401 } |
4410 } | 4402 } |
4411 | 4403 |
4412 framer.ProcessInput(frame->data(), frame->size()); | 4404 framer.ProcessInput(frame->data(), frame->size()); |
4413 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PAD_LOW) || | 4405 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PADDED)) { |
4414 (flags & DATA_FLAG_PAD_HIGH)) { | |
4415 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4406 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4416 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 4407 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, |
4417 framer.error_code()) | 4408 framer.error_code()) |
4418 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4409 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4419 } else { | 4410 } else { |
4420 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4411 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4421 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4412 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4422 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4413 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4423 } | 4414 } |
4424 } | 4415 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4679 if (IsSpdy4() && (flags & HEADERS_FLAG_PRIORITY)) { | 4670 if (IsSpdy4() && (flags & HEADERS_FLAG_PRIORITY)) { |
4680 headers_ir.set_priority(3); | 4671 headers_ir.set_priority(3); |
4681 headers_ir.set_has_priority(true); | 4672 headers_ir.set_has_priority(true); |
4682 } | 4673 } |
4683 headers_ir.SetHeader("foo", "bar"); | 4674 headers_ir.SetHeader("foo", "bar"); |
4684 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 4675 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
4685 int set_flags = flags; | 4676 int set_flags = flags; |
4686 if (IsSpdy4()) { | 4677 if (IsSpdy4()) { |
4687 // TODO(jgraettinger): Add padding to SpdyHeadersIR, | 4678 // TODO(jgraettinger): Add padding to SpdyHeadersIR, |
4688 // and implement framing. | 4679 // and implement framing. |
4689 set_flags &= ~HEADERS_FLAG_PAD_LOW; | 4680 set_flags &= ~HEADERS_FLAG_PADDED; |
4690 set_flags &= ~HEADERS_FLAG_PAD_HIGH; | |
4691 } | 4681 } |
4692 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4682 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4693 | 4683 |
4694 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4684 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4695 EXPECT_CALL(visitor, OnError(_)); | 4685 EXPECT_CALL(visitor, OnError(_)); |
4696 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4686 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4697 HEADERS_FLAG_END_HEADERS | | 4687 HEADERS_FLAG_END_HEADERS | |
4698 HEADERS_FLAG_END_SEGMENT | | 4688 HEADERS_FLAG_END_SEGMENT | |
4699 HEADERS_FLAG_PAD_LOW | | 4689 HEADERS_FLAG_PADDED | |
4700 HEADERS_FLAG_PAD_HIGH | | |
4701 HEADERS_FLAG_PRIORITY)) { | 4690 HEADERS_FLAG_PRIORITY)) { |
4702 EXPECT_CALL(visitor, OnError(_)); | 4691 EXPECT_CALL(visitor, OnError(_)); |
4703 } else { | 4692 } else { |
4704 if (spdy_version_ > SPDY3 && flags & HEADERS_FLAG_PRIORITY) { | 4693 if (spdy_version_ > SPDY3 && flags & HEADERS_FLAG_PRIORITY) { |
4705 EXPECT_CALL(visitor, OnSynStream(57, // stream id | 4694 EXPECT_CALL(visitor, OnSynStream(57, // stream id |
4706 0, // associated stream id | 4695 0, // associated stream id |
4707 3, // priority | 4696 3, // priority |
4708 flags & CONTROL_FLAG_FIN, | 4697 flags & CONTROL_FLAG_FIN, |
4709 false)); // unidirectional | 4698 false)); // unidirectional |
4710 } else { | 4699 } else { |
(...skipping 15 matching lines...) Expand all Loading... |
4726 | 4715 |
4727 framer.ProcessInput(frame->data(), frame->size()); | 4716 framer.ProcessInput(frame->data(), frame->size()); |
4728 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4717 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4729 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4718 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4730 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4719 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4731 framer.error_code()) | 4720 framer.error_code()) |
4732 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4721 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4733 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4722 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4734 HEADERS_FLAG_END_HEADERS | | 4723 HEADERS_FLAG_END_HEADERS | |
4735 HEADERS_FLAG_END_SEGMENT | | 4724 HEADERS_FLAG_END_SEGMENT | |
4736 HEADERS_FLAG_PAD_LOW | | 4725 HEADERS_FLAG_PADDED | |
4737 HEADERS_FLAG_PAD_HIGH | | |
4738 HEADERS_FLAG_PRIORITY)) { | 4726 HEADERS_FLAG_PRIORITY)) { |
4739 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4727 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4740 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4728 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4741 framer.error_code()) | 4729 framer.error_code()) |
4742 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4730 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4743 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { | 4731 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { |
4744 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4732 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4745 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4733 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4746 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4734 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4747 } else { | 4735 } else { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4834 framer.set_debug_visitor(&debug_visitor); | 4822 framer.set_debug_visitor(&debug_visitor); |
4835 | 4823 |
4836 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); | 4824 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); |
4837 | 4825 |
4838 SpdyPushPromiseIR push_promise(42, 57); | 4826 SpdyPushPromiseIR push_promise(42, 57); |
4839 push_promise.SetHeader("foo", "bar"); | 4827 push_promise.SetHeader("foo", "bar"); |
4840 scoped_ptr<SpdySerializedFrame> frame( | 4828 scoped_ptr<SpdySerializedFrame> frame( |
4841 framer.SerializePushPromise(push_promise)); | 4829 framer.SerializePushPromise(push_promise)); |
4842 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, | 4830 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
4843 // and implement framing. | 4831 // and implement framing. |
4844 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; | 4832 int set_flags = flags & ~HEADERS_FLAG_PADDED; |
4845 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4833 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4846 | 4834 |
4847 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | | 4835 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { |
4848 HEADERS_FLAG_PAD_LOW | | |
4849 HEADERS_FLAG_PAD_HIGH)) { | |
4850 EXPECT_CALL(visitor, OnError(_)); | 4836 EXPECT_CALL(visitor, OnError(_)); |
4851 } else { | 4837 } else { |
4852 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); | 4838 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); |
4853 EXPECT_CALL(visitor, OnPushPromise(42, 57, | 4839 EXPECT_CALL(visitor, OnPushPromise(42, 57, |
4854 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); | 4840 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); |
4855 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4841 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4856 .WillRepeatedly(testing::Return(true)); | 4842 .WillRepeatedly(testing::Return(true)); |
4857 } | 4843 } |
4858 | 4844 |
4859 framer.ProcessInput(frame->data(), frame->size()); | 4845 framer.ProcessInput(frame->data(), frame->size()); |
4860 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | | 4846 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { |
4861 HEADERS_FLAG_PAD_LOW | | |
4862 HEADERS_FLAG_PAD_HIGH)) { | |
4863 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4847 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4864 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4848 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4865 framer.error_code()) | 4849 framer.error_code()) |
4866 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4850 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4867 } else { | 4851 } else { |
4868 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4852 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4869 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4853 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4870 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4854 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4871 } | 4855 } |
4872 } | 4856 } |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5379 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); | 5363 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); |
5380 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); | 5364 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); |
5381 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); | 5365 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); |
5382 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); | 5366 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); |
5383 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); | 5367 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); |
5384 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); | 5368 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); |
5385 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); | 5369 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); |
5386 } | 5370 } |
5387 | 5371 |
5388 } // namespace net | 5372 } // namespace net |
OLD | NEW |