Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/spdy/spdy_framer.h" | 9 #include "net/spdy/spdy_framer.h" |
| 10 #include "net/spdy/spdy_protocol.h" | 10 #include "net/spdy/spdy_protocol.h" |
| 11 #include "net/spdy/spdy_frame_builder.h" | 11 #include "net/spdy/spdy_frame_builder.h" |
| 12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Default SPDY version for unit tests. | |
| 17 const int SPDY_VERSION_FOR_TESTS = 3; | |
| 18 | |
| 19 // The current default spdy version as a byte to be included in const | 16 // The current default spdy version as a byte to be included in const |
| 20 // byte arrays below. Name choice is unfortunate, but better to fit to four | 17 // byte arrays below. Name choice is unfortunate, but better to fit to four |
| 21 // bytes than not. | 18 // bytes than not. |
| 22 unsigned char kVer = SPDY_VERSION_FOR_TESTS; | 19 unsigned char kVer = 2; |
|
Ryan Hamilton
2012/03/14 17:32:08
Please eliminate this too. Using spdy_version_ in
| |
| 23 | 20 |
| 24 spdy::SpdySetting SpdySettingFromWireFormat(uint32 key, uint32 value) { | 21 spdy::SpdySetting SpdySettingFromWireFormat(uint32 key, uint32 value) { |
| 25 return spdy::SpdySetting( | 22 return spdy::SpdySetting( |
| 26 spdy::SettingsFlagsAndId::FromWireFormat(SPDY_VERSION_FOR_TESTS, key), | 23 spdy::SettingsFlagsAndId::FromWireFormat(kVer, key), |
| 27 value); | 24 value); |
| 28 } | 25 } |
| 29 | 26 |
| 30 } // namespace | 27 } // namespace |
| 31 | 28 |
| 32 namespace spdy { | 29 namespace spdy { |
| 33 | 30 |
| 34 namespace test_spdy3 { | 31 namespace test { |
| 35 | 32 |
| 36 static const size_t kMaxDecompressedSize = 1024; | 33 static const size_t kMaxDecompressedSize = 1024; |
| 37 | 34 |
| 38 class SpdyFramerTestUtil { | 35 class SpdyFramerTestUtil { |
| 39 public: | 36 public: |
| 40 // Decompress a single frame using the decompression context held by | 37 // Decompress a single frame using the decompression context held by |
| 41 // the SpdyFramer. The implemention will CHECK fail if the input is anything | 38 // the SpdyFramer. The implemention will CHECK fail if the input is anything |
| 42 // other than a single, well-formed compressed frame. | 39 // other than a single, well-formed compressed frame. |
| 43 // | 40 // |
| 44 // Returns a new decompressed SpdyFrame. | 41 // Returns a new decompressed SpdyFrame. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 SpdyControlType header_control_type_; | 439 SpdyControlType header_control_type_; |
| 443 bool header_buffer_valid_; | 440 bool header_buffer_valid_; |
| 444 SpdyHeaderBlock headers_; | 441 SpdyHeaderBlock headers_; |
| 445 | 442 |
| 446 scoped_array<char> credential_buffer_; | 443 scoped_array<char> credential_buffer_; |
| 447 size_t credential_buffer_length_; | 444 size_t credential_buffer_length_; |
| 448 size_t credential_buffer_size_; | 445 size_t credential_buffer_size_; |
| 449 SpdyCredential credential_; | 446 SpdyCredential credential_; |
| 450 }; | 447 }; |
| 451 | 448 |
| 452 } // namespace test_spdy3 | 449 } // namespace test |
| 453 | 450 |
| 454 } // namespace spdy | 451 } // namespace spdy |
| 455 | 452 |
| 456 using spdy::SpdyControlFlags; | 453 using spdy::SpdyControlFlags; |
| 457 using spdy::SpdyControlFrame; | 454 using spdy::SpdyControlFrame; |
| 458 using spdy::SpdyDataFrame; | 455 using spdy::SpdyDataFrame; |
| 459 using spdy::SpdyFrame; | 456 using spdy::SpdyFrame; |
| 460 using spdy::SpdyFrameBuilder; | 457 using spdy::SpdyFrameBuilder; |
| 461 using spdy::SpdyFramer; | 458 using spdy::SpdyFramer; |
| 462 using spdy::SpdyHeaderBlock; | 459 using spdy::SpdyHeaderBlock; |
| 463 using spdy::SpdySynStreamControlFrame; | 460 using spdy::SpdySynStreamControlFrame; |
| 464 using spdy::kControlFlagMask; | 461 using spdy::kControlFlagMask; |
| 465 using spdy::kLengthMask; | 462 using spdy::kLengthMask; |
| 466 using spdy::CONTROL_FLAG_NONE; | 463 using spdy::CONTROL_FLAG_NONE; |
| 467 using spdy::DATA_FLAG_COMPRESSED; | 464 using spdy::DATA_FLAG_COMPRESSED; |
| 468 using spdy::DATA_FLAG_FIN; | 465 using spdy::DATA_FLAG_FIN; |
| 469 using spdy::SYN_STREAM; | 466 using spdy::SYN_STREAM; |
| 470 using spdy::test_spdy3::CompareCharArraysWithHexError; | 467 using spdy::test::CompareCharArraysWithHexError; |
| 471 using spdy::test_spdy3::SpdyFramerTestUtil; | 468 using spdy::test::SpdyFramerTestUtil; |
| 472 using spdy::test_spdy3::TestSpdyVisitor; | 469 using spdy::test::TestSpdyVisitor; |
| 473 | 470 |
| 474 namespace spdy { | 471 namespace spdy { |
| 475 | 472 |
| 476 TEST(SpdyFrameBuilderSpdy3Test, WriteLimits) { | 473 TEST(SpdyFrameBuilderTest, WriteLimits) { |
| 477 SpdyFrameBuilder builder(kLengthMask + 4); | 474 SpdyFrameBuilder builder(kLengthMask + 4); |
| 478 // length field should fail. | 475 // length field should fail. |
| 479 EXPECT_FALSE(builder.WriteBytes(reinterpret_cast<const void*>(0x1), | 476 EXPECT_FALSE(builder.WriteBytes(reinterpret_cast<const void*>(0x1), |
| 480 kLengthMask + 1)); | 477 kLengthMask + 1)); |
| 481 EXPECT_EQ(0, builder.length()); | 478 EXPECT_EQ(0, builder.length()); |
| 482 | 479 |
| 483 // Writing a block of the maximum allowed size should succeed. | 480 // Writing a block of the maximum allowed size should succeed. |
| 484 const std::string kLargeData(kLengthMask, 'A'); | 481 const std::string kLargeData(kLengthMask, 'A'); |
| 485 builder.WriteUInt32(kLengthMask); | 482 builder.WriteUInt32(kLengthMask); |
| 486 EXPECT_EQ(4, builder.length()); | 483 EXPECT_EQ(4, builder.length()); |
| 487 EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask)); | 484 EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask)); |
| 488 EXPECT_EQ(4 + kLengthMask, static_cast<unsigned>(builder.length())); | 485 EXPECT_EQ(4 + kLengthMask, static_cast<unsigned>(builder.length())); |
| 489 } | 486 } |
| 490 | 487 |
| 491 class SpdyFramerSpdy3Test : public PlatformTest { | 488 enum SpdyFramerTestTypes { |
| 492 public: | 489 SPDY2, |
| 490 SPDY3, | |
| 491 }; | |
| 492 | |
| 493 class SpdyFramerTest | |
| 494 : public ::testing::TestWithParam<SpdyFramerTestTypes> { | |
| 495 protected: | |
| 496 virtual void SetUp() { | |
| 497 if (GetParam() == SPDY2) { | |
| 498 kVer = 2; | |
| 499 spdy_version_ = 2; | |
| 500 } else { | |
| 501 kVer = 3; | |
| 502 spdy_version_ = 3; | |
| 503 } | |
| 504 } | |
| 505 | |
| 493 virtual void TearDown() {} | 506 virtual void TearDown() {} |
| 494 | 507 |
| 495 protected: | |
| 496 void CompareFrame(const std::string& description, | 508 void CompareFrame(const std::string& description, |
| 497 const SpdyFrame& actual_frame, | 509 const SpdyFrame& actual_frame, |
| 498 const unsigned char* expected, | 510 const unsigned char* expected, |
| 499 const int expected_len) { | 511 const int expected_len) { |
| 500 const unsigned char* actual = | 512 const unsigned char* actual = |
| 501 reinterpret_cast<const unsigned char*>(actual_frame.data()); | 513 reinterpret_cast<const unsigned char*>(actual_frame.data()); |
| 502 int actual_len = actual_frame.length() + SpdyFrame::kHeaderSize; | 514 int actual_len = actual_frame.length() + SpdyFrame::kHeaderSize; |
| 503 CompareCharArraysWithHexError( | 515 CompareCharArraysWithHexError( |
| 504 description, actual, actual_len, expected, expected_len); | 516 description, actual, actual_len, expected, expected_len); |
| 505 } | 517 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 524 if (it->second.compare(it2->second) != 0) { | 536 if (it->second.compare(it2->second) != 0) { |
| 525 LOG(ERROR) << "Expected header named '" << it->first | 537 LOG(ERROR) << "Expected header named '" << it->first |
| 526 << "' to have a value of '" << it->second | 538 << "' to have a value of '" << it->second |
| 527 << "'. The actual value received was '" << it2->second | 539 << "'. The actual value received was '" << it2->second |
| 528 << "'." << std::endl; | 540 << "'." << std::endl; |
| 529 return false; | 541 return false; |
| 530 } | 542 } |
| 531 } | 543 } |
| 532 return true; | 544 return true; |
| 533 } | 545 } |
| 546 | |
| 547 // Default SPDY version for unit tests. | |
|
Ryan Hamilton
2012/03/14 17:32:08
// Version of SPDY protocol to be used
| |
| 548 int spdy_version_; | |
| 534 }; | 549 }; |
| 535 | 550 |
| 536 | 551 |
| 552 //----------------------------------------------------------------------------- | |
| 553 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. | |
| 554 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | |
| 555 SpdyFramerTest, | |
| 556 ::testing::Values(SPDY2, SPDY3)); | |
| 557 | |
| 537 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 558 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
| 538 TEST_F(SpdyFramerSpdy3Test, HeaderBlockInBuffer) { | 559 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
| 539 SpdyHeaderBlock headers; | 560 SpdyHeaderBlock headers; |
| 540 headers["alpha"] = "beta"; | 561 headers["alpha"] = "beta"; |
| 541 headers["gamma"] = "charlie"; | 562 headers["gamma"] = "charlie"; |
| 542 SpdyFramer framer(kVer); | 563 SpdyFramer framer(kVer); |
| 543 | 564 |
| 544 // Encode the header block into a SynStream frame. | 565 // Encode the header block into a SynStream frame. |
| 545 scoped_ptr<SpdySynStreamControlFrame> frame( | 566 scoped_ptr<SpdySynStreamControlFrame> frame( |
| 546 framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, &headers)); | 567 framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, &headers)); |
| 547 EXPECT_TRUE(frame.get() != NULL); | 568 EXPECT_TRUE(frame.get() != NULL); |
| 548 std::string serialized_headers(frame->header_block(), | 569 std::string serialized_headers(frame->header_block(), |
| 549 frame->header_block_len()); | 570 frame->header_block_len()); |
| 550 SpdyHeaderBlock new_headers; | 571 SpdyHeaderBlock new_headers; |
| 551 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 572 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
| 552 serialized_headers.size(), | 573 serialized_headers.size(), |
| 553 &new_headers)); | 574 &new_headers)); |
| 554 | 575 |
| 555 EXPECT_EQ(headers.size(), new_headers.size()); | 576 EXPECT_EQ(headers.size(), new_headers.size()); |
| 556 EXPECT_EQ(headers["alpha"], new_headers["alpha"]); | 577 EXPECT_EQ(headers["alpha"], new_headers["alpha"]); |
| 557 EXPECT_EQ(headers["gamma"], new_headers["gamma"]); | 578 EXPECT_EQ(headers["gamma"], new_headers["gamma"]); |
| 558 } | 579 } |
| 559 | 580 |
| 560 // Test that if there's not a full frame, we fail to parse it. | 581 // Test that if there's not a full frame, we fail to parse it. |
| 561 TEST_F(SpdyFramerSpdy3Test, UndersizedHeaderBlockInBuffer) { | 582 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { |
| 562 SpdyHeaderBlock headers; | 583 SpdyHeaderBlock headers; |
| 563 headers["alpha"] = "beta"; | 584 headers["alpha"] = "beta"; |
| 564 headers["gamma"] = "charlie"; | 585 headers["gamma"] = "charlie"; |
| 565 SpdyFramer framer(kVer); | 586 SpdyFramer framer(kVer); |
| 566 | 587 |
| 567 // Encode the header block into a SynStream frame. | 588 // Encode the header block into a SynStream frame. |
| 568 scoped_ptr<SpdySynStreamControlFrame> frame( | 589 scoped_ptr<SpdySynStreamControlFrame> frame( |
| 569 framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, &headers)); | 590 framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, false, &headers)); |
| 570 EXPECT_TRUE(frame.get() != NULL); | 591 EXPECT_TRUE(frame.get() != NULL); |
| 571 | 592 |
| 572 std::string serialized_headers(frame->header_block(), | 593 std::string serialized_headers(frame->header_block(), |
| 573 frame->header_block_len()); | 594 frame->header_block_len()); |
| 574 SpdyHeaderBlock new_headers; | 595 SpdyHeaderBlock new_headers; |
| 575 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 596 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
| 576 serialized_headers.size() - 2, | 597 serialized_headers.size() - 2, |
| 577 &new_headers)); | 598 &new_headers)); |
| 578 } | 599 } |
| 579 | 600 |
| 580 TEST_F(SpdyFramerSpdy3Test, OutOfOrderHeaders) { | 601 TEST_P(SpdyFramerTest, OutOfOrderHeaders) { |
| 581 // Frame builder with plentiful buffer size. | 602 // Frame builder with plentiful buffer size. |
| 582 SpdyFrameBuilder frame(1024); | 603 SpdyFrameBuilder frame(1024); |
| 583 | 604 |
| 584 frame.WriteUInt16(kControlFlagMask | 1); | 605 frame.WriteUInt16(kControlFlagMask | 1); |
| 585 frame.WriteUInt16(SYN_STREAM); | 606 frame.WriteUInt16(SYN_STREAM); |
| 586 frame.WriteUInt32(0); // Placeholder for the length. | 607 frame.WriteUInt32(0); // Placeholder for the length. |
| 587 frame.WriteUInt32(3); // stream_id | 608 frame.WriteUInt32(3); // stream_id |
| 588 frame.WriteUInt32(0); // Associated stream id | 609 frame.WriteUInt32(0); // Associated stream id |
| 589 frame.WriteUInt16(0); // Priority. | 610 frame.WriteUInt16(0); // Priority. |
| 590 | 611 |
| 591 if (SPDY_VERSION_FOR_TESTS < 3) { | 612 if (spdy_version_ < 3) { |
|
Ryan Hamilton
2012/03/14 17:32:08
I notice that this same predicate is used repeated
| |
| 592 frame.WriteUInt16(2); // Number of headers. | 613 frame.WriteUInt16(2); // Number of headers. |
| 593 frame.WriteString("gamma"); | 614 frame.WriteString("gamma"); |
| 594 frame.WriteString("gamma"); | 615 frame.WriteString("gamma"); |
| 595 frame.WriteString("alpha"); | 616 frame.WriteString("alpha"); |
| 596 frame.WriteString("alpha"); | 617 frame.WriteString("alpha"); |
| 597 } else { | 618 } else { |
| 598 frame.WriteUInt32(2); // Number of headers. | 619 frame.WriteUInt32(2); // Number of headers. |
| 599 frame.WriteStringPiece32("gamma"); | 620 frame.WriteStringPiece32("gamma"); |
| 600 frame.WriteStringPiece32("gamma"); | 621 frame.WriteStringPiece32("gamma"); |
| 601 frame.WriteStringPiece32("alpha"); | 622 frame.WriteStringPiece32("alpha"); |
| 602 frame.WriteStringPiece32("alpha"); | 623 frame.WriteStringPiece32("alpha"); |
| 603 } | 624 } |
| 604 // write the length | 625 // write the length |
| 605 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); | 626 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); |
| 606 | 627 |
| 607 SpdyHeaderBlock new_headers; | 628 SpdyHeaderBlock new_headers; |
| 608 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 629 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 609 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); | 630 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); |
| 610 std::string serialized_headers(syn_frame.header_block(), | 631 std::string serialized_headers(syn_frame.header_block(), |
| 611 syn_frame.header_block_len()); | 632 syn_frame.header_block_len()); |
| 612 SpdyFramer framer(kVer); | 633 SpdyFramer framer(kVer); |
| 613 framer.set_enable_compression(false); | 634 framer.set_enable_compression(false); |
| 614 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 635 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
| 615 serialized_headers.size(), | 636 serialized_headers.size(), |
| 616 &new_headers)); | 637 &new_headers)); |
| 617 } | 638 } |
| 618 | 639 |
| 619 TEST_F(SpdyFramerSpdy3Test, CreateCredential) { | 640 TEST_P(SpdyFramerTest, CreateCredential) { |
| 620 SpdyFramer framer(kVer); | 641 SpdyFramer framer(kVer); |
| 621 | 642 |
| 622 { | 643 { |
| 623 const char kDescription[] = "CREDENTIAL frame"; | 644 const char kDescription[] = "CREDENTIAL frame"; |
| 624 const unsigned char kFrameData[] = { | 645 const unsigned char kFrameData[] = { |
| 625 0x80, kVer, 0x00, 0x0A, | 646 0x80, kVer, 0x00, 0x0A, |
| 626 0x00, 0x00, 0x00, 0x33, | 647 0x00, 0x00, 0x00, 0x33, |
| 627 0x00, 0x03, 0x00, 0x00, | 648 0x00, 0x03, 0x00, 0x00, |
| 628 0x00, 0x05, 'p', 'r', | 649 0x00, 0x05, 'p', 'r', |
| 629 'o', 'o', 'f', 0x00, | 650 'o', 'o', 'f', 0x00, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 642 credential.slot = 3; | 663 credential.slot = 3; |
| 643 credential.proof = "proof"; | 664 credential.proof = "proof"; |
| 644 credential.certs.push_back("a cert"); | 665 credential.certs.push_back("a cert"); |
| 645 credential.certs.push_back("another cert"); | 666 credential.certs.push_back("another cert"); |
| 646 credential.certs.push_back("final cert"); | 667 credential.certs.push_back("final cert"); |
| 647 scoped_ptr<SpdyFrame> frame(framer.CreateCredentialFrame(credential)); | 668 scoped_ptr<SpdyFrame> frame(framer.CreateCredentialFrame(credential)); |
| 648 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 669 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 649 } | 670 } |
| 650 } | 671 } |
| 651 | 672 |
| 652 TEST_F(SpdyFramerSpdy3Test, ParseCredentialFrameData) { | 673 TEST_P(SpdyFramerTest, ParseCredentialFrameData) { |
| 653 SpdyFramer framer(kVer); | 674 SpdyFramer framer(kVer); |
| 654 | 675 |
| 655 { | 676 { |
| 656 unsigned char kFrameData[] = { | 677 unsigned char kFrameData[] = { |
| 657 0x80, kVer, 0x00, 0x0A, | 678 0x80, kVer, 0x00, 0x0A, |
| 658 0x00, 0x00, 0x00, 0x33, | 679 0x00, 0x00, 0x00, 0x33, |
| 659 0x00, 0x03, 0x00, 0x00, | 680 0x00, 0x03, 0x00, 0x00, |
| 660 0x00, 0x05, 'p', 'r', | 681 0x00, 0x05, 'p', 'r', |
| 661 'o', 'o', 'f', 0x00, | 682 'o', 'o', 'f', 0x00, |
| 662 0x00, 0x00, 0x06, 'a', | 683 0x00, 0x00, 0x06, 'a', |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 680 EXPECT_EQ("a cert", credential.certs.front()); | 701 EXPECT_EQ("a cert", credential.certs.front()); |
| 681 credential.certs.erase(credential.certs.begin()); | 702 credential.certs.erase(credential.certs.begin()); |
| 682 EXPECT_EQ("another cert", credential.certs.front()); | 703 EXPECT_EQ("another cert", credential.certs.front()); |
| 683 credential.certs.erase(credential.certs.begin()); | 704 credential.certs.erase(credential.certs.begin()); |
| 684 EXPECT_EQ("final cert", credential.certs.front()); | 705 EXPECT_EQ("final cert", credential.certs.front()); |
| 685 credential.certs.erase(credential.certs.begin()); | 706 credential.certs.erase(credential.certs.begin()); |
| 686 EXPECT_TRUE(credential.certs.empty()); | 707 EXPECT_TRUE(credential.certs.empty()); |
| 687 } | 708 } |
| 688 } | 709 } |
| 689 | 710 |
| 690 TEST_F(SpdyFramerSpdy3Test, DuplicateHeader) { | 711 TEST_P(SpdyFramerTest, DuplicateHeader) { |
| 691 // Frame builder with plentiful buffer size. | 712 // Frame builder with plentiful buffer size. |
| 692 SpdyFrameBuilder frame(1024); | 713 SpdyFrameBuilder frame(1024); |
| 693 | 714 |
| 694 frame.WriteUInt16(kControlFlagMask | 1); | 715 frame.WriteUInt16(kControlFlagMask | 1); |
| 695 frame.WriteUInt16(SYN_STREAM); | 716 frame.WriteUInt16(SYN_STREAM); |
| 696 frame.WriteUInt32(0); // Placeholder for the length. | 717 frame.WriteUInt32(0); // Placeholder for the length. |
| 697 frame.WriteUInt32(3); // stream_id | 718 frame.WriteUInt32(3); // stream_id |
| 698 frame.WriteUInt32(0); // associated stream id | 719 frame.WriteUInt32(0); // associated stream id |
| 699 frame.WriteUInt16(0); // Priority. | 720 frame.WriteUInt16(0); // Priority. |
| 700 | 721 |
| 701 if (SPDY_VERSION_FOR_TESTS < 3) { | 722 if (spdy_version_ < 3) { |
| 702 frame.WriteUInt16(2); // Number of headers. | 723 frame.WriteUInt16(2); // Number of headers. |
| 703 frame.WriteString("name"); | 724 frame.WriteString("name"); |
| 704 frame.WriteString("value1"); | 725 frame.WriteString("value1"); |
| 705 frame.WriteString("name"); | 726 frame.WriteString("name"); |
| 706 frame.WriteString("value2"); | 727 frame.WriteString("value2"); |
| 707 } else { | 728 } else { |
| 708 frame.WriteUInt32(2); // Number of headers. | 729 frame.WriteUInt32(2); // Number of headers. |
| 709 frame.WriteStringPiece32("name"); | 730 frame.WriteStringPiece32("name"); |
| 710 frame.WriteStringPiece32("value1"); | 731 frame.WriteStringPiece32("value1"); |
| 711 frame.WriteStringPiece32("name"); | 732 frame.WriteStringPiece32("name"); |
| 712 frame.WriteStringPiece32("value2"); | 733 frame.WriteStringPiece32("value2"); |
| 713 } | 734 } |
| 714 // write the length | 735 // write the length |
| 715 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); | 736 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); |
| 716 | 737 |
| 717 SpdyHeaderBlock new_headers; | 738 SpdyHeaderBlock new_headers; |
| 718 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 739 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 719 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); | 740 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); |
| 720 std::string serialized_headers(syn_frame.header_block(), | 741 std::string serialized_headers(syn_frame.header_block(), |
| 721 syn_frame.header_block_len()); | 742 syn_frame.header_block_len()); |
| 722 SpdyFramer framer(kVer); | 743 SpdyFramer framer(kVer); |
| 723 framer.set_enable_compression(false); | 744 framer.set_enable_compression(false); |
| 724 // This should fail because duplicate headers are verboten by the spec. | 745 // This should fail because duplicate headers are verboten by the spec. |
| 725 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 746 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
| 726 serialized_headers.size(), | 747 serialized_headers.size(), |
| 727 &new_headers)); | 748 &new_headers)); |
| 728 } | 749 } |
| 729 | 750 |
| 730 TEST_F(SpdyFramerSpdy3Test, MultiValueHeader) { | 751 TEST_P(SpdyFramerTest, MultiValueHeader) { |
| 731 // Frame builder with plentiful buffer size. | 752 // Frame builder with plentiful buffer size. |
| 732 SpdyFrameBuilder frame(1024); | 753 SpdyFrameBuilder frame(1024); |
| 733 | 754 |
| 734 frame.WriteUInt16(kControlFlagMask | 1); | 755 frame.WriteUInt16(kControlFlagMask | 1); |
| 735 frame.WriteUInt16(SYN_STREAM); | 756 frame.WriteUInt16(SYN_STREAM); |
| 736 frame.WriteUInt32(0); // Placeholder for the length. | 757 frame.WriteUInt32(0); // Placeholder for the length. |
| 737 frame.WriteUInt32(3); // stream_id | 758 frame.WriteUInt32(3); // stream_id |
| 738 frame.WriteUInt32(0); // associated stream id | 759 frame.WriteUInt32(0); // associated stream id |
| 739 frame.WriteUInt16(0); // Priority. | 760 frame.WriteUInt16(0); // Priority. |
| 740 | 761 |
| 741 std::string value("value1\0value2"); | 762 std::string value("value1\0value2"); |
| 742 if (SPDY_VERSION_FOR_TESTS < 3) { | 763 if (spdy_version_ < 3) { |
| 743 frame.WriteUInt16(1); // Number of headers. | 764 frame.WriteUInt16(1); // Number of headers. |
| 744 frame.WriteString("name"); | 765 frame.WriteString("name"); |
| 745 frame.WriteString(value); | 766 frame.WriteString(value); |
| 746 } else { | 767 } else { |
| 747 frame.WriteUInt32(1); // Number of headers. | 768 frame.WriteUInt32(1); // Number of headers. |
| 748 frame.WriteStringPiece32("name"); | 769 frame.WriteStringPiece32("name"); |
| 749 frame.WriteStringPiece32(value); | 770 frame.WriteStringPiece32(value); |
| 750 } | 771 } |
| 751 // write the length | 772 // write the length |
| 752 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); | 773 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); |
| 753 | 774 |
| 754 SpdyHeaderBlock new_headers; | 775 SpdyHeaderBlock new_headers; |
| 755 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 776 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 756 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); | 777 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); |
| 757 std::string serialized_headers(syn_frame.header_block(), | 778 std::string serialized_headers(syn_frame.header_block(), |
| 758 syn_frame.header_block_len()); | 779 syn_frame.header_block_len()); |
| 759 SpdyFramer framer(kVer); | 780 SpdyFramer framer(kVer); |
| 760 framer.set_enable_compression(false); | 781 framer.set_enable_compression(false); |
| 761 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), | 782 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), |
| 762 serialized_headers.size(), | 783 serialized_headers.size(), |
| 763 &new_headers)); | 784 &new_headers)); |
| 764 EXPECT_TRUE(new_headers.find("name") != new_headers.end()); | 785 EXPECT_TRUE(new_headers.find("name") != new_headers.end()); |
| 765 EXPECT_EQ(value, new_headers.find("name")->second); | 786 EXPECT_EQ(value, new_headers.find("name")->second); |
| 766 } | 787 } |
| 767 | 788 |
| 768 TEST_F(SpdyFramerSpdy3Test, BasicCompression) { | 789 TEST_P(SpdyFramerTest, BasicCompression) { |
| 769 SpdyHeaderBlock headers; | 790 SpdyHeaderBlock headers; |
| 770 headers["server"] = "SpdyServer 1.0"; | 791 headers["server"] = "SpdyServer 1.0"; |
| 771 headers["date"] = "Mon 12 Jan 2009 12:12:12 PST"; | 792 headers["date"] = "Mon 12 Jan 2009 12:12:12 PST"; |
| 772 headers["status"] = "200"; | 793 headers["status"] = "200"; |
| 773 headers["version"] = "HTTP/1.1"; | 794 headers["version"] = "HTTP/1.1"; |
| 774 headers["content-type"] = "text/html"; | 795 headers["content-type"] = "text/html"; |
| 775 headers["content-length"] = "12"; | 796 headers["content-length"] = "12"; |
| 776 | 797 |
| 777 SpdyFramer framer(kVer); | 798 SpdyFramer framer(kVer); |
| 778 framer.set_enable_compression(true); | 799 framer.set_enable_compression(true); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 804 // from scratch. | 825 // from scratch. |
| 805 scoped_ptr<SpdySynStreamControlFrame> | 826 scoped_ptr<SpdySynStreamControlFrame> |
| 806 uncompressed_frame(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, | 827 uncompressed_frame(framer.CreateSynStream(1, 0, 1, CONTROL_FLAG_NONE, |
| 807 false, &headers)); | 828 false, &headers)); |
| 808 EXPECT_EQ(frame3->length(), uncompressed_frame->length()); | 829 EXPECT_EQ(frame3->length(), uncompressed_frame->length()); |
| 809 EXPECT_EQ(0, | 830 EXPECT_EQ(0, |
| 810 memcmp(frame3->data(), uncompressed_frame->data(), | 831 memcmp(frame3->data(), uncompressed_frame->data(), |
| 811 SpdyFrame::kHeaderSize + uncompressed_frame->length())); | 832 SpdyFrame::kHeaderSize + uncompressed_frame->length())); |
| 812 } | 833 } |
| 813 | 834 |
| 814 TEST_F(SpdyFramerSpdy3Test, Basic) { | 835 TEST_P(SpdyFramerTest, Basic) { |
| 815 const unsigned char kV2Input[] = { | 836 const unsigned char kV2Input[] = { |
| 816 0x80, kVer, 0x00, 0x01, // SYN Stream #1 | 837 0x80, kVer, 0x00, 0x01, // SYN Stream #1 |
| 817 0x00, 0x00, 0x00, 0x14, | 838 0x00, 0x00, 0x00, 0x14, |
| 818 0x00, 0x00, 0x00, 0x01, | 839 0x00, 0x00, 0x00, 0x01, |
| 819 0x00, 0x00, 0x00, 0x00, | 840 0x00, 0x00, 0x00, 0x00, |
| 820 0x00, 0x00, 0x00, 0x01, | 841 0x00, 0x00, 0x00, 0x01, |
| 821 0x00, 0x02, 'h', 'h', | 842 0x00, 0x02, 'h', 'h', |
| 822 0x00, 0x02, 'v', 'v', | 843 0x00, 0x02, 'v', 'v', |
| 823 | 844 |
| 824 0x80, kVer, 0x00, 0x08, // HEADERS on Stream #1 | 845 0x80, kVer, 0x00, 0x08, // HEADERS on Stream #1 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 918 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 939 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 919 0x00, 0x00, 0x00, 0x00, | 940 0x00, 0x00, 0x00, 0x00, |
| 920 | 941 |
| 921 0x80, kVer, 0x00, 0x03, // RST_STREAM on Stream #3 | 942 0x80, kVer, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 922 0x00, 0x00, 0x00, 0x08, | 943 0x00, 0x00, 0x00, 0x08, |
| 923 0x00, 0x00, 0x00, 0x03, | 944 0x00, 0x00, 0x00, 0x03, |
| 924 0x00, 0x00, 0x00, 0x00, | 945 0x00, 0x00, 0x00, 0x00, |
| 925 }; | 946 }; |
| 926 | 947 |
| 927 TestSpdyVisitor visitor; | 948 TestSpdyVisitor visitor; |
| 928 if (SPDY_VERSION_FOR_TESTS < 3) { | 949 if (spdy_version_ < 3) { |
| 929 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 950 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 930 } else { | 951 } else { |
| 931 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 952 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| 932 } | 953 } |
| 933 | 954 |
| 934 EXPECT_EQ(0, visitor.error_count_); | 955 EXPECT_EQ(0, visitor.error_count_); |
| 935 EXPECT_EQ(2, visitor.syn_frame_count_); | 956 EXPECT_EQ(2, visitor.syn_frame_count_); |
| 936 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 957 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
| 937 EXPECT_EQ(1, visitor.headers_frame_count_); | 958 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 938 EXPECT_EQ(24, visitor.data_bytes_); | 959 EXPECT_EQ(24, visitor.data_bytes_); |
| 939 EXPECT_EQ(2, visitor.fin_frame_count_); | 960 EXPECT_EQ(2, visitor.fin_frame_count_); |
| 940 EXPECT_EQ(0, visitor.fin_flag_count_); | 961 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 941 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 962 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 942 EXPECT_EQ(4, visitor.data_frame_count_); | 963 EXPECT_EQ(4, visitor.data_frame_count_); |
| 943 } | 964 } |
| 944 | 965 |
| 945 // Test that the FIN flag on a data frame signifies EOF. | 966 // Test that the FIN flag on a data frame signifies EOF. |
| 946 TEST_F(SpdyFramerSpdy3Test, FinOnDataFrame) { | 967 TEST_P(SpdyFramerTest, FinOnDataFrame) { |
| 947 const unsigned char kV2Input[] = { | 968 const unsigned char kV2Input[] = { |
| 948 0x80, kVer, 0x00, 0x01, // SYN Stream #1 | 969 0x80, kVer, 0x00, 0x01, // SYN Stream #1 |
| 949 0x00, 0x00, 0x00, 0x14, | 970 0x00, 0x00, 0x00, 0x14, |
| 950 0x00, 0x00, 0x00, 0x01, | 971 0x00, 0x00, 0x00, 0x01, |
| 951 0x00, 0x00, 0x00, 0x00, | 972 0x00, 0x00, 0x00, 0x00, |
| 952 0x00, 0x00, 0x00, 0x01, | 973 0x00, 0x00, 0x00, 0x01, |
| 953 0x00, 0x02, 'h', 'h', | 974 0x00, 0x02, 'h', 'h', |
| 954 0x00, 0x02, 'v', 'v', | 975 0x00, 0x02, 'v', 'v', |
| 955 | 976 |
| 956 0x80, kVer, 0x00, 0x02, // SYN REPLY Stream #1 | 977 0x80, kVer, 0x00, 0x02, // SYN REPLY Stream #1 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 995 0xde, 0xad, 0xbe, 0xef, | 1016 0xde, 0xad, 0xbe, 0xef, |
| 996 0xde, 0xad, 0xbe, 0xef, | 1017 0xde, 0xad, 0xbe, 0xef, |
| 997 0xde, 0xad, 0xbe, 0xef, | 1018 0xde, 0xad, 0xbe, 0xef, |
| 998 | 1019 |
| 999 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF | 1020 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF |
| 1000 0x01, 0x00, 0x00, 0x04, | 1021 0x01, 0x00, 0x00, 0x04, |
| 1001 0xde, 0xad, 0xbe, 0xef, | 1022 0xde, 0xad, 0xbe, 0xef, |
| 1002 }; | 1023 }; |
| 1003 | 1024 |
| 1004 TestSpdyVisitor visitor; | 1025 TestSpdyVisitor visitor; |
| 1005 if (SPDY_VERSION_FOR_TESTS < 3) { | 1026 if (spdy_version_ < 3) { |
| 1006 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1027 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1007 } else { | 1028 } else { |
| 1008 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1029 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| 1009 } | 1030 } |
| 1010 | 1031 |
| 1011 EXPECT_EQ(0, visitor.error_count_); | 1032 EXPECT_EQ(0, visitor.error_count_); |
| 1012 EXPECT_EQ(1, visitor.syn_frame_count_); | 1033 EXPECT_EQ(1, visitor.syn_frame_count_); |
| 1013 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | 1034 EXPECT_EQ(1, visitor.syn_reply_frame_count_); |
| 1014 EXPECT_EQ(0, visitor.headers_frame_count_); | 1035 EXPECT_EQ(0, visitor.headers_frame_count_); |
| 1015 EXPECT_EQ(16, visitor.data_bytes_); | 1036 EXPECT_EQ(16, visitor.data_bytes_); |
| 1016 EXPECT_EQ(0, visitor.fin_frame_count_); | 1037 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1017 EXPECT_EQ(0, visitor.fin_flag_count_); | 1038 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1018 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1039 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1019 EXPECT_EQ(2, visitor.data_frame_count_); | 1040 EXPECT_EQ(2, visitor.data_frame_count_); |
| 1020 } | 1041 } |
| 1021 | 1042 |
| 1022 // Test that the FIN flag on a SYN reply frame signifies EOF. | 1043 // Test that the FIN flag on a SYN reply frame signifies EOF. |
| 1023 TEST_F(SpdyFramerSpdy3Test, FinOnSynReplyFrame) { | 1044 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { |
| 1024 const unsigned char kV2Input[] = { | 1045 const unsigned char kV2Input[] = { |
| 1025 0x80, kVer, 0x00, 0x01, // SYN Stream #1 | 1046 0x80, kVer, 0x00, 0x01, // SYN Stream #1 |
| 1026 0x00, 0x00, 0x00, 0x14, | 1047 0x00, 0x00, 0x00, 0x14, |
| 1027 0x00, 0x00, 0x00, 0x01, | 1048 0x00, 0x00, 0x00, 0x01, |
| 1028 0x00, 0x00, 0x00, 0x00, | 1049 0x00, 0x00, 0x00, 0x00, |
| 1029 0x00, 0x00, 0x00, 0x01, | 1050 0x00, 0x00, 0x00, 0x01, |
| 1030 0x00, 0x02, 'h', 'h', | 1051 0x00, 0x02, 'h', 'h', |
| 1031 0x00, 0x02, 'v', 'v', | 1052 0x00, 0x02, 'v', 'v', |
| 1032 | 1053 |
| 1033 0x80, kVer, 0x00, 0x02, // SYN REPLY Stream #1 | 1054 0x80, kVer, 0x00, 0x02, // SYN REPLY Stream #1 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1054 0x00, 0x00, 0x00, 0x01, | 1075 0x00, 0x00, 0x00, 0x01, |
| 1055 0x00, 0x00, 0x00, 0x00, | 1076 0x00, 0x00, 0x00, 0x00, |
| 1056 0x00, 0x00, 0x00, 0x00, | 1077 0x00, 0x00, 0x00, 0x00, |
| 1057 0x00, 0x01, 0x00, 0x00, | 1078 0x00, 0x01, 0x00, 0x00, |
| 1058 0x00, 0x02, 'a', 'a', | 1079 0x00, 0x02, 'a', 'a', |
| 1059 0x00, 0x00, 0x00, 0x02, | 1080 0x00, 0x00, 0x00, 0x02, |
| 1060 'b', 'b', | 1081 'b', 'b', |
| 1061 }; | 1082 }; |
| 1062 | 1083 |
| 1063 TestSpdyVisitor visitor; | 1084 TestSpdyVisitor visitor; |
| 1064 if (SPDY_VERSION_FOR_TESTS < 3) { | 1085 if (spdy_version_ < 3) { |
| 1065 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1086 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1066 } else { | 1087 } else { |
| 1067 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1088 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| 1068 } | 1089 } |
| 1069 | 1090 |
| 1070 EXPECT_EQ(0, visitor.error_count_); | 1091 EXPECT_EQ(0, visitor.error_count_); |
| 1071 EXPECT_EQ(1, visitor.syn_frame_count_); | 1092 EXPECT_EQ(1, visitor.syn_frame_count_); |
| 1072 EXPECT_EQ(1, visitor.syn_reply_frame_count_); | 1093 EXPECT_EQ(1, visitor.syn_reply_frame_count_); |
| 1073 EXPECT_EQ(0, visitor.headers_frame_count_); | 1094 EXPECT_EQ(0, visitor.headers_frame_count_); |
| 1074 EXPECT_EQ(0, visitor.data_bytes_); | 1095 EXPECT_EQ(0, visitor.data_bytes_); |
| 1075 EXPECT_EQ(0, visitor.fin_frame_count_); | 1096 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1076 EXPECT_EQ(1, visitor.fin_flag_count_); | 1097 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 1077 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1098 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1078 EXPECT_EQ(0, visitor.data_frame_count_); | 1099 EXPECT_EQ(0, visitor.data_frame_count_); |
| 1079 } | 1100 } |
| 1080 | 1101 |
| 1081 TEST_F(SpdyFramerSpdy3Test, HeaderCompression) { | 1102 TEST_P(SpdyFramerTest, HeaderCompression) { |
| 1082 SpdyFramer send_framer(kVer); | 1103 SpdyFramer send_framer(kVer); |
| 1083 SpdyFramer recv_framer(kVer); | 1104 SpdyFramer recv_framer(kVer); |
| 1084 | 1105 |
| 1085 send_framer.set_enable_compression(true); | 1106 send_framer.set_enable_compression(true); |
| 1086 recv_framer.set_enable_compression(true); | 1107 recv_framer.set_enable_compression(true); |
| 1087 | 1108 |
| 1088 const char kHeader1[] = "header1"; | 1109 const char kHeader1[] = "header1"; |
| 1089 const char kHeader2[] = "header2"; | 1110 const char kHeader2[] = "header2"; |
| 1090 const char kHeader3[] = "header3"; | 1111 const char kHeader3[] = "header3"; |
| 1091 const char kValue1[] = "value1"; | 1112 const char kValue1[] = "value1"; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1150 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); | 1171 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); |
| 1151 | 1172 |
| 1152 // We didn't have data streams, so we shouldn't have (de)compressors. | 1173 // We didn't have data streams, so we shouldn't have (de)compressors. |
| 1153 EXPECT_EQ(0, send_framer.num_stream_compressors()); | 1174 EXPECT_EQ(0, send_framer.num_stream_compressors()); |
| 1154 EXPECT_EQ(0, send_framer.num_stream_decompressors()); | 1175 EXPECT_EQ(0, send_framer.num_stream_decompressors()); |
| 1155 EXPECT_EQ(0, recv_framer.num_stream_compressors()); | 1176 EXPECT_EQ(0, recv_framer.num_stream_compressors()); |
| 1156 EXPECT_EQ(0, recv_framer.num_stream_decompressors()); | 1177 EXPECT_EQ(0, recv_framer.num_stream_decompressors()); |
| 1157 } | 1178 } |
| 1158 | 1179 |
| 1159 // Verify we don't leak when we leave streams unclosed | 1180 // Verify we don't leak when we leave streams unclosed |
| 1160 TEST_F(SpdyFramerSpdy3Test, UnclosedStreamDataCompressors) { | 1181 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressors) { |
| 1161 SpdyFramer send_framer(kVer); | 1182 SpdyFramer send_framer(kVer); |
| 1162 | 1183 |
| 1163 send_framer.set_enable_compression(true); | 1184 send_framer.set_enable_compression(true); |
| 1164 | 1185 |
| 1165 const char kHeader1[] = "header1"; | 1186 const char kHeader1[] = "header1"; |
| 1166 const char kHeader2[] = "header2"; | 1187 const char kHeader2[] = "header2"; |
| 1167 const char kValue1[] = "value1"; | 1188 const char kValue1[] = "value1"; |
| 1168 const char kValue2[] = "value2"; | 1189 const char kValue2[] = "value2"; |
| 1169 | 1190 |
| 1170 SpdyHeaderBlock block; | 1191 SpdyHeaderBlock block; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1203 | 1224 |
| 1204 // We closed the streams, so all compressors should be down. | 1225 // We closed the streams, so all compressors should be down. |
| 1205 EXPECT_EQ(0, visitor.framer_.num_stream_compressors()); | 1226 EXPECT_EQ(0, visitor.framer_.num_stream_compressors()); |
| 1206 EXPECT_EQ(0, visitor.framer_.num_stream_decompressors()); | 1227 EXPECT_EQ(0, visitor.framer_.num_stream_decompressors()); |
| 1207 EXPECT_EQ(0, send_framer.num_stream_compressors()); | 1228 EXPECT_EQ(0, send_framer.num_stream_compressors()); |
| 1208 EXPECT_EQ(0, send_framer.num_stream_decompressors()); | 1229 EXPECT_EQ(0, send_framer.num_stream_decompressors()); |
| 1209 } | 1230 } |
| 1210 | 1231 |
| 1211 // Verify we can decompress the stream even if handed over to the | 1232 // Verify we can decompress the stream even if handed over to the |
| 1212 // framer 1 byte at a time. | 1233 // framer 1 byte at a time. |
| 1213 TEST_F(SpdyFramerSpdy3Test, UnclosedStreamDataCompressorsOneByteAtATime) { | 1234 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { |
| 1214 SpdyFramer send_framer(kVer); | 1235 SpdyFramer send_framer(kVer); |
| 1215 | 1236 |
| 1216 send_framer.set_enable_compression(true); | 1237 send_framer.set_enable_compression(true); |
| 1217 | 1238 |
| 1218 const char kHeader1[] = "header1"; | 1239 const char kHeader1[] = "header1"; |
| 1219 const char kHeader2[] = "header2"; | 1240 const char kHeader2[] = "header2"; |
| 1220 const char kValue1[] = "value1"; | 1241 const char kValue1[] = "value1"; |
| 1221 const char kValue2[] = "value2"; | 1242 const char kValue2[] = "value2"; |
| 1222 | 1243 |
| 1223 SpdyHeaderBlock block; | 1244 SpdyHeaderBlock block; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1285 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1265 EXPECT_EQ(1, visitor.data_frame_count_); | 1286 EXPECT_EQ(1, visitor.data_frame_count_); |
| 1266 | 1287 |
| 1267 // We closed the streams, so all compressors should be down. | 1288 // We closed the streams, so all compressors should be down. |
| 1268 EXPECT_EQ(0, visitor.framer_.num_stream_compressors()); | 1289 EXPECT_EQ(0, visitor.framer_.num_stream_compressors()); |
| 1269 EXPECT_EQ(0, visitor.framer_.num_stream_decompressors()); | 1290 EXPECT_EQ(0, visitor.framer_.num_stream_decompressors()); |
| 1270 EXPECT_EQ(0, send_framer.num_stream_compressors()); | 1291 EXPECT_EQ(0, send_framer.num_stream_compressors()); |
| 1271 EXPECT_EQ(0, send_framer.num_stream_decompressors()); | 1292 EXPECT_EQ(0, send_framer.num_stream_decompressors()); |
| 1272 } | 1293 } |
| 1273 | 1294 |
| 1274 TEST_F(SpdyFramerSpdy3Test, WindowUpdateFrame) { | 1295 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
| 1275 SpdyFramer framer(kVer); | 1296 SpdyFramer framer(kVer); |
| 1276 scoped_ptr<SpdyWindowUpdateControlFrame> window_update_frame( | 1297 scoped_ptr<SpdyWindowUpdateControlFrame> window_update_frame( |
| 1277 framer.CreateWindowUpdate(1, 0x12345678)); | 1298 framer.CreateWindowUpdate(1, 0x12345678)); |
| 1278 | 1299 |
| 1279 const unsigned char expected_data_frame[] = { | 1300 const unsigned char expected_data_frame[] = { |
| 1280 0x80, kVer, 0x00, 0x09, | 1301 0x80, kVer, 0x00, 0x09, |
| 1281 0x00, 0x00, 0x00, 0x08, | 1302 0x00, 0x00, 0x00, 0x08, |
| 1282 0x00, 0x00, 0x00, 0x01, | 1303 0x00, 0x00, 0x00, 0x01, |
| 1283 0x12, 0x34, 0x56, 0x78 | 1304 0x12, 0x34, 0x56, 0x78 |
| 1284 }; | 1305 }; |
| 1285 | 1306 |
| 1286 EXPECT_EQ(16u, window_update_frame->size()); | 1307 EXPECT_EQ(16u, window_update_frame->size()); |
| 1287 EXPECT_EQ(0, | 1308 EXPECT_EQ(0, |
| 1288 memcmp(window_update_frame->data(), expected_data_frame, 16)); | 1309 memcmp(window_update_frame->data(), expected_data_frame, 16)); |
| 1289 } | 1310 } |
| 1290 | 1311 |
| 1291 TEST_F(SpdyFramerSpdy3Test, CreateDataFrame) { | 1312 TEST_P(SpdyFramerTest, CreateDataFrame) { |
| 1292 SpdyFramer framer(kVer); | 1313 SpdyFramer framer(kVer); |
| 1293 | 1314 |
| 1294 { | 1315 { |
| 1295 const char kDescription[] = "'hello' data frame, no FIN"; | 1316 const char kDescription[] = "'hello' data frame, no FIN"; |
| 1296 const unsigned char kFrameData[] = { | 1317 const unsigned char kFrameData[] = { |
| 1297 0x00, 0x00, 0x00, 0x01, | 1318 0x00, 0x00, 0x00, 0x01, |
| 1298 0x00, 0x00, 0x00, 0x05, | 1319 0x00, 0x00, 0x00, 0x05, |
| 1299 'h', 'e', 'l', 'l', | 1320 'h', 'e', 'l', 'l', |
| 1300 'o' | 1321 'o' |
| 1301 }; | 1322 }; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1367 new unsigned char[kFrameSize]); | 1388 new unsigned char[kFrameSize]); |
| 1368 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); | 1389 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); |
| 1369 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | 1390 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); |
| 1370 | 1391 |
| 1371 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame( | 1392 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame( |
| 1372 1, kData.data(), kData.size(), DATA_FLAG_FIN)); | 1393 1, kData.data(), kData.size(), DATA_FLAG_FIN)); |
| 1373 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); | 1394 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); |
| 1374 } | 1395 } |
| 1375 } | 1396 } |
| 1376 | 1397 |
| 1377 TEST_F(SpdyFramerSpdy3Test, CreateSynStreamUncompressed) { | 1398 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { |
| 1378 SpdyFramer framer(kVer); | 1399 SpdyFramer framer(kVer); |
| 1379 framer.set_enable_compression(false); | 1400 framer.set_enable_compression(false); |
| 1380 | 1401 |
| 1381 { | 1402 { |
| 1382 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; | 1403 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; |
| 1383 | 1404 |
| 1384 SpdyHeaderBlock headers; | 1405 SpdyHeaderBlock headers; |
| 1385 headers["bar"] = "foo"; | 1406 headers["bar"] = "foo"; |
| 1386 headers["foo"] = "bar"; | 1407 headers["foo"] = "bar"; |
| 1387 | 1408 |
| 1388 const unsigned char kPri = | 1409 const unsigned char kPri = (spdy_version_ != 2) ? 0xE0 : 0xC0; |
| 1389 (SPDY_VERSION_FOR_TESTS != 2) ? 0xE0 : 0xC0; | |
| 1390 const unsigned char kV2FrameData[] = { | 1410 const unsigned char kV2FrameData[] = { |
| 1391 0x80, kVer, 0x00, 0x01, | 1411 0x80, kVer, 0x00, 0x01, |
| 1392 0x00, 0x00, 0x00, 0x20, | 1412 0x00, 0x00, 0x00, 0x20, |
| 1393 0x00, 0x00, 0x00, 0x01, | 1413 0x00, 0x00, 0x00, 0x01, |
| 1394 0x00, 0x00, 0x00, 0x00, | 1414 0x00, 0x00, 0x00, 0x00, |
| 1395 kPri, 0x00, 0x00, 0x02, | 1415 kPri, 0x00, 0x00, 0x02, |
| 1396 0x00, 0x03, 'b', 'a', | 1416 0x00, 0x03, 'b', 'a', |
| 1397 'r', 0x00, 0x03, 'f', | 1417 'r', 0x00, 0x03, 'f', |
| 1398 'o', 'o', 0x00, 0x03, | 1418 'o', 'o', 0x00, 0x03, |
| 1399 'f', 'o', 'o', 0x00, | 1419 'f', 'o', 'o', 0x00, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1411 0x03, 'f', 'o', 'o', | 1431 0x03, 'f', 'o', 'o', |
| 1412 0x00, 0x00, 0x00, 0x03, | 1432 0x00, 0x00, 0x00, 0x03, |
| 1413 'f', 'o', 'o', 0x00, | 1433 'f', 'o', 'o', 0x00, |
| 1414 0x00, 0x00, 0x03, 'b', | 1434 0x00, 0x00, 0x03, 'b', |
| 1415 'a', 'r' | 1435 'a', 'r' |
| 1416 }; | 1436 }; |
| 1417 scoped_ptr<SpdySynStreamControlFrame> frame(framer.CreateSynStream( | 1437 scoped_ptr<SpdySynStreamControlFrame> frame(framer.CreateSynStream( |
| 1418 1, 0, framer.GetLowestPriority(), CONTROL_FLAG_NONE, false, &headers)); | 1438 1, 0, framer.GetLowestPriority(), CONTROL_FLAG_NONE, false, &headers)); |
| 1419 CompareFrame(kDescription, | 1439 CompareFrame(kDescription, |
| 1420 *frame, | 1440 *frame, |
| 1421 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1441 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1422 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1442 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1423 : arraysize(kV3FrameData)); | 1443 : arraysize(kV3FrameData)); |
| 1424 EXPECT_EQ(1u, SpdyFramer::GetControlFrameStreamId(frame.get())); | 1444 EXPECT_EQ(1u, SpdyFramer::GetControlFrameStreamId(frame.get())); |
| 1425 } | 1445 } |
| 1426 | 1446 |
| 1427 { | 1447 { |
| 1428 const char kDescription[] = | 1448 const char kDescription[] = |
| 1429 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " | 1449 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " |
| 1430 "max stream ID"; | 1450 "max stream ID"; |
| 1431 | 1451 |
| 1432 SpdyHeaderBlock headers; | 1452 SpdyHeaderBlock headers; |
| 1433 headers[""] = "foo"; | 1453 headers[""] = "foo"; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1457 'o', 0x00, 0x00, 0x00, | 1477 'o', 0x00, 0x00, 0x00, |
| 1458 0x03, 'f', 'o', 'o', | 1478 0x03, 'f', 'o', 'o', |
| 1459 0x00, 0x00, 0x00, 0x03, | 1479 0x00, 0x00, 0x00, 0x03, |
| 1460 'b', 'a', 'r' | 1480 'b', 'a', 'r' |
| 1461 }; | 1481 }; |
| 1462 scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( | 1482 scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( |
| 1463 0x7fffffff, 0x7fffffff, framer.GetHighestPriority(), CONTROL_FLAG_FIN, | 1483 0x7fffffff, 0x7fffffff, framer.GetHighestPriority(), CONTROL_FLAG_FIN, |
| 1464 false, &headers)); | 1484 false, &headers)); |
| 1465 CompareFrame(kDescription, | 1485 CompareFrame(kDescription, |
| 1466 *frame, | 1486 *frame, |
| 1467 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1487 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1468 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1488 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1469 : arraysize(kV3FrameData)); | 1489 : arraysize(kV3FrameData)); |
| 1470 } | 1490 } |
| 1471 | 1491 |
| 1472 { | 1492 { |
| 1473 const char kDescription[] = | 1493 const char kDescription[] = |
| 1474 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " | 1494 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " |
| 1475 "max stream ID"; | 1495 "max stream ID"; |
| 1476 | 1496 |
| 1477 SpdyHeaderBlock headers; | 1497 SpdyHeaderBlock headers; |
| 1478 headers["bar"] = "foo"; | 1498 headers["bar"] = "foo"; |
| 1479 headers["foo"] = ""; | 1499 headers["foo"] = ""; |
| 1480 | 1500 |
| 1481 const unsigned char kPri = | 1501 const unsigned char kPri = (spdy_version_ != 2) ? 0x20 : 0x40; |
| 1482 (SPDY_VERSION_FOR_TESTS != 2) ? 0x20 : 0x40; | |
| 1483 const unsigned char kV2FrameData[] = { | 1502 const unsigned char kV2FrameData[] = { |
| 1484 0x80, kVer, 0x00, 0x01, | 1503 0x80, kVer, 0x00, 0x01, |
| 1485 0x01, 0x00, 0x00, 0x1D, | 1504 0x01, 0x00, 0x00, 0x1D, |
| 1486 0x7f, 0xff, 0xff, 0xff, | 1505 0x7f, 0xff, 0xff, 0xff, |
| 1487 0x7f, 0xff, 0xff, 0xff, | 1506 0x7f, 0xff, 0xff, 0xff, |
| 1488 kPri, 0x00, 0x00, 0x02, | 1507 kPri, 0x00, 0x00, 0x02, |
| 1489 0x00, 0x03, 'b', 'a', | 1508 0x00, 0x03, 'b', 'a', |
| 1490 'r', 0x00, 0x03, 'f', | 1509 'r', 0x00, 0x03, 'f', |
| 1491 'o', 'o', 0x00, 0x03, | 1510 'o', 'o', 0x00, 0x03, |
| 1492 'f', 'o', 'o', 0x00, | 1511 'f', 'o', 'o', 0x00, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1503 'r', 0x00, 0x00, 0x00, | 1522 'r', 0x00, 0x00, 0x00, |
| 1504 0x03, 'f', 'o', 'o', | 1523 0x03, 'f', 'o', 'o', |
| 1505 0x00, 0x00, 0x00, 0x03, | 1524 0x00, 0x00, 0x00, 0x03, |
| 1506 'f', 'o', 'o', 0x00, | 1525 'f', 'o', 'o', 0x00, |
| 1507 0x00, 0x00, 0x00 | 1526 0x00, 0x00, 0x00 |
| 1508 }; | 1527 }; |
| 1509 scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( | 1528 scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( |
| 1510 0x7fffffff, 0x7fffffff, 1, CONTROL_FLAG_FIN, false, &headers)); | 1529 0x7fffffff, 0x7fffffff, 1, CONTROL_FLAG_FIN, false, &headers)); |
| 1511 CompareFrame(kDescription, | 1530 CompareFrame(kDescription, |
| 1512 *frame, | 1531 *frame, |
| 1513 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1532 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1514 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1533 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1515 : arraysize(kV3FrameData)); | 1534 : arraysize(kV3FrameData)); |
| 1516 } | 1535 } |
| 1517 } | 1536 } |
| 1518 | 1537 |
| 1519 TEST_F(SpdyFramerSpdy3Test, CreateSynStreamCompressed) { | 1538 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { |
| 1520 SpdyFramer framer(kVer); | 1539 SpdyFramer framer(kVer); |
| 1521 framer.set_enable_compression(true); | 1540 framer.set_enable_compression(true); |
| 1522 | 1541 |
| 1523 { | 1542 { |
| 1524 const char kDescription[] = | 1543 const char kDescription[] = |
| 1525 "SYN_STREAM frame, low pri, no FIN"; | 1544 "SYN_STREAM frame, low pri, no FIN"; |
| 1526 | 1545 |
| 1527 SpdyHeaderBlock headers; | 1546 SpdyHeaderBlock headers; |
| 1528 headers["bar"] = "foo"; | 1547 headers["bar"] = "foo"; |
| 1529 headers["foo"] = "bar"; | 1548 headers["foo"] = "bar"; |
| 1530 | 1549 |
| 1531 const SpdyPriority priority = | 1550 const SpdyPriority priority = (spdy_version_ != 2) ? 4 : 2; |
| 1532 (SPDY_VERSION_FOR_TESTS != 2) ? 4 : 2; | |
| 1533 const unsigned char kV2FrameData[] = { | 1551 const unsigned char kV2FrameData[] = { |
| 1534 0x80, kVer, 0x00, 0x01, | 1552 0x80, kVer, 0x00, 0x01, |
| 1535 0x00, 0x00, 0x00, 0x25, | 1553 0x00, 0x00, 0x00, 0x25, |
| 1536 0x00, 0x00, 0x00, 0x01, | 1554 0x00, 0x00, 0x00, 0x01, |
| 1537 0x00, 0x00, 0x00, 0x00, | 1555 0x00, 0x00, 0x00, 0x00, |
| 1538 0x80, 0x00, 0x38, 0xea, | 1556 0x80, 0x00, 0x38, 0xea, |
| 1539 0xdf, 0xa2, 0x51, 0xb2, | 1557 0xdf, 0xa2, 0x51, 0xb2, |
| 1540 0x62, 0x60, 0x62, 0x60, | 1558 0x62, 0x60, 0x62, 0x60, |
| 1541 0x4e, 0x4a, 0x2c, 0x62, | 1559 0x4e, 0x4a, 0x2c, 0x62, |
| 1542 0x60, 0x4e, 0xcb, 0xcf, | 1560 0x60, 0x4e, 0xcb, 0xcf, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1555 0xC2, 0x4B, 0x4A, 0x04, | 1573 0xC2, 0x4B, 0x4A, 0x04, |
| 1556 0xE5, 0x0B, 0xE6, 0xB4, | 1574 0xE5, 0x0B, 0xE6, 0xB4, |
| 1557 0xFC, 0x7C, 0x24, 0x0A, | 1575 0xFC, 0x7C, 0x24, 0x0A, |
| 1558 0x28, 0x08, 0x00, 0x00, | 1576 0x28, 0x08, 0x00, 0x00, |
| 1559 0x00, 0xFF, 0xFF | 1577 0x00, 0xFF, 0xFF |
| 1560 }; | 1578 }; |
| 1561 scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( | 1579 scoped_ptr<SpdyFrame> frame(framer.CreateSynStream( |
| 1562 1, 0, priority, CONTROL_FLAG_NONE, true, &headers)); | 1580 1, 0, priority, CONTROL_FLAG_NONE, true, &headers)); |
| 1563 CompareFrame(kDescription, | 1581 CompareFrame(kDescription, |
| 1564 *frame, | 1582 *frame, |
| 1565 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1583 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1566 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1584 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1567 : arraysize(kV3FrameData)); | 1585 : arraysize(kV3FrameData)); |
| 1568 } | 1586 } |
| 1569 } | 1587 } |
| 1570 | 1588 |
| 1571 TEST_F(SpdyFramerSpdy3Test, CreateSynReplyUncompressed) { | 1589 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
| 1572 SpdyFramer framer(kVer); | 1590 SpdyFramer framer(kVer); |
| 1573 framer.set_enable_compression(false); | 1591 framer.set_enable_compression(false); |
| 1574 | 1592 |
| 1575 { | 1593 { |
| 1576 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 1594 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
| 1577 | 1595 |
| 1578 SpdyHeaderBlock headers; | 1596 SpdyHeaderBlock headers; |
| 1579 headers["bar"] = "foo"; | 1597 headers["bar"] = "foo"; |
| 1580 headers["foo"] = "bar"; | 1598 headers["foo"] = "bar"; |
| 1581 | 1599 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1600 0x00, 0x00, 0x03, 'f', | 1618 0x00, 0x00, 0x03, 'f', |
| 1601 'o', 'o', 0x00, 0x00, | 1619 'o', 'o', 0x00, 0x00, |
| 1602 0x00, 0x03, 'f', 'o', | 1620 0x00, 0x03, 'f', 'o', |
| 1603 'o', 0x00, 0x00, 0x00, | 1621 'o', 0x00, 0x00, 0x00, |
| 1604 0x03, 'b', 'a', 'r' | 1622 0x03, 'b', 'a', 'r' |
| 1605 }; | 1623 }; |
| 1606 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( | 1624 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( |
| 1607 1, CONTROL_FLAG_NONE, false, &headers)); | 1625 1, CONTROL_FLAG_NONE, false, &headers)); |
| 1608 CompareFrame(kDescription, | 1626 CompareFrame(kDescription, |
| 1609 *frame, | 1627 *frame, |
| 1610 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1628 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1611 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1629 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1612 : arraysize(kV3FrameData)); | 1630 : arraysize(kV3FrameData)); |
| 1613 } | 1631 } |
| 1614 | 1632 |
| 1615 { | 1633 { |
| 1616 const char kDescription[] = | 1634 const char kDescription[] = |
| 1617 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; | 1635 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; |
| 1618 | 1636 |
| 1619 SpdyHeaderBlock headers; | 1637 SpdyHeaderBlock headers; |
| 1620 headers[""] = "foo"; | 1638 headers[""] = "foo"; |
| 1621 headers["foo"] = "bar"; | 1639 headers["foo"] = "bar"; |
| 1622 | 1640 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1641 'f', 'o', 'o', 0x00, | 1659 'f', 'o', 'o', 0x00, |
| 1642 0x00, 0x00, 0x03, 'f', | 1660 0x00, 0x00, 0x03, 'f', |
| 1643 'o', 'o', 0x00, 0x00, | 1661 'o', 'o', 0x00, 0x00, |
| 1644 0x00, 0x03, 'b', 'a', | 1662 0x00, 0x03, 'b', 'a', |
| 1645 'r' | 1663 'r' |
| 1646 }; | 1664 }; |
| 1647 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( | 1665 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( |
| 1648 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); | 1666 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); |
| 1649 CompareFrame(kDescription, | 1667 CompareFrame(kDescription, |
| 1650 *frame, | 1668 *frame, |
| 1651 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1669 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1652 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1670 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1653 : arraysize(kV3FrameData)); | 1671 : arraysize(kV3FrameData)); |
| 1654 } | 1672 } |
| 1655 | 1673 |
| 1656 { | 1674 { |
| 1657 const char kDescription[] = | 1675 const char kDescription[] = |
| 1658 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; | 1676 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; |
| 1659 | 1677 |
| 1660 SpdyHeaderBlock headers; | 1678 SpdyHeaderBlock headers; |
| 1661 headers["bar"] = "foo"; | 1679 headers["bar"] = "foo"; |
| 1662 headers["foo"] = ""; | 1680 headers["foo"] = ""; |
| 1663 | 1681 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1682 0x00, 0x00, 0x03, 'f', | 1700 0x00, 0x00, 0x03, 'f', |
| 1683 'o', 'o', 0x00, 0x00, | 1701 'o', 'o', 0x00, 0x00, |
| 1684 0x00, 0x03, 'f', 'o', | 1702 0x00, 0x03, 'f', 'o', |
| 1685 'o', 0x00, 0x00, 0x00, | 1703 'o', 0x00, 0x00, 0x00, |
| 1686 0x00 | 1704 0x00 |
| 1687 }; | 1705 }; |
| 1688 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( | 1706 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( |
| 1689 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); | 1707 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); |
| 1690 CompareFrame(kDescription, | 1708 CompareFrame(kDescription, |
| 1691 *frame, | 1709 *frame, |
| 1692 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1710 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1693 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1711 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1694 : arraysize(kV3FrameData)); | 1712 : arraysize(kV3FrameData)); |
| 1695 } | 1713 } |
| 1696 } | 1714 } |
| 1697 | 1715 |
| 1698 TEST_F(SpdyFramerSpdy3Test, CreateSynReplyCompressed) { | 1716 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { |
| 1699 SpdyFramer framer(kVer); | 1717 SpdyFramer framer(kVer); |
| 1700 framer.set_enable_compression(true); | 1718 framer.set_enable_compression(true); |
| 1701 | 1719 |
| 1702 { | 1720 { |
| 1703 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 1721 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
| 1704 | 1722 |
| 1705 SpdyHeaderBlock headers; | 1723 SpdyHeaderBlock headers; |
| 1706 headers["bar"] = "foo"; | 1724 headers["bar"] = "foo"; |
| 1707 headers["foo"] = "bar"; | 1725 headers["foo"] = "bar"; |
| 1708 | 1726 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1729 0x4a, 0x04, 0xe5, 0x0b, | 1747 0x4a, 0x04, 0xe5, 0x0b, |
| 1730 0xe6, 0xb4, 0xfc, 0x7c, | 1748 0xe6, 0xb4, 0xfc, 0x7c, |
| 1731 0x24, 0x0a, 0x28, 0x08, | 1749 0x24, 0x0a, 0x28, 0x08, |
| 1732 0x00, 0x00, 0x00, 0xff, | 1750 0x00, 0x00, 0x00, 0xff, |
| 1733 0xff | 1751 0xff |
| 1734 }; | 1752 }; |
| 1735 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( | 1753 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( |
| 1736 1, CONTROL_FLAG_NONE, true, &headers)); | 1754 1, CONTROL_FLAG_NONE, true, &headers)); |
| 1737 CompareFrame(kDescription, | 1755 CompareFrame(kDescription, |
| 1738 *frame, | 1756 *frame, |
| 1739 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 1757 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1740 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 1758 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1741 : arraysize(kV3FrameData)); | 1759 : arraysize(kV3FrameData)); |
| 1742 } | 1760 } |
| 1743 } | 1761 } |
| 1744 | 1762 |
| 1745 TEST_F(SpdyFramerSpdy3Test, CreateRstStream) { | 1763 TEST_P(SpdyFramerTest, CreateRstStream) { |
| 1746 SpdyFramer framer(kVer); | 1764 SpdyFramer framer(kVer); |
| 1747 | 1765 |
| 1748 { | 1766 { |
| 1749 const char kDescription[] = "RST_STREAM frame"; | 1767 const char kDescription[] = "RST_STREAM frame"; |
| 1750 const unsigned char kFrameData[] = { | 1768 const unsigned char kFrameData[] = { |
| 1751 0x80, kVer, 0x00, 0x03, | 1769 0x80, kVer, 0x00, 0x03, |
| 1752 0x00, 0x00, 0x00, 0x08, | 1770 0x00, 0x00, 0x00, 0x08, |
| 1753 0x00, 0x00, 0x00, 0x01, | 1771 0x00, 0x00, 0x00, 0x01, |
| 1754 0x00, 0x00, 0x00, 0x01, | 1772 0x00, 0x00, 0x00, 0x01, |
| 1755 }; | 1773 }; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1779 0x00, 0x00, 0x00, 0x08, | 1797 0x00, 0x00, 0x00, 0x08, |
| 1780 0x7f, 0xff, 0xff, 0xff, | 1798 0x7f, 0xff, 0xff, 0xff, |
| 1781 0x00, 0x00, 0x00, 0x06, | 1799 0x00, 0x00, 0x00, 0x06, |
| 1782 }; | 1800 }; |
| 1783 scoped_ptr<SpdyFrame> frame(framer.CreateRstStream(0x7FFFFFFF, | 1801 scoped_ptr<SpdyFrame> frame(framer.CreateRstStream(0x7FFFFFFF, |
| 1784 INTERNAL_ERROR)); | 1802 INTERNAL_ERROR)); |
| 1785 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 1803 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 1786 } | 1804 } |
| 1787 } | 1805 } |
| 1788 | 1806 |
| 1789 TEST_F(SpdyFramerSpdy3Test, CreateSettings) { | 1807 TEST_P(SpdyFramerTest, CreateSettings) { |
| 1790 SpdyFramer framer(kVer); | 1808 SpdyFramer framer(kVer); |
| 1791 | 1809 |
| 1792 { | 1810 { |
| 1793 const char kDescription[] = "Network byte order SETTINGS frame"; | 1811 const char kDescription[] = "Network byte order SETTINGS frame"; |
| 1794 | 1812 |
| 1795 uint32 kValue = 0x0a0b0c0d; | 1813 uint32 kValue = 0x0a0b0c0d; |
| 1796 uint8 kFlags = 0x04; | 1814 uint8 kFlags = 0x04; |
| 1797 uint32 kId = 0x030201; | 1815 uint32 kId = 0x030201; |
| 1798 SettingsFlagsAndId idAndFlags(kFlags, kId); | 1816 SettingsFlagsAndId idAndFlags(kFlags, kId); |
| 1799 | 1817 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1816 0x80, kVer, 0x00, 0x04, | 1834 0x80, kVer, 0x00, 0x04, |
| 1817 0x00, 0x00, 0x00, 0x0c, | 1835 0x00, 0x00, 0x00, 0x0c, |
| 1818 0x00, 0x00, 0x00, 0x01, | 1836 0x00, 0x00, 0x00, 0x01, |
| 1819 0x04, 0x03, 0x02, 0x01, | 1837 0x04, 0x03, 0x02, 0x01, |
| 1820 0x0a, 0x0b, 0x0c, 0x0d, | 1838 0x0a, 0x0b, 0x0c, 0x0d, |
| 1821 }; | 1839 }; |
| 1822 | 1840 |
| 1823 scoped_ptr<SpdySettingsControlFrame> frame(framer.CreateSettings(settings)); | 1841 scoped_ptr<SpdySettingsControlFrame> frame(framer.CreateSettings(settings)); |
| 1824 CompareFrame(kDescription, | 1842 CompareFrame(kDescription, |
| 1825 *frame, | 1843 *frame, |
| 1826 (SPDY_VERSION_FOR_TESTS < 3) ? kFrameDatav2 : kFrameDatav3, | 1844 (spdy_version_ < 3) ? kFrameDatav2 : kFrameDatav3, |
| 1827 arraysize(kFrameDatav3)); // Size is unchanged among versions. | 1845 arraysize(kFrameDatav3)); // Size is unchanged among versions. |
| 1828 EXPECT_EQ(SpdyFramer::kInvalidStream, | 1846 EXPECT_EQ(SpdyFramer::kInvalidStream, |
| 1829 SpdyFramer::GetControlFrameStreamId(frame.get())); | 1847 SpdyFramer::GetControlFrameStreamId(frame.get())); |
| 1830 | 1848 |
| 1831 // Make sure that ParseSettings also works as advertised. | 1849 // Make sure that ParseSettings also works as advertised. |
| 1832 SpdySettings parsed_settings; | 1850 SpdySettings parsed_settings; |
| 1833 EXPECT_TRUE(framer.ParseSettings(frame.get(), &parsed_settings)); | 1851 EXPECT_TRUE(framer.ParseSettings(frame.get(), &parsed_settings)); |
| 1834 EXPECT_EQ(settings.size(), parsed_settings.size()); | 1852 EXPECT_EQ(settings.size(), parsed_settings.size()); |
| 1835 EXPECT_EQ(kFlags, parsed_settings.back().first.flags()); | 1853 EXPECT_EQ(kFlags, parsed_settings.back().first.flags()); |
| 1836 EXPECT_EQ(kId, parsed_settings.back().first.id()); | 1854 EXPECT_EQ(kId, parsed_settings.back().first.id()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1898 const unsigned char kFrameData[] = { | 1916 const unsigned char kFrameData[] = { |
| 1899 0x80, kVer, 0x00, 0x04, | 1917 0x80, kVer, 0x00, 0x04, |
| 1900 0x00, 0x00, 0x00, 0x04, | 1918 0x00, 0x00, 0x00, 0x04, |
| 1901 0x00, 0x00, 0x00, 0x00, | 1919 0x00, 0x00, 0x00, 0x00, |
| 1902 }; | 1920 }; |
| 1903 scoped_ptr<SpdyFrame> frame(framer.CreateSettings(settings)); | 1921 scoped_ptr<SpdyFrame> frame(framer.CreateSettings(settings)); |
| 1904 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 1922 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 1905 } | 1923 } |
| 1906 } | 1924 } |
| 1907 | 1925 |
| 1908 TEST_F(SpdyFramerSpdy3Test, CreatePingFrame) { | 1926 TEST_P(SpdyFramerTest, CreatePingFrame) { |
| 1909 SpdyFramer framer(kVer); | 1927 SpdyFramer framer(kVer); |
| 1910 | 1928 |
| 1911 { | 1929 { |
| 1912 const char kDescription[] = "PING frame"; | 1930 const char kDescription[] = "PING frame"; |
| 1913 const unsigned char kFrameData[] = { | 1931 const unsigned char kFrameData[] = { |
| 1914 0x80, kVer, 0x00, 0x06, | 1932 0x80, kVer, 0x00, 0x06, |
| 1915 0x00, 0x00, 0x00, 0x04, | 1933 0x00, 0x00, 0x00, 0x04, |
| 1916 0x12, 0x34, 0x56, 0x78, | 1934 0x12, 0x34, 0x56, 0x78, |
| 1917 }; | 1935 }; |
| 1918 scoped_ptr<SpdyPingControlFrame> frame(framer.CreatePingFrame(0x12345678u)); | 1936 scoped_ptr<SpdyPingControlFrame> frame(framer.CreatePingFrame(0x12345678u)); |
| 1919 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 1937 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 1920 EXPECT_EQ(SpdyFramer::kInvalidStream, | 1938 EXPECT_EQ(SpdyFramer::kInvalidStream, |
| 1921 SpdyFramer::GetControlFrameStreamId(frame.get())); | 1939 SpdyFramer::GetControlFrameStreamId(frame.get())); |
| 1922 } | 1940 } |
| 1923 } | 1941 } |
| 1924 | 1942 |
| 1925 TEST_F(SpdyFramerSpdy3Test, CreateGoAway) { | 1943 TEST_P(SpdyFramerTest, CreateGoAway) { |
| 1926 SpdyFramer framer(kVer); | 1944 SpdyFramer framer(kVer); |
| 1927 | 1945 |
| 1928 { | 1946 { |
| 1929 const char kDescription[] = "GOAWAY frame"; | 1947 const char kDescription[] = "GOAWAY frame"; |
| 1930 const unsigned char kFrameData[] = { | 1948 const unsigned char kFrameData[] = { |
| 1931 0x80, kVer, 0x00, 0x07, | 1949 0x80, kVer, 0x00, 0x07, |
| 1932 0x00, 0x00, 0x00, 0x04, | 1950 0x00, 0x00, 0x00, 0x04, |
| 1933 0x00, 0x00, 0x00, 0x00, | 1951 0x00, 0x00, 0x00, 0x00, |
| 1934 }; | 1952 }; |
| 1935 scoped_ptr<SpdyGoAwayControlFrame> frame(framer.CreateGoAway(0)); | 1953 scoped_ptr<SpdyGoAwayControlFrame> frame(framer.CreateGoAway(0)); |
| 1936 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 1954 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 1937 EXPECT_EQ(SpdyFramer::kInvalidStream, | 1955 EXPECT_EQ(SpdyFramer::kInvalidStream, |
| 1938 SpdyFramer::GetControlFrameStreamId(frame.get())); | 1956 SpdyFramer::GetControlFrameStreamId(frame.get())); |
| 1939 } | 1957 } |
| 1940 | 1958 |
| 1941 { | 1959 { |
| 1942 const char kDescription[] = "GOAWAY frame with max stream ID"; | 1960 const char kDescription[] = "GOAWAY frame with max stream ID"; |
| 1943 const unsigned char kFrameData[] = { | 1961 const unsigned char kFrameData[] = { |
| 1944 0x80, kVer, 0x00, 0x07, | 1962 0x80, kVer, 0x00, 0x07, |
| 1945 0x00, 0x00, 0x00, 0x04, | 1963 0x00, 0x00, 0x00, 0x04, |
| 1946 0x7f, 0xff, 0xff, 0xff, | 1964 0x7f, 0xff, 0xff, 0xff, |
| 1947 }; | 1965 }; |
| 1948 scoped_ptr<SpdyFrame> frame(framer.CreateGoAway(0x7FFFFFFF)); | 1966 scoped_ptr<SpdyFrame> frame(framer.CreateGoAway(0x7FFFFFFF)); |
| 1949 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 1967 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 1950 } | 1968 } |
| 1951 } | 1969 } |
| 1952 | 1970 |
| 1953 TEST_F(SpdyFramerSpdy3Test, CreateHeadersUncompressed) { | 1971 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { |
| 1954 SpdyFramer framer(kVer); | 1972 SpdyFramer framer(kVer); |
| 1955 framer.set_enable_compression(false); | 1973 framer.set_enable_compression(false); |
| 1956 | 1974 |
| 1957 { | 1975 { |
| 1958 const char kDescription[] = "HEADERS frame, no FIN"; | 1976 const char kDescription[] = "HEADERS frame, no FIN"; |
| 1959 | 1977 |
| 1960 SpdyHeaderBlock headers; | 1978 SpdyHeaderBlock headers; |
| 1961 headers["bar"] = "foo"; | 1979 headers["bar"] = "foo"; |
| 1962 headers["foo"] = "bar"; | 1980 headers["foo"] = "bar"; |
| 1963 | 1981 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1982 0x00, 0x00, 0x03, 'f', | 2000 0x00, 0x00, 0x03, 'f', |
| 1983 'o', 'o', 0x00, 0x00, | 2001 'o', 'o', 0x00, 0x00, |
| 1984 0x00, 0x03, 'f', 'o', | 2002 0x00, 0x03, 'f', 'o', |
| 1985 'o', 0x00, 0x00, 0x00, | 2003 'o', 0x00, 0x00, 0x00, |
| 1986 0x03, 'b', 'a', 'r' | 2004 0x03, 'b', 'a', 'r' |
| 1987 }; | 2005 }; |
| 1988 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( | 2006 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( |
| 1989 1, CONTROL_FLAG_NONE, false, &headers)); | 2007 1, CONTROL_FLAG_NONE, false, &headers)); |
| 1990 CompareFrame(kDescription, | 2008 CompareFrame(kDescription, |
| 1991 *frame, | 2009 *frame, |
| 1992 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 2010 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 1993 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 2011 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 1994 : arraysize(kV3FrameData)); | 2012 : arraysize(kV3FrameData)); |
| 1995 } | 2013 } |
| 1996 | 2014 |
| 1997 { | 2015 { |
| 1998 const char kDescription[] = | 2016 const char kDescription[] = |
| 1999 "HEADERS frame with a 0-length header name, FIN, max stream ID"; | 2017 "HEADERS frame with a 0-length header name, FIN, max stream ID"; |
| 2000 | 2018 |
| 2001 SpdyHeaderBlock headers; | 2019 SpdyHeaderBlock headers; |
| 2002 headers[""] = "foo"; | 2020 headers[""] = "foo"; |
| 2003 headers["foo"] = "bar"; | 2021 headers["foo"] = "bar"; |
| 2004 | 2022 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2023 'f', 'o', 'o', 0x00, | 2041 'f', 'o', 'o', 0x00, |
| 2024 0x00, 0x00, 0x03, 'f', | 2042 0x00, 0x00, 0x03, 'f', |
| 2025 'o', 'o', 0x00, 0x00, | 2043 'o', 'o', 0x00, 0x00, |
| 2026 0x00, 0x03, 'b', 'a', | 2044 0x00, 0x03, 'b', 'a', |
| 2027 'r' | 2045 'r' |
| 2028 }; | 2046 }; |
| 2029 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( | 2047 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( |
| 2030 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); | 2048 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); |
| 2031 CompareFrame(kDescription, | 2049 CompareFrame(kDescription, |
| 2032 *frame, | 2050 *frame, |
| 2033 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 2051 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 2034 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 2052 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 2035 : arraysize(kV3FrameData)); | 2053 : arraysize(kV3FrameData)); |
| 2036 } | 2054 } |
| 2037 | 2055 |
| 2038 { | 2056 { |
| 2039 const char kDescription[] = | 2057 const char kDescription[] = |
| 2040 "HEADERS frame with a 0-length header val, FIN, max stream ID"; | 2058 "HEADERS frame with a 0-length header val, FIN, max stream ID"; |
| 2041 | 2059 |
| 2042 SpdyHeaderBlock headers; | 2060 SpdyHeaderBlock headers; |
| 2043 headers["bar"] = "foo"; | 2061 headers["bar"] = "foo"; |
| 2044 headers["foo"] = ""; | 2062 headers["foo"] = ""; |
| 2045 | 2063 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2064 0x00, 0x00, 0x03, 'f', | 2082 0x00, 0x00, 0x03, 'f', |
| 2065 'o', 'o', 0x00, 0x00, | 2083 'o', 'o', 0x00, 0x00, |
| 2066 0x00, 0x03, 'f', 'o', | 2084 0x00, 0x03, 'f', 'o', |
| 2067 'o', 0x00, 0x00, 0x00, | 2085 'o', 0x00, 0x00, 0x00, |
| 2068 0x00 | 2086 0x00 |
| 2069 }; | 2087 }; |
| 2070 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( | 2088 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( |
| 2071 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); | 2089 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); |
| 2072 CompareFrame(kDescription, | 2090 CompareFrame(kDescription, |
| 2073 *frame, | 2091 *frame, |
| 2074 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 2092 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 2075 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 2093 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 2076 : arraysize(kV3FrameData)); | 2094 : arraysize(kV3FrameData)); |
| 2077 } | 2095 } |
| 2078 } | 2096 } |
| 2079 | 2097 |
| 2080 TEST_F(SpdyFramerSpdy3Test, CreateHeadersCompressed) { | 2098 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
| 2081 SpdyFramer framer(kVer); | 2099 SpdyFramer framer(kVer); |
| 2082 framer.set_enable_compression(true); | 2100 framer.set_enable_compression(true); |
| 2083 | 2101 |
| 2084 { | 2102 { |
| 2085 const char kDescription[] = "HEADERS frame, no FIN"; | 2103 const char kDescription[] = "HEADERS frame, no FIN"; |
| 2086 | 2104 |
| 2087 SpdyHeaderBlock headers; | 2105 SpdyHeaderBlock headers; |
| 2088 headers["bar"] = "foo"; | 2106 headers["bar"] = "foo"; |
| 2089 headers["foo"] = "bar"; | 2107 headers["foo"] = "bar"; |
| 2090 | 2108 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 2111 0x4a, 0x04, 0xe5, 0x0b, | 2129 0x4a, 0x04, 0xe5, 0x0b, |
| 2112 0xe6, 0xb4, 0xfc, 0x7c, | 2130 0xe6, 0xb4, 0xfc, 0x7c, |
| 2113 0x24, 0x0a, 0x28, 0x08, | 2131 0x24, 0x0a, 0x28, 0x08, |
| 2114 0x00, 0x00, 0x00, 0xff, | 2132 0x00, 0x00, 0x00, 0xff, |
| 2115 0xff | 2133 0xff |
| 2116 }; | 2134 }; |
| 2117 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( | 2135 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( |
| 2118 1, CONTROL_FLAG_NONE, true, &headers)); | 2136 1, CONTROL_FLAG_NONE, true, &headers)); |
| 2119 CompareFrame(kDescription, | 2137 CompareFrame(kDescription, |
| 2120 *frame, | 2138 *frame, |
| 2121 (SPDY_VERSION_FOR_TESTS < 3) ? kV2FrameData : kV3FrameData, | 2139 (spdy_version_ < 3) ? kV2FrameData : kV3FrameData, |
| 2122 (SPDY_VERSION_FOR_TESTS < 3) ? arraysize(kV2FrameData) | 2140 (spdy_version_ < 3) ? arraysize(kV2FrameData) |
| 2123 : arraysize(kV3FrameData)); | 2141 : arraysize(kV3FrameData)); |
| 2124 } | 2142 } |
| 2125 } | 2143 } |
| 2126 | 2144 |
| 2127 TEST_F(SpdyFramerSpdy3Test, CreateWindowUpdate) { | 2145 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
| 2128 SpdyFramer framer(kVer); | 2146 SpdyFramer framer(kVer); |
| 2129 | 2147 |
| 2130 { | 2148 { |
| 2131 const char kDescription[] = "WINDOW_UPDATE frame"; | 2149 const char kDescription[] = "WINDOW_UPDATE frame"; |
| 2132 const unsigned char kFrameData[] = { | 2150 const unsigned char kFrameData[] = { |
| 2133 0x80, kVer, 0x00, 0x09, | 2151 0x80, kVer, 0x00, 0x09, |
| 2134 0x00, 0x00, 0x00, 0x08, | 2152 0x00, 0x00, 0x00, 0x08, |
| 2135 0x00, 0x00, 0x00, 0x01, | 2153 0x00, 0x00, 0x00, 0x01, |
| 2136 0x00, 0x00, 0x00, 0x01, | 2154 0x00, 0x00, 0x00, 0x01, |
| 2137 }; | 2155 }; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2159 0x80, kVer, 0x00, 0x09, | 2177 0x80, kVer, 0x00, 0x09, |
| 2160 0x00, 0x00, 0x00, 0x08, | 2178 0x00, 0x00, 0x00, 0x08, |
| 2161 0x00, 0x00, 0x00, 0x01, | 2179 0x00, 0x00, 0x00, 0x01, |
| 2162 0x7f, 0xff, 0xff, 0xff, | 2180 0x7f, 0xff, 0xff, 0xff, |
| 2163 }; | 2181 }; |
| 2164 scoped_ptr<SpdyFrame> frame(framer.CreateWindowUpdate(1, 0x7FFFFFFF)); | 2182 scoped_ptr<SpdyFrame> frame(framer.CreateWindowUpdate(1, 0x7FFFFFFF)); |
| 2165 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2183 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 2166 } | 2184 } |
| 2167 } | 2185 } |
| 2168 | 2186 |
| 2169 TEST_F(SpdyFramerSpdy3Test, DuplicateFrame) { | 2187 TEST_P(SpdyFramerTest, DuplicateFrame) { |
| 2170 SpdyFramer framer(kVer); | 2188 SpdyFramer framer(kVer); |
| 2171 | 2189 |
| 2172 { | 2190 { |
| 2173 const char kDescription[] = "PING frame"; | 2191 const char kDescription[] = "PING frame"; |
| 2174 const unsigned char kFrameData[] = { | 2192 const unsigned char kFrameData[] = { |
| 2175 0x80, kVer, 0x00, 0x06, | 2193 0x80, kVer, 0x00, 0x06, |
| 2176 0x00, 0x00, 0x00, 0x04, | 2194 0x00, 0x00, 0x00, 0x04, |
| 2177 0x12, 0x34, 0x56, 0x78, | 2195 0x12, 0x34, 0x56, 0x78, |
| 2178 }; | 2196 }; |
| 2179 scoped_ptr<SpdyFrame> frame1(framer.CreatePingFrame(0x12345678u)); | 2197 scoped_ptr<SpdyFrame> frame1(framer.CreatePingFrame(0x12345678u)); |
| 2180 CompareFrame(kDescription, *frame1, kFrameData, arraysize(kFrameData)); | 2198 CompareFrame(kDescription, *frame1, kFrameData, arraysize(kFrameData)); |
| 2181 | 2199 |
| 2182 scoped_ptr<SpdyFrame> frame2(framer.DuplicateFrame(*frame1)); | 2200 scoped_ptr<SpdyFrame> frame2(framer.DuplicateFrame(*frame1)); |
| 2183 CompareFrame(kDescription, *frame2, kFrameData, arraysize(kFrameData)); | 2201 CompareFrame(kDescription, *frame2, kFrameData, arraysize(kFrameData)); |
| 2184 } | 2202 } |
| 2185 } | 2203 } |
| 2186 | 2204 |
| 2187 // This test case reproduces conditions that caused ExpandControlFrameBuffer to | 2205 // This test case reproduces conditions that caused ExpandControlFrameBuffer to |
| 2188 // fail to expand the buffer control frame buffer when it should have, allowing | 2206 // fail to expand the buffer control frame buffer when it should have, allowing |
| 2189 // the framer to overrun the buffer, and smash other heap contents. This test | 2207 // the framer to overrun the buffer, and smash other heap contents. This test |
| 2190 // relies on the debug version of the heap manager, which checks for buffer | 2208 // relies on the debug version of the heap manager, which checks for buffer |
| 2191 // overrun errors during delete processing. Regression test for b/2974814. | 2209 // overrun errors during delete processing. Regression test for b/2974814. |
| 2192 TEST_F(SpdyFramerSpdy3Test, ExpandBuffer_HeapSmash) { | 2210 TEST_P(SpdyFramerTest, ExpandBuffer_HeapSmash) { |
| 2193 // Sweep through the area of problematic values, to make sure we always cover | 2211 // Sweep through the area of problematic values, to make sure we always cover |
| 2194 // the danger zone, even if it moves around at bit due to SPDY changes. | 2212 // the danger zone, even if it moves around at bit due to SPDY changes. |
| 2195 for (uint16 val2_len = SpdyFramer::kControlFrameBufferInitialSize - 50; | 2213 for (uint16 val2_len = SpdyFramer::kControlFrameBufferInitialSize - 50; |
| 2196 val2_len < SpdyFramer::kControlFrameBufferInitialSize; | 2214 val2_len < SpdyFramer::kControlFrameBufferInitialSize; |
| 2197 val2_len++) { | 2215 val2_len++) { |
| 2198 std::string val2 = std::string(val2_len, 'a'); | 2216 std::string val2 = std::string(val2_len, 'a'); |
| 2199 SpdyHeaderBlock headers; | 2217 SpdyHeaderBlock headers; |
| 2200 headers["bar"] = "foo"; | 2218 headers["bar"] = "foo"; |
| 2201 headers["foo"] = "baz"; | 2219 headers["foo"] = "baz"; |
| 2202 headers["grue"] = val2.c_str(); | 2220 headers["grue"] = val2.c_str(); |
| 2203 SpdyFramer framer(kVer); | 2221 SpdyFramer framer(kVer); |
| 2204 scoped_ptr<SpdySynStreamControlFrame> template_frame( | 2222 scoped_ptr<SpdySynStreamControlFrame> template_frame( |
| 2205 framer.CreateSynStream(1, // stream_id | 2223 framer.CreateSynStream(1, // stream_id |
| 2206 0, // associated_stream_id | 2224 0, // associated_stream_id |
| 2207 1, // priority | 2225 1, // priority |
| 2208 CONTROL_FLAG_NONE, | 2226 CONTROL_FLAG_NONE, |
| 2209 false, // compress | 2227 false, // compress |
| 2210 &headers)); | 2228 &headers)); |
| 2211 EXPECT_TRUE(template_frame.get() != NULL); | 2229 EXPECT_TRUE(template_frame.get() != NULL); |
| 2212 TestSpdyVisitor visitor; | 2230 TestSpdyVisitor visitor; |
| 2213 visitor.SimulateInFramer( | 2231 visitor.SimulateInFramer( |
| 2214 reinterpret_cast<unsigned char*>(template_frame.get()->data()), | 2232 reinterpret_cast<unsigned char*>(template_frame.get()->data()), |
| 2215 template_frame.get()->length() + SpdyControlFrame::kHeaderSize); | 2233 template_frame.get()->length() + SpdyControlFrame::kHeaderSize); |
| 2216 EXPECT_EQ(1, visitor.syn_frame_count_); | 2234 EXPECT_EQ(1, visitor.syn_frame_count_); |
| 2217 } | 2235 } |
| 2218 } | 2236 } |
| 2219 | 2237 |
| 2220 TEST_F(SpdyFramerSpdy3Test, ControlFrameSizesAreValidated) { | 2238 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 2221 // Create a GoAway frame that has a few extra bytes at the end. | 2239 // Create a GoAway frame that has a few extra bytes at the end. |
| 2222 // We create enough overhead to require the framer to expand its frame buffer. | 2240 // We create enough overhead to require the framer to expand its frame buffer. |
| 2223 size_t overhead = SpdyFramer::kUncompressedControlFrameBufferInitialSize; | 2241 size_t overhead = SpdyFramer::kUncompressedControlFrameBufferInitialSize; |
| 2224 SpdyFramer framer(kVer); | 2242 SpdyFramer framer(kVer); |
| 2225 scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1)); | 2243 scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1)); |
| 2226 goaway->set_length(goaway->length() + overhead); | 2244 goaway->set_length(goaway->length() + overhead); |
| 2227 std::string pad('A', overhead); | 2245 std::string pad('A', overhead); |
| 2228 TestSpdyVisitor visitor; | 2246 TestSpdyVisitor visitor; |
| 2229 | 2247 |
| 2230 // First attempt without validation on. | 2248 // First attempt without validation on. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 2243 visitor.SimulateInFramer( | 2261 visitor.SimulateInFramer( |
| 2244 reinterpret_cast<unsigned char*>(goaway->data()), | 2262 reinterpret_cast<unsigned char*>(goaway->data()), |
| 2245 goaway->length() - overhead + SpdyControlFrame::kHeaderSize); | 2263 goaway->length() - overhead + SpdyControlFrame::kHeaderSize); |
| 2246 visitor.SimulateInFramer( | 2264 visitor.SimulateInFramer( |
| 2247 reinterpret_cast<const unsigned char*>(pad.c_str()), | 2265 reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 2248 overhead); | 2266 overhead); |
| 2249 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2267 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
| 2250 EXPECT_EQ(1, visitor.goaway_count_); // Unchanged from before. | 2268 EXPECT_EQ(1, visitor.goaway_count_); // Unchanged from before. |
| 2251 } | 2269 } |
| 2252 | 2270 |
| 2253 TEST_F(SpdyFramerSpdy3Test, ReadZeroLenSettingsFrame) { | 2271 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 2254 SpdyFramer framer(kVer); | 2272 SpdyFramer framer(kVer); |
| 2255 SpdySettings settings; | 2273 SpdySettings settings; |
| 2256 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); | 2274 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); |
| 2257 control_frame->set_length(0); | 2275 control_frame->set_length(0); |
| 2258 TestSpdyVisitor visitor; | 2276 TestSpdyVisitor visitor; |
| 2259 visitor.use_compression_ = false; | 2277 visitor.use_compression_ = false; |
| 2260 visitor.SimulateInFramer( | 2278 visitor.SimulateInFramer( |
| 2261 reinterpret_cast<unsigned char*>(control_frame->data()), | 2279 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 2262 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); | 2280 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); |
| 2263 // Should generate an error, since zero-len settings frames are unsupported. | 2281 // Should generate an error, since zero-len settings frames are unsupported. |
| 2264 EXPECT_EQ(1, visitor.error_count_); | 2282 EXPECT_EQ(1, visitor.error_count_); |
| 2265 } | 2283 } |
| 2266 | 2284 |
| 2267 // Tests handling of SETTINGS frames with invalid length. | 2285 // Tests handling of SETTINGS frames with invalid length. |
| 2268 TEST_F(SpdyFramerSpdy3Test, ReadBogusLenSettingsFrame) { | 2286 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| 2269 SpdyFramer framer(kVer); | 2287 SpdyFramer framer(kVer); |
| 2270 SpdySettings settings; | 2288 SpdySettings settings; |
| 2271 // Add a setting to pad the frame so that we don't get a buffer overflow when | 2289 // Add a setting to pad the frame so that we don't get a buffer overflow when |
| 2272 // calling SimulateInFramer() below. | 2290 // calling SimulateInFramer() below. |
| 2273 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000002)); | 2291 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000002)); |
| 2274 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); | 2292 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); |
| 2275 control_frame->set_length(5); | 2293 control_frame->set_length(5); |
| 2276 TestSpdyVisitor visitor; | 2294 TestSpdyVisitor visitor; |
| 2277 visitor.use_compression_ = false; | 2295 visitor.use_compression_ = false; |
| 2278 visitor.SimulateInFramer( | 2296 visitor.SimulateInFramer( |
| 2279 reinterpret_cast<unsigned char*>(control_frame->data()), | 2297 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 2280 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); | 2298 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); |
| 2281 // Should generate an error, since zero-len settings frames are unsupported. | 2299 // Should generate an error, since zero-len settings frames are unsupported. |
| 2282 EXPECT_EQ(1, visitor.error_count_); | 2300 EXPECT_EQ(1, visitor.error_count_); |
| 2283 } | 2301 } |
| 2284 | 2302 |
| 2285 // Tests handling of SETTINGS frames larger than the frame buffer size. | 2303 // Tests handling of SETTINGS frames larger than the frame buffer size. |
| 2286 TEST_F(SpdyFramerSpdy3Test, ReadLargeSettingsFrame) { | 2304 TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { |
| 2287 SpdyFramer framer(kVer); | 2305 SpdyFramer framer(kVer); |
| 2288 SpdySettings settings; | 2306 SpdySettings settings; |
| 2289 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000002)); | 2307 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000002)); |
| 2290 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 2), 0x00000003)); | 2308 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 2), 0x00000003)); |
| 2291 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 3), 0x00000004)); | 2309 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 3), 0x00000004)); |
| 2292 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); | 2310 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); |
| 2293 EXPECT_LT(SpdyFramer::kUncompressedControlFrameBufferInitialSize, | 2311 EXPECT_LT(SpdyFramer::kUncompressedControlFrameBufferInitialSize, |
| 2294 control_frame->length() + SpdyControlFrame::kHeaderSize); | 2312 control_frame->length() + SpdyControlFrame::kHeaderSize); |
| 2295 TestSpdyVisitor visitor; | 2313 TestSpdyVisitor visitor; |
| 2296 visitor.use_compression_ = false; | 2314 visitor.use_compression_ = false; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 2315 to_read); | 2333 to_read); |
| 2316 unframed_data -= to_read; | 2334 unframed_data -= to_read; |
| 2317 framed_data += to_read; | 2335 framed_data += to_read; |
| 2318 } | 2336 } |
| 2319 EXPECT_EQ(0, visitor.error_count_); | 2337 EXPECT_EQ(0, visitor.error_count_); |
| 2320 EXPECT_EQ(settings.size() * 2, static_cast<unsigned>(visitor.setting_count_)); | 2338 EXPECT_EQ(settings.size() * 2, static_cast<unsigned>(visitor.setting_count_)); |
| 2321 EXPECT_EQ(2, visitor.settings_frame_count_); | 2339 EXPECT_EQ(2, visitor.settings_frame_count_); |
| 2322 } | 2340 } |
| 2323 | 2341 |
| 2324 // Tests handling of SETTINGS frame with duplicate entries. | 2342 // Tests handling of SETTINGS frame with duplicate entries. |
| 2325 TEST_F(SpdyFramerSpdy3Test, ReadDuplicateSettings) { | 2343 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 2326 SpdyFramer framer(kVer); | 2344 SpdyFramer framer(kVer); |
| 2327 SpdySettings settings; | 2345 SpdySettings settings; |
| 2328 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000002)); | 2346 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000002)); |
| 2329 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000003)); | 2347 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000003)); |
| 2330 // This last setting should not be processed due to error above. | 2348 // This last setting should not be processed due to error above. |
| 2331 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 3), 0x00000003)); | 2349 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 3), 0x00000003)); |
| 2332 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); | 2350 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); |
| 2333 TestSpdyVisitor visitor; | 2351 TestSpdyVisitor visitor; |
| 2334 visitor.use_compression_ = false; | 2352 visitor.use_compression_ = false; |
| 2335 | 2353 |
| 2336 visitor.SimulateInFramer( | 2354 visitor.SimulateInFramer( |
| 2337 reinterpret_cast<unsigned char*>(control_frame->data()), | 2355 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 2338 control_frame->length() + SpdyControlFrame::kHeaderSize); | 2356 control_frame->length() + SpdyControlFrame::kHeaderSize); |
| 2339 EXPECT_EQ(1, visitor.error_count_); | 2357 EXPECT_EQ(1, visitor.error_count_); |
| 2340 EXPECT_EQ(1, visitor.setting_count_); | 2358 EXPECT_EQ(1, visitor.setting_count_); |
| 2341 EXPECT_EQ(1, visitor.settings_frame_count_); | 2359 EXPECT_EQ(1, visitor.settings_frame_count_); |
| 2342 } | 2360 } |
| 2343 | 2361 |
| 2344 // Tests handling of SETTINGS frame with entries out of order. | 2362 // Tests handling of SETTINGS frame with entries out of order. |
| 2345 TEST_F(SpdyFramerSpdy3Test, ReadOutOfOrderSettings) { | 2363 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 2346 SpdyFramer framer(kVer); | 2364 SpdyFramer framer(kVer); |
| 2347 SpdySettings settings; | 2365 SpdySettings settings; |
| 2348 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 2), 0x00000002)); | 2366 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 2), 0x00000002)); |
| 2349 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000003)); | 2367 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 1), 0x00000003)); |
| 2350 // This last setting should not be processed due to error above. | 2368 // This last setting should not be processed due to error above. |
| 2351 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 3), 0x00000003)); | 2369 settings.push_back(SpdySetting(SettingsFlagsAndId(0, 3), 0x00000003)); |
| 2352 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); | 2370 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); |
| 2353 TestSpdyVisitor visitor; | 2371 TestSpdyVisitor visitor; |
| 2354 visitor.use_compression_ = false; | 2372 visitor.use_compression_ = false; |
| 2355 | 2373 |
| 2356 visitor.SimulateInFramer( | 2374 visitor.SimulateInFramer( |
| 2357 reinterpret_cast<unsigned char*>(control_frame->data()), | 2375 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 2358 control_frame->length() + SpdyControlFrame::kHeaderSize); | 2376 control_frame->length() + SpdyControlFrame::kHeaderSize); |
| 2359 EXPECT_EQ(1, visitor.error_count_); | 2377 EXPECT_EQ(1, visitor.error_count_); |
| 2360 EXPECT_EQ(1, visitor.setting_count_); | 2378 EXPECT_EQ(1, visitor.setting_count_); |
| 2361 EXPECT_EQ(1, visitor.settings_frame_count_); | 2379 EXPECT_EQ(1, visitor.settings_frame_count_); |
| 2362 } | 2380 } |
| 2363 | 2381 |
| 2364 TEST_F(SpdyFramerSpdy3Test, ReadCredentialFrame) { | 2382 TEST_P(SpdyFramerTest, ReadCredentialFrame) { |
| 2365 SpdyCredential credential; | 2383 SpdyCredential credential; |
| 2366 credential.slot = 3; | 2384 credential.slot = 3; |
| 2367 credential.proof = "proof"; | 2385 credential.proof = "proof"; |
| 2368 credential.certs.push_back("a cert"); | 2386 credential.certs.push_back("a cert"); |
| 2369 credential.certs.push_back("another cert"); | 2387 credential.certs.push_back("another cert"); |
| 2370 credential.certs.push_back("final cert"); | 2388 credential.certs.push_back("final cert"); |
| 2371 SpdyFramer framer(kVer); | 2389 SpdyFramer framer(kVer); |
| 2372 scoped_ptr<SpdyFrame> control_frame( | 2390 scoped_ptr<SpdyFrame> control_frame( |
| 2373 framer.CreateCredentialFrame(credential)); | 2391 framer.CreateCredentialFrame(credential)); |
| 2374 EXPECT_TRUE(control_frame.get() != NULL); | 2392 EXPECT_TRUE(control_frame.get() != NULL); |
| 2375 TestSpdyVisitor visitor; | 2393 TestSpdyVisitor visitor; |
| 2376 visitor.use_compression_ = false; | 2394 visitor.use_compression_ = false; |
| 2377 visitor.SimulateInFramer( | 2395 visitor.SimulateInFramer( |
| 2378 reinterpret_cast<unsigned char*>(control_frame.get()->data()), | 2396 reinterpret_cast<unsigned char*>(control_frame.get()->data()), |
| 2379 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); | 2397 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); |
| 2380 EXPECT_EQ(0, visitor.error_count_); | 2398 EXPECT_EQ(0, visitor.error_count_); |
| 2381 EXPECT_EQ(1, visitor.credential_count_); | 2399 EXPECT_EQ(1, visitor.credential_count_); |
| 2382 EXPECT_EQ(control_frame->length(), visitor.credential_buffer_length_); | 2400 EXPECT_EQ(control_frame->length(), visitor.credential_buffer_length_); |
| 2383 EXPECT_EQ(credential.slot, visitor.credential_.slot); | 2401 EXPECT_EQ(credential.slot, visitor.credential_.slot); |
| 2384 EXPECT_EQ(credential.proof, visitor.credential_.proof); | 2402 EXPECT_EQ(credential.proof, visitor.credential_.proof); |
| 2385 EXPECT_EQ(credential.certs.size(), visitor.credential_.certs.size()); | 2403 EXPECT_EQ(credential.certs.size(), visitor.credential_.certs.size()); |
| 2386 for (size_t i = 0; i < credential.certs.size(); i++) { | 2404 for (size_t i = 0; i < credential.certs.size(); i++) { |
| 2387 EXPECT_EQ(credential.certs[i], visitor.credential_.certs[i]); | 2405 EXPECT_EQ(credential.certs[i], visitor.credential_.certs[i]); |
| 2388 } | 2406 } |
| 2389 } | 2407 } |
| 2390 | 2408 |
| 2391 TEST_F(SpdyFramerSpdy3Test, ReadCredentialFrameWithCorruptProof) { | 2409 TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptProof) { |
| 2392 SpdyCredential credential; | 2410 SpdyCredential credential; |
| 2393 credential.slot = 3; | 2411 credential.slot = 3; |
| 2394 credential.proof = "proof"; | 2412 credential.proof = "proof"; |
| 2395 credential.certs.push_back("a cert"); | 2413 credential.certs.push_back("a cert"); |
| 2396 credential.certs.push_back("another cert"); | 2414 credential.certs.push_back("another cert"); |
| 2397 credential.certs.push_back("final cert"); | 2415 credential.certs.push_back("final cert"); |
| 2398 SpdyFramer framer(kVer); | 2416 SpdyFramer framer(kVer); |
| 2399 scoped_ptr<SpdyFrame> control_frame( | 2417 scoped_ptr<SpdyFrame> control_frame( |
| 2400 framer.CreateCredentialFrame(credential)); | 2418 framer.CreateCredentialFrame(credential)); |
| 2401 EXPECT_TRUE(control_frame.get() != NULL); | 2419 EXPECT_TRUE(control_frame.get() != NULL); |
| 2402 TestSpdyVisitor visitor; | 2420 TestSpdyVisitor visitor; |
| 2403 visitor.use_compression_ = false; | 2421 visitor.use_compression_ = false; |
| 2404 unsigned char* data = | 2422 unsigned char* data = |
| 2405 reinterpret_cast<unsigned char*>(control_frame.get()->data()); | 2423 reinterpret_cast<unsigned char*>(control_frame.get()->data()); |
| 2406 size_t offset = SpdyControlFrame::kHeaderSize + 4; | 2424 size_t offset = SpdyControlFrame::kHeaderSize + 4; |
| 2407 data[offset] = 0xFF; // Proof length is past the end of the frame | 2425 data[offset] = 0xFF; // Proof length is past the end of the frame |
| 2408 visitor.SimulateInFramer( | 2426 visitor.SimulateInFramer( |
| 2409 data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); | 2427 data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); |
| 2410 EXPECT_EQ(1, visitor.error_count_); | 2428 EXPECT_EQ(1, visitor.error_count_); |
| 2411 } | 2429 } |
| 2412 | 2430 |
| 2413 TEST_F(SpdyFramerSpdy3Test, ReadCredentialFrameWithCorruptCertificate) { | 2431 TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptCertificate) { |
| 2414 SpdyCredential credential; | 2432 SpdyCredential credential; |
| 2415 credential.slot = 3; | 2433 credential.slot = 3; |
| 2416 credential.proof = "proof"; | 2434 credential.proof = "proof"; |
| 2417 credential.certs.push_back("a cert"); | 2435 credential.certs.push_back("a cert"); |
| 2418 credential.certs.push_back("another cert"); | 2436 credential.certs.push_back("another cert"); |
| 2419 credential.certs.push_back("final cert"); | 2437 credential.certs.push_back("final cert"); |
| 2420 SpdyFramer framer(kVer); | 2438 SpdyFramer framer(kVer); |
| 2421 scoped_ptr<SpdyFrame> control_frame( | 2439 scoped_ptr<SpdyFrame> control_frame( |
| 2422 framer.CreateCredentialFrame(credential)); | 2440 framer.CreateCredentialFrame(credential)); |
| 2423 EXPECT_TRUE(control_frame.get() != NULL); | 2441 EXPECT_TRUE(control_frame.get() != NULL); |
| 2424 TestSpdyVisitor visitor; | 2442 TestSpdyVisitor visitor; |
| 2425 visitor.use_compression_ = false; | 2443 visitor.use_compression_ = false; |
| 2426 unsigned char* data = | 2444 unsigned char* data = |
| 2427 reinterpret_cast<unsigned char*>(control_frame.get()->data()); | 2445 reinterpret_cast<unsigned char*>(control_frame.get()->data()); |
| 2428 size_t offset = SpdyControlFrame::kHeaderSize + credential.proof.length(); | 2446 size_t offset = SpdyControlFrame::kHeaderSize + credential.proof.length(); |
| 2429 data[offset] = 0xFF; // Certificate length is past the end of the frame | 2447 data[offset] = 0xFF; // Certificate length is past the end of the frame |
| 2430 visitor.SimulateInFramer( | 2448 visitor.SimulateInFramer( |
| 2431 data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); | 2449 data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); |
| 2432 EXPECT_EQ(1, visitor.error_count_); | 2450 EXPECT_EQ(1, visitor.error_count_); |
| 2433 } | 2451 } |
| 2434 | 2452 |
| 2435 TEST_F(SpdyFramerSpdy3Test, ReadGarbage) { | 2453 TEST_P(SpdyFramerTest, ReadGarbage) { |
| 2436 SpdyFramer framer(kVer); | 2454 SpdyFramer framer(kVer); |
| 2437 unsigned char garbage_frame[256]; | 2455 unsigned char garbage_frame[256]; |
| 2438 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 2456 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 2439 TestSpdyVisitor visitor; | 2457 TestSpdyVisitor visitor; |
| 2440 visitor.use_compression_ = false; | 2458 visitor.use_compression_ = false; |
| 2441 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 2459 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 2442 EXPECT_EQ(1, visitor.error_count_); | 2460 EXPECT_EQ(1, visitor.error_count_); |
| 2443 } | 2461 } |
| 2444 | 2462 |
| 2445 TEST_F(SpdyFramerSpdy3Test, ReadGarbageWithValidVersion) { | 2463 TEST_P(SpdyFramerTest, ReadGarbageWithValidVersion) { |
| 2446 SpdyFramer framer(kVer); | 2464 SpdyFramer framer(kVer); |
| 2447 char garbage_frame[256]; | 2465 char garbage_frame[256]; |
| 2448 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 2466 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 2449 SpdyControlFrame control_frame(&garbage_frame[0], false); | 2467 SpdyControlFrame control_frame(&garbage_frame[0], false); |
| 2450 control_frame.set_version(SPDY_VERSION_FOR_TESTS); | 2468 control_frame.set_version(spdy_version_); |
| 2451 TestSpdyVisitor visitor; | 2469 TestSpdyVisitor visitor; |
| 2452 visitor.use_compression_ = false; | 2470 visitor.use_compression_ = false; |
| 2453 visitor.SimulateInFramer( | 2471 visitor.SimulateInFramer( |
| 2454 reinterpret_cast<unsigned char*>(control_frame.data()), | 2472 reinterpret_cast<unsigned char*>(control_frame.data()), |
| 2455 sizeof(garbage_frame)); | 2473 sizeof(garbage_frame)); |
| 2456 EXPECT_EQ(1, visitor.error_count_); | 2474 EXPECT_EQ(1, visitor.error_count_); |
| 2457 } | 2475 } |
| 2458 | 2476 |
| 2459 TEST_F(SpdyFramerSpdy3Test, StateToStringTest) { | 2477 TEST_P(SpdyFramerTest, StateToStringTest) { |
| 2460 EXPECT_STREQ("ERROR", | 2478 EXPECT_STREQ("ERROR", |
| 2461 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); | 2479 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); |
| 2462 EXPECT_STREQ("DONE", | 2480 EXPECT_STREQ("DONE", |
| 2463 SpdyFramer::StateToString(SpdyFramer::SPDY_DONE)); | 2481 SpdyFramer::StateToString(SpdyFramer::SPDY_DONE)); |
| 2464 EXPECT_STREQ("AUTO_RESET", | 2482 EXPECT_STREQ("AUTO_RESET", |
| 2465 SpdyFramer::StateToString(SpdyFramer::SPDY_AUTO_RESET)); | 2483 SpdyFramer::StateToString(SpdyFramer::SPDY_AUTO_RESET)); |
| 2466 EXPECT_STREQ("RESET", | 2484 EXPECT_STREQ("RESET", |
| 2467 SpdyFramer::StateToString(SpdyFramer::SPDY_RESET)); | 2485 SpdyFramer::StateToString(SpdyFramer::SPDY_RESET)); |
| 2468 EXPECT_STREQ("READING_COMMON_HEADER", | 2486 EXPECT_STREQ("READING_COMMON_HEADER", |
| 2469 SpdyFramer::StateToString( | 2487 SpdyFramer::StateToString( |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2487 SpdyFramer::StateToString( | 2505 SpdyFramer::StateToString( |
| 2488 SpdyFramer::SPDY_CREDENTIAL_FRAME_PAYLOAD)); | 2506 SpdyFramer::SPDY_CREDENTIAL_FRAME_PAYLOAD)); |
| 2489 EXPECT_STREQ("SPDY_SETTINGS_FRAME_PAYLOAD", | 2507 EXPECT_STREQ("SPDY_SETTINGS_FRAME_PAYLOAD", |
| 2490 SpdyFramer::StateToString( | 2508 SpdyFramer::StateToString( |
| 2491 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); | 2509 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); |
| 2492 EXPECT_STREQ("UNKNOWN_STATE", | 2510 EXPECT_STREQ("UNKNOWN_STATE", |
| 2493 SpdyFramer::StateToString( | 2511 SpdyFramer::StateToString( |
| 2494 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD + 1)); | 2512 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD + 1)); |
| 2495 } | 2513 } |
| 2496 | 2514 |
| 2497 TEST_F(SpdyFramerSpdy3Test, ErrorCodeToStringTest) { | 2515 TEST_P(SpdyFramerTest, ErrorCodeToStringTest) { |
| 2498 EXPECT_STREQ("NO_ERROR", | 2516 EXPECT_STREQ("NO_ERROR", |
| 2499 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); | 2517 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); |
| 2500 EXPECT_STREQ("INVALID_CONTROL_FRAME", | 2518 EXPECT_STREQ("INVALID_CONTROL_FRAME", |
| 2501 SpdyFramer::ErrorCodeToString( | 2519 SpdyFramer::ErrorCodeToString( |
| 2502 SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); | 2520 SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); |
| 2503 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", | 2521 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", |
| 2504 SpdyFramer::ErrorCodeToString( | 2522 SpdyFramer::ErrorCodeToString( |
| 2505 SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE)); | 2523 SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE)); |
| 2506 EXPECT_STREQ("ZLIB_INIT_FAILURE", | 2524 EXPECT_STREQ("ZLIB_INIT_FAILURE", |
| 2507 SpdyFramer::ErrorCodeToString( | 2525 SpdyFramer::ErrorCodeToString( |
| 2508 SpdyFramer::SPDY_ZLIB_INIT_FAILURE)); | 2526 SpdyFramer::SPDY_ZLIB_INIT_FAILURE)); |
| 2509 EXPECT_STREQ("UNSUPPORTED_VERSION", | 2527 EXPECT_STREQ("UNSUPPORTED_VERSION", |
| 2510 SpdyFramer::ErrorCodeToString( | 2528 SpdyFramer::ErrorCodeToString( |
| 2511 SpdyFramer::SPDY_UNSUPPORTED_VERSION)); | 2529 SpdyFramer::SPDY_UNSUPPORTED_VERSION)); |
| 2512 EXPECT_STREQ("DECOMPRESS_FAILURE", | 2530 EXPECT_STREQ("DECOMPRESS_FAILURE", |
| 2513 SpdyFramer::ErrorCodeToString( | 2531 SpdyFramer::ErrorCodeToString( |
| 2514 SpdyFramer::SPDY_DECOMPRESS_FAILURE)); | 2532 SpdyFramer::SPDY_DECOMPRESS_FAILURE)); |
| 2515 EXPECT_STREQ("COMPRESS_FAILURE", | 2533 EXPECT_STREQ("COMPRESS_FAILURE", |
| 2516 SpdyFramer::ErrorCodeToString( | 2534 SpdyFramer::ErrorCodeToString( |
| 2517 SpdyFramer::SPDY_COMPRESS_FAILURE)); | 2535 SpdyFramer::SPDY_COMPRESS_FAILURE)); |
| 2518 EXPECT_STREQ("UNKNOWN_ERROR", | 2536 EXPECT_STREQ("UNKNOWN_ERROR", |
| 2519 SpdyFramer::ErrorCodeToString(SpdyFramer::LAST_ERROR)); | 2537 SpdyFramer::ErrorCodeToString(SpdyFramer::LAST_ERROR)); |
| 2520 } | 2538 } |
| 2521 | 2539 |
| 2522 TEST_F(SpdyFramerSpdy3Test, StatusCodeToStringTest) { | 2540 TEST_P(SpdyFramerTest, StatusCodeToStringTest) { |
| 2523 EXPECT_STREQ("INVALID", | 2541 EXPECT_STREQ("INVALID", |
| 2524 SpdyFramer::StatusCodeToString(INVALID)); | 2542 SpdyFramer::StatusCodeToString(INVALID)); |
| 2525 EXPECT_STREQ("PROTOCOL_ERROR", | 2543 EXPECT_STREQ("PROTOCOL_ERROR", |
| 2526 SpdyFramer::StatusCodeToString(PROTOCOL_ERROR)); | 2544 SpdyFramer::StatusCodeToString(PROTOCOL_ERROR)); |
| 2527 EXPECT_STREQ("INVALID_STREAM", | 2545 EXPECT_STREQ("INVALID_STREAM", |
| 2528 SpdyFramer::StatusCodeToString(INVALID_STREAM)); | 2546 SpdyFramer::StatusCodeToString(INVALID_STREAM)); |
| 2529 EXPECT_STREQ("REFUSED_STREAM", | 2547 EXPECT_STREQ("REFUSED_STREAM", |
| 2530 SpdyFramer::StatusCodeToString(REFUSED_STREAM)); | 2548 SpdyFramer::StatusCodeToString(REFUSED_STREAM)); |
| 2531 EXPECT_STREQ("UNSUPPORTED_VERSION", | 2549 EXPECT_STREQ("UNSUPPORTED_VERSION", |
| 2532 SpdyFramer::StatusCodeToString(UNSUPPORTED_VERSION)); | 2550 SpdyFramer::StatusCodeToString(UNSUPPORTED_VERSION)); |
| 2533 EXPECT_STREQ("CANCEL", | 2551 EXPECT_STREQ("CANCEL", |
| 2534 SpdyFramer::StatusCodeToString(CANCEL)); | 2552 SpdyFramer::StatusCodeToString(CANCEL)); |
| 2535 EXPECT_STREQ("INTERNAL_ERROR", | 2553 EXPECT_STREQ("INTERNAL_ERROR", |
| 2536 SpdyFramer::StatusCodeToString(INTERNAL_ERROR)); | 2554 SpdyFramer::StatusCodeToString(INTERNAL_ERROR)); |
| 2537 EXPECT_STREQ("FLOW_CONTROL_ERROR", | 2555 EXPECT_STREQ("FLOW_CONTROL_ERROR", |
| 2538 SpdyFramer::StatusCodeToString(FLOW_CONTROL_ERROR)); | 2556 SpdyFramer::StatusCodeToString(FLOW_CONTROL_ERROR)); |
| 2539 EXPECT_STREQ("UNKNOWN_STATUS", | 2557 EXPECT_STREQ("UNKNOWN_STATUS", |
| 2540 SpdyFramer::StatusCodeToString(NUM_STATUS_CODES)); | 2558 SpdyFramer::StatusCodeToString(NUM_STATUS_CODES)); |
| 2541 } | 2559 } |
| 2542 | 2560 |
| 2543 TEST_F(SpdyFramerSpdy3Test, ControlTypeToStringTest) { | 2561 TEST_P(SpdyFramerTest, ControlTypeToStringTest) { |
| 2544 EXPECT_STREQ("SYN_STREAM", | 2562 EXPECT_STREQ("SYN_STREAM", |
| 2545 SpdyFramer::ControlTypeToString(SYN_STREAM)); | 2563 SpdyFramer::ControlTypeToString(SYN_STREAM)); |
| 2546 EXPECT_STREQ("SYN_REPLY", | 2564 EXPECT_STREQ("SYN_REPLY", |
| 2547 SpdyFramer::ControlTypeToString(SYN_REPLY)); | 2565 SpdyFramer::ControlTypeToString(SYN_REPLY)); |
| 2548 EXPECT_STREQ("RST_STREAM", | 2566 EXPECT_STREQ("RST_STREAM", |
| 2549 SpdyFramer::ControlTypeToString(RST_STREAM)); | 2567 SpdyFramer::ControlTypeToString(RST_STREAM)); |
| 2550 EXPECT_STREQ("SETTINGS", | 2568 EXPECT_STREQ("SETTINGS", |
| 2551 SpdyFramer::ControlTypeToString(SETTINGS)); | 2569 SpdyFramer::ControlTypeToString(SETTINGS)); |
| 2552 EXPECT_STREQ("NOOP", | 2570 EXPECT_STREQ("NOOP", |
| 2553 SpdyFramer::ControlTypeToString(NOOP)); | 2571 SpdyFramer::ControlTypeToString(NOOP)); |
| 2554 EXPECT_STREQ("PING", | 2572 EXPECT_STREQ("PING", |
| 2555 SpdyFramer::ControlTypeToString(PING)); | 2573 SpdyFramer::ControlTypeToString(PING)); |
| 2556 EXPECT_STREQ("GOAWAY", | 2574 EXPECT_STREQ("GOAWAY", |
| 2557 SpdyFramer::ControlTypeToString(GOAWAY)); | 2575 SpdyFramer::ControlTypeToString(GOAWAY)); |
| 2558 EXPECT_STREQ("HEADERS", | 2576 EXPECT_STREQ("HEADERS", |
| 2559 SpdyFramer::ControlTypeToString(HEADERS)); | 2577 SpdyFramer::ControlTypeToString(HEADERS)); |
| 2560 EXPECT_STREQ("WINDOW_UPDATE", | 2578 EXPECT_STREQ("WINDOW_UPDATE", |
| 2561 SpdyFramer::ControlTypeToString(WINDOW_UPDATE)); | 2579 SpdyFramer::ControlTypeToString(WINDOW_UPDATE)); |
| 2562 EXPECT_STREQ("CREDENTIAL", | 2580 EXPECT_STREQ("CREDENTIAL", |
| 2563 SpdyFramer::ControlTypeToString(CREDENTIAL)); | 2581 SpdyFramer::ControlTypeToString(CREDENTIAL)); |
| 2564 EXPECT_STREQ("UNKNOWN_CONTROL_TYPE", | 2582 EXPECT_STREQ("UNKNOWN_CONTROL_TYPE", |
| 2565 SpdyFramer::ControlTypeToString(NUM_CONTROL_FRAME_TYPES)); | 2583 SpdyFramer::ControlTypeToString(NUM_CONTROL_FRAME_TYPES)); |
| 2566 } | 2584 } |
| 2567 | 2585 |
| 2568 TEST_F(SpdyFramerSpdy3Test, GetMinimumControlFrameSizeTest) { | 2586 TEST_P(SpdyFramerTest, GetMinimumControlFrameSizeTest) { |
| 2569 EXPECT_EQ(SpdySynStreamControlFrame::size(), | 2587 EXPECT_EQ(SpdySynStreamControlFrame::size(), |
| 2570 SpdyFramer::GetMinimumControlFrameSize(SYN_STREAM)); | 2588 SpdyFramer::GetMinimumControlFrameSize(SYN_STREAM)); |
| 2571 EXPECT_EQ(SpdySynReplyControlFrame::size(), | 2589 EXPECT_EQ(SpdySynReplyControlFrame::size(), |
| 2572 SpdyFramer::GetMinimumControlFrameSize(SYN_REPLY)); | 2590 SpdyFramer::GetMinimumControlFrameSize(SYN_REPLY)); |
| 2573 EXPECT_EQ(SpdyRstStreamControlFrame::size(), | 2591 EXPECT_EQ(SpdyRstStreamControlFrame::size(), |
| 2574 SpdyFramer::GetMinimumControlFrameSize(RST_STREAM)); | 2592 SpdyFramer::GetMinimumControlFrameSize(RST_STREAM)); |
| 2575 EXPECT_EQ(SpdySettingsControlFrame::size(), | 2593 EXPECT_EQ(SpdySettingsControlFrame::size(), |
| 2576 SpdyFramer::GetMinimumControlFrameSize(SETTINGS)); | 2594 SpdyFramer::GetMinimumControlFrameSize(SETTINGS)); |
| 2577 EXPECT_EQ(SpdyFrame::kHeaderSize, | 2595 EXPECT_EQ(SpdyFrame::kHeaderSize, |
| 2578 SpdyFramer::GetMinimumControlFrameSize(NOOP)); | 2596 SpdyFramer::GetMinimumControlFrameSize(NOOP)); |
| 2579 EXPECT_EQ(SpdyPingControlFrame::size(), | 2597 EXPECT_EQ(SpdyPingControlFrame::size(), |
| 2580 SpdyFramer::GetMinimumControlFrameSize(PING)); | 2598 SpdyFramer::GetMinimumControlFrameSize(PING)); |
| 2581 EXPECT_EQ(SpdyGoAwayControlFrame::size(), | 2599 EXPECT_EQ(SpdyGoAwayControlFrame::size(), |
| 2582 SpdyFramer::GetMinimumControlFrameSize(GOAWAY)); | 2600 SpdyFramer::GetMinimumControlFrameSize(GOAWAY)); |
| 2583 EXPECT_EQ(SpdyHeadersControlFrame::size(), | 2601 EXPECT_EQ(SpdyHeadersControlFrame::size(), |
| 2584 SpdyFramer::GetMinimumControlFrameSize(HEADERS)); | 2602 SpdyFramer::GetMinimumControlFrameSize(HEADERS)); |
| 2585 EXPECT_EQ(SpdyWindowUpdateControlFrame::size(), | 2603 EXPECT_EQ(SpdyWindowUpdateControlFrame::size(), |
| 2586 SpdyFramer::GetMinimumControlFrameSize(WINDOW_UPDATE)); | 2604 SpdyFramer::GetMinimumControlFrameSize(WINDOW_UPDATE)); |
| 2587 EXPECT_EQ(SpdyCredentialControlFrame::size(), | 2605 EXPECT_EQ(SpdyCredentialControlFrame::size(), |
| 2588 SpdyFramer::GetMinimumControlFrameSize(CREDENTIAL)); | 2606 SpdyFramer::GetMinimumControlFrameSize(CREDENTIAL)); |
| 2589 EXPECT_EQ(static_cast<size_t>(0x7FFFFFFF), | 2607 EXPECT_EQ(static_cast<size_t>(0x7FFFFFFF), |
| 2590 SpdyFramer::GetMinimumControlFrameSize(NUM_CONTROL_FRAME_TYPES)); | 2608 SpdyFramer::GetMinimumControlFrameSize(NUM_CONTROL_FRAME_TYPES)); |
| 2591 } | 2609 } |
| 2592 | 2610 |
| 2593 TEST_F(SpdyFramerSpdy3Test, CatchProbableHttpResponse) { | 2611 TEST_P(SpdyFramerTest, CatchProbableHttpResponse) { |
| 2594 SpdyFramerTestUtil::DecompressionVisitor visitor; | 2612 SpdyFramerTestUtil::DecompressionVisitor visitor; |
| 2595 visitor.set_allow_data_frames(true); | 2613 visitor.set_allow_data_frames(true); |
| 2596 { | 2614 { |
| 2597 SpdyFramer framer(kVer); | 2615 SpdyFramer framer(kVer); |
| 2598 framer.set_visitor(&visitor); | 2616 framer.set_visitor(&visitor); |
| 2599 framer.ProcessInput("HTTP/1.1", 8); | 2617 framer.ProcessInput("HTTP/1.1", 8); |
| 2600 EXPECT_TRUE(framer.probable_http_response()); | 2618 EXPECT_TRUE(framer.probable_http_response()); |
| 2601 } | 2619 } |
| 2602 { | 2620 { |
| 2603 SpdyFramer framer(kVer); | 2621 SpdyFramer framer(kVer); |
| 2604 framer.set_visitor(&visitor); | 2622 framer.set_visitor(&visitor); |
| 2605 framer.ProcessInput("HTTP/1.0", 8); | 2623 framer.ProcessInput("HTTP/1.0", 8); |
| 2606 EXPECT_TRUE(framer.probable_http_response()); | 2624 EXPECT_TRUE(framer.probable_http_response()); |
| 2607 } | 2625 } |
| 2608 } | 2626 } |
| 2609 | 2627 |
| 2610 TEST_F(SpdyFramerSpdy3Test, SettingsFlagsAndId) { | 2628 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { |
| 2611 const uint32 kId = 0x020304; | 2629 const uint32 kId = 0x020304; |
| 2612 const uint32 kFlags = 0x01; | 2630 const uint32 kFlags = 0x01; |
| 2613 const uint32 kWireFormat = | 2631 const uint32 kWireFormat = |
| 2614 htonl((SPDY_VERSION_FOR_TESTS < 3) ? 0x04030201 : 0x01020304); | 2632 htonl((spdy_version_ < 3) ? 0x04030201 : 0x01020304); |
| 2615 | 2633 |
| 2616 SettingsFlagsAndId id_and_flags = | 2634 SettingsFlagsAndId id_and_flags = |
| 2617 SettingsFlagsAndId::FromWireFormat(SPDY_VERSION_FOR_TESTS, kWireFormat); | 2635 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); |
| 2618 EXPECT_EQ(kId, id_and_flags.id()); | 2636 EXPECT_EQ(kId, id_and_flags.id()); |
| 2619 EXPECT_EQ(kFlags, id_and_flags.flags()); | 2637 EXPECT_EQ(kFlags, id_and_flags.flags()); |
| 2620 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(SPDY_VERSION_FOR_TESTS)); | 2638 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
| 2621 } | 2639 } |
| 2622 | 2640 |
| 2623 } // namespace | 2641 } // namespace |
| OLD | NEW |