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