| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iostream> | 6 #include <iostream> |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 using testing::_; | 28 using testing::_; |
| 29 | 29 |
| 30 namespace net { | 30 namespace net { |
| 31 | 31 |
| 32 namespace test { | 32 namespace test { |
| 33 | 33 |
| 34 static const size_t kMaxDecompressedSize = 1024; | 34 static const size_t kMaxDecompressedSize = 1024; |
| 35 | 35 |
| 36 class MockDebugVisitor : public SpdyFramerDebugVisitorInterface { | 36 class MockDebugVisitor : public SpdyFramerDebugVisitorInterface { |
| 37 public: | 37 public: |
| 38 MOCK_METHOD4(OnSendCompressedFrame, void(SpdyStreamId stream_id, | 38 MOCK_METHOD4(OnSendCompressedFrame, |
| 39 SpdyFrameType type, | 39 void(SpdyStreamId stream_id, |
| 40 size_t payload_len, | 40 SpdyFrameType type, |
| 41 size_t frame_len)); | 41 size_t payload_len, |
| 42 size_t frame_len)); |
| 42 | 43 |
| 43 MOCK_METHOD3(OnReceiveCompressedFrame, void(SpdyStreamId stream_id, | 44 MOCK_METHOD3(OnReceiveCompressedFrame, |
| 44 SpdyFrameType type, | 45 void(SpdyStreamId stream_id, |
| 45 size_t frame_len)); | 46 SpdyFrameType type, |
| 47 size_t frame_len)); |
| 46 }; | 48 }; |
| 47 | 49 |
| 48 class SpdyFramerTestUtil { | 50 class SpdyFramerTestUtil { |
| 49 public: | 51 public: |
| 50 // Decompress a single frame using the decompression context held by | 52 // Decompress a single frame using the decompression context held by |
| 51 // the SpdyFramer. The implemention is meant for use only in tests | 53 // the SpdyFramer. The implemention is meant for use only in tests |
| 52 // and will CHECK fail if the input is anything other than a single, | 54 // and will CHECK fail if the input is anything other than a single, |
| 53 // well-formed compressed frame. | 55 // well-formed compressed frame. |
| 54 // | 56 // |
| 55 // Returns a new decompressed SpdyFrame. | 57 // Returns a new decompressed SpdyFrame. |
| 56 template<class SpdyFrameType> static SpdyFrame* DecompressFrame( | 58 template <class SpdyFrameType> |
| 57 SpdyFramer* framer, const SpdyFrameType& frame) { | 59 static SpdyFrame* DecompressFrame(SpdyFramer* framer, |
| 60 const SpdyFrameType& frame) { |
| 58 DecompressionVisitor visitor(framer->protocol_version()); | 61 DecompressionVisitor visitor(framer->protocol_version()); |
| 59 framer->set_visitor(&visitor); | 62 framer->set_visitor(&visitor); |
| 60 CHECK_EQ(frame.size(), framer->ProcessInput(frame.data(), frame.size())); | 63 CHECK_EQ(frame.size(), framer->ProcessInput(frame.data(), frame.size())); |
| 61 CHECK_EQ(SpdyFramer::SPDY_RESET, framer->state()); | 64 CHECK_EQ(SpdyFramer::SPDY_RESET, framer->state()); |
| 62 framer->set_visitor(NULL); | 65 framer->set_visitor(NULL); |
| 63 | 66 |
| 64 char* buffer = visitor.ReleaseBuffer(); | 67 char* buffer = visitor.ReleaseBuffer(); |
| 65 CHECK(buffer != NULL); | 68 CHECK(buffer != NULL); |
| 66 SpdyFrame* decompressed_frame = new SpdyFrame(buffer, visitor.size(), true); | 69 SpdyFrame* decompressed_frame = new SpdyFrame(buffer, visitor.size(), true); |
| 67 SetFrameLength(decompressed_frame, | 70 SetFrameLength(decompressed_frame, |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 }; | 223 }; |
| 221 | 224 |
| 222 class TestSpdyVisitor : public SpdyFramerVisitorInterface, | 225 class TestSpdyVisitor : public SpdyFramerVisitorInterface, |
| 223 public SpdyFramerDebugVisitorInterface { | 226 public SpdyFramerDebugVisitorInterface { |
| 224 public: | 227 public: |
| 225 // This is larger than our max frame size because header blocks that | 228 // This is larger than our max frame size because header blocks that |
| 226 // are too long can spill over into CONTINUATION frames. | 229 // are too long can spill over into CONTINUATION frames. |
| 227 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; | 230 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; |
| 228 | 231 |
| 229 explicit TestSpdyVisitor(SpdyMajorVersion version) | 232 explicit TestSpdyVisitor(SpdyMajorVersion version) |
| 230 : framer_(version), | 233 : framer_(version), |
| 231 use_compression_(false), | 234 use_compression_(false), |
| 232 error_count_(0), | 235 error_count_(0), |
| 233 syn_frame_count_(0), | 236 syn_frame_count_(0), |
| 234 syn_reply_frame_count_(0), | 237 syn_reply_frame_count_(0), |
| 235 headers_frame_count_(0), | 238 headers_frame_count_(0), |
| 236 push_promise_frame_count_(0), | 239 push_promise_frame_count_(0), |
| 237 goaway_count_(0), | 240 goaway_count_(0), |
| 238 setting_count_(0), | 241 setting_count_(0), |
| 239 settings_ack_sent_(0), | 242 settings_ack_sent_(0), |
| 240 settings_ack_received_(0), | 243 settings_ack_received_(0), |
| 241 continuation_count_(0), | 244 continuation_count_(0), |
| 242 last_window_update_stream_(0), | 245 last_window_update_stream_(0), |
| 243 last_window_update_delta_(0), | 246 last_window_update_delta_(0), |
| 244 last_push_promise_stream_(0), | 247 last_push_promise_stream_(0), |
| 245 last_push_promise_promised_stream_(0), | 248 last_push_promise_promised_stream_(0), |
| 246 data_bytes_(0), | 249 data_bytes_(0), |
| 247 fin_frame_count_(0), | 250 fin_frame_count_(0), |
| 248 fin_opaque_data_(), | 251 fin_opaque_data_(), |
| 249 fin_flag_count_(0), | 252 fin_flag_count_(0), |
| 250 zero_length_data_frame_count_(0), | 253 zero_length_data_frame_count_(0), |
| 251 control_frame_header_data_count_(0), | 254 control_frame_header_data_count_(0), |
| 252 zero_length_control_frame_header_data_count_(0), | 255 zero_length_control_frame_header_data_count_(0), |
| 253 data_frame_count_(0), | 256 data_frame_count_(0), |
| 254 last_payload_len_(0), | 257 last_payload_len_(0), |
| 255 last_frame_len_(0), | 258 last_frame_len_(0), |
| 256 header_buffer_(new char[kDefaultHeaderBufferSize]), | 259 header_buffer_(new char[kDefaultHeaderBufferSize]), |
| 257 header_buffer_length_(0), | 260 header_buffer_length_(0), |
| 258 header_buffer_size_(kDefaultHeaderBufferSize), | 261 header_buffer_size_(kDefaultHeaderBufferSize), |
| 259 header_stream_id_(-1), | 262 header_stream_id_(-1), |
| 260 header_control_type_(DATA), | 263 header_control_type_(DATA), |
| 261 header_buffer_valid_(false) { | 264 header_buffer_valid_(false) {} |
| 262 } | |
| 263 | 265 |
| 264 virtual void OnError(SpdyFramer* f) OVERRIDE { | 266 virtual void OnError(SpdyFramer* f) OVERRIDE { |
| 265 LOG(INFO) << "SpdyFramer Error: " | 267 LOG(INFO) << "SpdyFramer Error: " |
| 266 << SpdyFramer::ErrorCodeToString(f->error_code()); | 268 << SpdyFramer::ErrorCodeToString(f->error_code()); |
| 267 ++error_count_; | 269 ++error_count_; |
| 268 } | 270 } |
| 269 | 271 |
| 270 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 272 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
| 271 size_t length, | 273 size_t length, |
| 272 bool fin) OVERRIDE { | 274 bool fin) OVERRIDE { |
| 273 ++data_frame_count_; | 275 ++data_frame_count_; |
| 274 header_stream_id_ = stream_id; | 276 header_stream_id_ = stream_id; |
| 275 } | 277 } |
| 276 | 278 |
| 277 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 279 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
| 278 const char* data, | 280 const char* data, |
| 279 size_t len, | 281 size_t len, |
| 280 bool fin) OVERRIDE { | 282 bool fin) OVERRIDE { |
| 281 EXPECT_EQ(header_stream_id_, stream_id); | 283 EXPECT_EQ(header_stream_id_, stream_id); |
| 282 if (len == 0) | 284 if (len == 0) |
| 283 ++zero_length_data_frame_count_; | 285 ++zero_length_data_frame_count_; |
| 284 | 286 |
| 285 data_bytes_ += len; | 287 data_bytes_ += len; |
| 286 std::cerr << "OnStreamFrameData(" << stream_id << ", \""; | 288 std::cerr << "OnStreamFrameData(" << stream_id << ", \""; |
| 287 if (len > 0) { | 289 if (len > 0) { |
| 288 for (size_t i = 0 ; i < len; ++i) { | 290 for (size_t i = 0; i < len; ++i) { |
| 289 std::cerr << std::hex << (0xFF & (unsigned int)data[i]) << std::dec; | 291 std::cerr << std::hex << (0xFF & (unsigned int)data[i]) << std::dec; |
| 290 } | 292 } |
| 291 } | 293 } |
| 292 std::cerr << "\", " << len << ")\n"; | 294 std::cerr << "\", " << len << ")\n"; |
| 293 } | 295 } |
| 294 | 296 |
| 295 virtual bool OnControlFrameHeaderData(SpdyStreamId stream_id, | 297 virtual bool OnControlFrameHeaderData(SpdyStreamId stream_id, |
| 296 const char* header_data, | 298 const char* header_data, |
| 297 size_t len) OVERRIDE { | 299 size_t len) OVERRIDE { |
| 298 ++control_frame_header_data_count_; | 300 ++control_frame_header_data_count_; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 uint32 value) OVERRIDE { | 359 uint32 value) OVERRIDE { |
| 358 ++setting_count_; | 360 ++setting_count_; |
| 359 } | 361 } |
| 360 | 362 |
| 361 virtual void OnSettingsAck() OVERRIDE { | 363 virtual void OnSettingsAck() OVERRIDE { |
| 362 DCHECK_LT(SPDY3, framer_.protocol_version()); | 364 DCHECK_LT(SPDY3, framer_.protocol_version()); |
| 363 ++settings_ack_received_; | 365 ++settings_ack_received_; |
| 364 } | 366 } |
| 365 | 367 |
| 366 virtual void OnSettingsEnd() OVERRIDE { | 368 virtual void OnSettingsEnd() OVERRIDE { |
| 367 if (framer_.protocol_version() <= SPDY3) { return; } | 369 if (framer_.protocol_version() <= SPDY3) { |
| 370 return; |
| 371 } |
| 368 ++settings_ack_sent_; | 372 ++settings_ack_sent_; |
| 369 } | 373 } |
| 370 | 374 |
| 371 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE { | 375 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE { |
| 372 DLOG(FATAL); | 376 DLOG(FATAL); |
| 373 } | 377 } |
| 374 | 378 |
| 375 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 379 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
| 376 SpdyGoAwayStatus status) OVERRIDE { | 380 SpdyGoAwayStatus status) OVERRIDE { |
| 377 ++goaway_count_; | 381 ++goaway_count_; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 framer_.set_enable_compression(use_compression_); | 427 framer_.set_enable_compression(use_compression_); |
| 424 framer_.set_visitor(this); | 428 framer_.set_visitor(this); |
| 425 size_t input_remaining = size; | 429 size_t input_remaining = size; |
| 426 const char* input_ptr = reinterpret_cast<const char*>(input); | 430 const char* input_ptr = reinterpret_cast<const char*>(input); |
| 427 while (input_remaining > 0 && | 431 while (input_remaining > 0 && |
| 428 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { | 432 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { |
| 429 // To make the tests more interesting, we feed random (amd small) chunks | 433 // To make the tests more interesting, we feed random (amd small) chunks |
| 430 // into the framer. This simulates getting strange-sized reads from | 434 // into the framer. This simulates getting strange-sized reads from |
| 431 // the socket. | 435 // the socket. |
| 432 const size_t kMaxReadSize = 32; | 436 const size_t kMaxReadSize = 32; |
| 433 size_t bytes_read = | 437 size_t bytes_read = (rand() % min(input_remaining, kMaxReadSize)) + 1; |
| 434 (rand() % min(input_remaining, kMaxReadSize)) + 1; | |
| 435 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); | 438 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); |
| 436 input_remaining -= bytes_processed; | 439 input_remaining -= bytes_processed; |
| 437 input_ptr += bytes_processed; | 440 input_ptr += bytes_processed; |
| 438 } | 441 } |
| 439 } | 442 } |
| 440 | 443 |
| 441 void InitHeaderStreaming(SpdyFrameType header_control_type, | 444 void InitHeaderStreaming(SpdyFrameType header_control_type, |
| 442 SpdyStreamId stream_id) { | 445 SpdyStreamId stream_id) { |
| 443 DCHECK_GE(header_control_type, FIRST_CONTROL_TYPE); | 446 DCHECK_GE(header_control_type, FIRST_CONTROL_TYPE); |
| 444 DCHECK_LE(header_control_type, LAST_CONTROL_TYPE); | 447 DCHECK_LE(header_control_type, LAST_CONTROL_TYPE); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 uint8 flags; | 518 uint8 flags; |
| 516 reader.ReadUInt8(&flags); | 519 reader.ReadUInt8(&flags); |
| 517 if (flags & HEADERS_FLAG_PRIORITY) { | 520 if (flags & HEADERS_FLAG_PRIORITY) { |
| 518 frame_type = SYN_STREAM; | 521 frame_type = SYN_STREAM; |
| 519 } | 522 } |
| 520 } else { | 523 } else { |
| 521 uint16 serialized_type; | 524 uint16 serialized_type; |
| 522 reader.ReadUInt16(&serialized_type); | 525 reader.ReadUInt16(&serialized_type); |
| 523 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), | 526 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), |
| 524 serialized_type); | 527 serialized_type); |
| 525 DCHECK(frame_type == HEADERS || | 528 DCHECK(frame_type == HEADERS || frame_type == SYN_STREAM) << frame_type; |
| 526 frame_type == SYN_STREAM) << frame_type; | |
| 527 } | 529 } |
| 528 | 530 |
| 529 if (frame_type == SYN_STREAM) { | 531 if (frame_type == SYN_STREAM) { |
| 530 return StringPiece(frame->data() + framer.GetSynStreamMinimumSize(), | 532 return StringPiece(frame->data() + framer.GetSynStreamMinimumSize(), |
| 531 frame->size() - framer.GetSynStreamMinimumSize()); | 533 frame->size() - framer.GetSynStreamMinimumSize()); |
| 532 } else { | 534 } else { |
| 533 return StringPiece(frame->data() + framer.GetHeadersMinimumSize(), | 535 return StringPiece(frame->data() + framer.GetHeadersMinimumSize(), |
| 534 frame->size() - framer.GetHeadersMinimumSize()); | 536 frame->size() - framer.GetHeadersMinimumSize()); |
| 535 } | 537 } |
| 536 } | 538 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 SpdySynStreamIR syn_stream(1); | 629 SpdySynStreamIR syn_stream(1); |
| 628 syn_stream.set_priority(1); | 630 syn_stream.set_priority(1); |
| 629 syn_stream.SetHeader("alpha", "beta"); | 631 syn_stream.SetHeader("alpha", "beta"); |
| 630 syn_stream.SetHeader("gamma", "charlie"); | 632 syn_stream.SetHeader("gamma", "charlie"); |
| 631 syn_stream.SetHeader("cookie", "key1=value1; key2=value2"); | 633 syn_stream.SetHeader("cookie", "key1=value1; key2=value2"); |
| 632 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 634 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 633 EXPECT_TRUE(frame.get() != NULL); | 635 EXPECT_TRUE(frame.get() != NULL); |
| 634 | 636 |
| 635 TestSpdyVisitor visitor(spdy_version_); | 637 TestSpdyVisitor visitor(spdy_version_); |
| 636 visitor.use_compression_ = false; | 638 visitor.use_compression_ = false; |
| 637 visitor.SimulateInFramer( | 639 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame->data()), |
| 638 reinterpret_cast<unsigned char*>(frame->data()), | 640 frame->size()); |
| 639 frame->size()); | |
| 640 | 641 |
| 641 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 642 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 642 EXPECT_TRUE(CompareHeaderBlocks(&syn_stream.name_value_block(), | 643 EXPECT_TRUE( |
| 643 &visitor.headers_)); | 644 CompareHeaderBlocks(&syn_stream.name_value_block(), &visitor.headers_)); |
| 644 } | 645 } |
| 645 | 646 |
| 646 // Test that if there's not a full frame, we fail to parse it. | 647 // Test that if there's not a full frame, we fail to parse it. |
| 647 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { | 648 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { |
| 648 SpdyFramer framer(spdy_version_); | 649 SpdyFramer framer(spdy_version_); |
| 649 framer.set_enable_compression(false); | 650 framer.set_enable_compression(false); |
| 650 | 651 |
| 651 // Encode the header block into a SynStream frame. | 652 // Encode the header block into a SynStream frame. |
| 652 SpdySynStreamIR syn_stream(1); | 653 SpdySynStreamIR syn_stream(1); |
| 653 syn_stream.set_priority(1); | 654 syn_stream.set_priority(1); |
| 654 syn_stream.SetHeader("alpha", "beta"); | 655 syn_stream.SetHeader("alpha", "beta"); |
| 655 syn_stream.SetHeader("gamma", "charlie"); | 656 syn_stream.SetHeader("gamma", "charlie"); |
| 656 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 657 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 657 EXPECT_TRUE(frame.get() != NULL); | 658 EXPECT_TRUE(frame.get() != NULL); |
| 658 | 659 |
| 659 TestSpdyVisitor visitor(spdy_version_); | 660 TestSpdyVisitor visitor(spdy_version_); |
| 660 visitor.use_compression_ = false; | 661 visitor.use_compression_ = false; |
| 661 visitor.SimulateInFramer( | 662 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame->data()), |
| 662 reinterpret_cast<unsigned char*>(frame->data()), | 663 frame->size() - 2); |
| 663 frame->size() - 2); | |
| 664 | 664 |
| 665 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 665 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
| 666 EXPECT_EQ(0u, visitor.headers_.size()); | 666 EXPECT_EQ(0u, visitor.headers_.size()); |
| 667 } | 667 } |
| 668 | 668 |
| 669 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error | 669 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error |
| 670 // (but don't crash). | 670 // (but don't crash). |
| 671 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { | 671 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { |
| 672 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 672 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 673 SpdyFramer framer(spdy_version_); | 673 SpdyFramer framer(spdy_version_); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 return; | 738 return; |
| 739 } | 739 } |
| 740 | 740 |
| 741 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 741 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 742 SpdyFramer framer(spdy_version_); | 742 SpdyFramer framer(spdy_version_); |
| 743 framer.set_visitor(&visitor); | 743 framer.set_visitor(&visitor); |
| 744 | 744 |
| 745 SpdyPushPromiseIR push_promise(3, 0); | 745 SpdyPushPromiseIR push_promise(3, 0); |
| 746 push_promise.SetHeader("alpha", "beta"); | 746 push_promise.SetHeader("alpha", "beta"); |
| 747 scoped_ptr<SpdySerializedFrame> frame( | 747 scoped_ptr<SpdySerializedFrame> frame( |
| 748 framer.SerializePushPromise(push_promise)); | 748 framer.SerializePushPromise(push_promise)); |
| 749 ASSERT_TRUE(frame.get() != NULL); | 749 ASSERT_TRUE(frame.get() != NULL); |
| 750 | 750 |
| 751 // We shouldn't have to read the whole frame before we signal an error. | 751 // We shouldn't have to read the whole frame before we signal an error. |
| 752 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); | 752 EXPECT_CALL(visitor, OnError(testing::Eq(&framer))); |
| 753 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); | 753 EXPECT_GT(frame->size(), framer.ProcessInput(frame->data(), frame->size())); |
| 754 EXPECT_TRUE(framer.HasError()); | 754 EXPECT_TRUE(framer.HasError()); |
| 755 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 755 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 756 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 756 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 757 } | 757 } |
| 758 | 758 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 } | 791 } |
| 792 // write the length | 792 // write the length |
| 793 frame.RewriteLength(framer); | 793 frame.RewriteLength(framer); |
| 794 | 794 |
| 795 SpdyHeaderBlock new_headers; | 795 SpdyHeaderBlock new_headers; |
| 796 framer.set_enable_compression(false); | 796 framer.set_enable_compression(false); |
| 797 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 797 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 798 base::StringPiece serialized_headers = | 798 base::StringPiece serialized_headers = |
| 799 GetSerializedHeaders(control_frame.get(), framer); | 799 GetSerializedHeaders(control_frame.get(), framer); |
| 800 // This should fail because duplicate headers are verboten by the spec. | 800 // This should fail because duplicate headers are verboten by the spec. |
| 801 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 801 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer( |
| 802 serialized_headers.size(), | 802 serialized_headers.data(), serialized_headers.size(), &new_headers)); |
| 803 &new_headers)); | |
| 804 } | 803 } |
| 805 | 804 |
| 806 TEST_P(SpdyFramerTest, MultiValueHeader) { | 805 TEST_P(SpdyFramerTest, MultiValueHeader) { |
| 807 SpdyFramer framer(spdy_version_); | 806 SpdyFramer framer(spdy_version_); |
| 808 // Frame builder with plentiful buffer size. | 807 // Frame builder with plentiful buffer size. |
| 809 SpdyFrameBuilder frame(1024, spdy_version_); | 808 SpdyFrameBuilder frame(1024, spdy_version_); |
| 810 if (spdy_version_ <= SPDY3) { | 809 if (spdy_version_ <= SPDY3) { |
| 811 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); | 810 frame.WriteControlFrameHeader(framer, SYN_STREAM, CONTROL_FLAG_NONE); |
| 812 frame.WriteUInt32(3); // stream_id | 811 frame.WriteUInt32(3); // stream_id |
| 813 frame.WriteUInt32(0); // associated stream id | 812 frame.WriteUInt32(0); // associated stream id |
| 814 frame.WriteUInt16(0); // Priority. | 813 frame.WriteUInt16(0); // Priority. |
| 815 } else { | 814 } else { |
| 816 frame.BeginNewFrame(framer, | 815 frame.BeginNewFrame( |
| 817 HEADERS, | 816 framer, HEADERS, HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, 3); |
| 818 HEADERS_FLAG_PRIORITY | HEADERS_FLAG_END_HEADERS, | |
| 819 3); | |
| 820 frame.WriteUInt32(framer.GetHighestPriority()); | 817 frame.WriteUInt32(framer.GetHighestPriority()); |
| 821 } | 818 } |
| 822 | 819 |
| 823 string value("value1\0value2", 13); | 820 string value("value1\0value2", 13); |
| 824 if (IsSpdy2()) { | 821 if (IsSpdy2()) { |
| 825 frame.WriteUInt16(1); // Number of headers. | 822 frame.WriteUInt16(1); // Number of headers. |
| 826 frame.WriteString("name"); | 823 frame.WriteString("name"); |
| 827 frame.WriteString(value); | 824 frame.WriteString(value); |
| 828 } else if (spdy_version_ > SPDY3) { | 825 } else if (spdy_version_ > SPDY3) { |
| 829 // TODO(jgraettinger): If this pattern appears again, move to test class. | 826 // TODO(jgraettinger): If this pattern appears again, move to test class. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 843 | 840 |
| 844 framer.set_enable_compression(false); | 841 framer.set_enable_compression(false); |
| 845 scoped_ptr<SpdyFrame> control_frame(frame.take()); | 842 scoped_ptr<SpdyFrame> control_frame(frame.take()); |
| 846 | 843 |
| 847 TestSpdyVisitor visitor(spdy_version_); | 844 TestSpdyVisitor visitor(spdy_version_); |
| 848 visitor.use_compression_ = false; | 845 visitor.use_compression_ = false; |
| 849 visitor.SimulateInFramer( | 846 visitor.SimulateInFramer( |
| 850 reinterpret_cast<unsigned char*>(control_frame->data()), | 847 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 851 control_frame->size()); | 848 control_frame->size()); |
| 852 | 849 |
| 853 EXPECT_THAT(visitor.headers_, ElementsAre( | 850 EXPECT_THAT(visitor.headers_, ElementsAre(Pair("name", value))); |
| 854 Pair("name", value))); | |
| 855 } | 851 } |
| 856 | 852 |
| 857 TEST_P(SpdyFramerTest, BasicCompression) { | 853 TEST_P(SpdyFramerTest, BasicCompression) { |
| 858 if (spdy_version_ > SPDY3) { | 854 if (spdy_version_ > SPDY3) { |
| 859 // Deflate compression doesn't apply to HPACK. | 855 // Deflate compression doesn't apply to HPACK. |
| 860 return; | 856 return; |
| 861 } | 857 } |
| 862 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); | 858 scoped_ptr<TestSpdyVisitor> visitor(new TestSpdyVisitor(spdy_version_)); |
| 863 SpdyFramer framer(spdy_version_); | 859 SpdyFramer framer(spdy_version_); |
| 864 framer.set_debug_visitor(visitor.get()); | 860 framer.set_debug_visitor(visitor.get()); |
| 865 SpdySynStreamIR syn_stream(1); | 861 SpdySynStreamIR syn_stream(1); |
| 866 syn_stream.set_priority(1); | 862 syn_stream.set_priority(1); |
| 867 syn_stream.SetHeader("server", "SpdyServer 1.0"); | 863 syn_stream.SetHeader("server", "SpdyServer 1.0"); |
| 868 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 864 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
| 869 syn_stream.SetHeader("status", "200"); | 865 syn_stream.SetHeader("status", "200"); |
| 870 syn_stream.SetHeader("version", "HTTP/1.1"); | 866 syn_stream.SetHeader("version", "HTTP/1.1"); |
| 871 syn_stream.SetHeader("content-type", "text/html"); | 867 syn_stream.SetHeader("content-type", "text/html"); |
| 872 syn_stream.SetHeader("content-length", "12"); | 868 syn_stream.SetHeader("content-length", "12"); |
| 873 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); | 869 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); |
| 874 size_t uncompressed_size1 = visitor->last_payload_len_; | 870 size_t uncompressed_size1 = visitor->last_payload_len_; |
| 875 size_t compressed_size1 = | 871 size_t compressed_size1 = |
| 876 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 872 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
| 877 if (IsSpdy2()) { | 873 if (IsSpdy2()) { |
| 878 EXPECT_EQ(139u, uncompressed_size1); | 874 EXPECT_EQ(139u, uncompressed_size1); |
| 879 #if defined(USE_SYSTEM_ZLIB) | 875 #if defined(USE_SYSTEM_ZLIB) |
| 880 EXPECT_EQ(155u, compressed_size1); | 876 EXPECT_EQ(155u, compressed_size1); |
| 881 #else // !defined(USE_SYSTEM_ZLIB) | 877 #else // !defined(USE_SYSTEM_ZLIB) |
| 882 EXPECT_EQ(135u, compressed_size1); | 878 EXPECT_EQ(135u, compressed_size1); |
| 883 #endif // !defined(USE_SYSTEM_ZLIB) | 879 #endif // !defined(USE_SYSTEM_ZLIB) |
| 884 } else { | 880 } else { |
| 885 EXPECT_EQ(165u, uncompressed_size1); | 881 EXPECT_EQ(165u, uncompressed_size1); |
| 886 #if defined(USE_SYSTEM_ZLIB) | 882 #if defined(USE_SYSTEM_ZLIB) |
| 887 EXPECT_EQ(181u, compressed_size1); | 883 EXPECT_EQ(181u, compressed_size1); |
| 888 #else // !defined(USE_SYSTEM_ZLIB) | 884 #else // !defined(USE_SYSTEM_ZLIB) |
| 889 EXPECT_EQ(117u, compressed_size1); | 885 EXPECT_EQ(117u, compressed_size1); |
| 890 #endif // !defined(USE_SYSTEM_ZLIB) | 886 #endif // !defined(USE_SYSTEM_ZLIB) |
| 891 } | 887 } |
| 892 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); | 888 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); |
| 893 size_t uncompressed_size2 = visitor->last_payload_len_; | 889 size_t uncompressed_size2 = visitor->last_payload_len_; |
| 894 size_t compressed_size2 = | 890 size_t compressed_size2 = |
| 895 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 891 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
| 896 | 892 |
| 897 // Expect the second frame to be more compact than the first. | 893 // Expect the second frame to be more compact than the first. |
| 898 EXPECT_LE(frame2->size(), frame1->size()); | 894 EXPECT_LE(frame2->size(), frame1->size()); |
| 899 | 895 |
| 900 // Decompress the first frame | 896 // Decompress the first frame |
| 901 scoped_ptr<SpdyFrame> frame3(SpdyFramerTestUtil::DecompressFrame( | 897 scoped_ptr<SpdyFrame> frame3( |
| 902 &framer, *frame1.get())); | 898 SpdyFramerTestUtil::DecompressFrame(&framer, *frame1.get())); |
| 903 | 899 |
| 904 // Decompress the second frame | 900 // Decompress the second frame |
| 905 visitor.reset(new TestSpdyVisitor(spdy_version_)); | 901 visitor.reset(new TestSpdyVisitor(spdy_version_)); |
| 906 framer.set_debug_visitor(visitor.get()); | 902 framer.set_debug_visitor(visitor.get()); |
| 907 scoped_ptr<SpdyFrame> frame4(SpdyFramerTestUtil::DecompressFrame( | 903 scoped_ptr<SpdyFrame> frame4( |
| 908 &framer, *frame2.get())); | 904 SpdyFramerTestUtil::DecompressFrame(&framer, *frame2.get())); |
| 909 size_t uncompressed_size4 = | 905 size_t uncompressed_size4 = frame4->size() - framer.GetSynStreamMinimumSize(); |
| 910 frame4->size() - framer.GetSynStreamMinimumSize(); | |
| 911 size_t compressed_size4 = | 906 size_t compressed_size4 = |
| 912 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 907 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
| 913 if (IsSpdy2()) { | 908 if (IsSpdy2()) { |
| 914 EXPECT_EQ(139u, uncompressed_size4); | 909 EXPECT_EQ(139u, uncompressed_size4); |
| 915 #if defined(USE_SYSTEM_ZLIB) | 910 #if defined(USE_SYSTEM_ZLIB) |
| 916 EXPECT_EQ(149u, compressed_size4); | 911 EXPECT_EQ(149u, compressed_size4); |
| 917 #else // !defined(USE_SYSTEM_ZLIB) | 912 #else // !defined(USE_SYSTEM_ZLIB) |
| 918 EXPECT_EQ(101u, compressed_size4); | 913 EXPECT_EQ(101u, compressed_size4); |
| 919 #endif // !defined(USE_SYSTEM_ZLIB) | 914 #endif // !defined(USE_SYSTEM_ZLIB) |
| 920 } else { | 915 } else { |
| 921 EXPECT_EQ(165u, uncompressed_size4); | 916 EXPECT_EQ(165u, uncompressed_size4); |
| 922 #if defined(USE_SYSTEM_ZLIB) | 917 #if defined(USE_SYSTEM_ZLIB) |
| 923 EXPECT_EQ(175u, compressed_size4); | 918 EXPECT_EQ(175u, compressed_size4); |
| 924 #else // !defined(USE_SYSTEM_ZLIB) | 919 #else // !defined(USE_SYSTEM_ZLIB) |
| 925 EXPECT_EQ(102u, compressed_size4); | 920 EXPECT_EQ(102u, compressed_size4); |
| 926 #endif // !defined(USE_SYSTEM_ZLIB) | 921 #endif // !defined(USE_SYSTEM_ZLIB) |
| 927 } | 922 } |
| 928 | 923 |
| 929 EXPECT_EQ(uncompressed_size1, uncompressed_size2); | 924 EXPECT_EQ(uncompressed_size1, uncompressed_size2); |
| 930 EXPECT_EQ(uncompressed_size1, uncompressed_size4); | 925 EXPECT_EQ(uncompressed_size1, uncompressed_size4); |
| 931 EXPECT_EQ(compressed_size2, compressed_size4); | 926 EXPECT_EQ(compressed_size2, compressed_size4); |
| 932 | 927 |
| 933 // Expect frames 3 & 4 to be the same. | 928 // Expect frames 3 & 4 to be the same. |
| 934 CompareFrames("Uncompressed SYN_STREAM", *frame3, *frame4); | 929 CompareFrames("Uncompressed SYN_STREAM", *frame3, *frame4); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 952 syn_stream.SetHeader("content-length", "12"); | 947 syn_stream.SetHeader("content-length", "12"); |
| 953 syn_stream.SetHeader("x-empty-header", ""); | 948 syn_stream.SetHeader("x-empty-header", ""); |
| 954 | 949 |
| 955 SpdyFramer framer(spdy_version_); | 950 SpdyFramer framer(spdy_version_); |
| 956 framer.set_enable_compression(true); | 951 framer.set_enable_compression(true); |
| 957 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); | 952 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); |
| 958 } | 953 } |
| 959 | 954 |
| 960 TEST_P(SpdyFramerTest, Basic) { | 955 TEST_P(SpdyFramerTest, Basic) { |
| 961 const unsigned char kV2Input[] = { | 956 const unsigned char kV2Input[] = { |
| 962 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 957 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 963 0x00, 0x00, 0x00, 0x14, | 958 0x00, 0x00, 0x00, 0x14, |
| 964 0x00, 0x00, 0x00, 0x01, | 959 0x00, 0x00, 0x00, 0x01, |
| 965 0x00, 0x00, 0x00, 0x00, | 960 0x00, 0x00, 0x00, 0x00, |
| 966 0x00, 0x00, 0x00, 0x01, | 961 0x00, 0x00, 0x00, 0x01, |
| 967 0x00, 0x02, 'h', 'h', | 962 0x00, 0x02, 'h', 'h', |
| 968 0x00, 0x02, 'v', 'v', | 963 0x00, 0x02, 'v', 'v', |
| 969 | 964 0x80, spdy_version_ch_, 0x00, 0x08, // HEADERS on Stream #1 |
| 970 0x80, spdy_version_ch_, 0x00, 0x08, // HEADERS on Stream #1 | 965 0x00, 0x00, 0x00, 0x18, |
| 971 0x00, 0x00, 0x00, 0x18, | 966 0x00, 0x00, 0x00, 0x01, |
| 972 0x00, 0x00, 0x00, 0x01, | 967 0x00, 0x00, 0x00, 0x02, |
| 973 0x00, 0x00, 0x00, 0x02, | 968 0x00, 0x02, 'h', '2', |
| 974 0x00, 0x02, 'h', '2', | 969 0x00, 0x02, 'v', '2', |
| 975 0x00, 0x02, 'v', '2', | 970 0x00, 0x02, 'h', '3', |
| 976 0x00, 0x02, 'h', '3', | 971 0x00, 0x02, 'v', '3', |
| 977 0x00, 0x02, 'v', '3', | 972 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 978 | 973 0x00, 0x00, 0x00, 0x0c, |
| 979 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 974 0xde, 0xad, 0xbe, 0xef, |
| 980 0x00, 0x00, 0x00, 0x0c, | 975 0xde, 0xad, 0xbe, 0xef, |
| 981 0xde, 0xad, 0xbe, 0xef, | 976 0xde, 0xad, 0xbe, 0xef, |
| 982 0xde, 0xad, 0xbe, 0xef, | 977 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #3 |
| 983 0xde, 0xad, 0xbe, 0xef, | 978 0x00, 0x00, 0x00, 0x0c, |
| 984 | 979 0x00, 0x00, 0x00, 0x03, |
| 985 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #3 | 980 0x00, 0x00, 0x00, 0x00, |
| 986 0x00, 0x00, 0x00, 0x0c, | 981 0x00, 0x00, 0x00, 0x00, |
| 987 0x00, 0x00, 0x00, 0x03, | 982 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 988 0x00, 0x00, 0x00, 0x00, | 983 0x00, 0x00, 0x00, 0x08, |
| 989 0x00, 0x00, 0x00, 0x00, | 984 0xde, 0xad, 0xbe, 0xef, |
| 990 | 985 0xde, 0xad, 0xbe, 0xef, |
| 991 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 986 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 992 0x00, 0x00, 0x00, 0x08, | 987 0x00, 0x00, 0x00, 0x04, |
| 993 0xde, 0xad, 0xbe, 0xef, | 988 0xde, 0xad, 0xbe, 0xef, |
| 994 0xde, 0xad, 0xbe, 0xef, | 989 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 |
| 995 | 990 0x00, 0x00, 0x00, 0x08, |
| 996 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 991 0x00, 0x00, 0x00, 0x01, |
| 997 0x00, 0x00, 0x00, 0x04, | 992 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 998 0xde, 0xad, 0xbe, 0xef, | 993 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 999 | 994 0x00, 0x00, 0x00, 0x00, |
| 1000 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | 995 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 1001 0x00, 0x00, 0x00, 0x08, | 996 0x00, 0x00, 0x00, 0x08, |
| 1002 0x00, 0x00, 0x00, 0x01, | 997 0x00, 0x00, 0x00, 0x03, |
| 1003 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | 998 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1004 | |
| 1005 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | |
| 1006 0x00, 0x00, 0x00, 0x00, | |
| 1007 | |
| 1008 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | |
| 1009 0x00, 0x00, 0x00, 0x08, | |
| 1010 0x00, 0x00, 0x00, 0x03, | |
| 1011 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
| 1012 }; | 999 }; |
| 1013 | 1000 |
| 1014 const unsigned char kV3Input[] = { | 1001 const unsigned char kV3Input[] = { |
| 1015 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1002 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 1016 0x00, 0x00, 0x00, 0x1a, | 1003 0x00, 0x00, 0x00, 0x1a, |
| 1017 0x00, 0x00, 0x00, 0x01, | 1004 0x00, 0x00, 0x00, 0x01, |
| 1018 0x00, 0x00, 0x00, 0x00, | 1005 0x00, 0x00, 0x00, 0x00, |
| 1019 0x00, 0x00, 0x00, 0x00, | 1006 0x00, 0x00, 0x00, 0x00, |
| 1020 0x00, 0x01, 0x00, 0x00, | 1007 0x00, 0x01, 0x00, 0x00, |
| 1021 0x00, 0x02, 'h', 'h', | 1008 0x00, 0x02, 'h', 'h', |
| 1022 0x00, 0x00, 0x00, 0x02, | 1009 0x00, 0x00, 0x00, 0x02, |
| 1023 'v', 'v', | 1010 'v', 'v', 0x80, spdy_version_ch_, |
| 1024 | 1011 0x00, 0x08, // HEADERS on Stream #1 |
| 1025 0x80, spdy_version_ch_, 0x00, 0x08, // HEADERS on Stream #1 | 1012 0x00, 0x00, 0x00, 0x20, |
| 1026 0x00, 0x00, 0x00, 0x20, | 1013 0x00, 0x00, 0x00, 0x01, |
| 1027 0x00, 0x00, 0x00, 0x01, | 1014 0x00, 0x00, 0x00, 0x02, |
| 1028 0x00, 0x00, 0x00, 0x02, | 1015 0x00, 0x00, 0x00, 0x02, |
| 1029 0x00, 0x00, 0x00, 0x02, | 1016 'h', '2', 0x00, 0x00, |
| 1030 'h', '2', | 1017 0x00, 0x02, 'v', '2', |
| 1031 0x00, 0x00, 0x00, 0x02, | 1018 0x00, 0x00, 0x00, 0x02, |
| 1032 'v', '2', 0x00, 0x00, | 1019 'h', '3', 0x00, 0x00, |
| 1033 0x00, 0x02, 'h', '3', | 1020 0x00, 0x02, 'v', '3', |
| 1034 0x00, 0x00, 0x00, 0x02, | 1021 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1035 'v', '3', | 1022 0x00, 0x00, 0x00, 0x0c, |
| 1036 | 1023 0xde, 0xad, 0xbe, 0xef, |
| 1037 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 1024 0xde, 0xad, 0xbe, 0xef, |
| 1038 0x00, 0x00, 0x00, 0x0c, | 1025 0xde, 0xad, 0xbe, 0xef, |
| 1039 0xde, 0xad, 0xbe, 0xef, | 1026 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #3 |
| 1040 0xde, 0xad, 0xbe, 0xef, | 1027 0x00, 0x00, 0x00, 0x0e, |
| 1041 0xde, 0xad, 0xbe, 0xef, | 1028 0x00, 0x00, 0x00, 0x03, |
| 1042 | 1029 0x00, 0x00, 0x00, 0x00, |
| 1043 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #3 | 1030 0x00, 0x00, 0x00, 0x00, |
| 1044 0x00, 0x00, 0x00, 0x0e, | 1031 0x00, 0x00, 0x00, 0x00, |
| 1045 0x00, 0x00, 0x00, 0x03, | 1032 0x00, 0x03, // DATA on Stream #3 |
| 1046 0x00, 0x00, 0x00, 0x00, | 1033 0x00, 0x00, 0x00, 0x08, |
| 1047 0x00, 0x00, 0x00, 0x00, | 1034 0xde, 0xad, 0xbe, 0xef, |
| 1048 0x00, 0x00, | 1035 0xde, 0xad, 0xbe, 0xef, |
| 1049 | 1036 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1050 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | 1037 0x00, 0x00, 0x00, 0x04, |
| 1051 0x00, 0x00, 0x00, 0x08, | 1038 0xde, 0xad, 0xbe, 0xef, |
| 1052 0xde, 0xad, 0xbe, 0xef, | 1039 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 |
| 1053 0xde, 0xad, 0xbe, 0xef, | 1040 0x00, 0x00, 0x00, 0x08, |
| 1054 | 1041 0x00, 0x00, 0x00, 0x01, |
| 1055 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 1042 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1056 0x00, 0x00, 0x00, 0x04, | 1043 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 |
| 1057 0xde, 0xad, 0xbe, 0xef, | 1044 0x00, 0x00, 0x00, 0x00, |
| 1058 | 1045 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
| 1059 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #1 | 1046 0x00, 0x00, 0x00, 0x08, |
| 1060 0x00, 0x00, 0x00, 0x08, | 1047 0x00, 0x00, 0x00, 0x03, |
| 1061 0x00, 0x00, 0x00, 0x01, | 1048 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
| 1062 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
| 1063 | |
| 1064 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 | |
| 1065 0x00, 0x00, 0x00, 0x00, | |
| 1066 | |
| 1067 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | |
| 1068 0x00, 0x00, 0x00, 0x08, | |
| 1069 0x00, 0x00, 0x00, 0x03, | |
| 1070 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | |
| 1071 }; | 1049 }; |
| 1072 | 1050 |
| 1073 // SYN_STREAM doesn't exist in SPDY4, so instead we send | 1051 // SYN_STREAM doesn't exist in SPDY4, so instead we send |
| 1074 // HEADERS frames with PRIORITY and END_HEADERS set. | 1052 // HEADERS frames with PRIORITY and END_HEADERS set. |
| 1075 const unsigned char kV4Input[] = { | 1053 const unsigned char kV4Input[] = { |
| 1076 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1054 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS |
| 1077 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1055 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1078 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1056 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1079 0x82, // :method: GET | 1057 0x82, // :method: GET |
| 1080 | 1058 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS |
| 1081 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS | 1059 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1082 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1060 0x8c, // :status: 200 |
| 1083 0x8c, // :status: 200 | 1061 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 |
| 1084 | 1062 0x00, 0x00, 0x00, 0x01, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, |
| 1085 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 | 1063 0xef, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x05, 0x01, 0x0c, // HEADERS: |
| 1086 0x00, 0x00, 0x00, 0x01, | 1064 // PRIORITY | |
| 1087 0xde, 0xad, 0xbe, 0xef, | 1065 // END_HEADERS |
| 1088 0xde, 0xad, 0xbe, 0xef, | 1066 0x00, 0x00, 0x00, 0x03, // Stream 3 |
| 1089 0xde, 0xad, 0xbe, 0xef, | 1067 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1090 | 1068 0x82, // :method: GET |
| 1091 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1069 0x00, 0x08, 0x00, 0x00, // DATA on Stream #3 |
| 1092 0x00, 0x00, 0x00, 0x03, // Stream 3 | 1070 0x00, 0x00, 0x00, 0x03, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, |
| 1093 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1071 0xef, 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 |
| 1094 0x82, // :method: GET | 1072 0x00, 0x00, 0x00, 0x01, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x04, 0x03, |
| 1095 | 1073 0x00, // RST_STREAM on Stream #1 |
| 1096 0x00, 0x08, 0x00, 0x00, // DATA on Stream #3 | 1074 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL |
| 1097 0x00, 0x00, 0x00, 0x03, | 1075 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 |
| 1098 0xde, 0xad, 0xbe, 0xef, | 1076 0x00, 0x00, 0x00, 0x03, 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream |
| 1099 0xde, 0xad, 0xbe, 0xef, | 1077 // #3 |
| 1100 | 1078 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL |
| 1101 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 | 1079 0x52, 0x45, 0x53, 0x45, // opaque data |
| 1102 0x00, 0x00, 0x00, 0x01, | 1080 0x54, 0x53, 0x54, 0x52, 0x45, 0x41, 0x4d, |
| 1103 0xde, 0xad, 0xbe, 0xef, | |
| 1104 | |
| 1105 0x00, 0x04, 0x03, 0x00, // RST_STREAM on Stream #1 | |
| 1106 0x00, 0x00, 0x00, 0x01, | |
| 1107 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL | |
| 1108 | |
| 1109 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 | |
| 1110 0x00, 0x00, 0x00, 0x03, | |
| 1111 | |
| 1112 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream #3 | |
| 1113 0x00, 0x00, 0x00, 0x03, | |
| 1114 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL | |
| 1115 0x52, 0x45, 0x53, 0x45, // opaque data | |
| 1116 0x54, 0x53, 0x54, 0x52, | |
| 1117 0x45, 0x41, 0x4d, | |
| 1118 }; | 1081 }; |
| 1119 | 1082 |
| 1120 TestSpdyVisitor visitor(spdy_version_); | 1083 TestSpdyVisitor visitor(spdy_version_); |
| 1121 if (IsSpdy2()) { | 1084 if (IsSpdy2()) { |
| 1122 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1085 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1123 } else if (IsSpdy3()) { | 1086 } else if (IsSpdy3()) { |
| 1124 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1087 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| 1125 } else { | 1088 } else { |
| 1126 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); | 1089 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); |
| 1127 } | 1090 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1143 | 1106 |
| 1144 EXPECT_EQ(0, visitor.fin_flag_count_); | 1107 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1145 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 1108 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 1146 EXPECT_EQ(4, visitor.data_frame_count_); | 1109 EXPECT_EQ(4, visitor.data_frame_count_); |
| 1147 visitor.fin_opaque_data_.clear(); | 1110 visitor.fin_opaque_data_.clear(); |
| 1148 } | 1111 } |
| 1149 | 1112 |
| 1150 // Test that the FIN flag on a data frame signifies EOF. | 1113 // Test that the FIN flag on a data frame signifies EOF. |
| 1151 TEST_P(SpdyFramerTest, FinOnDataFrame) { | 1114 TEST_P(SpdyFramerTest, FinOnDataFrame) { |
| 1152 const unsigned char kV2Input[] = { | 1115 const unsigned char kV2Input[] = { |
| 1153 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1116 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 1154 0x00, 0x00, 0x00, 0x14, | 1117 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, |
| 1155 0x00, 0x00, 0x00, 0x01, | 1118 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 1156 0x00, 0x00, 0x00, 0x00, | 1119 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, |
| 1157 0x00, 0x00, 0x00, 0x01, | 1120 'h', 'h', 0x00, 0x02, 'v', 'v', |
| 1158 0x00, 0x02, 'h', 'h', | 1121 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 |
| 1159 0x00, 0x02, 'v', 'v', | 1122 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, |
| 1160 | 1123 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 1161 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 | 1124 0x00, 0x02, 'a', 'a', 0x00, 0x02, |
| 1162 0x00, 0x00, 0x00, 0x10, | 1125 'b', 'b', 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1163 0x00, 0x00, 0x00, 0x01, | 1126 0x00, 0x00, 0x00, 0x0c, 0xde, 0xad, |
| 1164 0x00, 0x00, 0x00, 0x01, | 1127 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, |
| 1165 0x00, 0x02, 'a', 'a', | 1128 0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, |
| 1166 0x00, 0x02, 'b', 'b', | 1129 0x00, 0x01, // DATA on Stream #1, with EOF |
| 1167 | 1130 0x01, 0x00, 0x00, 0x04, 0xde, 0xad, |
| 1168 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | 1131 0xbe, 0xef, |
| 1169 0x00, 0x00, 0x00, 0x0c, | |
| 1170 0xde, 0xad, 0xbe, 0xef, | |
| 1171 0xde, 0xad, 0xbe, 0xef, | |
| 1172 0xde, 0xad, 0xbe, 0xef, | |
| 1173 | |
| 1174 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF | |
| 1175 0x01, 0x00, 0x00, 0x04, | |
| 1176 0xde, 0xad, 0xbe, 0xef, | |
| 1177 }; | 1132 }; |
| 1178 const unsigned char kV3Input[] = { | 1133 const unsigned char kV3Input[] = { |
| 1179 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1134 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 1180 0x00, 0x00, 0x00, 0x1a, | 1135 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x01, |
| 1181 0x00, 0x00, 0x00, 0x01, | 1136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1182 0x00, 0x00, 0x00, 0x00, | 1137 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 'h', 'h', |
| 1183 0x00, 0x00, 0x00, 0x00, | 1138 0x00, 0x00, 0x00, 0x02, 'v', 'v', 0x80, spdy_version_ch_, |
| 1184 0x00, 0x01, 0x00, 0x00, | 1139 0x00, 0x02, // SYN REPLY Stream #1 |
| 1185 0x00, 0x02, 'h', 'h', | 1140 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, |
| 1186 0x00, 0x00, 0x00, 0x02, | 1141 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, |
| 1187 'v', 'v', | 1142 'a', 'a', 0x00, 0x00, 0x00, 0x02, 'b', 'b', |
| 1188 | 1143 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 |
| 1189 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 | 1144 0x00, 0x00, 0x00, 0x0c, 0xde, 0xad, 0xbe, 0xef, |
| 1190 0x00, 0x00, 0x00, 0x14, | 1145 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, |
| 1191 0x00, 0x00, 0x00, 0x01, | 1146 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF |
| 1192 0x00, 0x00, 0x00, 0x01, | 1147 0x01, 0x00, 0x00, 0x04, 0xde, 0xad, 0xbe, 0xef, |
| 1193 0x00, 0x00, 0x00, 0x02, | |
| 1194 'a', 'a', 0x00, 0x00, | |
| 1195 0x00, 0x02, 'b', 'b', | |
| 1196 | |
| 1197 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
| 1198 0x00, 0x00, 0x00, 0x0c, | |
| 1199 0xde, 0xad, 0xbe, 0xef, | |
| 1200 0xde, 0xad, 0xbe, 0xef, | |
| 1201 0xde, 0xad, 0xbe, 0xef, | |
| 1202 | |
| 1203 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF | |
| 1204 0x01, 0x00, 0x00, 0x04, | |
| 1205 0xde, 0xad, 0xbe, 0xef, | |
| 1206 }; | 1148 }; |
| 1207 | 1149 |
| 1208 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send | 1150 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send |
| 1209 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. | 1151 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. |
| 1210 const unsigned char kV4Input[] = { | 1152 const unsigned char kV4Input[] = { |
| 1211 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1153 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS |
| 1212 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1154 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1213 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1155 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1214 0x82, // :method: GET | 1156 0x82, // :method: GET |
| 1215 | 1157 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS |
| 1216 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS | 1158 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1217 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1159 0x8c, // :status: 200 |
| 1218 0x8c, // :status: 200 | 1160 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 |
| 1219 | 1161 0x00, 0x00, 0x00, 0x01, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, |
| 1220 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 | 1162 0xef, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x04, 0x00, 0x01, // DATA on Stream |
| 1221 0x00, 0x00, 0x00, 0x01, | 1163 // #1, with FIN |
| 1222 0xde, 0xad, 0xbe, 0xef, | 1164 0x00, 0x00, 0x00, 0x01, 0xde, 0xad, 0xbe, 0xef, |
| 1223 0xde, 0xad, 0xbe, 0xef, | |
| 1224 0xde, 0xad, 0xbe, 0xef, | |
| 1225 | |
| 1226 0x00, 0x04, 0x00, 0x01, // DATA on Stream #1, with FIN | |
| 1227 0x00, 0x00, 0x00, 0x01, | |
| 1228 0xde, 0xad, 0xbe, 0xef, | |
| 1229 }; | 1165 }; |
| 1230 | 1166 |
| 1231 TestSpdyVisitor visitor(spdy_version_); | 1167 TestSpdyVisitor visitor(spdy_version_); |
| 1232 if (IsSpdy2()) { | 1168 if (IsSpdy2()) { |
| 1233 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1169 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1234 } else if (IsSpdy3()) { | 1170 } else if (IsSpdy3()) { |
| 1235 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1171 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| 1236 } else { | 1172 } else { |
| 1237 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); | 1173 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); |
| 1238 } | 1174 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1249 EXPECT_EQ(16, visitor.data_bytes_); | 1185 EXPECT_EQ(16, visitor.data_bytes_); |
| 1250 EXPECT_EQ(0, visitor.fin_frame_count_); | 1186 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1251 EXPECT_EQ(0, visitor.fin_flag_count_); | 1187 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1252 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1188 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1253 EXPECT_EQ(2, visitor.data_frame_count_); | 1189 EXPECT_EQ(2, visitor.data_frame_count_); |
| 1254 } | 1190 } |
| 1255 | 1191 |
| 1256 // Test that the FIN flag on a SYN reply frame signifies EOF. | 1192 // Test that the FIN flag on a SYN reply frame signifies EOF. |
| 1257 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { | 1193 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { |
| 1258 const unsigned char kV2Input[] = { | 1194 const unsigned char kV2Input[] = { |
| 1259 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1195 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 1260 0x00, 0x00, 0x00, 0x14, | 1196 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, |
| 1261 0x00, 0x00, 0x00, 0x01, | 1197 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 1262 0x00, 0x00, 0x00, 0x00, | 1198 0x00, 0x02, 'h', 'h', 0x00, 0x02, 'v', 'v', |
| 1263 0x00, 0x00, 0x00, 0x01, | 1199 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 |
| 1264 0x00, 0x02, 'h', 'h', | 1200 0x01, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, |
| 1265 0x00, 0x02, 'v', 'v', | 1201 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 'a', 'a', |
| 1266 | 1202 0x00, 0x02, 'b', 'b', |
| 1267 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 | |
| 1268 0x01, 0x00, 0x00, 0x10, | |
| 1269 0x00, 0x00, 0x00, 0x01, | |
| 1270 0x00, 0x00, 0x00, 0x01, | |
| 1271 0x00, 0x02, 'a', 'a', | |
| 1272 0x00, 0x02, 'b', 'b', | |
| 1273 }; | 1203 }; |
| 1274 const unsigned char kV3Input[] = { | 1204 const unsigned char kV3Input[] = { |
| 1275 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1205 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
| 1276 0x00, 0x00, 0x00, 0x1a, | 1206 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1277 0x00, 0x00, 0x00, 0x01, | 1207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1278 0x00, 0x00, 0x00, 0x00, | 1208 0x00, 0x02, 'h', 'h', 0x00, 0x00, 0x00, 0x02, 'v', 'v', |
| 1279 0x00, 0x00, 0x00, 0x00, | 1209 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 |
| 1280 0x00, 0x01, 0x00, 0x00, | 1210 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1281 0x00, 0x02, 'h', 'h', | 1211 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 'a', 'a', 0x00, 0x00, |
| 1282 0x00, 0x00, 0x00, 0x02, | 1212 0x00, 0x02, 'b', 'b', |
| 1283 'v', 'v', | |
| 1284 | |
| 1285 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 | |
| 1286 0x01, 0x00, 0x00, 0x14, | |
| 1287 0x00, 0x00, 0x00, 0x01, | |
| 1288 0x00, 0x00, 0x00, 0x01, | |
| 1289 0x00, 0x00, 0x00, 0x02, | |
| 1290 'a', 'a', 0x00, 0x00, | |
| 1291 0x00, 0x02, 'b', 'b', | |
| 1292 }; | 1213 }; |
| 1293 | 1214 |
| 1294 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send | 1215 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send |
| 1295 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. | 1216 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. |
| 1296 const unsigned char kV4Input[] = { | 1217 const unsigned char kV4Input[] = { |
| 1297 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1218 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS |
| 1298 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1219 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1299 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1220 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1300 0x82, // :method: GET | 1221 0x82, // :method: GET |
| 1301 | 1222 0x00, 0x01, 0x01, 0x05, // HEADERS: FIN | END_HEADERS |
| 1302 0x00, 0x01, 0x01, 0x05, // HEADERS: FIN | END_HEADERS | 1223 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1303 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1224 0x8c, // :status: 200 |
| 1304 0x8c, // :status: 200 | |
| 1305 }; | 1225 }; |
| 1306 | 1226 |
| 1307 TestSpdyVisitor visitor(spdy_version_); | 1227 TestSpdyVisitor visitor(spdy_version_); |
| 1308 if (IsSpdy2()) { | 1228 if (IsSpdy2()) { |
| 1309 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); | 1229 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); |
| 1310 } else if (IsSpdy3()) { | 1230 } else if (IsSpdy3()) { |
| 1311 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); | 1231 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); |
| 1312 } else { | 1232 } else { |
| 1313 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); | 1233 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); |
| 1314 } | 1234 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 scoped_ptr<SpdyFrame> syn_frame_2(send_framer.SerializeSynStream(syn_stream)); | 1283 scoped_ptr<SpdyFrame> syn_frame_2(send_framer.SerializeSynStream(syn_stream)); |
| 1364 EXPECT_TRUE(syn_frame_2.get() != NULL); | 1284 EXPECT_TRUE(syn_frame_2.get() != NULL); |
| 1365 | 1285 |
| 1366 // Now start decompressing | 1286 // Now start decompressing |
| 1367 scoped_ptr<SpdyFrame> decompressed; | 1287 scoped_ptr<SpdyFrame> decompressed; |
| 1368 scoped_ptr<SpdyFrame> uncompressed; | 1288 scoped_ptr<SpdyFrame> uncompressed; |
| 1369 base::StringPiece serialized_headers; | 1289 base::StringPiece serialized_headers; |
| 1370 SpdyHeaderBlock decompressed_headers; | 1290 SpdyHeaderBlock decompressed_headers; |
| 1371 | 1291 |
| 1372 // Decompress SYN_STREAM #1 | 1292 // Decompress SYN_STREAM #1 |
| 1373 decompressed.reset(SpdyFramerTestUtil::DecompressFrame( | 1293 decompressed.reset( |
| 1374 &recv_framer, *syn_frame_1.get())); | 1294 SpdyFramerTestUtil::DecompressFrame(&recv_framer, *syn_frame_1.get())); |
| 1375 EXPECT_TRUE(decompressed.get() != NULL); | 1295 EXPECT_TRUE(decompressed.get() != NULL); |
| 1376 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); | 1296 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); |
| 1377 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 1297 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
| 1378 serialized_headers.size(), | 1298 serialized_headers.size(), |
| 1379 &decompressed_headers)); | 1299 &decompressed_headers)); |
| 1380 EXPECT_EQ(2u, decompressed_headers.size()); | 1300 EXPECT_EQ(2u, decompressed_headers.size()); |
| 1381 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); | 1301 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); |
| 1382 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); | 1302 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); |
| 1383 | 1303 |
| 1384 // Decompress SYN_STREAM #2 | 1304 // Decompress SYN_STREAM #2 |
| 1385 decompressed.reset(SpdyFramerTestUtil::DecompressFrame( | 1305 decompressed.reset( |
| 1386 &recv_framer, *syn_frame_2.get())); | 1306 SpdyFramerTestUtil::DecompressFrame(&recv_framer, *syn_frame_2.get())); |
| 1387 EXPECT_TRUE(decompressed.get() != NULL); | 1307 EXPECT_TRUE(decompressed.get() != NULL); |
| 1388 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); | 1308 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); |
| 1389 decompressed_headers.clear(); | 1309 decompressed_headers.clear(); |
| 1390 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 1310 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
| 1391 serialized_headers.size(), | 1311 serialized_headers.size(), |
| 1392 &decompressed_headers)); | 1312 &decompressed_headers)); |
| 1393 EXPECT_EQ(3u, decompressed_headers.size()); | 1313 EXPECT_EQ(3u, decompressed_headers.size()); |
| 1394 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); | 1314 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); |
| 1395 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); | 1315 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); |
| 1396 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); | 1316 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 EXPECT_EQ(0, visitor.headers_frame_count_); | 1404 EXPECT_EQ(0, visitor.headers_frame_count_); |
| 1485 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); | 1405 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); |
| 1486 EXPECT_EQ(0, visitor.fin_frame_count_); | 1406 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 1487 EXPECT_EQ(0, visitor.fin_flag_count_); | 1407 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 1488 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1408 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 1489 EXPECT_EQ(1, visitor.data_frame_count_); | 1409 EXPECT_EQ(1, visitor.data_frame_count_); |
| 1490 } | 1410 } |
| 1491 | 1411 |
| 1492 TEST_P(SpdyFramerTest, WindowUpdateFrame) { | 1412 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
| 1493 SpdyFramer framer(spdy_version_); | 1413 SpdyFramer framer(spdy_version_); |
| 1494 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 1414 scoped_ptr<SpdyFrame> frame( |
| 1495 SpdyWindowUpdateIR(1, 0x12345678))); | 1415 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x12345678))); |
| 1496 | 1416 |
| 1497 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; | 1417 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; |
| 1498 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1418 const unsigned char kV3FrameData[] = { |
| 1499 0x80, spdy_version_ch_, 0x00, 0x09, | 1419 // Also applies for V2. |
| 1500 0x00, 0x00, 0x00, 0x08, | 1420 0x80, spdy_version_ch_, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, |
| 1501 0x00, 0x00, 0x00, 0x01, | 1421 0x00, 0x01, 0x12, 0x34, 0x56, 0x78}; |
| 1502 0x12, 0x34, 0x56, 0x78 | 1422 const unsigned char kV4FrameData[] = {0x00, 0x04, 0x08, 0x00, 0x00, 0x00, |
| 1503 }; | 1423 0x00, 0x01, 0x12, 0x34, 0x56, 0x78}; |
| 1504 const unsigned char kV4FrameData[] = { | |
| 1505 0x00, 0x04, 0x08, 0x00, | |
| 1506 0x00, 0x00, 0x00, 0x01, | |
| 1507 0x12, 0x34, 0x56, 0x78 | |
| 1508 }; | |
| 1509 | 1424 |
| 1510 if (IsSpdy4()) { | 1425 if (IsSpdy4()) { |
| 1511 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1426 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1512 } else { | 1427 } else { |
| 1513 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1428 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1514 } | 1429 } |
| 1515 } | 1430 } |
| 1516 | 1431 |
| 1517 TEST_P(SpdyFramerTest, CreateDataFrame) { | 1432 TEST_P(SpdyFramerTest, CreateDataFrame) { |
| 1518 SpdyFramer framer(spdy_version_); | 1433 SpdyFramer framer(spdy_version_); |
| 1519 | 1434 |
| 1520 { | 1435 { |
| 1521 const char kDescription[] = "'hello' data frame, no FIN"; | 1436 const char kDescription[] = "'hello' data frame, no FIN"; |
| 1522 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1437 const unsigned char kV3FrameData[] = {// Also applies for V2. |
| 1523 0x00, 0x00, 0x00, 0x01, | 1438 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1524 0x00, 0x00, 0x00, 0x05, | 1439 0x00, 0x05, 'h', 'e', 'l', 'l', 'o'}; |
| 1525 'h', 'e', 'l', 'l', | 1440 const unsigned char kV4FrameData[] = {0x00, 0x05, 0x00, 0x00, 0x00, |
| 1526 'o' | 1441 0x00, 0x00, 0x01, 'h', 'e', |
| 1527 }; | 1442 'l', 'l', 'o'}; |
| 1528 const unsigned char kV4FrameData[] = { | |
| 1529 0x00, 0x05, 0x00, 0x00, | |
| 1530 0x00, 0x00, 0x00, 0x01, | |
| 1531 'h', 'e', 'l', 'l', | |
| 1532 'o' | |
| 1533 }; | |
| 1534 const char bytes[] = "hello"; | 1443 const char bytes[] = "hello"; |
| 1535 | 1444 |
| 1536 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1445 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1537 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1446 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1538 if (IsSpdy4()) { | 1447 if (IsSpdy4()) { |
| 1539 CompareFrame( | 1448 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1540 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1541 } else { | 1449 } else { |
| 1542 CompareFrame( | 1450 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1543 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1544 } | 1451 } |
| 1545 | 1452 |
| 1546 SpdyDataIR data_header_ir(1); | 1453 SpdyDataIR data_header_ir(1); |
| 1547 data_header_ir.SetDataShallow(base::StringPiece(bytes, strlen(bytes))); | 1454 data_header_ir.SetDataShallow(base::StringPiece(bytes, strlen(bytes))); |
| 1548 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField( | 1455 frame.reset( |
| 1549 data_header_ir)); | 1456 framer.SerializeDataFrameHeaderWithPaddingLengthField(data_header_ir)); |
| 1550 CompareCharArraysWithHexError( | 1457 CompareCharArraysWithHexError( |
| 1551 kDescription, | 1458 kDescription, |
| 1552 reinterpret_cast<const unsigned char*>(frame->data()), | 1459 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1553 framer.GetDataFrameMinimumSize(), | 1460 framer.GetDataFrameMinimumSize(), |
| 1554 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1461 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1555 framer.GetDataFrameMinimumSize()); | 1462 framer.GetDataFrameMinimumSize()); |
| 1556 } | 1463 } |
| 1557 | 1464 |
| 1558 { | 1465 { |
| 1559 const char kDescription[] = "'hello' data frame with more padding, no FIN"; | 1466 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
| 1560 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1467 const unsigned char kV3FrameData[] = {// Also applies for V2. |
| 1561 0x00, 0x00, 0x00, 0x01, | 1468 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1562 0x00, 0x00, 0x00, 0x05, | 1469 0x00, 0x05, 'h', 'e', 'l', 'l', 'o'}; |
| 1563 'h', 'e', 'l', 'l', | |
| 1564 'o' | |
| 1565 }; | |
| 1566 | 1470 |
| 1567 const unsigned char kV4FrameData[] = { | 1471 const unsigned char kV4FrameData[] = { |
| 1568 0x01, 0x0b, 0x00, 0x30, // Length = 267. PAD_HIGH and PAD_LOW set. | 1472 0x01, 0x0b, 0x00, 0x30, // Length = 267. PAD_HIGH and PAD_LOW set. |
| 1569 0x00, 0x00, 0x00, 0x01, | 1473 0x00, 0x00, 0x00, 0x01, 0x01, 0x04, // Pad Low and Pad High fields. |
| 1570 0x01, 0x04, // Pad Low and Pad High fields. | 1474 'h', 'e', 'l', 'l', // Data |
| 1571 'h', 'e', 'l', 'l', // Data | 1475 'o', |
| 1572 'o', | 1476 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). |
| 1573 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). | 1477 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1574 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1478 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1575 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1479 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1576 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1480 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1577 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1481 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1578 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1482 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1579 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1483 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1580 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1484 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1581 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1485 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1582 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1486 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1583 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1487 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1584 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1488 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1585 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1489 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1586 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1490 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1587 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1491 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1588 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1492 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1589 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1493 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1590 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1494 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1591 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1495 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1592 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1496 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
| 1593 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | |
| 1594 }; | 1497 }; |
| 1595 const char bytes[] = "hello"; | 1498 const char bytes[] = "hello"; |
| 1596 | 1499 |
| 1597 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1500 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1598 // 260 zeros and the pad low/high fields make the overall padding to be 262 | 1501 // 260 zeros and the pad low/high fields make the overall padding to be 262 |
| 1599 // bytes. | 1502 // bytes. |
| 1600 data_ir.set_padding_len(262); | 1503 data_ir.set_padding_len(262); |
| 1601 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1504 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1602 if (IsSpdy4()) { | 1505 if (IsSpdy4()) { |
| 1603 CompareFrame( | 1506 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1604 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1605 } else { | 1507 } else { |
| 1606 CompareFrame( | 1508 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1607 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1608 } | 1509 } |
| 1609 | 1510 |
| 1610 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); | 1511 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1611 CompareCharArraysWithHexError( | 1512 CompareCharArraysWithHexError( |
| 1612 kDescription, | 1513 kDescription, |
| 1613 reinterpret_cast<const unsigned char*>(frame->data()), | 1514 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1614 framer.GetDataFrameMinimumSize(), | 1515 framer.GetDataFrameMinimumSize(), |
| 1615 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1516 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1616 framer.GetDataFrameMinimumSize()); | 1517 framer.GetDataFrameMinimumSize()); |
| 1617 } | 1518 } |
| 1618 | 1519 |
| 1619 { | 1520 { |
| 1620 const char kDescription[] = "'hello' data frame with few padding, no FIN"; | 1521 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
| 1621 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1522 const unsigned char kV3FrameData[] = {// Also applies for V2. |
| 1622 0x00, 0x00, 0x00, 0x01, | 1523 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1623 0x00, 0x00, 0x00, 0x05, | 1524 0x00, 0x05, 'h', 'e', 'l', 'l', 'o'}; |
| 1624 'h', 'e', 'l', 'l', | |
| 1625 'o' | |
| 1626 }; | |
| 1627 | 1525 |
| 1628 const unsigned char kV4FrameData[] = { | 1526 const unsigned char kV4FrameData[] = { |
| 1629 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. | 1527 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. |
| 1630 0x00, 0x00, 0x00, 0x01, | 1528 0x00, 0x00, 0x00, 0x01, |
| 1631 0x07, // Pad Low field. | 1529 0x07, // Pad Low field. |
| 1632 'h', 'e', 'l', 'l', // Data | 1530 'h', 'e', 'l', 'l', // Data |
| 1633 'o', | 1531 'o', '0', '0', '0', '0', // Padding |
| 1634 '0', '0', '0', '0', // Padding | 1532 '0', '0', '0'}; |
| 1635 '0', '0', '0' | |
| 1636 }; | |
| 1637 const char bytes[] = "hello"; | 1533 const char bytes[] = "hello"; |
| 1638 | 1534 |
| 1639 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1535 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1640 // 7 zeros and the pad low field make the overall padding to be 8 bytes. | 1536 // 7 zeros and the pad low field make the overall padding to be 8 bytes. |
| 1641 data_ir.set_padding_len(8); | 1537 data_ir.set_padding_len(8); |
| 1642 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1538 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1643 if (IsSpdy4()) { | 1539 if (IsSpdy4()) { |
| 1644 CompareFrame( | 1540 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1645 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1646 } else { | 1541 } else { |
| 1647 CompareFrame( | 1542 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1648 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1649 } | 1543 } |
| 1650 } | 1544 } |
| 1651 | 1545 |
| 1652 { | 1546 { |
| 1653 const char kDescription[] = | 1547 const char kDescription[] = |
| 1654 "'hello' data frame with 1 byte padding, no FIN"; | 1548 "'hello' data frame with 1 byte padding, no FIN"; |
| 1655 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1549 const unsigned char kV3FrameData[] = {// Also applies for V2. |
| 1656 0x00, 0x00, 0x00, 0x01, | 1550 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 1657 0x00, 0x00, 0x00, 0x05, | 1551 0x00, 0x05, 'h', 'e', 'l', 'l', 'o'}; |
| 1658 'h', 'e', 'l', 'l', | |
| 1659 'o' | |
| 1660 }; | |
| 1661 | 1552 |
| 1662 const unsigned char kV4FrameData[] = { | 1553 const unsigned char kV4FrameData[] = { |
| 1663 0x00, 0x06, 0x00, 0x10, // Length = 6. PAD_LOW set. | 1554 0x00, 0x06, 0x00, 0x10, // Length = 6. PAD_LOW set. |
| 1664 0x00, 0x00, 0x00, 0x01, | 1555 0x00, 0x00, 0x00, 0x01, |
| 1665 0x00, // Pad Low field. | 1556 0x00, // Pad Low field. |
| 1666 'h', 'e', 'l', 'l', // Data | 1557 'h', 'e', 'l', 'l', // Data |
| 1667 'o', | 1558 'o', |
| 1668 }; | 1559 }; |
| 1669 const char bytes[] = "hello"; | 1560 const char bytes[] = "hello"; |
| 1670 | 1561 |
| 1671 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1562 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
| 1672 // The pad low field itself is used for the 1-byte padding and no padding | 1563 // The pad low field itself is used for the 1-byte padding and no padding |
| 1673 // payload is needed. | 1564 // payload is needed. |
| 1674 data_ir.set_padding_len(1); | 1565 data_ir.set_padding_len(1); |
| 1675 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1566 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1676 if (IsSpdy4()) { | 1567 if (IsSpdy4()) { |
| 1677 CompareFrame( | 1568 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1678 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1679 } else { | 1569 } else { |
| 1680 CompareFrame( | 1570 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1681 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1682 } | 1571 } |
| 1683 | 1572 |
| 1684 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); | 1573 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1685 CompareCharArraysWithHexError( | 1574 CompareCharArraysWithHexError( |
| 1686 kDescription, | 1575 kDescription, |
| 1687 reinterpret_cast<const unsigned char*>(frame->data()), | 1576 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1688 framer.GetDataFrameMinimumSize(), | 1577 framer.GetDataFrameMinimumSize(), |
| 1689 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1578 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1690 framer.GetDataFrameMinimumSize()); | 1579 framer.GetDataFrameMinimumSize()); |
| 1691 } | 1580 } |
| 1692 | 1581 |
| 1693 { | 1582 { |
| 1694 const char kDescription[] = "Data frame with negative data byte, no FIN"; | 1583 const char kDescription[] = "Data frame with negative data byte, no FIN"; |
| 1695 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1584 const unsigned char kV3FrameData[] = { |
| 1696 0x00, 0x00, 0x00, 0x01, | 1585 // Also applies for V2. |
| 1697 0x00, 0x00, 0x00, 0x01, | 1586 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0xff}; |
| 1698 0xff | 1587 const unsigned char kV4FrameData[] = {0x00, 0x01, 0x00, 0x00, 0x00, |
| 1699 }; | 1588 0x00, 0x00, 0x01, 0xff}; |
| 1700 const unsigned char kV4FrameData[] = { | |
| 1701 0x00, 0x01, 0x00, 0x00, | |
| 1702 0x00, 0x00, 0x00, 0x01, | |
| 1703 0xff | |
| 1704 }; | |
| 1705 SpdyDataIR data_ir(1, StringPiece("\xff", 1)); | 1589 SpdyDataIR data_ir(1, StringPiece("\xff", 1)); |
| 1706 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1590 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1707 if (IsSpdy4()) { | 1591 if (IsSpdy4()) { |
| 1708 CompareFrame( | 1592 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1709 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1710 } else { | 1593 } else { |
| 1711 CompareFrame( | 1594 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1712 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1713 } | 1595 } |
| 1714 } | 1596 } |
| 1715 | 1597 |
| 1716 { | 1598 { |
| 1717 const char kDescription[] = "'hello' data frame, with FIN"; | 1599 const char kDescription[] = "'hello' data frame, with FIN"; |
| 1718 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1600 const unsigned char kV3FrameData[] = {// Also applies for V2. |
| 1719 0x00, 0x00, 0x00, 0x01, | 1601 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, |
| 1720 0x01, 0x00, 0x00, 0x05, | 1602 0x00, 0x05, 'h', 'e', 'l', 'l', 'o'}; |
| 1721 'h', 'e', 'l', 'l', | 1603 const unsigned char kV4FrameData[] = {0x00, 0x05, 0x00, 0x01, 0x00, |
| 1722 'o' | 1604 0x00, 0x00, 0x01, 'h', 'e', |
| 1723 }; | 1605 'l', 'l', 'o'}; |
| 1724 const unsigned char kV4FrameData[] = { | |
| 1725 0x00, 0x05, 0x00, 0x01, | |
| 1726 0x00, 0x00, 0x00, 0x01, | |
| 1727 'h', 'e', 'l', 'l', | |
| 1728 'o' | |
| 1729 }; | |
| 1730 SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 1606 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 1731 data_ir.set_fin(true); | 1607 data_ir.set_fin(true); |
| 1732 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1608 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1733 if (IsSpdy4()) { | 1609 if (IsSpdy4()) { |
| 1734 CompareFrame( | 1610 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1735 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1736 } else { | 1611 } else { |
| 1737 CompareFrame( | 1612 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1738 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1739 } | 1613 } |
| 1740 } | 1614 } |
| 1741 | 1615 |
| 1742 { | 1616 { |
| 1743 const char kDescription[] = "Empty data frame"; | 1617 const char kDescription[] = "Empty data frame"; |
| 1744 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1618 const unsigned char kV3FrameData[] = { |
| 1745 0x00, 0x00, 0x00, 0x01, | 1619 // Also applies for V2. |
| 1746 0x00, 0x00, 0x00, 0x00, | 1620 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 1747 }; | 1621 }; |
| 1748 const unsigned char kV4FrameData[] = { | 1622 const unsigned char kV4FrameData[] = { |
| 1749 0x00, 0x00, 0x00, 0x00, | 1623 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, |
| 1750 0x00, 0x00, 0x00, 0x01, | |
| 1751 }; | 1624 }; |
| 1752 SpdyDataIR data_ir(1, StringPiece()); | 1625 SpdyDataIR data_ir(1, StringPiece()); |
| 1753 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1626 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1754 if (IsSpdy4()) { | 1627 if (IsSpdy4()) { |
| 1755 CompareFrame( | 1628 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1756 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1757 } else { | 1629 } else { |
| 1758 CompareFrame( | 1630 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1759 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1760 } | 1631 } |
| 1761 | 1632 |
| 1762 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); | 1633 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
| 1763 CompareCharArraysWithHexError( | 1634 CompareCharArraysWithHexError( |
| 1764 kDescription, | 1635 kDescription, |
| 1765 reinterpret_cast<const unsigned char*>(frame->data()), | 1636 reinterpret_cast<const unsigned char*>(frame->data()), |
| 1766 framer.GetDataFrameMinimumSize(), | 1637 framer.GetDataFrameMinimumSize(), |
| 1767 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1638 IsSpdy4() ? kV4FrameData : kV3FrameData, |
| 1768 framer.GetDataFrameMinimumSize()); | 1639 framer.GetDataFrameMinimumSize()); |
| 1769 } | 1640 } |
| 1770 | 1641 |
| 1771 { | 1642 { |
| 1772 const char kDescription[] = "Data frame with max stream ID"; | 1643 const char kDescription[] = "Data frame with max stream ID"; |
| 1773 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1644 const unsigned char kV3FrameData[] = {// Also applies for V2. |
| 1774 0x7f, 0xff, 0xff, 0xff, | 1645 0x7f, 0xff, 0xff, 0xff, 0x01, 0x00, |
| 1775 0x01, 0x00, 0x00, 0x05, | 1646 0x00, 0x05, 'h', 'e', 'l', 'l', 'o'}; |
| 1776 'h', 'e', 'l', 'l', | 1647 const unsigned char kV4FrameData[] = {0x00, 0x05, 0x00, 0x01, 0x7f, |
| 1777 'o' | 1648 0xff, 0xff, 0xff, 'h', 'e', |
| 1778 }; | 1649 'l', 'l', 'o'}; |
| 1779 const unsigned char kV4FrameData[] = { | |
| 1780 0x00, 0x05, 0x00, 0x01, | |
| 1781 0x7f, 0xff, 0xff, 0xff, | |
| 1782 'h', 'e', 'l', 'l', | |
| 1783 'o' | |
| 1784 }; | |
| 1785 SpdyDataIR data_ir(0x7fffffff, "hello"); | 1650 SpdyDataIR data_ir(0x7fffffff, "hello"); |
| 1786 data_ir.set_fin(true); | 1651 data_ir.set_fin(true); |
| 1787 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1652 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1788 if (IsSpdy4()) { | 1653 if (IsSpdy4()) { |
| 1789 CompareFrame( | 1654 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1790 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | |
| 1791 } else { | 1655 } else { |
| 1792 CompareFrame( | 1656 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1793 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | |
| 1794 } | 1657 } |
| 1795 } | 1658 } |
| 1796 | 1659 |
| 1797 if (!IsSpdy4()) { | 1660 if (!IsSpdy4()) { |
| 1798 // This test does not apply to SPDY 4 because the max frame size is smaller | 1661 // This test does not apply to SPDY 4 because the max frame size is smaller |
| 1799 // than 4MB. | 1662 // than 4MB. |
| 1800 const char kDescription[] = "Large data frame"; | 1663 const char kDescription[] = "Large data frame"; |
| 1801 const int kDataSize = 4 * 1024 * 1024; // 4 MB | 1664 const int kDataSize = 4 * 1024 * 1024; // 4 MB |
| 1802 const string kData(kDataSize, 'A'); | 1665 const string kData(kDataSize, 'A'); |
| 1803 const unsigned char kFrameHeader[] = { | 1666 const unsigned char kFrameHeader[] = { |
| 1804 0x00, 0x00, 0x00, 0x01, | 1667 0x00, 0x00, 0x00, 0x01, 0x01, 0x40, 0x00, 0x00, |
| 1805 0x01, 0x40, 0x00, 0x00, | |
| 1806 }; | 1668 }; |
| 1807 | 1669 |
| 1808 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; | 1670 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; |
| 1809 scoped_ptr<unsigned char[]> expected_frame_data( | 1671 scoped_ptr<unsigned char[]> expected_frame_data( |
| 1810 new unsigned char[kFrameSize]); | 1672 new unsigned char[kFrameSize]); |
| 1811 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); | 1673 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); |
| 1812 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | 1674 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); |
| 1813 | 1675 |
| 1814 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); | 1676 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); |
| 1815 data_ir.set_fin(true); | 1677 data_ir.set_fin(true); |
| 1816 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1678 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 1817 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); | 1679 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); |
| 1818 } | 1680 } |
| 1819 } | 1681 } |
| 1820 | 1682 |
| 1821 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { | 1683 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { |
| 1822 SpdyFramer framer(spdy_version_); | 1684 SpdyFramer framer(spdy_version_); |
| 1823 framer.set_enable_compression(false); | 1685 framer.set_enable_compression(false); |
| 1824 | 1686 |
| 1825 { | 1687 { |
| 1826 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; | 1688 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; |
| 1827 | 1689 |
| 1828 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; | 1690 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; |
| 1829 const unsigned char kV2FrameData[] = { | 1691 const unsigned char kV2FrameData[] = { |
| 1830 0x80, spdy_version_ch_, 0x00, 0x01, | 1692 0x80, spdy_version_ch_, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, |
| 1831 0x00, 0x00, 0x00, 0x20, | 1693 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, kPri, 0x00, 0x00, 0x02, |
| 1832 0x00, 0x00, 0x00, 0x01, | 1694 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x03, 'f', 'o', 'o', |
| 1833 0x00, 0x00, 0x00, 0x00, | 1695 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x03, 'b', 'a', 'r'}; |
| 1834 kPri, 0x00, 0x00, 0x02, | |
| 1835 0x00, 0x03, 'b', 'a', | |
| 1836 'r', 0x00, 0x03, 'f', | |
| 1837 'o', 'o', 0x00, 0x03, | |
| 1838 'f', 'o', 'o', 0x00, | |
| 1839 0x03, 'b', 'a', 'r' | |
| 1840 }; | |
| 1841 const unsigned char kV3FrameData[] = { | 1696 const unsigned char kV3FrameData[] = { |
| 1842 0x80, spdy_version_ch_, 0x00, 0x01, | 1697 0x80, spdy_version_ch_, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, |
| 1843 0x00, 0x00, 0x00, 0x2a, | 1698 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, kPri, 0x00, 0x00, 0x00, |
| 1844 0x00, 0x00, 0x00, 0x01, | 1699 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r', 0x00, |
| 1845 0x00, 0x00, 0x00, 0x00, | 1700 0x00, 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, |
| 1846 kPri, 0x00, 0x00, 0x00, | 1701 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r'}; |
| 1847 0x00, 0x02, 0x00, 0x00, | |
| 1848 0x00, 0x03, 'b', 'a', | |
| 1849 'r', 0x00, 0x00, 0x00, | |
| 1850 0x03, 'f', 'o', 'o', | |
| 1851 0x00, 0x00, 0x00, 0x03, | |
| 1852 'f', 'o', 'o', 0x00, | |
| 1853 0x00, 0x00, 0x03, 'b', | |
| 1854 'a', 'r' | |
| 1855 }; | |
| 1856 const unsigned char kV4FrameData[] = { | 1702 const unsigned char kV4FrameData[] = { |
| 1857 0x00, 0x16, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1703 0x00, 0x16, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS |
| 1858 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1704 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 1859 0x00, 0x00, 0x00, 0x07, // Priority 7 | 1705 0x00, 0x00, 0x00, 0x07, // Priority 7 |
| 1860 0x40, 0x03, 0x62, 0x61, // @.ba | 1706 0x40, 0x03, 0x62, 0x61, // @.ba |
| 1861 0x72, 0x03, 0x66, 0x6f, // r.fo | 1707 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 1862 0x6f, 0x40, 0x03, 0x66, // o@.f | 1708 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 1863 0x6f, 0x6f, 0x03, 0x62, // oo.b | 1709 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 1864 0x61, 0x72, // ar | 1710 0x61, 0x72, // ar |
| 1865 }; | 1711 }; |
| 1866 SpdySynStreamIR syn_stream(1); | 1712 SpdySynStreamIR syn_stream(1); |
| 1867 syn_stream.set_priority(framer.GetLowestPriority()); | 1713 syn_stream.set_priority(framer.GetLowestPriority()); |
| 1868 syn_stream.SetHeader("bar", "foo"); | 1714 syn_stream.SetHeader("bar", "foo"); |
| 1869 syn_stream.SetHeader("foo", "bar"); | 1715 syn_stream.SetHeader("foo", "bar"); |
| 1870 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1716 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 1871 if (IsSpdy2()) { | 1717 if (IsSpdy2()) { |
| 1872 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1718 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 1873 } else if (IsSpdy3()) { | 1719 } else if (IsSpdy3()) { |
| 1874 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1720 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1875 } else { | 1721 } else { |
| 1876 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1722 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1877 } | 1723 } |
| 1878 } | 1724 } |
| 1879 | 1725 |
| 1880 { | 1726 { |
| 1881 const char kDescription[] = | 1727 const char kDescription[] = |
| 1882 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " | 1728 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " |
| 1883 "max stream ID"; | 1729 "max stream ID"; |
| 1884 | 1730 |
| 1885 const unsigned char kV2FrameData[] = { | 1731 const unsigned char kV2FrameData[] = { |
| 1886 0x80, spdy_version_ch_, 0x00, 0x01, | 1732 0x80, spdy_version_ch_, 0x00, 0x01, 0x01, 0x00, 0x00, 0x1D, 0x7f, 0xff, |
| 1887 0x01, 0x00, 0x00, 0x1D, | 1733 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, |
| 1888 0x7f, 0xff, 0xff, 0xff, | 1734 0x00, 0x00, 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x03, 'f', |
| 1889 0x7f, 0xff, 0xff, 0xff, | 1735 'o', 'o', 0x00, 0x03, 'b', 'a', 'r'}; |
| 1890 0x00, 0x00, 0x00, 0x02, | |
| 1891 0x00, 0x00, 0x00, 0x03, | |
| 1892 'f', 'o', 'o', 0x00, | |
| 1893 0x03, 'f', 'o', 'o', | |
| 1894 0x00, 0x03, 'b', 'a', | |
| 1895 'r' | |
| 1896 }; | |
| 1897 const unsigned char kV3FrameData[] = { | 1736 const unsigned char kV3FrameData[] = { |
| 1898 0x80, spdy_version_ch_, 0x00, 0x01, | 1737 0x80, spdy_version_ch_, 0x00, 0x01, 0x01, 0x00, 0x00, 0x27, 0x7f, 0xff, |
| 1899 0x01, 0x00, 0x00, 0x27, | 1738 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, |
| 1900 0x7f, 0xff, 0xff, 0xff, | 1739 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, |
| 1901 0x7f, 0xff, 0xff, 0xff, | 1740 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, 'f', 'o', 'o', |
| 1902 0x00, 0x00, 0x00, 0x00, | 1741 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r'}; |
| 1903 0x00, 0x02, 0x00, 0x00, | |
| 1904 0x00, 0x00, 0x00, 0x00, | |
| 1905 0x00, 0x03, 'f', 'o', | |
| 1906 'o', 0x00, 0x00, 0x00, | |
| 1907 0x03, 'f', 'o', 'o', | |
| 1908 0x00, 0x00, 0x00, 0x03, | |
| 1909 'b', 'a', 'r' | |
| 1910 }; | |
| 1911 const unsigned char kV4FrameData[] = { | 1742 const unsigned char kV4FrameData[] = { |
| 1912 0x00, 0x13, 0x01, 0x0d, // HEADERS: PRIORITY | FIN | END_HEADERS | 1743 0x00, 0x13, 0x01, 0x0d, // HEADERS: PRIORITY | FIN | END_HEADERS |
| 1913 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 1744 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 1914 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1745 0x00, 0x00, 0x00, 0x00, // Priority 0 |
| 1915 0x40, 0x00, 0x03, 0x66, // @..f | 1746 0x40, 0x00, 0x03, 0x66, // @..f |
| 1916 0x6f, 0x6f, 0x40, 0x03, // oo@. | 1747 0x6f, 0x6f, 0x40, 0x03, // oo@. |
| 1917 0x66, 0x6f, 0x6f, 0x03, // foo. | 1748 0x66, 0x6f, 0x6f, 0x03, // foo. |
| 1918 0x62, 0x61, 0x72, // bar | 1749 0x62, 0x61, 0x72, // bar |
| 1919 }; | 1750 }; |
| 1920 SpdySynStreamIR syn_stream(0x7fffffff); | 1751 SpdySynStreamIR syn_stream(0x7fffffff); |
| 1921 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1752 syn_stream.set_associated_to_stream_id(0x7fffffff); |
| 1922 syn_stream.set_priority(framer.GetHighestPriority()); | 1753 syn_stream.set_priority(framer.GetHighestPriority()); |
| 1923 syn_stream.set_fin(true); | 1754 syn_stream.set_fin(true); |
| 1924 syn_stream.SetHeader("", "foo"); | 1755 syn_stream.SetHeader("", "foo"); |
| 1925 syn_stream.SetHeader("foo", "bar"); | 1756 syn_stream.SetHeader("foo", "bar"); |
| 1926 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1757 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 1927 if (IsSpdy2()) { | 1758 if (IsSpdy2()) { |
| 1928 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1759 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 1929 } else if (IsSpdy3()) { | 1760 } else if (IsSpdy3()) { |
| 1930 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1761 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1931 } else { | 1762 } else { |
| 1932 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1763 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1933 } | 1764 } |
| 1934 } | 1765 } |
| 1935 | 1766 |
| 1936 { | 1767 { |
| 1937 const char kDescription[] = | 1768 const char kDescription[] = |
| 1938 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " | 1769 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " |
| 1939 "max stream ID"; | 1770 "max stream ID"; |
| 1940 | 1771 |
| 1941 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20; | 1772 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20; |
| 1942 const unsigned char kV2FrameData[] = { | 1773 const unsigned char kV2FrameData[] = { |
| 1943 0x80, spdy_version_ch_, 0x00, 0x01, | 1774 0x80, spdy_version_ch_, 0x00, 0x01, 0x01, 0x00, 0x00, 0x1D, 0x7f, 0xff, |
| 1944 0x01, 0x00, 0x00, 0x1D, | 1775 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, kPri, 0x00, 0x00, 0x02, |
| 1945 0x7f, 0xff, 0xff, 0xff, | 1776 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x03, 'f', 'o', 'o', |
| 1946 0x7f, 0xff, 0xff, 0xff, | 1777 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x00}; |
| 1947 kPri, 0x00, 0x00, 0x02, | |
| 1948 0x00, 0x03, 'b', 'a', | |
| 1949 'r', 0x00, 0x03, 'f', | |
| 1950 'o', 'o', 0x00, 0x03, | |
| 1951 'f', 'o', 'o', 0x00, | |
| 1952 0x00 | |
| 1953 }; | |
| 1954 const unsigned char kV3FrameData[] = { | 1778 const unsigned char kV3FrameData[] = { |
| 1955 0x80, spdy_version_ch_, 0x00, 0x01, | 1779 0x80, spdy_version_ch_, 0x00, 0x01, 0x01, 0x00, 0x00, 0x27, 0x7f, 0xff, |
| 1956 0x01, 0x00, 0x00, 0x27, | 1780 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, kPri, 0x00, 0x00, 0x00, |
| 1957 0x7f, 0xff, 0xff, 0xff, | 1781 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r', 0x00, |
| 1958 0x7f, 0xff, 0xff, 0xff, | 1782 0x00, 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, |
| 1959 kPri, 0x00, 0x00, 0x00, | 1783 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x00}; |
| 1960 0x00, 0x02, 0x00, 0x00, | |
| 1961 0x00, 0x03, 'b', 'a', | |
| 1962 'r', 0x00, 0x00, 0x00, | |
| 1963 0x03, 'f', 'o', 'o', | |
| 1964 0x00, 0x00, 0x00, 0x03, | |
| 1965 'f', 'o', 'o', 0x00, | |
| 1966 0x00, 0x00, 0x00 | |
| 1967 }; | |
| 1968 const unsigned char kV4FrameData[] = { | 1784 const unsigned char kV4FrameData[] = { |
| 1969 0x00, 0x13, 0x01, 0x0d, // HEADERS: PRIORITY | FIN | END_HEADERS | 1785 0x00, 0x13, 0x01, 0x0d, // HEADERS: PRIORITY | FIN | END_HEADERS |
| 1970 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 1786 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 1971 0x00, 0x00, 0x00, 0x01, // Priority 1 | 1787 0x00, 0x00, 0x00, 0x01, // Priority 1 |
| 1972 0x40, 0x03, 0x62, 0x61, // @.ba | 1788 0x40, 0x03, 0x62, 0x61, // @.ba |
| 1973 0x72, 0x03, 0x66, 0x6f, // r.fo | 1789 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 1974 0x6f, 0x40, 0x03, 0x66, // o@.f | 1790 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 1975 0x6f, 0x6f, 0x00, // oo. | 1791 0x6f, 0x6f, 0x00, // oo. |
| 1976 }; | 1792 }; |
| 1977 SpdySynStreamIR syn_stream(0x7fffffff); | 1793 SpdySynStreamIR syn_stream(0x7fffffff); |
| 1978 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1794 syn_stream.set_associated_to_stream_id(0x7fffffff); |
| 1979 syn_stream.set_priority(1); | 1795 syn_stream.set_priority(1); |
| 1980 syn_stream.set_fin(true); | 1796 syn_stream.set_fin(true); |
| 1981 syn_stream.SetHeader("bar", "foo"); | 1797 syn_stream.SetHeader("bar", "foo"); |
| 1982 syn_stream.SetHeader("foo", ""); | 1798 syn_stream.SetHeader("foo", ""); |
| 1983 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1799 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 1984 if (IsSpdy2()) { | 1800 if (IsSpdy2()) { |
| 1985 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1801 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 1986 } else if (IsSpdy3()) { | 1802 } else if (IsSpdy3()) { |
| 1987 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1803 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 1988 } else { | 1804 } else { |
| 1989 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1805 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 1990 } | 1806 } |
| 1991 } | 1807 } |
| 1992 } | 1808 } |
| 1993 | 1809 |
| 1994 // TODO(phajdan.jr): Clean up after we no longer need | 1810 // TODO(phajdan.jr): Clean up after we no longer need |
| 1995 // to workaround http://crbug.com/139744. | 1811 // to workaround http://crbug.com/139744. |
| 1996 #if !defined(USE_SYSTEM_ZLIB) | 1812 #if !defined(USE_SYSTEM_ZLIB) |
| 1997 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { | 1813 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { |
| 1998 SpdyFramer framer(spdy_version_); | 1814 SpdyFramer framer(spdy_version_); |
| 1999 framer.set_enable_compression(true); | 1815 framer.set_enable_compression(true); |
| 2000 | 1816 |
| 2001 { | 1817 { |
| 2002 const char kDescription[] = | 1818 const char kDescription[] = "SYN_STREAM frame, low pri, no FIN"; |
| 2003 "SYN_STREAM frame, low pri, no FIN"; | |
| 2004 | 1819 |
| 2005 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | 1820 const SpdyPriority priority = IsSpdy2() ? 2 : 4; |
| 2006 const unsigned char kV2FrameData[] = { | 1821 const unsigned char kV2FrameData[] = { |
| 2007 0x80, spdy_version_ch_, 0x00, 0x01, | 1822 0x80, spdy_version_ch_, 0x00, 0x01, 0x00, 0x00, 0x00, 0x36, 0x00, |
| 2008 0x00, 0x00, 0x00, 0x36, | 1823 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, |
| 2009 0x00, 0x00, 0x00, 0x01, | 1824 0x38, 0xea, 0xdf, 0xa2, 0x51, 0xb2, 0x62, 0x60, 0x62, |
| 2010 0x00, 0x00, 0x00, 0x00, | 1825 0x60, 0x4e, 0x4a, 0x2c, 0x62, 0x60, 0x06, 0x08, 0xa0, |
| 2011 0x80, 0x00, 0x38, 0xea, | 1826 0xb4, 0xfc, 0x7c, 0x80, 0x00, 0x62, 0x60, 0x4e, 0xcb, |
| 2012 0xdf, 0xa2, 0x51, 0xb2, | 1827 0xcf, 0x67, 0x60, 0x06, 0x08, 0xa0, 0xa4, 0xc4, 0x22, |
| 2013 0x62, 0x60, 0x62, 0x60, | 1828 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 2014 0x4e, 0x4a, 0x2c, 0x62, | |
| 2015 0x60, 0x06, 0x08, 0xa0, | |
| 2016 0xb4, 0xfc, 0x7c, 0x80, | |
| 2017 0x00, 0x62, 0x60, 0x4e, | |
| 2018 0xcb, 0xcf, 0x67, 0x60, | |
| 2019 0x06, 0x08, 0xa0, 0xa4, | |
| 2020 0xc4, 0x22, 0x80, 0x00, | |
| 2021 0x02, 0x00, 0x00, 0x00, | |
| 2022 0xff, 0xff, | |
| 2023 }; | 1829 }; |
| 2024 const unsigned char kV3FrameData[] = { | 1830 const unsigned char kV3FrameData[] = { |
| 2025 0x80, spdy_version_ch_, 0x00, 0x01, | 1831 0x80, spdy_version_ch_, 0x00, 0x01, 0x00, 0x00, 0x00, 0x37, 0x00, |
| 2026 0x00, 0x00, 0x00, 0x37, | 1832 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, |
| 2027 0x00, 0x00, 0x00, 0x01, | 1833 0x38, 0xEA, 0xE3, 0xC6, 0xA7, 0xC2, 0x02, 0xE5, 0x0E, |
| 2028 0x00, 0x00, 0x00, 0x00, | 1834 0x50, 0xC2, 0x4B, 0x4A, 0x04, 0xE5, 0x0B, 0x66, 0x80, |
| 2029 0x80, 0x00, 0x38, 0xEA, | 1835 0x00, 0x4A, 0xCB, 0xCF, 0x07, 0x08, 0x20, 0x10, 0x95, |
| 2030 0xE3, 0xC6, 0xA7, 0xC2, | 1836 0x96, 0x9F, 0x0F, 0xA2, 0x00, 0x02, 0x28, 0x29, 0xB1, |
| 2031 0x02, 0xE5, 0x0E, 0x50, | 1837 0x08, 0x20, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, |
| 2032 0xC2, 0x4B, 0x4A, 0x04, | |
| 2033 0xE5, 0x0B, 0x66, 0x80, | |
| 2034 0x00, 0x4A, 0xCB, 0xCF, | |
| 2035 0x07, 0x08, 0x20, 0x10, | |
| 2036 0x95, 0x96, 0x9F, 0x0F, | |
| 2037 0xA2, 0x00, 0x02, 0x28, | |
| 2038 0x29, 0xB1, 0x08, 0x20, | |
| 2039 0x80, 0x00, 0x00, 0x00, | |
| 2040 0x00, 0xFF, 0xFF, | |
| 2041 }; | 1838 }; |
| 2042 SpdySynStreamIR syn_stream(1); | 1839 SpdySynStreamIR syn_stream(1); |
| 2043 syn_stream.set_priority(priority); | 1840 syn_stream.set_priority(priority); |
| 2044 syn_stream.SetHeader("bar", "foo"); | 1841 syn_stream.SetHeader("bar", "foo"); |
| 2045 syn_stream.SetHeader("foo", "bar"); | 1842 syn_stream.SetHeader("foo", "bar"); |
| 2046 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1843 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
| 2047 if (IsSpdy2()) { | 1844 if (IsSpdy2()) { |
| 2048 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1845 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2049 } else if (IsSpdy3()) { | 1846 } else if (IsSpdy3()) { |
| 2050 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1847 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2051 } else { | 1848 } else { |
| 2052 // Deflate compression doesn't apply to HPACK. | 1849 // Deflate compression doesn't apply to HPACK. |
| 2053 } | 1850 } |
| 2054 } | 1851 } |
| 2055 } | 1852 } |
| 2056 #endif // !defined(USE_SYSTEM_ZLIB) | 1853 #endif // !defined(USE_SYSTEM_ZLIB) |
| 2057 | 1854 |
| 2058 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | 1855 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
| 2059 SpdyFramer framer(spdy_version_); | 1856 SpdyFramer framer(spdy_version_); |
| 2060 framer.set_enable_compression(false); | 1857 framer.set_enable_compression(false); |
| 2061 | 1858 |
| 2062 { | 1859 { |
| 2063 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 1860 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
| 2064 | 1861 |
| 2065 const unsigned char kV2FrameData[] = { | 1862 const unsigned char kV2FrameData[] = { |
| 2066 0x80, spdy_version_ch_, 0x00, 0x02, | 1863 0x80, spdy_version_ch_, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 2067 0x00, 0x00, 0x00, 0x1C, | 1864 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, |
| 2068 0x00, 0x00, 0x00, 0x01, | 1865 'b', 'a', 'r', 0x00, 0x03, 'f', 'o', 'o', 0x00, |
| 2069 0x00, 0x00, 0x00, 0x02, | 1866 0x03, 'f', 'o', 'o', 0x00, 0x03, 'b', 'a', 'r'}; |
| 2070 0x00, 0x03, 'b', 'a', | |
| 2071 'r', 0x00, 0x03, 'f', | |
| 2072 'o', 'o', 0x00, 0x03, | |
| 2073 'f', 'o', 'o', 0x00, | |
| 2074 0x03, 'b', 'a', 'r' | |
| 2075 }; | |
| 2076 const unsigned char kV3FrameData[] = { | 1867 const unsigned char kV3FrameData[] = { |
| 2077 0x80, spdy_version_ch_, 0x00, 0x02, | 1868 0x80, spdy_version_ch_, 0x00, 0x02, 0x00, 0x00, 0x00, 0x24, 0x00, |
| 2078 0x00, 0x00, 0x00, 0x24, | 1869 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2079 0x00, 0x00, 0x00, 0x01, | 1870 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x00, 0x00, 0x03, |
| 2080 0x00, 0x00, 0x00, 0x02, | 1871 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, 'f', 'o', |
| 2081 0x00, 0x00, 0x00, 0x03, | 1872 'o', 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r'}; |
| 2082 'b', 'a', 'r', 0x00, | |
| 2083 0x00, 0x00, 0x03, 'f', | |
| 2084 'o', 'o', 0x00, 0x00, | |
| 2085 0x00, 0x03, 'f', 'o', | |
| 2086 'o', 0x00, 0x00, 0x00, | |
| 2087 0x03, 'b', 'a', 'r' | |
| 2088 }; | |
| 2089 const unsigned char kV4FrameData[] = { | 1873 const unsigned char kV4FrameData[] = { |
| 2090 0x00, 0x12, 0x01, 0x04, // HEADER: END_HEADERS | 1874 0x00, 0x12, 0x01, 0x04, // HEADER: END_HEADERS |
| 2091 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1875 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 2092 0x40, 0x03, 0x62, 0x61, // @.ba | 1876 0x40, 0x03, 0x62, 0x61, // @.ba |
| 2093 0x72, 0x03, 0x66, 0x6f, // r.fo | 1877 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2094 0x6f, 0x40, 0x03, 0x66, // o@.f | 1878 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 2095 0x6f, 0x6f, 0x03, 0x62, // oo.b | 1879 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 2096 0x61, 0x72, // ar | 1880 0x61, 0x72, // ar |
| 2097 }; | 1881 }; |
| 2098 SpdySynReplyIR syn_reply(1); | 1882 SpdySynReplyIR syn_reply(1); |
| 2099 syn_reply.SetHeader("bar", "foo"); | 1883 syn_reply.SetHeader("bar", "foo"); |
| 2100 syn_reply.SetHeader("foo", "bar"); | 1884 syn_reply.SetHeader("foo", "bar"); |
| 2101 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1885 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
| 2102 if (IsSpdy2()) { | 1886 if (IsSpdy2()) { |
| 2103 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1887 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2104 } else if (IsSpdy3()) { | 1888 } else if (IsSpdy3()) { |
| 2105 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1889 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2106 } else { | 1890 } else { |
| 2107 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1891 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2108 } | 1892 } |
| 2109 } | 1893 } |
| 2110 | 1894 |
| 2111 { | 1895 { |
| 2112 const char kDescription[] = | 1896 const char kDescription[] = |
| 2113 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; | 1897 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; |
| 2114 | 1898 |
| 2115 const unsigned char kV2FrameData[] = { | 1899 const unsigned char kV2FrameData[] = { |
| 2116 0x80, spdy_version_ch_, 0x00, 0x02, | 1900 0x80, spdy_version_ch_, 0x00, 0x02, 0x01, 0x00, 0x00, 0x19, 0x7f, |
| 2117 0x01, 0x00, 0x00, 0x19, | 1901 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2118 0x7f, 0xff, 0xff, 0xff, | 1902 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x03, 'f', 'o', |
| 2119 0x00, 0x00, 0x00, 0x02, | 1903 'o', 0x00, 0x03, 'b', 'a', 'r'}; |
| 2120 0x00, 0x00, 0x00, 0x03, | |
| 2121 'f', 'o', 'o', 0x00, | |
| 2122 0x03, 'f', 'o', 'o', | |
| 2123 0x00, 0x03, 'b', 'a', | |
| 2124 'r' | |
| 2125 }; | |
| 2126 const unsigned char kV3FrameData[] = { | 1904 const unsigned char kV3FrameData[] = { |
| 2127 0x80, spdy_version_ch_, 0x00, 0x02, | 1905 0x80, spdy_version_ch_, 0x00, 0x02, 0x01, 0x00, 0x00, 0x21, 0x7f, |
| 2128 0x01, 0x00, 0x00, 0x21, | 1906 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2129 0x7f, 0xff, 0xff, 0xff, | 1907 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 'f', 'o', 'o', |
| 2130 0x00, 0x00, 0x00, 0x02, | 1908 0x00, 0x00, 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x00, |
| 2131 0x00, 0x00, 0x00, 0x00, | 1909 0x00, 0x03, 'b', 'a', 'r'}; |
| 2132 0x00, 0x00, 0x00, 0x03, | |
| 2133 'f', 'o', 'o', 0x00, | |
| 2134 0x00, 0x00, 0x03, 'f', | |
| 2135 'o', 'o', 0x00, 0x00, | |
| 2136 0x00, 0x03, 'b', 'a', | |
| 2137 'r' | |
| 2138 }; | |
| 2139 const unsigned char kV4FrameData[] = { | 1910 const unsigned char kV4FrameData[] = { |
| 2140 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS | 1911 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS |
| 2141 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 1912 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 2142 0x40, 0x00, 0x03, 0x66, // @..f | 1913 0x40, 0x00, 0x03, 0x66, // @..f |
| 2143 0x6f, 0x6f, 0x40, 0x03, // oo@. | 1914 0x6f, 0x6f, 0x40, 0x03, // oo@. |
| 2144 0x66, 0x6f, 0x6f, 0x03, // foo. | 1915 0x66, 0x6f, 0x6f, 0x03, // foo. |
| 2145 0x62, 0x61, 0x72, // bar | 1916 0x62, 0x61, 0x72, // bar |
| 2146 }; | 1917 }; |
| 2147 SpdySynReplyIR syn_reply(0x7fffffff); | 1918 SpdySynReplyIR syn_reply(0x7fffffff); |
| 2148 syn_reply.set_fin(true); | 1919 syn_reply.set_fin(true); |
| 2149 syn_reply.SetHeader("", "foo"); | 1920 syn_reply.SetHeader("", "foo"); |
| 2150 syn_reply.SetHeader("foo", "bar"); | 1921 syn_reply.SetHeader("foo", "bar"); |
| 2151 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1922 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
| 2152 if (IsSpdy2()) { | 1923 if (IsSpdy2()) { |
| 2153 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1924 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2154 } else if (IsSpdy3()) { | 1925 } else if (IsSpdy3()) { |
| 2155 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1926 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2156 } else { | 1927 } else { |
| 2157 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1928 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2158 } | 1929 } |
| 2159 } | 1930 } |
| 2160 | 1931 |
| 2161 { | 1932 { |
| 2162 const char kDescription[] = | 1933 const char kDescription[] = |
| 2163 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; | 1934 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; |
| 2164 | 1935 |
| 2165 const unsigned char kV2FrameData[] = { | 1936 const unsigned char kV2FrameData[] = { |
| 2166 0x80, spdy_version_ch_, 0x00, 0x02, | 1937 0x80, spdy_version_ch_, 0x00, 0x02, 0x01, 0x00, 0x00, 0x19, 0x7f, |
| 2167 0x01, 0x00, 0x00, 0x19, | 1938 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, |
| 2168 0x7f, 0xff, 0xff, 0xff, | 1939 'b', 'a', 'r', 0x00, 0x03, 'f', 'o', 'o', 0x00, |
| 2169 0x00, 0x00, 0x00, 0x02, | 1940 0x03, 'f', 'o', 'o', 0x00, 0x00}; |
| 2170 0x00, 0x03, 'b', 'a', | |
| 2171 'r', 0x00, 0x03, 'f', | |
| 2172 'o', 'o', 0x00, 0x03, | |
| 2173 'f', 'o', 'o', 0x00, | |
| 2174 0x00 | |
| 2175 }; | |
| 2176 const unsigned char kV3FrameData[] = { | 1941 const unsigned char kV3FrameData[] = { |
| 2177 0x80, spdy_version_ch_, 0x00, 0x02, | 1942 0x80, spdy_version_ch_, 0x00, 0x02, 0x01, 0x00, 0x00, 0x21, 0x7f, |
| 2178 0x01, 0x00, 0x00, 0x21, | 1943 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2179 0x7f, 0xff, 0xff, 0xff, | 1944 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x00, 0x00, 0x03, |
| 2180 0x00, 0x00, 0x00, 0x02, | 1945 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, 'f', 'o', |
| 2181 0x00, 0x00, 0x00, 0x03, | 1946 'o', 0x00, 0x00, 0x00, 0x00}; |
| 2182 'b', 'a', 'r', 0x00, | |
| 2183 0x00, 0x00, 0x03, 'f', | |
| 2184 'o', 'o', 0x00, 0x00, | |
| 2185 0x00, 0x03, 'f', 'o', | |
| 2186 'o', 0x00, 0x00, 0x00, | |
| 2187 0x00 | |
| 2188 }; | |
| 2189 const unsigned char kV4FrameData[] = { | 1947 const unsigned char kV4FrameData[] = { |
| 2190 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS | 1948 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS |
| 2191 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 1949 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 2192 0x40, 0x03, 0x62, 0x61, // @.ba | 1950 0x40, 0x03, 0x62, 0x61, // @.ba |
| 2193 0x72, 0x03, 0x66, 0x6f, // r.fo | 1951 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2194 0x6f, 0x40, 0x03, 0x66, // o@.f | 1952 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 2195 0x6f, 0x6f, 0x00, // oo. | 1953 0x6f, 0x6f, 0x00, // oo. |
| 2196 }; | 1954 }; |
| 2197 SpdySynReplyIR syn_reply(0x7fffffff); | 1955 SpdySynReplyIR syn_reply(0x7fffffff); |
| 2198 syn_reply.set_fin(true); | 1956 syn_reply.set_fin(true); |
| 2199 syn_reply.SetHeader("bar", "foo"); | 1957 syn_reply.SetHeader("bar", "foo"); |
| 2200 syn_reply.SetHeader("foo", ""); | 1958 syn_reply.SetHeader("foo", ""); |
| 2201 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1959 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
| 2202 if (IsSpdy2()) { | 1960 if (IsSpdy2()) { |
| 2203 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1961 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2204 } else if (IsSpdy3()) { | 1962 } else if (IsSpdy3()) { |
| 2205 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1963 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2206 } else { | 1964 } else { |
| 2207 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1965 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2208 } | 1966 } |
| 2209 } | 1967 } |
| 2210 } | 1968 } |
| 2211 | 1969 |
| 2212 // TODO(phajdan.jr): Clean up after we no longer need | 1970 // TODO(phajdan.jr): Clean up after we no longer need |
| 2213 // to workaround http://crbug.com/139744. | 1971 // to workaround http://crbug.com/139744. |
| 2214 #if !defined(USE_SYSTEM_ZLIB) | 1972 #if !defined(USE_SYSTEM_ZLIB) |
| 2215 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { | 1973 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { |
| 2216 SpdyFramer framer(spdy_version_); | 1974 SpdyFramer framer(spdy_version_); |
| 2217 framer.set_enable_compression(true); | 1975 framer.set_enable_compression(true); |
| 2218 | 1976 |
| 2219 { | 1977 { |
| 2220 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 1978 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
| 2221 | 1979 |
| 2222 const unsigned char kV2FrameData[] = { | 1980 const unsigned char kV2FrameData[] = { |
| 2223 0x80, spdy_version_ch_, 0x00, 0x02, | 1981 0x80, spdy_version_ch_, 0x00, 0x02, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, |
| 2224 0x00, 0x00, 0x00, 0x32, | 1982 0x00, 0x01, 0x00, 0x00, 0x38, 0xea, 0xdf, 0xa2, 0x51, 0xb2, |
| 2225 0x00, 0x00, 0x00, 0x01, | 1983 0x62, 0x60, 0x62, 0x60, 0x4e, 0x4a, 0x2c, 0x62, 0x60, 0x06, |
| 2226 0x00, 0x00, 0x38, 0xea, | 1984 0x08, 0xa0, 0xb4, 0xfc, 0x7c, 0x80, 0x00, 0x62, 0x60, 0x4e, |
| 2227 0xdf, 0xa2, 0x51, 0xb2, | 1985 0xcb, 0xcf, 0x67, 0x60, 0x06, 0x08, 0xa0, 0xa4, 0xc4, 0x22, |
| 2228 0x62, 0x60, 0x62, 0x60, | 1986 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 2229 0x4e, 0x4a, 0x2c, 0x62, | |
| 2230 0x60, 0x06, 0x08, 0xa0, | |
| 2231 0xb4, 0xfc, 0x7c, 0x80, | |
| 2232 0x00, 0x62, 0x60, 0x4e, | |
| 2233 0xcb, 0xcf, 0x67, 0x60, | |
| 2234 0x06, 0x08, 0xa0, 0xa4, | |
| 2235 0xc4, 0x22, 0x80, 0x00, | |
| 2236 0x02, 0x00, 0x00, 0x00, | |
| 2237 0xff, 0xff, | |
| 2238 }; | 1987 }; |
| 2239 const unsigned char kV3FrameData[] = { | 1988 const unsigned char kV3FrameData[] = { |
| 2240 0x80, spdy_version_ch_, 0x00, 0x02, | 1989 0x80, spdy_version_ch_, 0x00, 0x02, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, |
| 2241 0x00, 0x00, 0x00, 0x31, | 1990 0x00, 0x01, 0x38, 0xea, 0xe3, 0xc6, 0xa7, 0xc2, 0x02, 0xe5, |
| 2242 0x00, 0x00, 0x00, 0x01, | 1991 0x0e, 0x50, 0xc2, 0x4b, 0x4a, 0x04, 0xe5, 0x0b, 0x66, 0x80, |
| 2243 0x38, 0xea, 0xe3, 0xc6, | 1992 0x00, 0x4a, 0xcb, 0xcf, 0x07, 0x08, 0x20, 0x10, 0x95, 0x96, |
| 2244 0xa7, 0xc2, 0x02, 0xe5, | 1993 0x9f, 0x0f, 0xa2, 0x00, 0x02, 0x28, 0x29, 0xb1, 0x08, 0x20, |
| 2245 0x0e, 0x50, 0xc2, 0x4b, | 1994 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 2246 0x4a, 0x04, 0xe5, 0x0b, | |
| 2247 0x66, 0x80, 0x00, 0x4a, | |
| 2248 0xcb, 0xcf, 0x07, 0x08, | |
| 2249 0x20, 0x10, 0x95, 0x96, | |
| 2250 0x9f, 0x0f, 0xa2, 0x00, | |
| 2251 0x02, 0x28, 0x29, 0xb1, | |
| 2252 0x08, 0x20, 0x80, 0x00, | |
| 2253 0x00, 0x00, 0x00, 0xff, | |
| 2254 0xff, | |
| 2255 }; | 1995 }; |
| 2256 SpdySynReplyIR syn_reply(1); | 1996 SpdySynReplyIR syn_reply(1); |
| 2257 syn_reply.SetHeader("bar", "foo"); | 1997 syn_reply.SetHeader("bar", "foo"); |
| 2258 syn_reply.SetHeader("foo", "bar"); | 1998 syn_reply.SetHeader("foo", "bar"); |
| 2259 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 1999 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
| 2260 if (IsSpdy2()) { | 2000 if (IsSpdy2()) { |
| 2261 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2001 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2262 } else if (IsSpdy3()) { | 2002 } else if (IsSpdy3()) { |
| 2263 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2003 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2264 } else { | 2004 } else { |
| 2265 // Deflate compression doesn't apply to HPACK. | 2005 // Deflate compression doesn't apply to HPACK. |
| 2266 } | 2006 } |
| 2267 } | 2007 } |
| 2268 } | 2008 } |
| 2269 #endif // !defined(USE_SYSTEM_ZLIB) | 2009 #endif // !defined(USE_SYSTEM_ZLIB) |
| 2270 | 2010 |
| 2271 TEST_P(SpdyFramerTest, CreateRstStream) { | 2011 TEST_P(SpdyFramerTest, CreateRstStream) { |
| 2272 SpdyFramer framer(spdy_version_); | 2012 SpdyFramer framer(spdy_version_); |
| 2273 | 2013 |
| 2274 { | 2014 { |
| 2275 const char kDescription[] = "RST_STREAM frame"; | 2015 const char kDescription[] = "RST_STREAM frame"; |
| 2276 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2016 const unsigned char kV3FrameData[] = { |
| 2277 0x80, spdy_version_ch_, 0x00, 0x03, | 2017 // Also applies for V2. |
| 2278 0x00, 0x00, 0x00, 0x08, | 2018 0x80, spdy_version_ch_, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, |
| 2279 0x00, 0x00, 0x00, 0x01, | 2019 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 2280 0x00, 0x00, 0x00, 0x01, | |
| 2281 }; | 2020 }; |
| 2282 const unsigned char kV4FrameData[] = { | 2021 const unsigned char kV4FrameData[] = {0x00, 0x07, 0x03, 0x00, 0x00, |
| 2283 0x00, 0x07, 0x03, 0x00, | 2022 0x00, 0x00, 0x01, 0x00, 0x00, |
| 2284 0x00, 0x00, 0x00, 0x01, | 2023 0x00, 0x01, 0x52, 0x53, 0x54}; |
| 2285 0x00, 0x00, 0x00, 0x01, | |
| 2286 0x52, 0x53, 0x54 | |
| 2287 }; | |
| 2288 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR, "RST"); | 2024 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR, "RST"); |
| 2289 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 2025 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 2290 if (IsSpdy4()) { | 2026 if (IsSpdy4()) { |
| 2291 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2027 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2292 } else { | 2028 } else { |
| 2293 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2029 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2294 } | 2030 } |
| 2295 } | 2031 } |
| 2296 | 2032 |
| 2297 { | 2033 { |
| 2298 const char kDescription[] = "RST_STREAM frame with max stream ID"; | 2034 const char kDescription[] = "RST_STREAM frame with max stream ID"; |
| 2299 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2035 const unsigned char kV3FrameData[] = { |
| 2300 0x80, spdy_version_ch_, 0x00, 0x03, | 2036 // Also applies for V2. |
| 2301 0x00, 0x00, 0x00, 0x08, | 2037 0x80, spdy_version_ch_, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x7f, 0xff, |
| 2302 0x7f, 0xff, 0xff, 0xff, | 2038 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, |
| 2303 0x00, 0x00, 0x00, 0x01, | |
| 2304 }; | 2039 }; |
| 2305 const unsigned char kV4FrameData[] = { | 2040 const unsigned char kV4FrameData[] = { |
| 2306 0x00, 0x04, 0x03, 0x00, | 2041 0x00, 0x04, 0x03, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, |
| 2307 0x7f, 0xff, 0xff, 0xff, | |
| 2308 0x00, 0x00, 0x00, 0x01, | |
| 2309 }; | 2042 }; |
| 2310 SpdyRstStreamIR rst_stream(0x7FFFFFFF, | 2043 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_PROTOCOL_ERROR, ""); |
| 2311 RST_STREAM_PROTOCOL_ERROR, | |
| 2312 ""); | |
| 2313 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 2044 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 2314 if (IsSpdy4()) { | 2045 if (IsSpdy4()) { |
| 2315 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2046 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2316 } else { | 2047 } else { |
| 2317 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2048 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2318 } | 2049 } |
| 2319 } | 2050 } |
| 2320 | 2051 |
| 2321 { | 2052 { |
| 2322 const char kDescription[] = "RST_STREAM frame with max status code"; | 2053 const char kDescription[] = "RST_STREAM frame with max status code"; |
| 2323 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2054 const unsigned char kV3FrameData[] = { |
| 2324 0x80, spdy_version_ch_, 0x00, 0x03, | 2055 // Also applies for V2. |
| 2325 0x00, 0x00, 0x00, 0x08, | 2056 0x80, spdy_version_ch_, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x7f, 0xff, |
| 2326 0x7f, 0xff, 0xff, 0xff, | 2057 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, |
| 2327 0x00, 0x00, 0x00, 0x06, | |
| 2328 }; | 2058 }; |
| 2329 const unsigned char kV4FrameData[] = { | 2059 const unsigned char kV4FrameData[] = { |
| 2330 0x00, 0x04, 0x03, 0x00, | 2060 0x00, 0x04, 0x03, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x06, |
| 2331 0x7f, 0xff, 0xff, 0xff, | |
| 2332 0x00, 0x00, 0x00, 0x06, | |
| 2333 }; | 2061 }; |
| 2334 SpdyRstStreamIR rst_stream(0x7FFFFFFF, | 2062 SpdyRstStreamIR rst_stream(0x7FFFFFFF, RST_STREAM_INTERNAL_ERROR, ""); |
| 2335 RST_STREAM_INTERNAL_ERROR, | |
| 2336 ""); | |
| 2337 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); | 2063 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); |
| 2338 if (IsSpdy4()) { | 2064 if (IsSpdy4()) { |
| 2339 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2065 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2340 } else { | 2066 } else { |
| 2341 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2067 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2342 } | 2068 } |
| 2343 } | 2069 } |
| 2344 } | 2070 } |
| 2345 | 2071 |
| 2346 TEST_P(SpdyFramerTest, CreateSettings) { | 2072 TEST_P(SpdyFramerTest, CreateSettings) { |
| 2347 SpdyFramer framer(spdy_version_); | 2073 SpdyFramer framer(spdy_version_); |
| 2348 | 2074 |
| 2349 { | 2075 { |
| 2350 const char kDescription[] = "Network byte order SETTINGS frame"; | 2076 const char kDescription[] = "Network byte order SETTINGS frame"; |
| 2351 | 2077 |
| 2352 const unsigned char kV2FrameData[] = { | 2078 const unsigned char kV2FrameData[] = { |
| 2353 0x80, spdy_version_ch_, 0x00, 0x04, | 2079 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 2354 0x00, 0x00, 0x00, 0x0c, | 2080 0x00, 0x01, 0x07, 0x00, 0x00, 0x01, 0x0a, 0x0b, 0x0c, 0x0d, |
| 2355 0x00, 0x00, 0x00, 0x01, | |
| 2356 0x07, 0x00, 0x00, 0x01, | |
| 2357 0x0a, 0x0b, 0x0c, 0x0d, | |
| 2358 }; | 2081 }; |
| 2359 const unsigned char kV3FrameData[] = { | 2082 const unsigned char kV3FrameData[] = { |
| 2360 0x80, spdy_version_ch_, 0x00, 0x04, | 2083 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, |
| 2361 0x00, 0x00, 0x00, 0x0c, | 2084 0x00, 0x01, 0x01, 0x00, 0x00, 0x07, 0x0a, 0x0b, 0x0c, 0x0d, |
| 2362 0x00, 0x00, 0x00, 0x01, | |
| 2363 0x01, 0x00, 0x00, 0x07, | |
| 2364 0x0a, 0x0b, 0x0c, 0x0d, | |
| 2365 }; | 2085 }; |
| 2366 const unsigned char kV4FrameData[] = { | 2086 const unsigned char kV4FrameData[] = { |
| 2367 0x00, 0x05, 0x04, 0x00, | 2087 0x00, 0x05, 0x04, 0x00, 0x00, 0x00, 0x00, |
| 2368 0x00, 0x00, 0x00, 0x00, | 2088 0x00, 0x04, 0x0a, 0x0b, 0x0c, 0x0d, |
| 2369 0x04, 0x0a, 0x0b, 0x0c, | |
| 2370 0x0d, | |
| 2371 }; | 2089 }; |
| 2372 | 2090 |
| 2373 uint32 kValue = 0x0a0b0c0d; | 2091 uint32 kValue = 0x0a0b0c0d; |
| 2374 SpdySettingsIR settings_ir; | 2092 SpdySettingsIR settings_ir; |
| 2375 | 2093 |
| 2376 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); | 2094 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); |
| 2377 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; | 2095 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; |
| 2378 SettingsMap settings; | 2096 SettingsMap settings; |
| 2379 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); | 2097 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); |
| 2380 EXPECT_EQ(kFlags, settings[kId].first); | 2098 EXPECT_EQ(kFlags, settings[kId].first); |
| 2381 EXPECT_EQ(kValue, settings[kId].second); | 2099 EXPECT_EQ(kValue, settings[kId].second); |
| 2382 settings_ir.AddSetting(kId, | 2100 settings_ir.AddSetting(kId, |
| 2383 kFlags & SETTINGS_FLAG_PLEASE_PERSIST, | 2101 kFlags & SETTINGS_FLAG_PLEASE_PERSIST, |
| 2384 kFlags & SETTINGS_FLAG_PERSISTED, | 2102 kFlags & SETTINGS_FLAG_PERSISTED, |
| 2385 kValue); | 2103 kValue); |
| 2386 | 2104 |
| 2387 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 2105 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| 2388 if (IsSpdy2()) { | 2106 if (IsSpdy2()) { |
| 2389 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2107 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2390 } else if (IsSpdy3()) { | 2108 } else if (IsSpdy3()) { |
| 2391 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2109 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2392 } else { | 2110 } else { |
| 2393 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2111 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2394 } | 2112 } |
| 2395 } | 2113 } |
| 2396 | 2114 |
| 2397 { | 2115 { |
| 2398 const char kDescription[] = "Basic SETTINGS frame"; | 2116 const char kDescription[] = "Basic SETTINGS frame"; |
| 2399 | 2117 |
| 2400 const unsigned char kV2FrameData[] = { | 2118 const unsigned char |
| 2401 0x80, spdy_version_ch_, 0x00, 0x04, | 2119 kV2FrameData |
| 2402 0x00, 0x00, 0x00, 0x24, | 2120 [] = { |
| 2403 0x00, 0x00, 0x00, 0x04, | 2121 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, |
| 2404 0x01, 0x00, 0x00, 0x00, // 1st Setting | 2122 0x00, 0x24, 0x00, 0x00, 0x00, 0x04, |
| 2405 0x00, 0x00, 0x00, 0x05, | 2123 0x01, 0x00, 0x00, 0x00, // 1st Setting |
| 2406 0x02, 0x00, 0x00, 0x00, // 2nd Setting | 2124 0x00, 0x00, 0x00, 0x05, 0x02, 0x00, |
| 2407 0x00, 0x00, 0x00, 0x06, | 2125 0x00, 0x00, // 2nd Setting |
| 2408 0x03, 0x00, 0x00, 0x00, // 3rd Setting | 2126 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, |
| 2409 0x00, 0x00, 0x00, 0x07, | 2127 0x00, 0x00, // 3rd Setting |
| 2410 0x04, 0x00, 0x00, 0x00, // 4th Setting | 2128 0x00, 0x00, 0x00, 0x07, 0x04, 0x00, |
| 2411 0x00, 0x00, 0x00, 0x08, | 2129 0x00, 0x00, // 4th Setting |
| 2412 }; | 2130 0x00, 0x00, 0x00, 0x08, |
| 2413 const unsigned char kV3FrameData[] = { | 2131 }; |
| 2414 0x80, spdy_version_ch_, 0x00, 0x04, | 2132 const unsigned char |
| 2415 0x00, 0x00, 0x00, 0x24, | 2133 kV3FrameData |
| 2416 0x00, 0x00, 0x00, 0x04, | 2134 [] = { |
| 2417 0x00, 0x00, 0x00, 0x01, // 1st Setting | 2135 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, |
| 2418 0x00, 0x00, 0x00, 0x05, | 2136 0x00, 0x24, 0x00, 0x00, 0x00, 0x04, |
| 2419 0x00, 0x00, 0x00, 0x02, // 2nd Setting | 2137 0x00, 0x00, 0x00, 0x01, // 1st Setting |
| 2420 0x00, 0x00, 0x00, 0x06, | 2138 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, |
| 2421 0x00, 0x00, 0x00, 0x03, // 3rd Setting | 2139 0x00, 0x02, // 2nd Setting |
| 2422 0x00, 0x00, 0x00, 0x07, | 2140 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, |
| 2423 0x00, 0x00, 0x00, 0x04, // 4th Setting | 2141 0x00, 0x03, // 3rd Setting |
| 2424 0x00, 0x00, 0x00, 0x08, | 2142 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, |
| 2425 }; | 2143 0x00, 0x04, // 4th Setting |
| 2144 0x00, 0x00, 0x00, 0x08, |
| 2145 }; |
| 2426 // These end up seemingly out of order because of the way that our internal | 2146 // These end up seemingly out of order because of the way that our internal |
| 2427 // ordering for settings_ir works. HTTP2 has no requirement on ordering on | 2147 // ordering for settings_ir works. HTTP2 has no requirement on ordering on |
| 2428 // the wire. | 2148 // the wire. |
| 2429 const unsigned char kV4FrameData[] = { | 2149 const unsigned char kV4FrameData[] = { |
| 2430 0x00, 0x14, 0x04, 0x00, | 2150 0x00, 0x14, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2431 0x00, 0x00, 0x00, 0x00, | 2151 0x03, // 3rd Setting |
| 2432 0x03, // 3rd Setting | 2152 0x00, 0x00, 0x00, 0x07, |
| 2433 0x00, 0x00, 0x00, 0x07, | 2153 0x04, // 4th Setting |
| 2434 0x04, // 4th Setting | 2154 0x00, 0x00, 0x00, 0x08, |
| 2435 0x00, 0x00, 0x00, 0x08, | 2155 0x01, // 1st Setting |
| 2436 0x01, // 1st Setting | 2156 0x00, 0x00, 0x00, 0x05, |
| 2437 0x00, 0x00, 0x00, 0x05, | 2157 0x02, // 2nd Setting |
| 2438 0x02, // 2nd Setting | 2158 0x00, 0x00, 0x00, 0x06, |
| 2439 0x00, 0x00, 0x00, 0x06, | |
| 2440 }; | 2159 }; |
| 2441 | 2160 |
| 2442 SpdySettingsIR settings_ir; | 2161 SpdySettingsIR settings_ir; |
| 2443 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), | 2162 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), |
| 2444 false, // persist | 2163 false, // persist |
| 2445 false, // persisted | 2164 false, // persisted |
| 2446 5); | 2165 5); |
| 2447 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), | 2166 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), |
| 2448 false, // persist | 2167 false, // persist |
| 2449 false, // persisted | 2168 false, // persisted |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2463 } else if (IsSpdy3()) { | 2182 } else if (IsSpdy3()) { |
| 2464 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2183 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2465 } else { | 2184 } else { |
| 2466 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2185 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2467 } | 2186 } |
| 2468 } | 2187 } |
| 2469 | 2188 |
| 2470 { | 2189 { |
| 2471 const char kDescription[] = "Empty SETTINGS frame"; | 2190 const char kDescription[] = "Empty SETTINGS frame"; |
| 2472 | 2191 |
| 2473 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2192 const unsigned char kV3FrameData[] = { |
| 2474 0x80, spdy_version_ch_, 0x00, 0x04, | 2193 // Also applies for V2. |
| 2475 0x00, 0x00, 0x00, 0x04, | 2194 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, |
| 2476 0x00, 0x00, 0x00, 0x00, | 2195 0x00, 0x00, |
| 2477 }; | 2196 }; |
| 2478 const unsigned char kV4FrameData[] = { | 2197 const unsigned char kV4FrameData[] = { |
| 2479 0x00, 0x00, 0x04, 0x00, | 2198 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2480 0x00, 0x00, 0x00, 0x00, | |
| 2481 }; | 2199 }; |
| 2482 SpdySettingsIR settings_ir; | 2200 SpdySettingsIR settings_ir; |
| 2483 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 2201 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| 2484 if (IsSpdy4()) { | 2202 if (IsSpdy4()) { |
| 2485 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2203 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2486 } else { | 2204 } else { |
| 2487 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2205 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2488 } | 2206 } |
| 2489 } | 2207 } |
| 2490 } | 2208 } |
| 2491 | 2209 |
| 2492 TEST_P(SpdyFramerTest, CreatePingFrame) { | 2210 TEST_P(SpdyFramerTest, CreatePingFrame) { |
| 2493 SpdyFramer framer(spdy_version_); | 2211 SpdyFramer framer(spdy_version_); |
| 2494 | 2212 |
| 2495 { | 2213 { |
| 2496 const char kDescription[] = "PING frame"; | 2214 const char kDescription[] = "PING frame"; |
| 2497 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2215 const unsigned char kV3FrameData[] = { |
| 2498 0x80, spdy_version_ch_, 0x00, 0x06, | 2216 // Also applies for V2. |
| 2499 0x00, 0x00, 0x00, 0x04, | 2217 0x80, spdy_version_ch_, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x12, 0x34, |
| 2500 0x12, 0x34, 0x56, 0x78, | 2218 0x56, 0x78, |
| 2501 }; | 2219 }; |
| 2502 const unsigned char kV4FrameData[] = { | 2220 const unsigned char kV4FrameData[] = { |
| 2503 0x00, 0x08, 0x06, 0x00, | 2221 0x00, 0x08, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2504 0x00, 0x00, 0x00, 0x00, | 2222 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, |
| 2505 0x12, 0x34, 0x56, 0x78, | |
| 2506 0x9a, 0xbc, 0xde, 0xff, | |
| 2507 }; | 2223 }; |
| 2508 const unsigned char kV4FrameDataWithAck[] = { | 2224 const unsigned char kV4FrameDataWithAck[] = { |
| 2509 0x00, 0x08, 0x06, 0x01, | 2225 0x00, 0x08, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 2510 0x00, 0x00, 0x00, 0x00, | 2226 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xff, |
| 2511 0x12, 0x34, 0x56, 0x78, | |
| 2512 0x9a, 0xbc, 0xde, 0xff, | |
| 2513 }; | 2227 }; |
| 2514 scoped_ptr<SpdyFrame> frame; | 2228 scoped_ptr<SpdyFrame> frame; |
| 2515 if (IsSpdy4()) { | 2229 if (IsSpdy4()) { |
| 2516 const SpdyPingId kPingId = 0x123456789abcdeffULL; | 2230 const SpdyPingId kPingId = 0x123456789abcdeffULL; |
| 2517 SpdyPingIR ping_ir(kPingId); | 2231 SpdyPingIR ping_ir(kPingId); |
| 2518 // Tests SpdyPingIR when the ping is not an ack. | 2232 // Tests SpdyPingIR when the ping is not an ack. |
| 2519 ASSERT_FALSE(ping_ir.is_ack()); | 2233 ASSERT_FALSE(ping_ir.is_ack()); |
| 2520 frame.reset(framer.SerializePing(ping_ir)); | 2234 frame.reset(framer.SerializePing(ping_ir)); |
| 2521 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2235 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2522 | 2236 |
| 2523 // Tests SpdyPingIR when the ping is an ack. | 2237 // Tests SpdyPingIR when the ping is an ack. |
| 2524 ping_ir.set_is_ack(true); | 2238 ping_ir.set_is_ack(true); |
| 2525 frame.reset(framer.SerializePing(ping_ir)); | 2239 frame.reset(framer.SerializePing(ping_ir)); |
| 2526 CompareFrame(kDescription, *frame, | 2240 CompareFrame(kDescription, |
| 2527 kV4FrameDataWithAck, arraysize(kV4FrameDataWithAck)); | 2241 *frame, |
| 2242 kV4FrameDataWithAck, |
| 2243 arraysize(kV4FrameDataWithAck)); |
| 2528 | 2244 |
| 2529 } else { | 2245 } else { |
| 2530 frame.reset(framer.SerializePing(SpdyPingIR(0x12345678ull))); | 2246 frame.reset(framer.SerializePing(SpdyPingIR(0x12345678ull))); |
| 2531 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2247 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2532 } | 2248 } |
| 2533 } | 2249 } |
| 2534 } | 2250 } |
| 2535 | 2251 |
| 2536 TEST_P(SpdyFramerTest, CreateGoAway) { | 2252 TEST_P(SpdyFramerTest, CreateGoAway) { |
| 2537 SpdyFramer framer(spdy_version_); | 2253 SpdyFramer framer(spdy_version_); |
| 2538 | 2254 |
| 2539 { | 2255 { |
| 2540 const char kDescription[] = "GOAWAY frame"; | 2256 const char kDescription[] = "GOAWAY frame"; |
| 2541 const unsigned char kV2FrameData[] = { | 2257 const unsigned char kV2FrameData[] = { |
| 2542 0x80, spdy_version_ch_, 0x00, 0x07, | 2258 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, |
| 2543 0x00, 0x00, 0x00, 0x04, | 2259 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, // Stream Id |
| 2544 0x00, 0x00, 0x00, 0x00, // Stream Id | |
| 2545 }; | 2260 }; |
| 2546 const unsigned char kV3FrameData[] = { | 2261 const unsigned char kV3FrameData[] = { |
| 2547 0x80, spdy_version_ch_, 0x00, 0x07, | 2262 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, |
| 2548 0x00, 0x00, 0x00, 0x08, | 2263 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, // Stream Id |
| 2549 0x00, 0x00, 0x00, 0x00, // Stream Id | 2264 0x00, 0x00, 0x00, 0x00, // Status |
| 2550 0x00, 0x00, 0x00, 0x00, // Status | |
| 2551 }; | 2265 }; |
| 2552 const unsigned char kV4FrameData[] = { | 2266 const unsigned char kV4FrameData[] = { |
| 2553 0x00, 0x0a, 0x07, 0x00, | 2267 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, |
| 2554 0x00, 0x00, 0x00, 0x00, | 2268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Stream id |
| 2555 0x00, 0x00, 0x00, 0x00, // Stream id | 2269 0x00, 0x00, 0x00, 0x00, // Status |
| 2556 0x00, 0x00, 0x00, 0x00, // Status | 2270 0x47, 0x41, // Opaque Description |
| 2557 0x47, 0x41, // Opaque Description | |
| 2558 }; | 2271 }; |
| 2559 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); | 2272 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); |
| 2560 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); | 2273 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); |
| 2561 if (IsSpdy2()) { | 2274 if (IsSpdy2()) { |
| 2562 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2275 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2563 } else if (IsSpdy3()) { | 2276 } else if (IsSpdy3()) { |
| 2564 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2277 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2565 } else { | 2278 } else { |
| 2566 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2279 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2567 } | 2280 } |
| 2568 } | 2281 } |
| 2569 | 2282 |
| 2570 { | 2283 { |
| 2571 const char kDescription[] = "GOAWAY frame with max stream ID, status"; | 2284 const char kDescription[] = "GOAWAY frame with max stream ID, status"; |
| 2572 const unsigned char kV2FrameData[] = { | 2285 const unsigned char kV2FrameData[] = { |
| 2573 0x80, spdy_version_ch_, 0x00, 0x07, | 2286 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, |
| 2574 0x00, 0x00, 0x00, 0x04, | 2287 0x00, 0x04, 0x7f, 0xff, 0xff, 0xff, // Stream Id |
| 2575 0x7f, 0xff, 0xff, 0xff, // Stream Id | |
| 2576 }; | 2288 }; |
| 2577 const unsigned char kV3FrameData[] = { | 2289 const unsigned char kV3FrameData[] = { |
| 2578 0x80, spdy_version_ch_, 0x00, 0x07, | 2290 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, |
| 2579 0x00, 0x00, 0x00, 0x08, | 2291 0x00, 0x08, 0x7f, 0xff, 0xff, 0xff, // Stream Id |
| 2580 0x7f, 0xff, 0xff, 0xff, // Stream Id | 2292 0x00, 0x00, 0x00, 0x02, // Status |
| 2581 0x00, 0x00, 0x00, 0x02, // Status | |
| 2582 }; | 2293 }; |
| 2583 const unsigned char kV4FrameData[] = { | 2294 const unsigned char kV4FrameData[] = { |
| 2584 0x00, 0x0a, 0x07, 0x00, | 2295 0x00, 0x0a, 0x07, 0x00, 0x00, 0x00, |
| 2585 0x00, 0x00, 0x00, 0x00, | 2296 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, // Stream Id |
| 2586 0x7f, 0xff, 0xff, 0xff, // Stream Id | 2297 0x00, 0x00, 0x00, 0x02, // Status |
| 2587 0x00, 0x00, 0x00, 0x02, // Status | 2298 0x47, 0x41, // Opaque Description |
| 2588 0x47, 0x41, // Opaque Description | |
| 2589 }; | 2299 }; |
| 2590 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); | 2300 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); |
| 2591 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); | 2301 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); |
| 2592 if (IsSpdy2()) { | 2302 if (IsSpdy2()) { |
| 2593 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2303 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2594 } else if (IsSpdy3()) { | 2304 } else if (IsSpdy3()) { |
| 2595 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2305 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2596 } else { | 2306 } else { |
| 2597 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2307 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2598 } | 2308 } |
| 2599 } | 2309 } |
| 2600 } | 2310 } |
| 2601 | 2311 |
| 2602 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { | 2312 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { |
| 2603 SpdyFramer framer(spdy_version_); | 2313 SpdyFramer framer(spdy_version_); |
| 2604 framer.set_enable_compression(false); | 2314 framer.set_enable_compression(false); |
| 2605 | 2315 |
| 2606 { | 2316 { |
| 2607 const char kDescription[] = "HEADERS frame, no FIN"; | 2317 const char kDescription[] = "HEADERS frame, no FIN"; |
| 2608 | 2318 |
| 2609 const unsigned char kV2FrameData[] = { | 2319 const unsigned char kV2FrameData[] = { |
| 2610 0x80, spdy_version_ch_, 0x00, 0x08, | 2320 0x80, spdy_version_ch_, 0x00, 0x08, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 2611 0x00, 0x00, 0x00, 0x1C, | 2321 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, |
| 2612 0x00, 0x00, 0x00, 0x01, | 2322 'b', 'a', 'r', 0x00, 0x03, 'f', 'o', 'o', 0x00, |
| 2613 0x00, 0x00, 0x00, 0x02, | 2323 0x03, 'f', 'o', 'o', 0x00, 0x03, 'b', 'a', 'r'}; |
| 2614 0x00, 0x03, 'b', 'a', | |
| 2615 'r', 0x00, 0x03, 'f', | |
| 2616 'o', 'o', 0x00, 0x03, | |
| 2617 'f', 'o', 'o', 0x00, | |
| 2618 0x03, 'b', 'a', 'r' | |
| 2619 }; | |
| 2620 const unsigned char kV3FrameData[] = { | 2324 const unsigned char kV3FrameData[] = { |
| 2621 0x80, spdy_version_ch_, 0x00, 0x08, | 2325 0x80, spdy_version_ch_, 0x00, 0x08, 0x00, 0x00, 0x00, 0x24, 0x00, |
| 2622 0x00, 0x00, 0x00, 0x24, | 2326 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2623 0x00, 0x00, 0x00, 0x01, | 2327 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x00, 0x00, 0x03, |
| 2624 0x00, 0x00, 0x00, 0x02, | 2328 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, 'f', 'o', |
| 2625 0x00, 0x00, 0x00, 0x03, | 2329 'o', 0x00, 0x00, 0x00, 0x03, 'b', 'a', 'r'}; |
| 2626 'b', 'a', 'r', 0x00, | |
| 2627 0x00, 0x00, 0x03, 'f', | |
| 2628 'o', 'o', 0x00, 0x00, | |
| 2629 0x00, 0x03, 'f', 'o', | |
| 2630 'o', 0x00, 0x00, 0x00, | |
| 2631 0x03, 'b', 'a', 'r' | |
| 2632 }; | |
| 2633 const unsigned char kV4FrameData[] = { | 2330 const unsigned char kV4FrameData[] = { |
| 2634 0x00, 0x12, 0x01, 0x04, // Headers: END_HEADERS | 2331 0x00, 0x12, 0x01, 0x04, // Headers: END_HEADERS |
| 2635 0x00, 0x00, 0x00, 0x01, // Stream 1 | 2332 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 2636 0x40, 0x03, 0x62, 0x61, // @.ba | 2333 0x40, 0x03, 0x62, 0x61, // @.ba |
| 2637 0x72, 0x03, 0x66, 0x6f, // r.fo | 2334 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2638 0x6f, 0x40, 0x03, 0x66, // o@.f | 2335 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 2639 0x6f, 0x6f, 0x03, 0x62, // oo.b | 2336 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 2640 0x61, 0x72, // ar | 2337 0x61, 0x72, // ar |
| 2641 }; | 2338 }; |
| 2642 SpdyHeadersIR headers_ir(1); | 2339 SpdyHeadersIR headers_ir(1); |
| 2643 headers_ir.SetHeader("bar", "foo"); | 2340 headers_ir.SetHeader("bar", "foo"); |
| 2644 headers_ir.SetHeader("foo", "bar"); | 2341 headers_ir.SetHeader("foo", "bar"); |
| 2645 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2342 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 2646 if (IsSpdy2()) { | 2343 if (IsSpdy2()) { |
| 2647 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2344 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2648 } else if (IsSpdy3()) { | 2345 } else if (IsSpdy3()) { |
| 2649 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2346 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2650 } else { | 2347 } else { |
| 2651 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2348 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2652 } | 2349 } |
| 2653 } | 2350 } |
| 2654 | 2351 |
| 2655 { | 2352 { |
| 2656 const char kDescription[] = | 2353 const char kDescription[] = |
| 2657 "HEADERS frame with a 0-length header name, FIN, max stream ID"; | 2354 "HEADERS frame with a 0-length header name, FIN, max stream ID"; |
| 2658 | 2355 |
| 2659 const unsigned char kV2FrameData[] = { | 2356 const unsigned char kV2FrameData[] = { |
| 2660 0x80, spdy_version_ch_, 0x00, 0x08, | 2357 0x80, spdy_version_ch_, 0x00, 0x08, 0x01, 0x00, 0x00, 0x19, 0x7f, |
| 2661 0x01, 0x00, 0x00, 0x19, | 2358 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2662 0x7f, 0xff, 0xff, 0xff, | 2359 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x03, 'f', 'o', |
| 2663 0x00, 0x00, 0x00, 0x02, | 2360 'o', 0x00, 0x03, 'b', 'a', 'r'}; |
| 2664 0x00, 0x00, 0x00, 0x03, | |
| 2665 'f', 'o', 'o', 0x00, | |
| 2666 0x03, 'f', 'o', 'o', | |
| 2667 0x00, 0x03, 'b', 'a', | |
| 2668 'r' | |
| 2669 }; | |
| 2670 const unsigned char kV3FrameData[] = { | 2361 const unsigned char kV3FrameData[] = { |
| 2671 0x80, spdy_version_ch_, 0x00, 0x08, | 2362 0x80, spdy_version_ch_, 0x00, 0x08, 0x01, 0x00, 0x00, 0x21, 0x7f, |
| 2672 0x01, 0x00, 0x00, 0x21, | 2363 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2673 0x7f, 0xff, 0xff, 0xff, | 2364 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 'f', 'o', 'o', |
| 2674 0x00, 0x00, 0x00, 0x02, | 2365 0x00, 0x00, 0x00, 0x03, 'f', 'o', 'o', 0x00, 0x00, |
| 2675 0x00, 0x00, 0x00, 0x00, | 2366 0x00, 0x03, 'b', 'a', 'r'}; |
| 2676 0x00, 0x00, 0x00, 0x03, | |
| 2677 'f', 'o', 'o', 0x00, | |
| 2678 0x00, 0x00, 0x03, 'f', | |
| 2679 'o', 'o', 0x00, 0x00, | |
| 2680 0x00, 0x03, 'b', 'a', | |
| 2681 'r' | |
| 2682 }; | |
| 2683 const unsigned char kV4FrameData[] = { | 2367 const unsigned char kV4FrameData[] = { |
| 2684 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS | 2368 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS |
| 2685 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 2369 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 2686 0x40, 0x00, 0x03, 0x66, // @..f | 2370 0x40, 0x00, 0x03, 0x66, // @..f |
| 2687 0x6f, 0x6f, 0x40, 0x03, // oo@. | 2371 0x6f, 0x6f, 0x40, 0x03, // oo@. |
| 2688 0x66, 0x6f, 0x6f, 0x03, // foo. | 2372 0x66, 0x6f, 0x6f, 0x03, // foo. |
| 2689 0x62, 0x61, 0x72, // bar | 2373 0x62, 0x61, 0x72, // bar |
| 2690 }; | 2374 }; |
| 2691 SpdyHeadersIR headers_ir(0x7fffffff); | 2375 SpdyHeadersIR headers_ir(0x7fffffff); |
| 2692 headers_ir.set_fin(true); | 2376 headers_ir.set_fin(true); |
| 2693 headers_ir.SetHeader("", "foo"); | 2377 headers_ir.SetHeader("", "foo"); |
| 2694 headers_ir.SetHeader("foo", "bar"); | 2378 headers_ir.SetHeader("foo", "bar"); |
| 2695 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2379 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 2696 if (IsSpdy2()) { | 2380 if (IsSpdy2()) { |
| 2697 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2381 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2698 } else if (IsSpdy3()) { | 2382 } else if (IsSpdy3()) { |
| 2699 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2383 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2700 } else { | 2384 } else { |
| 2701 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2385 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2702 } | 2386 } |
| 2703 } | 2387 } |
| 2704 | 2388 |
| 2705 { | 2389 { |
| 2706 const char kDescription[] = | 2390 const char kDescription[] = |
| 2707 "HEADERS frame with a 0-length header val, FIN, max stream ID"; | 2391 "HEADERS frame with a 0-length header val, FIN, max stream ID"; |
| 2708 | 2392 |
| 2709 const unsigned char kV2FrameData[] = { | 2393 const unsigned char kV2FrameData[] = { |
| 2710 0x80, spdy_version_ch_, 0x00, 0x08, | 2394 0x80, spdy_version_ch_, 0x00, 0x08, 0x01, 0x00, 0x00, 0x19, 0x7f, |
| 2711 0x01, 0x00, 0x00, 0x19, | 2395 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, |
| 2712 0x7f, 0xff, 0xff, 0xff, | 2396 'b', 'a', 'r', 0x00, 0x03, 'f', 'o', 'o', 0x00, |
| 2713 0x00, 0x00, 0x00, 0x02, | 2397 0x03, 'f', 'o', 'o', 0x00, 0x00}; |
| 2714 0x00, 0x03, 'b', 'a', | |
| 2715 'r', 0x00, 0x03, 'f', | |
| 2716 'o', 'o', 0x00, 0x03, | |
| 2717 'f', 'o', 'o', 0x00, | |
| 2718 0x00 | |
| 2719 }; | |
| 2720 const unsigned char kV3FrameData[] = { | 2398 const unsigned char kV3FrameData[] = { |
| 2721 0x80, spdy_version_ch_, 0x00, 0x08, | 2399 0x80, spdy_version_ch_, 0x00, 0x08, 0x01, 0x00, 0x00, 0x21, 0x7f, |
| 2722 0x01, 0x00, 0x00, 0x21, | 2400 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, |
| 2723 0x7f, 0xff, 0xff, 0xff, | 2401 0x00, 0x03, 'b', 'a', 'r', 0x00, 0x00, 0x00, 0x03, |
| 2724 0x00, 0x00, 0x00, 0x02, | 2402 'f', 'o', 'o', 0x00, 0x00, 0x00, 0x03, 'f', 'o', |
| 2725 0x00, 0x00, 0x00, 0x03, | 2403 'o', 0x00, 0x00, 0x00, 0x00}; |
| 2726 'b', 'a', 'r', 0x00, | |
| 2727 0x00, 0x00, 0x03, 'f', | |
| 2728 'o', 'o', 0x00, 0x00, | |
| 2729 0x00, 0x03, 'f', 'o', | |
| 2730 'o', 0x00, 0x00, 0x00, | |
| 2731 0x00 | |
| 2732 }; | |
| 2733 const unsigned char kV4FrameData[] = { | 2404 const unsigned char kV4FrameData[] = { |
| 2734 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS | 2405 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS |
| 2735 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 2406 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 2736 0x40, 0x03, 0x62, 0x61, // @.ba | 2407 0x40, 0x03, 0x62, 0x61, // @.ba |
| 2737 0x72, 0x03, 0x66, 0x6f, // r.fo | 2408 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2738 0x6f, 0x40, 0x03, 0x66, // o@.f | 2409 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 2739 0x6f, 0x6f, 0x00, // oo. | 2410 0x6f, 0x6f, 0x00, // oo. |
| 2740 }; | 2411 }; |
| 2741 SpdyHeadersIR headers_ir(0x7fffffff); | 2412 SpdyHeadersIR headers_ir(0x7fffffff); |
| 2742 headers_ir.set_fin(true); | 2413 headers_ir.set_fin(true); |
| 2743 headers_ir.SetHeader("bar", "foo"); | 2414 headers_ir.SetHeader("bar", "foo"); |
| 2744 headers_ir.SetHeader("foo", ""); | 2415 headers_ir.SetHeader("foo", ""); |
| 2745 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2416 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 2746 if (IsSpdy2()) { | 2417 if (IsSpdy2()) { |
| 2747 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2418 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2748 } else if (IsSpdy3()) { | 2419 } else if (IsSpdy3()) { |
| 2749 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2420 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2750 } else { | 2421 } else { |
| 2751 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2422 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2752 } | 2423 } |
| 2753 } | 2424 } |
| 2754 } | 2425 } |
| 2755 | 2426 |
| 2756 // TODO(phajdan.jr): Clean up after we no longer need | 2427 // TODO(phajdan.jr): Clean up after we no longer need |
| 2757 // to workaround http://crbug.com/139744. | 2428 // to workaround http://crbug.com/139744. |
| 2758 #if !defined(USE_SYSTEM_ZLIB) | 2429 #if !defined(USE_SYSTEM_ZLIB) |
| 2759 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { | 2430 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
| 2760 SpdyFramer framer(spdy_version_); | 2431 SpdyFramer framer(spdy_version_); |
| 2761 framer.set_enable_compression(true); | 2432 framer.set_enable_compression(true); |
| 2762 | 2433 |
| 2763 { | 2434 { |
| 2764 const char kDescription[] = "HEADERS frame, no FIN"; | 2435 const char kDescription[] = "HEADERS frame, no FIN"; |
| 2765 | 2436 |
| 2766 const unsigned char kV2FrameData[] = { | 2437 const unsigned char kV2FrameData[] = { |
| 2767 0x80, spdy_version_ch_, 0x00, 0x08, | 2438 0x80, spdy_version_ch_, 0x00, 0x08, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, |
| 2768 0x00, 0x00, 0x00, 0x32, | 2439 0x00, 0x01, 0x00, 0x00, 0x38, 0xea, 0xdf, 0xa2, 0x51, 0xb2, |
| 2769 0x00, 0x00, 0x00, 0x01, | 2440 0x62, 0x60, 0x62, 0x60, 0x4e, 0x4a, 0x2c, 0x62, 0x60, 0x06, |
| 2770 0x00, 0x00, 0x38, 0xea, | 2441 0x08, 0xa0, 0xb4, 0xfc, 0x7c, 0x80, 0x00, 0x62, 0x60, 0x4e, |
| 2771 0xdf, 0xa2, 0x51, 0xb2, | 2442 0xcb, 0xcf, 0x67, 0x60, 0x06, 0x08, 0xa0, 0xa4, 0xc4, 0x22, |
| 2772 0x62, 0x60, 0x62, 0x60, | 2443 0x80, 0x00, 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 2773 0x4e, 0x4a, 0x2c, 0x62, | |
| 2774 0x60, 0x06, 0x08, 0xa0, | |
| 2775 0xb4, 0xfc, 0x7c, 0x80, | |
| 2776 0x00, 0x62, 0x60, 0x4e, | |
| 2777 0xcb, 0xcf, 0x67, 0x60, | |
| 2778 0x06, 0x08, 0xa0, 0xa4, | |
| 2779 0xc4, 0x22, 0x80, 0x00, | |
| 2780 0x02, 0x00, 0x00, 0x00, | |
| 2781 0xff, 0xff, | |
| 2782 }; | 2444 }; |
| 2783 const unsigned char kV3FrameData[] = { | 2445 const unsigned char kV3FrameData[] = { |
| 2784 0x80, spdy_version_ch_, 0x00, 0x08, | 2446 0x80, spdy_version_ch_, 0x00, 0x08, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, |
| 2785 0x00, 0x00, 0x00, 0x31, | 2447 0x00, 0x01, 0x38, 0xea, 0xe3, 0xc6, 0xa7, 0xc2, 0x02, 0xe5, |
| 2786 0x00, 0x00, 0x00, 0x01, | 2448 0x0e, 0x50, 0xc2, 0x4b, 0x4a, 0x04, 0xe5, 0x0b, 0x66, 0x80, |
| 2787 0x38, 0xea, 0xe3, 0xc6, | 2449 0x00, 0x4a, 0xcb, 0xcf, 0x07, 0x08, 0x20, 0x10, 0x95, 0x96, |
| 2788 0xa7, 0xc2, 0x02, 0xe5, | 2450 0x9f, 0x0f, 0xa2, 0x00, 0x02, 0x28, 0x29, 0xb1, 0x08, 0x20, |
| 2789 0x0e, 0x50, 0xc2, 0x4b, | 2451 0x80, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, |
| 2790 0x4a, 0x04, 0xe5, 0x0b, | |
| 2791 0x66, 0x80, 0x00, 0x4a, | |
| 2792 0xcb, 0xcf, 0x07, 0x08, | |
| 2793 0x20, 0x10, 0x95, 0x96, | |
| 2794 0x9f, 0x0f, 0xa2, 0x00, | |
| 2795 0x02, 0x28, 0x29, 0xb1, | |
| 2796 0x08, 0x20, 0x80, 0x00, | |
| 2797 0x00, 0x00, 0x00, 0xff, | |
| 2798 0xff, | |
| 2799 }; | 2452 }; |
| 2800 SpdyHeadersIR headers_ir(1); | 2453 SpdyHeadersIR headers_ir(1); |
| 2801 headers_ir.SetHeader("bar", "foo"); | 2454 headers_ir.SetHeader("bar", "foo"); |
| 2802 headers_ir.SetHeader("foo", "bar"); | 2455 headers_ir.SetHeader("foo", "bar"); |
| 2803 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2456 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 2804 if (IsSpdy2()) { | 2457 if (IsSpdy2()) { |
| 2805 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2458 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
| 2806 } else if (IsSpdy3()) { | 2459 } else if (IsSpdy3()) { |
| 2807 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2460 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2808 } else { | 2461 } else { |
| 2809 // Deflate compression doesn't apply to HPACK. | 2462 // Deflate compression doesn't apply to HPACK. |
| 2810 } | 2463 } |
| 2811 } | 2464 } |
| 2812 } | 2465 } |
| 2813 #endif // !defined(USE_SYSTEM_ZLIB) | 2466 #endif // !defined(USE_SYSTEM_ZLIB) |
| 2814 | 2467 |
| 2815 TEST_P(SpdyFramerTest, CreateWindowUpdate) { | 2468 TEST_P(SpdyFramerTest, CreateWindowUpdate) { |
| 2816 SpdyFramer framer(spdy_version_); | 2469 SpdyFramer framer(spdy_version_); |
| 2817 | 2470 |
| 2818 { | 2471 { |
| 2819 const char kDescription[] = "WINDOW_UPDATE frame"; | 2472 const char kDescription[] = "WINDOW_UPDATE frame"; |
| 2820 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2473 const unsigned char kV3FrameData[] = { |
| 2821 0x80, spdy_version_ch_, 0x00, 0x09, | 2474 // Also applies for V2. |
| 2822 0x00, 0x00, 0x00, 0x08, | 2475 0x80, spdy_version_ch_, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, |
| 2823 0x00, 0x00, 0x00, 0x01, | 2476 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 2824 0x00, 0x00, 0x00, 0x01, | |
| 2825 }; | 2477 }; |
| 2826 const unsigned char kV4FrameData[] = { | 2478 const unsigned char kV4FrameData[] = { |
| 2827 0x00, 0x04, 0x08, 0x00, | 2479 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, |
| 2828 0x00, 0x00, 0x00, 0x01, | |
| 2829 0x00, 0x00, 0x00, 0x01, | |
| 2830 }; | 2480 }; |
| 2831 scoped_ptr<SpdyFrame> frame( | 2481 scoped_ptr<SpdyFrame> frame( |
| 2832 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); | 2482 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); |
| 2833 if (IsSpdy4()) { | 2483 if (IsSpdy4()) { |
| 2834 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2484 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2835 } else { | 2485 } else { |
| 2836 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2486 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2837 } | 2487 } |
| 2838 } | 2488 } |
| 2839 | 2489 |
| 2840 { | 2490 { |
| 2841 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; | 2491 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; |
| 2842 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2492 const unsigned char kV3FrameData[] = { |
| 2843 0x80, spdy_version_ch_, 0x00, 0x09, | 2493 // Also applies for V2. |
| 2844 0x00, 0x00, 0x00, 0x08, | 2494 0x80, spdy_version_ch_, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08, 0x7f, 0xff, |
| 2845 0x7f, 0xff, 0xff, 0xff, | 2495 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, |
| 2846 0x00, 0x00, 0x00, 0x01, | |
| 2847 }; | 2496 }; |
| 2848 const unsigned char kV4FrameData[] = { | 2497 const unsigned char kV4FrameData[] = { |
| 2849 0x00, 0x04, 0x08, 0x00, | 2498 0x00, 0x04, 0x08, 0x00, 0x7f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, |
| 2850 0x7f, 0xff, 0xff, 0xff, | |
| 2851 0x00, 0x00, 0x00, 0x01, | |
| 2852 }; | 2499 }; |
| 2853 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 2500 scoped_ptr<SpdyFrame> frame( |
| 2854 SpdyWindowUpdateIR(0x7FFFFFFF, 1))); | 2501 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(0x7FFFFFFF, 1))); |
| 2855 if (IsSpdy4()) { | 2502 if (IsSpdy4()) { |
| 2856 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2503 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2857 } else { | 2504 } else { |
| 2858 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2505 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2859 } | 2506 } |
| 2860 } | 2507 } |
| 2861 | 2508 |
| 2862 { | 2509 { |
| 2863 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; | 2510 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; |
| 2864 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2511 const unsigned char kV3FrameData[] = { |
| 2865 0x80, spdy_version_ch_, 0x00, 0x09, | 2512 // Also applies for V2. |
| 2866 0x00, 0x00, 0x00, 0x08, | 2513 0x80, spdy_version_ch_, 0x00, 0x09, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, |
| 2867 0x00, 0x00, 0x00, 0x01, | 2514 0x00, 0x01, 0x7f, 0xff, 0xff, 0xff, |
| 2868 0x7f, 0xff, 0xff, 0xff, | |
| 2869 }; | 2515 }; |
| 2870 const unsigned char kV4FrameData[] = { | 2516 const unsigned char kV4FrameData[] = { |
| 2871 0x00, 0x04, 0x08, 0x00, | 2517 0x00, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x01, 0x7f, 0xff, 0xff, 0xff, |
| 2872 0x00, 0x00, 0x00, 0x01, | |
| 2873 0x7f, 0xff, 0xff, 0xff, | |
| 2874 }; | 2518 }; |
| 2875 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 2519 scoped_ptr<SpdyFrame> frame( |
| 2876 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2520 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
| 2877 if (IsSpdy4()) { | 2521 if (IsSpdy4()) { |
| 2878 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2522 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2879 } else { | 2523 } else { |
| 2880 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2524 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
| 2881 } | 2525 } |
| 2882 } | 2526 } |
| 2883 } | 2527 } |
| 2884 | 2528 |
| 2885 TEST_P(SpdyFramerTest, SerializeBlocked) { | 2529 TEST_P(SpdyFramerTest, SerializeBlocked) { |
| 2886 if (spdy_version_ < SPDY4) { | 2530 if (spdy_version_ < SPDY4) { |
| 2887 return; | 2531 return; |
| 2888 } | 2532 } |
| 2889 | 2533 |
| 2890 SpdyFramer framer(spdy_version_); | 2534 SpdyFramer framer(spdy_version_); |
| 2891 | 2535 |
| 2892 const char kDescription[] = "BLOCKED frame"; | 2536 const char kDescription[] = "BLOCKED frame"; |
| 2893 const unsigned char kFrameData[] = { | 2537 const unsigned char kFrameData[] = { |
| 2894 0x00, 0x00, 0x0a, 0x00, | 2538 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 2895 0x00, 0x00, 0x00, 0x00, | |
| 2896 }; | 2539 }; |
| 2897 SpdyBlockedIR blocked_ir(0); | 2540 SpdyBlockedIR blocked_ir(0); |
| 2898 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 2541 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 2899 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2542 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 2900 } | 2543 } |
| 2901 | 2544 |
| 2902 TEST_P(SpdyFramerTest, CreateBlocked) { | 2545 TEST_P(SpdyFramerTest, CreateBlocked) { |
| 2903 if (spdy_version_ < SPDY4) { | 2546 if (spdy_version_ < SPDY4) { |
| 2904 return; | 2547 return; |
| 2905 } | 2548 } |
| 2906 | 2549 |
| 2907 SpdyFramer framer(spdy_version_); | 2550 SpdyFramer framer(spdy_version_); |
| 2908 | 2551 |
| 2909 const char kDescription[] = "BLOCKED frame"; | 2552 const char kDescription[] = "BLOCKED frame"; |
| 2910 const SpdyStreamId kStreamId = 3; | 2553 const SpdyStreamId kStreamId = 3; |
| 2911 | 2554 |
| 2912 scoped_ptr<SpdySerializedFrame> frame_serialized( | 2555 scoped_ptr<SpdySerializedFrame> frame_serialized( |
| 2913 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2556 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
| 2914 SpdyBlockedIR blocked_ir(kStreamId); | 2557 SpdyBlockedIR blocked_ir(kStreamId); |
| 2915 scoped_ptr<SpdySerializedFrame> frame_created( | 2558 scoped_ptr<SpdySerializedFrame> frame_created( |
| 2916 framer.SerializeFrame(blocked_ir)); | 2559 framer.SerializeFrame(blocked_ir)); |
| 2917 | 2560 |
| 2918 CompareFrames(kDescription, *frame_serialized, *frame_created); | 2561 CompareFrames(kDescription, *frame_serialized, *frame_created); |
| 2919 } | 2562 } |
| 2920 | 2563 |
| 2921 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2564 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
| 2922 if (spdy_version_ < SPDY4) { | 2565 if (spdy_version_ < SPDY4) { |
| 2923 return; | 2566 return; |
| 2924 } | 2567 } |
| 2925 | 2568 |
| 2926 SpdyFramer framer(spdy_version_); | 2569 SpdyFramer framer(spdy_version_); |
| 2927 framer.set_enable_compression(false); | 2570 framer.set_enable_compression(false); |
| 2928 const char kDescription[] = "PUSH_PROMISE frame"; | 2571 const char kDescription[] = "PUSH_PROMISE frame"; |
| 2929 | 2572 |
| 2930 const unsigned char kFrameData[] = { | 2573 const unsigned char kFrameData[] = { |
| 2931 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS | 2574 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS |
| 2932 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 2575 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
| 2933 0x00, 0x00, 0x00, 0x39, // Promised stream 57 | 2576 0x00, 0x00, 0x00, 0x39, // Promised stream 57 |
| 2934 0x40, 0x03, 0x62, 0x61, // @.ba | 2577 0x40, 0x03, 0x62, 0x61, // @.ba |
| 2935 0x72, 0x03, 0x66, 0x6f, // r.fo | 2578 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2936 0x6f, 0x40, 0x03, 0x66, // o@.f | 2579 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 2937 0x6f, 0x6f, 0x03, 0x62, // oo.b | 2580 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 2938 0x61, 0x72, // ar | 2581 0x61, 0x72, // ar |
| 2939 }; | 2582 }; |
| 2940 | 2583 |
| 2941 SpdyPushPromiseIR push_promise(42, 57); | 2584 SpdyPushPromiseIR push_promise(42, 57); |
| 2942 push_promise.SetHeader("bar", "foo"); | 2585 push_promise.SetHeader("bar", "foo"); |
| 2943 push_promise.SetHeader("foo", "bar"); | 2586 push_promise.SetHeader("foo", "bar"); |
| 2944 scoped_ptr<SpdySerializedFrame> frame( | 2587 scoped_ptr<SpdySerializedFrame> frame( |
| 2945 framer.SerializePushPromise(push_promise)); | 2588 framer.SerializePushPromise(push_promise)); |
| 2946 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2589 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 2947 } | 2590 } |
| 2948 | 2591 |
| 2949 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { | 2592 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { |
| 2950 SpdyFramer framer(spdy_version_); | 2593 SpdyFramer framer(spdy_version_); |
| 2951 SpdySynStreamIR syn_stream(1); | 2594 SpdySynStreamIR syn_stream(1); |
| 2952 syn_stream.set_priority(1); | 2595 syn_stream.set_priority(1); |
| 2953 syn_stream.SetHeader("aa", "vv"); | 2596 syn_stream.SetHeader("aa", "vv"); |
| 2954 syn_stream.SetHeader("bb", "ww"); | 2597 syn_stream.SetHeader("bb", "ww"); |
| 2955 SpdyHeaderBlock headers = syn_stream.name_value_block(); | 2598 SpdyHeaderBlock headers = syn_stream.name_value_block(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3089 | 2732 |
| 3090 // Create a frame at exatly that size. | 2733 // Create a frame at exatly that size. |
| 3091 string big_value(kBigValueSize, 'x'); | 2734 string big_value(kBigValueSize, 'x'); |
| 3092 syn_stream.SetHeader("aa", big_value.c_str()); | 2735 syn_stream.SetHeader("aa", big_value.c_str()); |
| 3093 // Upstream branches here and wraps SPDY4 with EXPECT_DEBUG_DFATAL. We | 2736 // Upstream branches here and wraps SPDY4 with EXPECT_DEBUG_DFATAL. We |
| 3094 // neither support that in Chromium, nor do we use the same DFATAL (see | 2737 // neither support that in Chromium, nor do we use the same DFATAL (see |
| 3095 // SpdyFrameBuilder::WriteFramePrefix()). | 2738 // SpdyFrameBuilder::WriteFramePrefix()). |
| 3096 control_frame.reset(framer.SerializeSynStream(syn_stream)); | 2739 control_frame.reset(framer.SerializeSynStream(syn_stream)); |
| 3097 | 2740 |
| 3098 EXPECT_TRUE(control_frame.get() != NULL); | 2741 EXPECT_TRUE(control_frame.get() != NULL); |
| 3099 EXPECT_EQ(framer.GetControlFrameBufferMaxSize() + 1, | 2742 EXPECT_EQ(framer.GetControlFrameBufferMaxSize() + 1, control_frame->size()); |
| 3100 control_frame->size()); | |
| 3101 | 2743 |
| 3102 TestSpdyVisitor visitor(spdy_version_); | 2744 TestSpdyVisitor visitor(spdy_version_); |
| 3103 visitor.SimulateInFramer( | 2745 visitor.SimulateInFramer( |
| 3104 reinterpret_cast<unsigned char*>(control_frame->data()), | 2746 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3105 control_frame->size()); | 2747 control_frame->size()); |
| 3106 EXPECT_FALSE(visitor.header_buffer_valid_); | 2748 EXPECT_FALSE(visitor.header_buffer_valid_); |
| 3107 EXPECT_EQ(1, visitor.error_count_); | 2749 EXPECT_EQ(1, visitor.error_count_); |
| 3108 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, | 2750 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, |
| 3109 visitor.framer_.error_code()) | 2751 visitor.framer_.error_code()) |
| 3110 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2752 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3235 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()) | 2877 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()) |
| 3236 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2878 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3237 EXPECT_EQ(0u, visitor.header_buffer_length_); | 2879 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3238 } | 2880 } |
| 3239 | 2881 |
| 3240 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { | 2882 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { |
| 3241 SpdyFramer framer(spdy_version_); | 2883 SpdyFramer framer(spdy_version_); |
| 3242 // Create a GoAway frame that has a few extra bytes at the end. | 2884 // Create a GoAway frame that has a few extra bytes at the end. |
| 3243 // We create enough overhead to overflow the framer's control frame buffer. | 2885 // We create enough overhead to overflow the framer's control frame buffer. |
| 3244 ASSERT_GE(250u, SpdyFramer::kControlFrameBufferSize); | 2886 ASSERT_GE(250u, SpdyFramer::kControlFrameBufferSize); |
| 3245 const unsigned char length = 1 + SpdyFramer::kControlFrameBufferSize; | 2887 const unsigned char length = 1 + SpdyFramer::kControlFrameBufferSize; |
| 3246 const unsigned char kV3FrameData[] = { // Also applies for V2. | 2888 const unsigned char kV3FrameData[] = { |
| 3247 0x80, spdy_version_ch_, 0x00, 0x07, | 2889 // Also applies for V2. |
| 3248 0x00, 0x00, 0x00, length, | 2890 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, 0x00, length, 0x00, 0x00, |
| 3249 0x00, 0x00, 0x00, 0x00, // Stream ID | 2891 0x00, 0x00, // Stream ID |
| 3250 0x00, 0x00, 0x00, 0x00, // Status | 2892 0x00, 0x00, 0x00, 0x00, // Status |
| 3251 }; | 2893 }; |
| 3252 | 2894 |
| 3253 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length, | 2895 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length, |
| 3254 // since it may carry opaque data. Verify that minimal length is tested. | 2896 // since it may carry opaque data. Verify that minimal length is tested. |
| 3255 const unsigned char less_than_min_length = | 2897 const unsigned char less_than_min_length = |
| 3256 framer.GetGoAwayMinimumSize() - framer.GetControlFrameHeaderSize() - 1; | 2898 framer.GetGoAwayMinimumSize() - framer.GetControlFrameHeaderSize() - 1; |
| 3257 const unsigned char kV4FrameData[] = { | 2899 const unsigned char kV4FrameData[] = { |
| 3258 0x00, static_cast<uint8>(less_than_min_length), 0x07, 0x00, | 2900 0x00, static_cast<uint8>(less_than_min_length), 0x07, 0x00, |
| 3259 0x00, 0x00, 0x00, 0x00, | 2901 0x00, 0x00, 0x00, 0x00, |
| 3260 0x00, 0x00, 0x00, 0x00, // Stream Id | 2902 0x00, 0x00, 0x00, 0x00, // Stream Id |
| 3261 0x00, 0x00, 0x00, 0x00, // Status | 2903 0x00, 0x00, 0x00, 0x00, // Status |
| 3262 }; | 2904 }; |
| 3263 const size_t pad_length = | 2905 const size_t pad_length = |
| 3264 length + framer.GetControlFrameHeaderSize() - | 2906 length + framer.GetControlFrameHeaderSize() - |
| 3265 (IsSpdy4() ? sizeof(kV4FrameData) : sizeof(kV3FrameData)); | 2907 (IsSpdy4() ? sizeof(kV4FrameData) : sizeof(kV3FrameData)); |
| 3266 string pad('A', pad_length); | 2908 string pad('A', pad_length); |
| 3267 TestSpdyVisitor visitor(spdy_version_); | 2909 TestSpdyVisitor visitor(spdy_version_); |
| 3268 | 2910 |
| 3269 if (IsSpdy4()) { | 2911 if (IsSpdy4()) { |
| 3270 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 2912 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
| 3271 } else { | 2913 } else { |
| 3272 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 2914 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 3273 } | 2915 } |
| 3274 visitor.SimulateInFramer( | 2916 visitor.SimulateInFramer(reinterpret_cast<const unsigned char*>(pad.c_str()), |
| 3275 reinterpret_cast<const unsigned char*>(pad.c_str()), | 2917 pad.length()); |
| 3276 pad.length()); | |
| 3277 | 2918 |
| 3278 EXPECT_EQ(1, visitor.error_count_); // This generated an error. | 2919 EXPECT_EQ(1, visitor.error_count_); // This generated an error. |
| 3279 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 2920 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 3280 visitor.framer_.error_code()) | 2921 visitor.framer_.error_code()) |
| 3281 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 2922 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3282 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. | 2923 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. |
| 3283 } | 2924 } |
| 3284 | 2925 |
| 3285 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { | 2926 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { |
| 3286 SpdyFramer framer(spdy_version_); | 2927 SpdyFramer framer(spdy_version_); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3301 } | 2942 } |
| 3302 } | 2943 } |
| 3303 | 2944 |
| 3304 // Tests handling of SETTINGS frames with invalid length. | 2945 // Tests handling of SETTINGS frames with invalid length. |
| 3305 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { | 2946 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { |
| 3306 SpdyFramer framer(spdy_version_); | 2947 SpdyFramer framer(spdy_version_); |
| 3307 SpdySettingsIR settings_ir; | 2948 SpdySettingsIR settings_ir; |
| 3308 | 2949 |
| 3309 // Add a setting to pad the frame so that we don't get a buffer overflow when | 2950 // Add a setting to pad the frame so that we don't get a buffer overflow when |
| 3310 // calling SimulateInFramer() below. | 2951 // calling SimulateInFramer() below. |
| 3311 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, | 2952 settings_ir.AddSetting( |
| 3312 false, | 2953 SETTINGS_INITIAL_WINDOW_SIZE, false, false, 0x00000002); |
| 3313 false, | |
| 3314 0x00000002); | |
| 3315 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); | 2954 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); |
| 3316 const size_t kNewLength = 14; | 2955 const size_t kNewLength = 14; |
| 3317 SetFrameLength(control_frame.get(), kNewLength, spdy_version_); | 2956 SetFrameLength(control_frame.get(), kNewLength, spdy_version_); |
| 3318 TestSpdyVisitor visitor(spdy_version_); | 2957 TestSpdyVisitor visitor(spdy_version_); |
| 3319 visitor.use_compression_ = false; | 2958 visitor.use_compression_ = false; |
| 3320 visitor.SimulateInFramer( | 2959 visitor.SimulateInFramer( |
| 3321 reinterpret_cast<unsigned char*>(control_frame->data()), | 2960 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3322 framer.GetControlFrameHeaderSize() + kNewLength); | 2961 framer.GetControlFrameHeaderSize() + kNewLength); |
| 3323 // Should generate an error, since its not possible to have a | 2962 // Should generate an error, since its not possible to have a |
| 3324 // settings frame of length kNewLength. | 2963 // settings frame of length kNewLength. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3336 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), | 2975 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), |
| 3337 false, // persist | 2976 false, // persist |
| 3338 false, // persisted | 2977 false, // persisted |
| 3339 6); | 2978 6); |
| 3340 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), | 2979 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 3), |
| 3341 false, // persist | 2980 false, // persist |
| 3342 false, // persisted | 2981 false, // persisted |
| 3343 7); | 2982 7); |
| 3344 | 2983 |
| 3345 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); | 2984 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir)); |
| 3346 EXPECT_LT(SpdyFramer::kControlFrameBufferSize, | 2985 EXPECT_LT(SpdyFramer::kControlFrameBufferSize, control_frame->size()); |
| 3347 control_frame->size()); | |
| 3348 TestSpdyVisitor visitor(spdy_version_); | 2986 TestSpdyVisitor visitor(spdy_version_); |
| 3349 visitor.use_compression_ = false; | 2987 visitor.use_compression_ = false; |
| 3350 | 2988 |
| 3351 // Read all at once. | 2989 // Read all at once. |
| 3352 visitor.SimulateInFramer( | 2990 visitor.SimulateInFramer( |
| 3353 reinterpret_cast<unsigned char*>(control_frame->data()), | 2991 reinterpret_cast<unsigned char*>(control_frame->data()), |
| 3354 control_frame->size()); | 2992 control_frame->size()); |
| 3355 EXPECT_EQ(0, visitor.error_count_); | 2993 EXPECT_EQ(0, visitor.error_count_); |
| 3356 EXPECT_EQ(3, visitor.setting_count_); | 2994 EXPECT_EQ(3, visitor.setting_count_); |
| 3357 if (spdy_version_ > SPDY3) { | 2995 if (spdy_version_ > SPDY3) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3375 if (spdy_version_ > SPDY3) { | 3013 if (spdy_version_ > SPDY3) { |
| 3376 EXPECT_EQ(2, visitor.settings_ack_sent_); | 3014 EXPECT_EQ(2, visitor.settings_ack_sent_); |
| 3377 } | 3015 } |
| 3378 } | 3016 } |
| 3379 | 3017 |
| 3380 // Tests handling of SETTINGS frame with duplicate entries. | 3018 // Tests handling of SETTINGS frame with duplicate entries. |
| 3381 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { | 3019 TEST_P(SpdyFramerTest, ReadDuplicateSettings) { |
| 3382 SpdyFramer framer(spdy_version_); | 3020 SpdyFramer framer(spdy_version_); |
| 3383 | 3021 |
| 3384 const unsigned char kV2FrameData[] = { | 3022 const unsigned char kV2FrameData[] = { |
| 3385 0x80, spdy_version_ch_, 0x00, 0x04, | 3023 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 3386 0x00, 0x00, 0x00, 0x1C, | 3024 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, // 1st Setting |
| 3387 0x00, 0x00, 0x00, 0x03, | 3025 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, // 2nd |
| 3388 0x01, 0x00, 0x00, 0x00, // 1st Setting | 3026 // (duplicate
) |
| 3389 0x00, 0x00, 0x00, 0x02, | 3027 // Setting |
| 3390 0x01, 0x00, 0x00, 0x00, // 2nd (duplicate) Setting | 3028 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, // 3rd |
| 3391 0x00, 0x00, 0x00, 0x03, | 3029 // (unprocess
ed) |
| 3392 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting | 3030 // Setting |
| 3393 0x00, 0x00, 0x00, 0x03, | 3031 0x00, 0x00, 0x00, 0x03, |
| 3394 }; | 3032 }; |
| 3395 const unsigned char kV3FrameData[] = { | 3033 const unsigned char kV3FrameData[] = { |
| 3396 0x80, spdy_version_ch_, 0x00, 0x04, | 3034 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 3397 0x00, 0x00, 0x00, 0x1C, | 3035 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, // 1st Setting |
| 3398 0x00, 0x00, 0x00, 0x03, | 3036 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, // 2nd |
| 3399 0x00, 0x00, 0x00, 0x01, // 1st Setting | 3037 // (duplicate
) |
| 3400 0x00, 0x00, 0x00, 0x02, | 3038 // Setting |
| 3401 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting | 3039 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, // 3rd |
| 3402 0x00, 0x00, 0x00, 0x03, | 3040 // (unprocess
ed) |
| 3403 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting | 3041 // Setting |
| 3404 0x00, 0x00, 0x00, 0x03, | 3042 0x00, 0x00, 0x00, 0x03, |
| 3405 }; | 3043 }; |
| 3406 const unsigned char kV4FrameData[] = { | 3044 const unsigned char kV4FrameData[] = { |
| 3407 0x00, 0x0f, 0x04, 0x00, | 3045 0x00, 0x0f, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 3408 0x00, 0x00, 0x00, 0x00, | 3046 0x01, // 1st Setting |
| 3409 0x01, // 1st Setting | 3047 0x00, 0x00, 0x00, 0x02, |
| 3410 0x00, 0x00, 0x00, 0x02, | 3048 0x01, // 2nd (duplicate) Setting |
| 3411 0x01, // 2nd (duplicate) Setting | 3049 0x00, 0x00, 0x00, 0x03, |
| 3412 0x00, 0x00, 0x00, 0x03, | 3050 0x03, // 3rd (unprocessed) Setting |
| 3413 0x03, // 3rd (unprocessed) Setting | 3051 0x00, 0x00, 0x00, 0x03, |
| 3414 0x00, 0x00, 0x00, 0x03, | |
| 3415 }; | 3052 }; |
| 3416 | 3053 |
| 3417 TestSpdyVisitor visitor(spdy_version_); | 3054 TestSpdyVisitor visitor(spdy_version_); |
| 3418 visitor.use_compression_ = false; | 3055 visitor.use_compression_ = false; |
| 3419 if (IsSpdy2()) { | 3056 if (IsSpdy2()) { |
| 3420 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | 3057 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
| 3421 } else if (IsSpdy3()) { | 3058 } else if (IsSpdy3()) { |
| 3422 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3059 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 3423 } else { | 3060 } else { |
| 3424 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3061 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
| 3425 } | 3062 } |
| 3426 | 3063 |
| 3427 if (!IsSpdy4()) { | 3064 if (!IsSpdy4()) { |
| 3428 EXPECT_EQ(1, visitor.setting_count_); | 3065 EXPECT_EQ(1, visitor.setting_count_); |
| 3429 EXPECT_EQ(1, visitor.error_count_); | 3066 EXPECT_EQ(1, visitor.error_count_); |
| 3430 } else { | 3067 } else { |
| 3431 // In SPDY 4+, duplicate settings are allowed; | 3068 // In SPDY 4+, duplicate settings are allowed; |
| 3432 // each setting replaces the previous value for that setting. | 3069 // each setting replaces the previous value for that setting. |
| 3433 EXPECT_EQ(3, visitor.setting_count_); | 3070 EXPECT_EQ(3, visitor.setting_count_); |
| 3434 EXPECT_EQ(0, visitor.error_count_); | 3071 EXPECT_EQ(0, visitor.error_count_); |
| 3435 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3072 EXPECT_EQ(1, visitor.settings_ack_sent_); |
| 3436 } | 3073 } |
| 3437 } | 3074 } |
| 3438 | 3075 |
| 3439 // Tests handling of SETTINGS frame with entries out of order. | 3076 // Tests handling of SETTINGS frame with entries out of order. |
| 3440 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 3077 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
| 3441 SpdyFramer framer(spdy_version_); | 3078 SpdyFramer framer(spdy_version_); |
| 3442 | 3079 |
| 3443 const unsigned char kV2FrameData[] = { | 3080 const unsigned char kV2FrameData[] = { |
| 3444 0x80, spdy_version_ch_, 0x00, 0x04, | 3081 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 3445 0x00, 0x00, 0x00, 0x1C, | 3082 0x00, 0x00, 0x03, 0x02, 0x00, 0x00, 0x00, // 1st Setting |
| 3446 0x00, 0x00, 0x00, 0x03, | 3083 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, // 2nd (out |
| 3447 0x02, 0x00, 0x00, 0x00, // 1st Setting | 3084 // of order) |
| 3448 0x00, 0x00, 0x00, 0x02, | 3085 // Setting |
| 3449 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting | 3086 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, // 3rd |
| 3450 0x00, 0x00, 0x00, 0x03, | 3087 // (unprocess
ed) |
| 3451 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting | 3088 // Setting |
| 3452 0x00, 0x00, 0x00, 0x03, | 3089 0x00, 0x00, 0x00, 0x03, |
| 3453 }; | 3090 }; |
| 3454 const unsigned char kV3FrameData[] = { | 3091 const unsigned char kV3FrameData[] = { |
| 3455 0x80, spdy_version_ch_, 0x00, 0x04, | 3092 0x80, spdy_version_ch_, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1C, 0x00, |
| 3456 0x00, 0x00, 0x00, 0x1C, | 3093 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, // 1st Setting |
| 3457 0x00, 0x00, 0x00, 0x03, | 3094 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, // 2nd (out |
| 3458 0x00, 0x00, 0x00, 0x02, // 1st Setting | 3095 // of order) |
| 3459 0x00, 0x00, 0x00, 0x02, | 3096 // Setting |
| 3460 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting | 3097 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x03, // 3rd |
| 3461 0x00, 0x00, 0x00, 0x03, | 3098 // (unprocess
ed) |
| 3462 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting | 3099 // Setting |
| 3463 0x00, 0x00, 0x00, 0x03, | 3100 0x00, 0x00, 0x00, 0x03, |
| 3464 }; | 3101 }; |
| 3465 const unsigned char kV4FrameData[] = { | 3102 const unsigned char kV4FrameData[] = { |
| 3466 0x00, 0x0f, 0x04, 0x00, | 3103 0x00, 0x0f, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 3467 0x00, 0x00, 0x00, 0x00, | 3104 0x02, // 1st Setting |
| 3468 0x02, // 1st Setting | 3105 0x00, 0x00, 0x00, 0x02, |
| 3469 0x00, 0x00, 0x00, 0x02, | 3106 0x01, // 2nd (out of order) Setting |
| 3470 0x01, // 2nd (out of order) Setting | 3107 0x00, 0x00, 0x00, 0x03, |
| 3471 0x00, 0x00, 0x00, 0x03, | 3108 0x03, // 3rd (unprocessed) Setting |
| 3472 0x03, // 3rd (unprocessed) Setting | 3109 0x00, 0x00, 0x00, 0x03, |
| 3473 0x00, 0x00, 0x00, 0x03, | |
| 3474 }; | 3110 }; |
| 3475 | 3111 |
| 3476 TestSpdyVisitor visitor(spdy_version_); | 3112 TestSpdyVisitor visitor(spdy_version_); |
| 3477 visitor.use_compression_ = false; | 3113 visitor.use_compression_ = false; |
| 3478 if (IsSpdy2()) { | 3114 if (IsSpdy2()) { |
| 3479 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | 3115 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
| 3480 } else if (IsSpdy3()) { | 3116 } else if (IsSpdy3()) { |
| 3481 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3117 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
| 3482 } else { | 3118 } else { |
| 3483 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3119 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3494 } | 3130 } |
| 3495 } | 3131 } |
| 3496 | 3132 |
| 3497 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { | 3133 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { |
| 3498 if (spdy_version_ <= SPDY3) { | 3134 if (spdy_version_ <= SPDY3) { |
| 3499 return; | 3135 return; |
| 3500 } | 3136 } |
| 3501 SpdyFramer framer(spdy_version_); | 3137 SpdyFramer framer(spdy_version_); |
| 3502 | 3138 |
| 3503 const unsigned char kFrameData[] = { | 3139 const unsigned char kFrameData[] = { |
| 3504 0x00, 0x00, 0x04, 0x01, | 3140 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, |
| 3505 0x00, 0x00, 0x00, 0x00, | |
| 3506 }; | 3141 }; |
| 3507 | 3142 |
| 3508 TestSpdyVisitor visitor(spdy_version_); | 3143 TestSpdyVisitor visitor(spdy_version_); |
| 3509 visitor.use_compression_ = false; | 3144 visitor.use_compression_ = false; |
| 3510 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 3145 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 3511 | 3146 |
| 3512 EXPECT_EQ(0, visitor.error_count_); | 3147 EXPECT_EQ(0, visitor.error_count_); |
| 3513 EXPECT_EQ(0, visitor.setting_count_); | 3148 EXPECT_EQ(0, visitor.setting_count_); |
| 3514 EXPECT_EQ(1, visitor.settings_ack_received_); | 3149 EXPECT_EQ(1, visitor.settings_ack_received_); |
| 3515 } | 3150 } |
| 3516 | 3151 |
| 3517 | |
| 3518 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 3152 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
| 3519 if (spdy_version_ <= SPDY3) { | 3153 if (spdy_version_ <= SPDY3) { |
| 3520 return; | 3154 return; |
| 3521 } | 3155 } |
| 3522 | 3156 |
| 3523 const int kPaddingLen = 512; // So we get two bytes for padding length field. | 3157 const int kPaddingLen = 512; // So we get two bytes for padding length field. |
| 3524 const char data_payload[] = "hello"; | 3158 const char data_payload[] = "hello"; |
| 3525 | 3159 |
| 3526 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3160 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 3527 SpdyFramer framer(spdy_version_); | 3161 SpdyFramer framer(spdy_version_); |
| 3528 framer.set_visitor(&visitor); | 3162 framer.set_visitor(&visitor); |
| 3529 | 3163 |
| 3530 SpdyDataIR data_ir(1, StringPiece(data_payload, strlen(data_payload))); | 3164 SpdyDataIR data_ir(1, StringPiece(data_payload, strlen(data_payload))); |
| 3531 data_ir.set_padding_len(kPaddingLen); | 3165 data_ir.set_padding_len(kPaddingLen); |
| 3532 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 3166 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| 3533 ASSERT_TRUE(frame.get() != NULL); | 3167 ASSERT_TRUE(frame.get() != NULL); |
| 3534 | 3168 |
| 3535 int bytes_consumed = 0; | 3169 int bytes_consumed = 0; |
| 3536 | 3170 |
| 3537 // Send the frame header. | 3171 // Send the frame header. |
| 3538 EXPECT_CALL(visitor, OnDataFrameHeader(1, | 3172 EXPECT_CALL(visitor, |
| 3539 kPaddingLen + strlen(data_payload), | 3173 OnDataFrameHeader(1, kPaddingLen + strlen(data_payload), false)); |
| 3540 false)); | |
| 3541 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); | 3174 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); |
| 3542 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); | 3175 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); |
| 3543 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3176 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 3544 bytes_consumed += 8; | 3177 bytes_consumed += 8; |
| 3545 | 3178 |
| 3546 // Send the first byte of the padding length field. | 3179 // Send the first byte of the padding length field. |
| 3547 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); | 3180 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); |
| 3548 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); | 3181 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); |
| 3549 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3182 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
| 3550 bytes_consumed += 1; | 3183 bytes_consumed += 1; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3593 control_frame->size()); | 3226 control_frame->size()); |
| 3594 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3227 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 3595 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 3228 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
| 3596 } | 3229 } |
| 3597 | 3230 |
| 3598 TEST_P(SpdyFramerTest, ReceiveCredentialFrame) { | 3231 TEST_P(SpdyFramerTest, ReceiveCredentialFrame) { |
| 3599 if (!IsSpdy3()) { | 3232 if (!IsSpdy3()) { |
| 3600 return; | 3233 return; |
| 3601 } | 3234 } |
| 3602 SpdyFramer framer(spdy_version_); | 3235 SpdyFramer framer(spdy_version_); |
| 3603 const unsigned char kV3FrameData[] = { // Also applies for V2. | 3236 const unsigned char kV3FrameData[] = { |
| 3604 0x80, spdy_version_ch_, 0x00, 0x0A, | 3237 // Also applies for V2. |
| 3605 0x00, 0x00, 0x00, 0x33, | 3238 0x80, spdy_version_ch_, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x33, 0x00, 0x03, |
| 3606 0x00, 0x03, 0x00, 0x00, | 3239 0x00, 0x00, 0x00, 0x05, 'p', 'r', 'o', 'o', 'f', 0x00, 0x00, 0x00, 0x06, |
| 3607 0x00, 0x05, 'p', 'r', | 3240 'a', ' ', 'c', 'e', 'r', 't', 0x00, 0x00, 0x00, 0x0C, 'a', 'n', 'o', 't', |
| 3608 'o', 'o', 'f', 0x00, | 3241 'h', 'e', 'r', ' ', 'c', 'e', 'r', 't', 0x00, 0x00, 0x00, 0x0A, 'f', 'i', |
| 3609 0x00, 0x00, 0x06, 'a', | 3242 'n', 'a', 'l', ' ', 'c', 'e', 'r', 't', |
| 3610 ' ', 'c', 'e', 'r', | |
| 3611 't', 0x00, 0x00, 0x00, | |
| 3612 0x0C, 'a', 'n', 'o', | |
| 3613 't', 'h', 'e', 'r', | |
| 3614 ' ', 'c', 'e', 'r', | |
| 3615 't', 0x00, 0x00, 0x00, | |
| 3616 0x0A, 'f', 'i', 'n', | |
| 3617 'a', 'l', ' ', 'c', | |
| 3618 'e', 'r', 't', | |
| 3619 }; | 3243 }; |
| 3620 TestSpdyVisitor visitor(spdy_version_); | 3244 TestSpdyVisitor visitor(spdy_version_); |
| 3621 visitor.use_compression_ = false; | 3245 visitor.use_compression_ = false; |
| 3622 visitor.SimulateInFramer(kV3FrameData, arraysize(kV3FrameData)); | 3246 visitor.SimulateInFramer(kV3FrameData, arraysize(kV3FrameData)); |
| 3623 EXPECT_EQ(0, visitor.error_count_); | 3247 EXPECT_EQ(0, visitor.error_count_); |
| 3624 } | 3248 } |
| 3625 | 3249 |
| 3626 TEST_P(SpdyFramerTest, ReadCredentialFrameFollowedByAnotherFrame) { | 3250 TEST_P(SpdyFramerTest, ReadCredentialFrameFollowedByAnotherFrame) { |
| 3627 if (!IsSpdy3()) { | 3251 if (!IsSpdy3()) { |
| 3628 return; | 3252 return; |
| 3629 } | 3253 } |
| 3630 SpdyFramer framer(spdy_version_); | 3254 SpdyFramer framer(spdy_version_); |
| 3631 const unsigned char kV3FrameData[] = { // Also applies for V2. | 3255 const unsigned char kV3FrameData[] = { |
| 3632 0x80, spdy_version_ch_, 0x00, 0x0A, | 3256 // Also applies for V2. |
| 3633 0x00, 0x00, 0x00, 0x33, | 3257 0x80, spdy_version_ch_, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x33, 0x00, 0x03, |
| 3634 0x00, 0x03, 0x00, 0x00, | 3258 0x00, 0x00, 0x00, 0x05, 'p', 'r', 'o', 'o', 'f', 0x00, 0x00, 0x00, 0x06, |
| 3635 0x00, 0x05, 'p', 'r', | 3259 'a', ' ', 'c', 'e', 'r', 't', 0x00, 0x00, 0x00, 0x0C, 'a', 'n', 'o', 't', |
| 3636 'o', 'o', 'f', 0x00, | 3260 'h', 'e', 'r', ' ', 'c', 'e', 'r', 't', 0x00, 0x00, 0x00, 0x0A, 'f', 'i', |
| 3637 0x00, 0x00, 0x06, 'a', | 3261 'n', 'a', 'l', ' ', 'c', 'e', 'r', 't', |
| 3638 ' ', 'c', 'e', 'r', | |
| 3639 't', 0x00, 0x00, 0x00, | |
| 3640 0x0C, 'a', 'n', 'o', | |
| 3641 't', 'h', 'e', 'r', | |
| 3642 ' ', 'c', 'e', 'r', | |
| 3643 't', 0x00, 0x00, 0x00, | |
| 3644 0x0A, 'f', 'i', 'n', | |
| 3645 'a', 'l', ' ', 'c', | |
| 3646 'e', 'r', 't', | |
| 3647 }; | 3262 }; |
| 3648 TestSpdyVisitor visitor(spdy_version_); | 3263 TestSpdyVisitor visitor(spdy_version_); |
| 3649 visitor.use_compression_ = false; | 3264 visitor.use_compression_ = false; |
| 3650 string multiple_frame_data(reinterpret_cast<const char*>(kV3FrameData), | 3265 string multiple_frame_data(reinterpret_cast<const char*>(kV3FrameData), |
| 3651 arraysize(kV3FrameData)); | 3266 arraysize(kV3FrameData)); |
| 3652 scoped_ptr<SpdyFrame> control_frame( | 3267 scoped_ptr<SpdyFrame> control_frame( |
| 3653 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 3268 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
| 3654 multiple_frame_data.append(string(control_frame->data(), | 3269 multiple_frame_data.append( |
| 3655 control_frame->size())); | 3270 string(control_frame->data(), control_frame->size())); |
| 3656 visitor.SimulateInFramer( | 3271 visitor.SimulateInFramer( |
| 3657 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), | 3272 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), |
| 3658 multiple_frame_data.length()); | 3273 multiple_frame_data.length()); |
| 3659 EXPECT_EQ(0, visitor.error_count_); | 3274 EXPECT_EQ(0, visitor.error_count_); |
| 3660 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3275 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
| 3661 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 3276 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
| 3662 } | 3277 } |
| 3663 | 3278 |
| 3664 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { | 3279 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
| 3665 if (spdy_version_ < SPDY4) { | 3280 if (spdy_version_ < SPDY4) { |
| 3666 return; | 3281 return; |
| 3667 } | 3282 } |
| 3668 | 3283 |
| 3669 SpdyFramer framer(spdy_version_); | 3284 SpdyFramer framer(spdy_version_); |
| 3670 framer.set_enable_compression(false); | 3285 framer.set_enable_compression(false); |
| 3671 const char kDescription[] = "CONTINUATION frame"; | 3286 const char kDescription[] = "CONTINUATION frame"; |
| 3672 | 3287 |
| 3673 const unsigned char kFrameData[] = { | 3288 const unsigned char kFrameData[] = { |
| 3674 0x00, 0x12, 0x09, 0x00, // CONTINUATION | 3289 0x00, 0x12, 0x09, 0x00, // CONTINUATION |
| 3675 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 3290 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
| 3676 0x40, 0x03, 0x62, 0x61, // @.ba | 3291 0x40, 0x03, 0x62, 0x61, // @.ba |
| 3677 0x72, 0x03, 0x66, 0x6f, // r.fo | 3292 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 3678 0x6f, 0x40, 0x03, 0x66, // o@.f | 3293 0x6f, 0x40, 0x03, 0x66, // o@.f |
| 3679 0x6f, 0x6f, 0x03, 0x62, // oo.b | 3294 0x6f, 0x6f, 0x03, 0x62, // oo.b |
| 3680 0x61, 0x72, // ar | 3295 0x61, 0x72, // ar |
| 3681 }; | 3296 }; |
| 3682 | 3297 |
| 3683 SpdyContinuationIR continuation(42); | 3298 SpdyContinuationIR continuation(42); |
| 3684 continuation.SetHeader("bar", "foo"); | 3299 continuation.SetHeader("bar", "foo"); |
| 3685 continuation.SetHeader("foo", "bar"); | 3300 continuation.SetHeader("foo", "bar"); |
| 3686 scoped_ptr<SpdySerializedFrame> frame( | 3301 scoped_ptr<SpdySerializedFrame> frame( |
| 3687 framer.SerializeContinuation(continuation)); | 3302 framer.SerializeContinuation(continuation)); |
| 3688 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 3303 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 3689 } | 3304 } |
| 3690 | 3305 |
| 3691 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { | 3306 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { |
| 3692 if (spdy_version_ <= SPDY3) { | 3307 if (spdy_version_ <= SPDY3) { |
| 3693 return; | 3308 return; |
| 3694 } | 3309 } |
| 3695 | 3310 |
| 3696 SpdyFramer framer(spdy_version_); | 3311 SpdyFramer framer(spdy_version_); |
| 3697 SpdyPushPromiseIR push_promise(42, 57); | 3312 SpdyPushPromiseIR push_promise(42, 57); |
| 3698 push_promise.SetHeader("foo", "bar"); | 3313 push_promise.SetHeader("foo", "bar"); |
| 3699 push_promise.SetHeader("bar", "foofoo"); | 3314 push_promise.SetHeader("bar", "foofoo"); |
| 3700 SpdyHeaderBlock headers = push_promise.name_value_block(); | 3315 SpdyHeaderBlock headers = push_promise.name_value_block(); |
| 3701 scoped_ptr<SpdySerializedFrame> frame( | 3316 scoped_ptr<SpdySerializedFrame> frame( |
| 3702 framer.SerializePushPromise(push_promise)); | 3317 framer.SerializePushPromise(push_promise)); |
| 3703 EXPECT_TRUE(frame.get() != NULL); | 3318 EXPECT_TRUE(frame.get() != NULL); |
| 3704 TestSpdyVisitor visitor(spdy_version_); | 3319 TestSpdyVisitor visitor(spdy_version_); |
| 3705 visitor.use_compression_ = true; | 3320 visitor.use_compression_ = true; |
| 3706 visitor.SimulateInFramer( | 3321 visitor.SimulateInFramer(reinterpret_cast<unsigned char*>(frame->data()), |
| 3707 reinterpret_cast<unsigned char*>(frame->data()), | 3322 frame->size()); |
| 3708 frame->size()); | |
| 3709 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3323 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
| 3710 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3324 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
| 3711 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3325 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
| 3712 } | 3326 } |
| 3713 | 3327 |
| 3714 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3328 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
| 3715 if (spdy_version_ <= SPDY3) { | 3329 if (spdy_version_ <= SPDY3) { |
| 3716 return; | 3330 return; |
| 3717 } | 3331 } |
| 3718 | 3332 |
| 3719 const unsigned char kInput[] = { | 3333 const unsigned char kInput[] = { |
| 3720 0x00, 0x10, 0x01, 0x00, // HEADERS | 3334 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3721 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3335 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3722 0x40, 0x06, 0x43, 0x6f, | 3336 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x07, 0x66, 0x6f, |
| 3723 0x6f, 0x6b, 0x69, 0x65, | 3337 0x6f, 0x3d, 0x62, 0x61, 0x72, 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
| 3724 0x07, 0x66, 0x6f, 0x6f, | 3338 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3725 0x3d, 0x62, 0x61, 0x72, | 3339 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x08, 0x62, 0x61, |
| 3726 | 3340 0x7a, 0x3d, 0x62, 0x69, 0x6e, 0x67, 0x40, 0x06, 0x43, 0x00, 0x12, |
| 3727 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3341 0x09, 0x04, // CONTINUATION: END_HEADERS |
| 3728 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3342 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3729 0x40, 0x06, 0x43, 0x6f, | 3343 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x00, 0x40, 0x04, 0x6e, 0x61, 0x6d, |
| 3730 0x6f, 0x6b, 0x69, 0x65, | 3344 0x65, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, |
| 3731 0x08, 0x62, 0x61, 0x7a, | |
| 3732 0x3d, 0x62, 0x69, 0x6e, | |
| 3733 0x67, 0x40, 0x06, 0x43, | |
| 3734 | |
| 3735 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | |
| 3736 0x00, 0x00, 0x00, 0x01, // Stream 1 | |
| 3737 0x6f, 0x6f, 0x6b, 0x69, | |
| 3738 0x65, 0x00, 0x40, 0x04, | |
| 3739 0x6e, 0x61, 0x6d, 0x65, | |
| 3740 0x05, 0x76, 0x61, 0x6c, | |
| 3741 0x75, 0x65, | |
| 3742 }; | 3345 }; |
| 3743 | 3346 |
| 3744 SpdyFramer framer(spdy_version_); | 3347 SpdyFramer framer(spdy_version_); |
| 3745 TestSpdyVisitor visitor(spdy_version_); | 3348 TestSpdyVisitor visitor(spdy_version_); |
| 3746 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3349 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3747 | 3350 |
| 3748 EXPECT_EQ(0, visitor.error_count_); | 3351 EXPECT_EQ(0, visitor.error_count_); |
| 3749 EXPECT_EQ(1, visitor.headers_frame_count_); | 3352 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3750 EXPECT_EQ(2, visitor.continuation_count_); | 3353 EXPECT_EQ(2, visitor.continuation_count_); |
| 3751 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3354 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3752 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3355 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3753 | 3356 |
| 3754 EXPECT_THAT(visitor.headers_, ElementsAre( | 3357 EXPECT_THAT(visitor.headers_, |
| 3755 Pair("Cookie", "foo=bar; baz=bing; "), | 3358 ElementsAre(Pair("Cookie", "foo=bar; baz=bing; "), |
| 3756 Pair("name", "value"))); | 3359 Pair("name", "value"))); |
| 3757 } | 3360 } |
| 3758 | 3361 |
| 3759 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { | 3362 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { |
| 3760 if (spdy_version_ <= SPDY3) { | 3363 if (spdy_version_ <= SPDY3) { |
| 3761 return; | 3364 return; |
| 3762 } | 3365 } |
| 3763 | 3366 |
| 3764 const unsigned char kInput[] = { | 3367 const unsigned char kInput[] = { |
| 3765 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN | 3368 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN |
| 3766 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3369 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3767 0x40, 0x06, 0x43, 0x6f, | 3370 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x07, 0x66, 0x6f, |
| 3768 0x6f, 0x6b, 0x69, 0x65, | 3371 0x6f, 0x3d, 0x62, 0x61, 0x72, 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
| 3769 0x07, 0x66, 0x6f, 0x6f, | 3372 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3770 0x3d, 0x62, 0x61, 0x72, | 3373 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x08, 0x62, 0x61, |
| 3771 | 3374 0x7a, 0x3d, 0x62, 0x69, 0x6e, 0x67, 0x40, 0x06, 0x43, 0x00, 0x12, |
| 3772 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3375 0x09, 0x04, // CONTINUATION: END_HEADERS |
| 3773 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3376 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3774 0x40, 0x06, 0x43, 0x6f, | 3377 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x00, 0x40, 0x04, 0x6e, 0x61, 0x6d, |
| 3775 0x6f, 0x6b, 0x69, 0x65, | 3378 0x65, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, |
| 3776 0x08, 0x62, 0x61, 0x7a, | |
| 3777 0x3d, 0x62, 0x69, 0x6e, | |
| 3778 0x67, 0x40, 0x06, 0x43, | |
| 3779 | |
| 3780 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | |
| 3781 0x00, 0x00, 0x00, 0x01, // Stream 1 | |
| 3782 0x6f, 0x6f, 0x6b, 0x69, | |
| 3783 0x65, 0x00, 0x40, 0x04, | |
| 3784 0x6e, 0x61, 0x6d, 0x65, | |
| 3785 0x05, 0x76, 0x61, 0x6c, | |
| 3786 0x75, 0x65, | |
| 3787 }; | 3379 }; |
| 3788 | 3380 |
| 3789 SpdyFramer framer(spdy_version_); | 3381 SpdyFramer framer(spdy_version_); |
| 3790 TestSpdyVisitor visitor(spdy_version_); | 3382 TestSpdyVisitor visitor(spdy_version_); |
| 3791 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3383 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3792 | 3384 |
| 3793 EXPECT_EQ(0, visitor.error_count_); | 3385 EXPECT_EQ(0, visitor.error_count_); |
| 3794 EXPECT_EQ(1, visitor.headers_frame_count_); | 3386 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3795 EXPECT_EQ(2, visitor.continuation_count_); | 3387 EXPECT_EQ(2, visitor.continuation_count_); |
| 3796 EXPECT_EQ(1, visitor.fin_flag_count_); | 3388 EXPECT_EQ(1, visitor.fin_flag_count_); |
| 3797 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3389 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3798 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3390 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
| 3799 | 3391 |
| 3800 EXPECT_THAT(visitor.headers_, ElementsAre( | 3392 EXPECT_THAT(visitor.headers_, |
| 3801 Pair("Cookie", "foo=bar; baz=bing; "), | 3393 ElementsAre(Pair("Cookie", "foo=bar; baz=bing; "), |
| 3802 Pair("name", "value"))); | 3394 Pair("name", "value"))); |
| 3803 } | 3395 } |
| 3804 | 3396 |
| 3805 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3397 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
| 3806 if (spdy_version_ <= SPDY3) { | 3398 if (spdy_version_ <= SPDY3) { |
| 3807 return; | 3399 return; |
| 3808 } | 3400 } |
| 3809 | 3401 |
| 3810 const unsigned char kInput[] = { | 3402 const unsigned char kInput[] = { |
| 3811 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE | 3403 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE |
| 3812 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3404 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3813 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3405 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
| 3814 0x40, 0x06, 0x43, 0x6f, | 3406 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x07, 0x66, 0x6f, |
| 3815 0x6f, 0x6b, 0x69, 0x65, | 3407 0x6f, 0x3d, 0x62, 0x61, 0x72, 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
| 3816 0x07, 0x66, 0x6f, 0x6f, | 3408 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3817 0x3d, 0x62, 0x61, 0x72, | 3409 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x08, 0x62, 0x61, |
| 3818 | 3410 0x7a, 0x3d, 0x62, 0x69, 0x6e, 0x67, 0x40, 0x06, 0x43, 0x00, 0x12, |
| 3819 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3411 0x09, 0x04, // CONTINUATION: END_HEADERS |
| 3820 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3412 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3821 0x40, 0x06, 0x43, 0x6f, | 3413 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x00, 0x40, 0x04, 0x6e, 0x61, 0x6d, |
| 3822 0x6f, 0x6b, 0x69, 0x65, | 3414 0x65, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, |
| 3823 0x08, 0x62, 0x61, 0x7a, | |
| 3824 0x3d, 0x62, 0x69, 0x6e, | |
| 3825 0x67, 0x40, 0x06, 0x43, | |
| 3826 | |
| 3827 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | |
| 3828 0x00, 0x00, 0x00, 0x01, // Stream 1 | |
| 3829 0x6f, 0x6f, 0x6b, 0x69, | |
| 3830 0x65, 0x00, 0x40, 0x04, | |
| 3831 0x6e, 0x61, 0x6d, 0x65, | |
| 3832 0x05, 0x76, 0x61, 0x6c, | |
| 3833 0x75, 0x65, | |
| 3834 }; | 3415 }; |
| 3835 | 3416 |
| 3836 SpdyFramer framer(spdy_version_); | 3417 SpdyFramer framer(spdy_version_); |
| 3837 TestSpdyVisitor visitor(spdy_version_); | 3418 TestSpdyVisitor visitor(spdy_version_); |
| 3838 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3419 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3839 | 3420 |
| 3840 EXPECT_EQ(0, visitor.error_count_); | 3421 EXPECT_EQ(0, visitor.error_count_); |
| 3841 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3422 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
| 3842 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3423 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
| 3843 EXPECT_EQ(2, visitor.continuation_count_); | 3424 EXPECT_EQ(2, visitor.continuation_count_); |
| 3844 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3425 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 3845 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3426 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
| 3846 | 3427 |
| 3847 EXPECT_THAT(visitor.headers_, ElementsAre( | 3428 EXPECT_THAT(visitor.headers_, |
| 3848 Pair("Cookie", "foo=bar; baz=bing; "), | 3429 ElementsAre(Pair("Cookie", "foo=bar; baz=bing; "), |
| 3849 Pair("name", "value"))); | 3430 Pair("name", "value"))); |
| 3850 } | 3431 } |
| 3851 | 3432 |
| 3852 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { | 3433 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { |
| 3853 if (spdy_version_ <= SPDY3) { | 3434 if (spdy_version_ <= SPDY3) { |
| 3854 return; | 3435 return; |
| 3855 } | 3436 } |
| 3856 | 3437 |
| 3857 const unsigned char kInput[] = { | 3438 const unsigned char kInput[] = { |
| 3858 0x00, 0x10, 0x01, 0x00, // HEADERS | 3439 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3859 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3440 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3860 0x40, 0x06, 0x43, 0x6f, | 3441 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x07, 0x66, 0x6f, |
| 3861 0x6f, 0x6b, 0x69, 0x65, | 3442 0x6f, 0x3d, 0x62, 0x61, 0x72, 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
| 3862 0x07, 0x66, 0x6f, 0x6f, | 3443 0x00, 0x00, 0x00, 0x02, // Stream 2 |
| 3863 0x3d, 0x62, 0x61, 0x72, | 3444 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x08, 0x62, 0x61, |
| 3864 | 3445 0x7a, 0x3d, 0x62, 0x69, 0x6e, 0x67, 0x40, 0x06, 0x43, |
| 3865 0x00, 0x14, 0x09, 0x00, // CONTINUATION | |
| 3866 0x00, 0x00, 0x00, 0x02, // Stream 2 | |
| 3867 0x40, 0x06, 0x43, 0x6f, | |
| 3868 0x6f, 0x6b, 0x69, 0x65, | |
| 3869 0x08, 0x62, 0x61, 0x7a, | |
| 3870 0x3d, 0x62, 0x69, 0x6e, | |
| 3871 0x67, 0x40, 0x06, 0x43, | |
| 3872 }; | 3446 }; |
| 3873 | 3447 |
| 3874 SpdyFramer framer(spdy_version_); | 3448 SpdyFramer framer(spdy_version_); |
| 3875 TestSpdyVisitor visitor(spdy_version_); | 3449 TestSpdyVisitor visitor(spdy_version_); |
| 3876 framer.set_visitor(&visitor); | 3450 framer.set_visitor(&visitor); |
| 3877 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3451 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3878 | 3452 |
| 3879 EXPECT_EQ(1, visitor.error_count_); | 3453 EXPECT_EQ(1, visitor.error_count_); |
| 3880 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 3454 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 3881 visitor.framer_.error_code()) | 3455 visitor.framer_.error_code()) |
| 3882 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3456 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3883 EXPECT_EQ(1, visitor.headers_frame_count_); | 3457 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3884 EXPECT_EQ(0, visitor.continuation_count_); | 3458 EXPECT_EQ(0, visitor.continuation_count_); |
| 3885 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3459 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3886 } | 3460 } |
| 3887 | 3461 |
| 3888 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { | 3462 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { |
| 3889 if (spdy_version_ <= SPDY3) { | 3463 if (spdy_version_ <= SPDY3) { |
| 3890 return; | 3464 return; |
| 3891 } | 3465 } |
| 3892 | 3466 |
| 3893 const unsigned char kInput[] = { | 3467 const unsigned char kInput[] = { |
| 3894 0x00, 0x10, 0x09, 0x00, // CONTINUATION | 3468 0x00, 0x10, 0x09, 0x00, // CONTINUATION |
| 3895 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3469 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3896 0x40, 0x06, 0x43, 0x6f, | 3470 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, |
| 3897 0x6f, 0x6b, 0x69, 0x65, | 3471 0x07, 0x66, 0x6f, 0x6f, 0x3d, 0x62, 0x61, 0x72, |
| 3898 0x07, 0x66, 0x6f, 0x6f, | |
| 3899 0x3d, 0x62, 0x61, 0x72, | |
| 3900 }; | 3472 }; |
| 3901 | 3473 |
| 3902 SpdyFramer framer(spdy_version_); | 3474 SpdyFramer framer(spdy_version_); |
| 3903 TestSpdyVisitor visitor(spdy_version_); | 3475 TestSpdyVisitor visitor(spdy_version_); |
| 3904 framer.set_visitor(&visitor); | 3476 framer.set_visitor(&visitor); |
| 3905 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3477 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3906 | 3478 |
| 3907 EXPECT_EQ(1, visitor.error_count_); | 3479 EXPECT_EQ(1, visitor.error_count_); |
| 3908 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 3480 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3909 visitor.framer_.error_code()) | |
| 3910 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3481 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3911 EXPECT_EQ(0, visitor.continuation_count_); | 3482 EXPECT_EQ(0, visitor.continuation_count_); |
| 3912 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3483 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3913 } | 3484 } |
| 3914 | 3485 |
| 3915 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { | 3486 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { |
| 3916 if (spdy_version_ <= SPDY3) { | 3487 if (spdy_version_ <= SPDY3) { |
| 3917 return; | 3488 return; |
| 3918 } | 3489 } |
| 3919 | 3490 |
| 3920 const unsigned char kInput[] = { | 3491 const unsigned char kInput[] = { |
| 3921 0x00, 0x10, 0x01, 0x00, // HEADERS | 3492 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3922 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3493 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3923 0x40, 0x06, 0x43, 0x6f, | 3494 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x07, 0x66, 0x6f, |
| 3924 0x6f, 0x6b, 0x69, 0x65, | 3495 0x6f, 0x3d, 0x62, 0x61, 0x72, 0x00, 0x00, 0x00, 0x01, // DATA on Stream |
| 3925 0x07, 0x66, 0x6f, 0x6f, | 3496 // #1 |
| 3926 0x3d, 0x62, 0x61, 0x72, | 3497 0x00, 0x00, 0x00, 0x04, 0xde, 0xad, 0xbe, 0xef, |
| 3927 | |
| 3928 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 | |
| 3929 0x00, 0x00, 0x00, 0x04, | |
| 3930 0xde, 0xad, 0xbe, 0xef, | |
| 3931 }; | 3498 }; |
| 3932 | 3499 |
| 3933 SpdyFramer framer(spdy_version_); | 3500 SpdyFramer framer(spdy_version_); |
| 3934 TestSpdyVisitor visitor(spdy_version_); | 3501 TestSpdyVisitor visitor(spdy_version_); |
| 3935 framer.set_visitor(&visitor); | 3502 framer.set_visitor(&visitor); |
| 3936 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3503 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3937 | 3504 |
| 3938 EXPECT_EQ(1, visitor.error_count_); | 3505 EXPECT_EQ(1, visitor.error_count_); |
| 3939 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 3506 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3940 visitor.framer_.error_code()) | |
| 3941 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3507 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3942 EXPECT_EQ(1, visitor.headers_frame_count_); | 3508 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3943 EXPECT_EQ(0, visitor.continuation_count_); | 3509 EXPECT_EQ(0, visitor.continuation_count_); |
| 3944 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3510 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3945 EXPECT_EQ(0, visitor.data_frame_count_); | 3511 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3946 } | 3512 } |
| 3947 | 3513 |
| 3948 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { | 3514 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { |
| 3949 if (spdy_version_ <= SPDY3) { | 3515 if (spdy_version_ <= SPDY3) { |
| 3950 return; | 3516 return; |
| 3951 } | 3517 } |
| 3952 | 3518 |
| 3953 const unsigned char kInput[] = { | 3519 const unsigned char kInput[] = { |
| 3954 0x00, 0x10, 0x01, 0x00, // HEADERS | 3520 0x00, 0x10, 0x01, 0x00, // HEADERS |
| 3955 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3521 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3956 0x40, 0x06, 0x43, 0x6f, | 3522 0x40, 0x06, 0x43, 0x6f, 0x6f, 0x6b, 0x69, 0x65, 0x07, 0x66, |
| 3957 0x6f, 0x6b, 0x69, 0x65, | 3523 0x6f, 0x6f, 0x3d, 0x62, 0x61, 0x72, 0x00, 0x14, 0x08, 0x00, // HEADERS |
| 3958 0x07, 0x66, 0x6f, 0x6f, | 3524 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3959 0x3d, 0x62, 0x61, 0x72, | 3525 0x40, 0x06, 0x43, 0x6f, // (Note this is a valid continued encoding). |
| 3960 | 3526 0x6f, 0x6b, 0x69, 0x65, 0x08, 0x62, 0x61, 0x7a, 0x3d, 0x62, |
| 3961 0x00, 0x14, 0x08, 0x00, // HEADERS | 3527 0x69, 0x6e, 0x67, 0x40, 0x06, 0x43, |
| 3962 0x00, 0x00, 0x00, 0x01, // Stream 1 | |
| 3963 0x40, 0x06, 0x43, 0x6f, // (Note this is a valid continued encoding). | |
| 3964 0x6f, 0x6b, 0x69, 0x65, | |
| 3965 0x08, 0x62, 0x61, 0x7a, | |
| 3966 0x3d, 0x62, 0x69, 0x6e, | |
| 3967 0x67, 0x40, 0x06, 0x43, | |
| 3968 }; | 3528 }; |
| 3969 | 3529 |
| 3970 SpdyFramer framer(spdy_version_); | 3530 SpdyFramer framer(spdy_version_); |
| 3971 TestSpdyVisitor visitor(spdy_version_); | 3531 TestSpdyVisitor visitor(spdy_version_); |
| 3972 framer.set_visitor(&visitor); | 3532 framer.set_visitor(&visitor); |
| 3973 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3533 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 3974 | 3534 |
| 3975 EXPECT_EQ(1, visitor.error_count_); | 3535 EXPECT_EQ(1, visitor.error_count_); |
| 3976 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 3536 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, visitor.framer_.error_code()) |
| 3977 visitor.framer_.error_code()) | |
| 3978 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3537 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 3979 EXPECT_EQ(1, visitor.headers_frame_count_); | 3538 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 3980 EXPECT_EQ(0, visitor.continuation_count_); | 3539 EXPECT_EQ(0, visitor.continuation_count_); |
| 3981 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3540 EXPECT_EQ(0u, visitor.header_buffer_length_); |
| 3982 EXPECT_EQ(0, visitor.data_frame_count_); | 3541 EXPECT_EQ(0, visitor.data_frame_count_); |
| 3983 } | 3542 } |
| 3984 | 3543 |
| 3985 TEST_P(SpdyFramerTest, ReadGarbage) { | 3544 TEST_P(SpdyFramerTest, ReadGarbage) { |
| 3986 SpdyFramer framer(spdy_version_); | 3545 SpdyFramer framer(spdy_version_); |
| 3987 unsigned char garbage_frame[256]; | 3546 unsigned char garbage_frame[256]; |
| 3988 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 3547 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
| 3989 TestSpdyVisitor visitor(spdy_version_); | 3548 TestSpdyVisitor visitor(spdy_version_); |
| 3990 visitor.use_compression_ = false; | 3549 visitor.use_compression_ = false; |
| 3991 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 3550 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
| 3992 EXPECT_EQ(1, visitor.error_count_); | 3551 EXPECT_EQ(1, visitor.error_count_); |
| 3993 } | 3552 } |
| 3994 | 3553 |
| 3995 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { | 3554 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { |
| 3996 if (!IsSpdy4()) { | 3555 if (!IsSpdy4()) { |
| 3997 return; | 3556 return; |
| 3998 } | 3557 } |
| 3999 SpdyFramer framer(spdy_version_); | 3558 SpdyFramer framer(spdy_version_); |
| 4000 const unsigned char kFrameData[] = { | 3559 const unsigned char kFrameData[] = { |
| 4001 0x00, 0x10, 0xff, 0xff, | 3560 0x00, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 4002 0xff, 0xff, 0xff, 0xff, | 3561 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 4003 0xff, 0xff, 0xff, 0xff, | |
| 4004 0xff, 0xff, 0xff, 0xff, | |
| 4005 }; | 3562 }; |
| 4006 TestSpdyVisitor visitor(spdy_version_); | 3563 TestSpdyVisitor visitor(spdy_version_); |
| 4007 visitor.use_compression_ = false; | 3564 visitor.use_compression_ = false; |
| 4008 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 3565 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
| 4009 EXPECT_EQ(1, visitor.error_count_); | 3566 EXPECT_EQ(1, visitor.error_count_); |
| 4010 } | 3567 } |
| 4011 | 3568 |
| 4012 TEST_P(SpdyFramerTest, ReadGarbageWithValidVersion) { | 3569 TEST_P(SpdyFramerTest, ReadGarbageWithValidVersion) { |
| 4013 if (IsSpdy4()) { | 3570 if (IsSpdy4()) { |
| 4014 // Not valid for SPDY 4 since there is no version field. | 3571 // Not valid for SPDY 4 since there is no version field. |
| 4015 return; | 3572 return; |
| 4016 } | 3573 } |
| 4017 SpdyFramer framer(spdy_version_); | 3574 SpdyFramer framer(spdy_version_); |
| 4018 const unsigned char kFrameData[] = { | 3575 const unsigned char kFrameData[] = { |
| 4019 0x80, spdy_version_ch_, 0xff, 0xff, | 3576 0x80, spdy_version_ch_, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 4020 0xff, 0xff, 0xff, 0xff, | |
| 4021 }; | 3577 }; |
| 4022 TestSpdyVisitor visitor(spdy_version_); | 3578 TestSpdyVisitor visitor(spdy_version_); |
| 4023 visitor.use_compression_ = false; | 3579 visitor.use_compression_ = false; |
| 4024 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 3580 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
| 4025 EXPECT_EQ(1, visitor.error_count_); | 3581 EXPECT_EQ(1, visitor.error_count_); |
| 4026 } | 3582 } |
| 4027 | 3583 |
| 4028 TEST_P(SpdyFramerTest, SizesTest) { | 3584 TEST_P(SpdyFramerTest, SizesTest) { |
| 4029 SpdyFramer framer(spdy_version_); | 3585 SpdyFramer framer(spdy_version_); |
| 4030 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); | 3586 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4051 EXPECT_EQ(IsSpdy2() ? 12u : 16u, framer.GetGoAwayMinimumSize()); | 3607 EXPECT_EQ(IsSpdy2() ? 12u : 16u, framer.GetGoAwayMinimumSize()); |
| 4052 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetHeadersMinimumSize()); | 3608 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetHeadersMinimumSize()); |
| 4053 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); | 3609 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); |
| 4054 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); | 3610 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); |
| 4055 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize()); | 3611 EXPECT_EQ(16777223u, framer.GetFrameMaximumSize()); |
| 4056 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload()); | 3612 EXPECT_EQ(16777215u, framer.GetDataFrameMaximumPayload()); |
| 4057 } | 3613 } |
| 4058 } | 3614 } |
| 4059 | 3615 |
| 4060 TEST_P(SpdyFramerTest, StateToStringTest) { | 3616 TEST_P(SpdyFramerTest, StateToStringTest) { |
| 4061 EXPECT_STREQ("ERROR", | 3617 EXPECT_STREQ("ERROR", SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); |
| 4062 SpdyFramer::StateToString(SpdyFramer::SPDY_ERROR)); | |
| 4063 EXPECT_STREQ("AUTO_RESET", | 3618 EXPECT_STREQ("AUTO_RESET", |
| 4064 SpdyFramer::StateToString(SpdyFramer::SPDY_AUTO_RESET)); | 3619 SpdyFramer::StateToString(SpdyFramer::SPDY_AUTO_RESET)); |
| 4065 EXPECT_STREQ("RESET", | 3620 EXPECT_STREQ("RESET", SpdyFramer::StateToString(SpdyFramer::SPDY_RESET)); |
| 4066 SpdyFramer::StateToString(SpdyFramer::SPDY_RESET)); | 3621 EXPECT_STREQ( |
| 4067 EXPECT_STREQ("READING_COMMON_HEADER", | 3622 "READING_COMMON_HEADER", |
| 4068 SpdyFramer::StateToString( | 3623 SpdyFramer::StateToString(SpdyFramer::SPDY_READING_COMMON_HEADER)); |
| 4069 SpdyFramer::SPDY_READING_COMMON_HEADER)); | 3624 EXPECT_STREQ( |
| 4070 EXPECT_STREQ("CONTROL_FRAME_PAYLOAD", | 3625 "CONTROL_FRAME_PAYLOAD", |
| 4071 SpdyFramer::StateToString( | 3626 SpdyFramer::StateToString(SpdyFramer::SPDY_CONTROL_FRAME_PAYLOAD)); |
| 4072 SpdyFramer::SPDY_CONTROL_FRAME_PAYLOAD)); | 3627 EXPECT_STREQ( |
| 4073 EXPECT_STREQ("IGNORE_REMAINING_PAYLOAD", | 3628 "IGNORE_REMAINING_PAYLOAD", |
| 4074 SpdyFramer::StateToString( | 3629 SpdyFramer::StateToString(SpdyFramer::SPDY_IGNORE_REMAINING_PAYLOAD)); |
| 4075 SpdyFramer::SPDY_IGNORE_REMAINING_PAYLOAD)); | 3630 EXPECT_STREQ( |
| 4076 EXPECT_STREQ("FORWARD_STREAM_FRAME", | 3631 "FORWARD_STREAM_FRAME", |
| 4077 SpdyFramer::StateToString( | 3632 SpdyFramer::StateToString(SpdyFramer::SPDY_FORWARD_STREAM_FRAME)); |
| 4078 SpdyFramer::SPDY_FORWARD_STREAM_FRAME)); | |
| 4079 EXPECT_STREQ("SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK", | 3633 EXPECT_STREQ("SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK", |
| 4080 SpdyFramer::StateToString( | 3634 SpdyFramer::StateToString( |
| 4081 SpdyFramer::SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK)); | 3635 SpdyFramer::SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK)); |
| 4082 EXPECT_STREQ("SPDY_CONTROL_FRAME_HEADER_BLOCK", | 3636 EXPECT_STREQ( |
| 4083 SpdyFramer::StateToString( | 3637 "SPDY_CONTROL_FRAME_HEADER_BLOCK", |
| 4084 SpdyFramer::SPDY_CONTROL_FRAME_HEADER_BLOCK)); | 3638 SpdyFramer::StateToString(SpdyFramer::SPDY_CONTROL_FRAME_HEADER_BLOCK)); |
| 4085 EXPECT_STREQ("SPDY_SETTINGS_FRAME_PAYLOAD", | 3639 EXPECT_STREQ( |
| 4086 SpdyFramer::StateToString( | 3640 "SPDY_SETTINGS_FRAME_PAYLOAD", |
| 4087 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); | 3641 SpdyFramer::StateToString(SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); |
| 4088 EXPECT_STREQ("UNKNOWN_STATE", | 3642 EXPECT_STREQ( |
| 4089 SpdyFramer::StateToString( | 3643 "UNKNOWN_STATE", |
| 4090 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD + 1)); | 3644 SpdyFramer::StateToString(SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD + 1)); |
| 4091 } | 3645 } |
| 4092 | 3646 |
| 4093 TEST_P(SpdyFramerTest, ErrorCodeToStringTest) { | 3647 TEST_P(SpdyFramerTest, ErrorCodeToStringTest) { |
| 4094 EXPECT_STREQ("NO_ERROR", | 3648 EXPECT_STREQ("NO_ERROR", |
| 4095 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); | 3649 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); |
| 4096 EXPECT_STREQ("INVALID_CONTROL_FRAME", | 3650 EXPECT_STREQ( |
| 4097 SpdyFramer::ErrorCodeToString( | 3651 "INVALID_CONTROL_FRAME", |
| 4098 SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); | 3652 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); |
| 4099 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", | 3653 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", |
| 4100 SpdyFramer::ErrorCodeToString( | 3654 SpdyFramer::ErrorCodeToString( |
| 4101 SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE)); | 3655 SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE)); |
| 4102 EXPECT_STREQ("ZLIB_INIT_FAILURE", | 3656 EXPECT_STREQ( |
| 4103 SpdyFramer::ErrorCodeToString( | 3657 "ZLIB_INIT_FAILURE", |
| 4104 SpdyFramer::SPDY_ZLIB_INIT_FAILURE)); | 3658 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_ZLIB_INIT_FAILURE)); |
| 4105 EXPECT_STREQ("UNSUPPORTED_VERSION", | 3659 EXPECT_STREQ( |
| 4106 SpdyFramer::ErrorCodeToString( | 3660 "UNSUPPORTED_VERSION", |
| 4107 SpdyFramer::SPDY_UNSUPPORTED_VERSION)); | 3661 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_UNSUPPORTED_VERSION)); |
| 4108 EXPECT_STREQ("DECOMPRESS_FAILURE", | 3662 EXPECT_STREQ( |
| 4109 SpdyFramer::ErrorCodeToString( | 3663 "DECOMPRESS_FAILURE", |
| 4110 SpdyFramer::SPDY_DECOMPRESS_FAILURE)); | 3664 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_DECOMPRESS_FAILURE)); |
| 4111 EXPECT_STREQ("COMPRESS_FAILURE", | 3665 EXPECT_STREQ( |
| 4112 SpdyFramer::ErrorCodeToString( | 3666 "COMPRESS_FAILURE", |
| 4113 SpdyFramer::SPDY_COMPRESS_FAILURE)); | 3667 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_COMPRESS_FAILURE)); |
| 4114 EXPECT_STREQ("SPDY_INVALID_DATA_FRAME_FLAGS", | 3668 EXPECT_STREQ( |
| 4115 SpdyFramer::ErrorCodeToString( | 3669 "SPDY_INVALID_DATA_FRAME_FLAGS", |
| 4116 SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS)); | 3670 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS)); |
| 4117 EXPECT_STREQ("SPDY_INVALID_CONTROL_FRAME_FLAGS", | 3671 EXPECT_STREQ("SPDY_INVALID_CONTROL_FRAME_FLAGS", |
| 4118 SpdyFramer::ErrorCodeToString( | 3672 SpdyFramer::ErrorCodeToString( |
| 4119 SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS)); | 3673 SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS)); |
| 4120 EXPECT_STREQ("UNKNOWN_ERROR", | 3674 EXPECT_STREQ("UNKNOWN_ERROR", |
| 4121 SpdyFramer::ErrorCodeToString(SpdyFramer::LAST_ERROR)); | 3675 SpdyFramer::ErrorCodeToString(SpdyFramer::LAST_ERROR)); |
| 4122 } | 3676 } |
| 4123 | 3677 |
| 4124 TEST_P(SpdyFramerTest, StatusCodeToStringTest) { | 3678 TEST_P(SpdyFramerTest, StatusCodeToStringTest) { |
| 4125 EXPECT_STREQ("INVALID", | 3679 EXPECT_STREQ("INVALID", SpdyFramer::StatusCodeToString(RST_STREAM_INVALID)); |
| 4126 SpdyFramer::StatusCodeToString(RST_STREAM_INVALID)); | |
| 4127 EXPECT_STREQ("PROTOCOL_ERROR", | 3680 EXPECT_STREQ("PROTOCOL_ERROR", |
| 4128 SpdyFramer::StatusCodeToString(RST_STREAM_PROTOCOL_ERROR)); | 3681 SpdyFramer::StatusCodeToString(RST_STREAM_PROTOCOL_ERROR)); |
| 4129 EXPECT_STREQ("INVALID_STREAM", | 3682 EXPECT_STREQ("INVALID_STREAM", |
| 4130 SpdyFramer::StatusCodeToString(RST_STREAM_INVALID_STREAM)); | 3683 SpdyFramer::StatusCodeToString(RST_STREAM_INVALID_STREAM)); |
| 4131 EXPECT_STREQ("REFUSED_STREAM", | 3684 EXPECT_STREQ("REFUSED_STREAM", |
| 4132 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); | 3685 SpdyFramer::StatusCodeToString(RST_STREAM_REFUSED_STREAM)); |
| 4133 EXPECT_STREQ("UNSUPPORTED_VERSION", | 3686 EXPECT_STREQ("UNSUPPORTED_VERSION", |
| 4134 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); | 3687 SpdyFramer::StatusCodeToString(RST_STREAM_UNSUPPORTED_VERSION)); |
| 4135 EXPECT_STREQ("CANCEL", | 3688 EXPECT_STREQ("CANCEL", SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); |
| 4136 SpdyFramer::StatusCodeToString(RST_STREAM_CANCEL)); | |
| 4137 EXPECT_STREQ("INTERNAL_ERROR", | 3689 EXPECT_STREQ("INTERNAL_ERROR", |
| 4138 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); | 3690 SpdyFramer::StatusCodeToString(RST_STREAM_INTERNAL_ERROR)); |
| 4139 EXPECT_STREQ("FLOW_CONTROL_ERROR", | 3691 EXPECT_STREQ("FLOW_CONTROL_ERROR", |
| 4140 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); | 3692 SpdyFramer::StatusCodeToString(RST_STREAM_FLOW_CONTROL_ERROR)); |
| 4141 EXPECT_STREQ("UNKNOWN_STATUS", | 3693 EXPECT_STREQ("UNKNOWN_STATUS", SpdyFramer::StatusCodeToString(-1)); |
| 4142 SpdyFramer::StatusCodeToString(-1)); | |
| 4143 } | 3694 } |
| 4144 | 3695 |
| 4145 TEST_P(SpdyFramerTest, FrameTypeToStringTest) { | 3696 TEST_P(SpdyFramerTest, FrameTypeToStringTest) { |
| 4146 EXPECT_STREQ("DATA", | 3697 EXPECT_STREQ("DATA", SpdyFramer::FrameTypeToString(DATA)); |
| 4147 SpdyFramer::FrameTypeToString(DATA)); | 3698 EXPECT_STREQ("SYN_STREAM", SpdyFramer::FrameTypeToString(SYN_STREAM)); |
| 4148 EXPECT_STREQ("SYN_STREAM", | 3699 EXPECT_STREQ("SYN_REPLY", SpdyFramer::FrameTypeToString(SYN_REPLY)); |
| 4149 SpdyFramer::FrameTypeToString(SYN_STREAM)); | 3700 EXPECT_STREQ("RST_STREAM", SpdyFramer::FrameTypeToString(RST_STREAM)); |
| 4150 EXPECT_STREQ("SYN_REPLY", | 3701 EXPECT_STREQ("SETTINGS", SpdyFramer::FrameTypeToString(SETTINGS)); |
| 4151 SpdyFramer::FrameTypeToString(SYN_REPLY)); | 3702 EXPECT_STREQ("NOOP", SpdyFramer::FrameTypeToString(NOOP)); |
| 4152 EXPECT_STREQ("RST_STREAM", | 3703 EXPECT_STREQ("PING", SpdyFramer::FrameTypeToString(PING)); |
| 4153 SpdyFramer::FrameTypeToString(RST_STREAM)); | 3704 EXPECT_STREQ("GOAWAY", SpdyFramer::FrameTypeToString(GOAWAY)); |
| 4154 EXPECT_STREQ("SETTINGS", | 3705 EXPECT_STREQ("HEADERS", SpdyFramer::FrameTypeToString(HEADERS)); |
| 4155 SpdyFramer::FrameTypeToString(SETTINGS)); | 3706 EXPECT_STREQ("WINDOW_UPDATE", SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); |
| 4156 EXPECT_STREQ("NOOP", | 3707 EXPECT_STREQ("PUSH_PROMISE", SpdyFramer::FrameTypeToString(PUSH_PROMISE)); |
| 4157 SpdyFramer::FrameTypeToString(NOOP)); | 3708 EXPECT_STREQ("CREDENTIAL", SpdyFramer::FrameTypeToString(CREDENTIAL)); |
| 4158 EXPECT_STREQ("PING", | 3709 EXPECT_STREQ("CONTINUATION", SpdyFramer::FrameTypeToString(CONTINUATION)); |
| 4159 SpdyFramer::FrameTypeToString(PING)); | |
| 4160 EXPECT_STREQ("GOAWAY", | |
| 4161 SpdyFramer::FrameTypeToString(GOAWAY)); | |
| 4162 EXPECT_STREQ("HEADERS", | |
| 4163 SpdyFramer::FrameTypeToString(HEADERS)); | |
| 4164 EXPECT_STREQ("WINDOW_UPDATE", | |
| 4165 SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); | |
| 4166 EXPECT_STREQ("PUSH_PROMISE", | |
| 4167 SpdyFramer::FrameTypeToString(PUSH_PROMISE)); | |
| 4168 EXPECT_STREQ("CREDENTIAL", | |
| 4169 SpdyFramer::FrameTypeToString(CREDENTIAL)); | |
| 4170 EXPECT_STREQ("CONTINUATION", | |
| 4171 SpdyFramer::FrameTypeToString(CONTINUATION)); | |
| 4172 } | 3710 } |
| 4173 | 3711 |
| 4174 TEST_P(SpdyFramerTest, CatchProbableHttpResponse) { | 3712 TEST_P(SpdyFramerTest, CatchProbableHttpResponse) { |
| 4175 if (IsSpdy4()) { | 3713 if (IsSpdy4()) { |
| 4176 // TODO(hkhalil): catch probable HTTP response in SPDY 4? | 3714 // TODO(hkhalil): catch probable HTTP response in SPDY 4? |
| 4177 return; | 3715 return; |
| 4178 } | 3716 } |
| 4179 { | 3717 { |
| 4180 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3718 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4181 SpdyFramer framer(spdy_version_); | 3719 SpdyFramer framer(spdy_version_); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4224 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 3762 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
| 4225 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); | 3763 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); |
| 4226 if (flags & DATA_FLAG_FIN) { | 3764 if (flags & DATA_FLAG_FIN) { |
| 4227 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 3765 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
| 4228 } | 3766 } |
| 4229 } | 3767 } |
| 4230 | 3768 |
| 4231 framer.ProcessInput(frame->data(), frame->size()); | 3769 framer.ProcessInput(frame->data(), frame->size()); |
| 4232 if (flags & ~DATA_FLAG_FIN) { | 3770 if (flags & ~DATA_FLAG_FIN) { |
| 4233 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 3771 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4234 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 3772 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) |
| 4235 framer.error_code()) | |
| 4236 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3773 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4237 } else { | 3774 } else { |
| 4238 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 3775 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4239 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3776 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4240 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3777 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4241 } | 3778 } |
| 4242 } | 3779 } |
| 4243 } | 3780 } |
| 4244 | 3781 |
| 4245 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 3782 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
| 4246 if (spdy_version_ <= SPDY3) { | 3783 if (spdy_version_ <= SPDY3) { |
| 4247 return; | 3784 return; |
| 4248 } | 3785 } |
| 4249 | 3786 |
| 4250 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | | 3787 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | |
| 4251 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; | 3788 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; |
| 4252 | 3789 |
| 4253 for (int flags = 0; flags < 256; ++flags) { | 3790 for (int flags = 0; flags < 256; ++flags) { |
| 4254 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 3791 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4255 | 3792 |
| 4256 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3793 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4257 SpdyFramer framer(spdy_version_); | 3794 SpdyFramer framer(spdy_version_); |
| 4258 framer.set_visitor(&visitor); | 3795 framer.set_visitor(&visitor); |
| 4259 | 3796 |
| 4260 SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 3797 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
| 4261 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 3798 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4272 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); | 3809 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); |
| 4273 if (flags & DATA_FLAG_FIN) { | 3810 if (flags & DATA_FLAG_FIN) { |
| 4274 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 3811 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
| 4275 } | 3812 } |
| 4276 } | 3813 } |
| 4277 } | 3814 } |
| 4278 | 3815 |
| 4279 framer.ProcessInput(frame->data(), frame->size()); | 3816 framer.ProcessInput(frame->data(), frame->size()); |
| 4280 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PAD_LOW) || | 3817 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PAD_LOW) || |
| 4281 (flags & DATA_FLAG_PAD_HIGH)) { | 3818 (flags & DATA_FLAG_PAD_HIGH)) { |
| 4282 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 3819 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4283 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 3820 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, framer.error_code()) |
| 4284 framer.error_code()) | 3821 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4285 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
| 4286 } else { | 3822 } else { |
| 4287 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 3823 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4288 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3824 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4289 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3825 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4290 } | 3826 } |
| 4291 } | 3827 } |
| 4292 } | 3828 } |
| 4293 | 3829 |
| 4294 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { | 3830 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { |
| 4295 for (int flags = 0; flags < 256; ++flags) { | 3831 for (int flags = 0; flags < 256; ++flags) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4312 if (IsSpdy4()) { | 3848 if (IsSpdy4()) { |
| 4313 // PRIORITY required for SYN_STREAM simulation. | 3849 // PRIORITY required for SYN_STREAM simulation. |
| 4314 set_flags |= HEADERS_FLAG_PRIORITY; | 3850 set_flags |= HEADERS_FLAG_PRIORITY; |
| 4315 } | 3851 } |
| 4316 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 3852 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
| 4317 | 3853 |
| 4318 if (!IsSpdy4() && | 3854 if (!IsSpdy4() && |
| 4319 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 3855 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
| 4320 EXPECT_CALL(visitor, OnError(_)); | 3856 EXPECT_CALL(visitor, OnError(_)); |
| 4321 } else if (IsSpdy4() && | 3857 } else if (IsSpdy4() && |
| 4322 flags & ~(CONTROL_FLAG_FIN | | 3858 flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY | |
| 4323 HEADERS_FLAG_PRIORITY | | |
| 4324 HEADERS_FLAG_END_HEADERS)) { | 3859 HEADERS_FLAG_END_HEADERS)) { |
| 4325 EXPECT_CALL(visitor, OnError(_)); | 3860 EXPECT_CALL(visitor, OnError(_)); |
| 4326 } else { | 3861 } else { |
| 4327 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); | 3862 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); |
| 4328 if (IsSpdy4()) { | 3863 if (IsSpdy4()) { |
| 4329 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, | 3864 EXPECT_CALL(visitor, |
| 4330 false)); | 3865 OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, false)); |
| 4331 } else { | 3866 } else { |
| 4332 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, | 3867 EXPECT_CALL(visitor, |
| 4333 flags & CONTROL_FLAG_UNIDIRECTIONAL)); | 3868 OnSynStream(8, |
| 3869 3, |
| 3870 1, |
| 3871 flags & CONTROL_FLAG_FIN, |
| 3872 flags & CONTROL_FLAG_UNIDIRECTIONAL)); |
| 4334 } | 3873 } |
| 4335 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) | 3874 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) |
| 4336 .WillRepeatedly(testing::Return(true)); | 3875 .WillRepeatedly(testing::Return(true)); |
| 4337 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || | 3876 if (flags & DATA_FLAG_FIN && |
| 4338 flags & HEADERS_FLAG_END_HEADERS)) { | 3877 (!IsSpdy4() || flags & HEADERS_FLAG_END_HEADERS)) { |
| 4339 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 3878 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
| 4340 } else { | 3879 } else { |
| 4341 // Do not close the stream if we are expecting a CONTINUATION frame. | 3880 // Do not close the stream if we are expecting a CONTINUATION frame. |
| 4342 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 3881 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
| 4343 } | 3882 } |
| 4344 } | 3883 } |
| 4345 | 3884 |
| 4346 framer.ProcessInput(frame->data(), frame->size()); | 3885 framer.ProcessInput(frame->data(), frame->size()); |
| 4347 if (!IsSpdy4() && | 3886 if (!IsSpdy4() && |
| 4348 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 3887 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
| 4349 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 3888 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4350 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 3889 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4351 framer.error_code()) | 3890 framer.error_code()) |
| 4352 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3891 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4353 } else if (IsSpdy4() && | 3892 } else if (IsSpdy4() && |
| 4354 flags & ~(CONTROL_FLAG_FIN | | 3893 flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY | |
| 4355 HEADERS_FLAG_PRIORITY | | 3894 HEADERS_FLAG_END_HEADERS)) { |
| 4356 HEADERS_FLAG_END_HEADERS)) { | |
| 4357 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 3895 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4358 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 3896 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4359 framer.error_code()) | 3897 framer.error_code()) |
| 4360 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3898 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4361 } else { | 3899 } else { |
| 4362 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 3900 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4363 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3901 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4364 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3902 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4365 } | 3903 } |
| 4366 } | 3904 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4434 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3972 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4435 } else { | 3973 } else { |
| 4436 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 3974 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4437 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 3975 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4438 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3976 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4439 } | 3977 } |
| 4440 } | 3978 } |
| 4441 } | 3979 } |
| 4442 | 3980 |
| 4443 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { | 3981 TEST_P(SpdyFramerTest, SettingsFrameFlagsOldFormat) { |
| 4444 if (spdy_version_ > SPDY3) { return; } | 3982 if (spdy_version_ > SPDY3) { |
| 3983 return; |
| 3984 } |
| 4445 for (int flags = 0; flags < 256; ++flags) { | 3985 for (int flags = 0; flags < 256; ++flags) { |
| 4446 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 3986 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4447 | 3987 |
| 4448 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3988 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4449 SpdyFramer framer(spdy_version_); | 3989 SpdyFramer framer(spdy_version_); |
| 4450 framer.set_visitor(&visitor); | 3990 framer.set_visitor(&visitor); |
| 4451 | 3991 |
| 4452 SpdySettingsIR settings_ir; | 3992 SpdySettingsIR settings_ir; |
| 4453 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, | 3993 settings_ir.AddSetting(SETTINGS_UPLOAD_BANDWIDTH, false, false, 54321); |
| 4454 false, | |
| 4455 false, | |
| 4456 54321); | |
| 4457 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 3994 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| 4458 SetFrameFlags(frame.get(), flags, spdy_version_); | 3995 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4459 | 3996 |
| 4460 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { | 3997 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { |
| 4461 EXPECT_CALL(visitor, OnError(_)); | 3998 EXPECT_CALL(visitor, OnError(_)); |
| 4462 } else { | 3999 } else { |
| 4463 EXPECT_CALL(visitor, OnSettings( | 4000 EXPECT_CALL( |
| 4464 flags & SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS)); | 4001 visitor, |
| 4465 EXPECT_CALL(visitor, OnSetting(SETTINGS_UPLOAD_BANDWIDTH, | 4002 OnSettings(flags & |
| 4466 SETTINGS_FLAG_NONE, 54321)); | 4003 SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS)); |
| 4004 EXPECT_CALL( |
| 4005 visitor, |
| 4006 OnSetting(SETTINGS_UPLOAD_BANDWIDTH, SETTINGS_FLAG_NONE, 54321)); |
| 4467 EXPECT_CALL(visitor, OnSettingsEnd()); | 4007 EXPECT_CALL(visitor, OnSettingsEnd()); |
| 4468 } | 4008 } |
| 4469 | 4009 |
| 4470 framer.ProcessInput(frame->data(), frame->size()); | 4010 framer.ProcessInput(frame->data(), frame->size()); |
| 4471 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { | 4011 if (flags & ~SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS) { |
| 4472 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4012 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4473 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4013 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4474 framer.error_code()) | 4014 framer.error_code()) |
| 4475 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4015 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4476 } else { | 4016 } else { |
| 4477 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4017 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4478 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4018 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4479 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4019 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4480 } | 4020 } |
| 4481 } | 4021 } |
| 4482 } | 4022 } |
| 4483 | 4023 |
| 4484 TEST_P(SpdyFramerTest, SettingsFrameFlags) { | 4024 TEST_P(SpdyFramerTest, SettingsFrameFlags) { |
| 4485 if (spdy_version_ <= SPDY3) { return; } | 4025 if (spdy_version_ <= SPDY3) { |
| 4026 return; |
| 4027 } |
| 4486 for (int flags = 0; flags < 256; ++flags) { | 4028 for (int flags = 0; flags < 256; ++flags) { |
| 4487 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4029 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4488 | 4030 |
| 4489 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4031 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4490 SpdyFramer framer(spdy_version_); | 4032 SpdyFramer framer(spdy_version_); |
| 4491 framer.set_visitor(&visitor); | 4033 framer.set_visitor(&visitor); |
| 4492 | 4034 |
| 4493 SpdySettingsIR settings_ir; | 4035 SpdySettingsIR settings_ir; |
| 4494 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); | 4036 settings_ir.AddSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 0, 16); |
| 4495 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); | 4037 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); |
| 4496 SetFrameFlags(frame.get(), flags, spdy_version_); | 4038 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4497 | 4039 |
| 4498 if (flags != 0) { | 4040 if (flags != 0) { |
| 4499 EXPECT_CALL(visitor, OnError(_)); | 4041 EXPECT_CALL(visitor, OnError(_)); |
| 4500 } else { | 4042 } else { |
| 4501 EXPECT_CALL(visitor, OnSettings(flags & SETTINGS_FLAG_ACK)); | 4043 EXPECT_CALL(visitor, OnSettings(flags & SETTINGS_FLAG_ACK)); |
| 4502 EXPECT_CALL(visitor, OnSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 16)); | 4044 EXPECT_CALL(visitor, OnSetting(SETTINGS_INITIAL_WINDOW_SIZE, 0, 16)); |
| 4503 EXPECT_CALL(visitor, OnSettingsEnd()); | 4045 EXPECT_CALL(visitor, OnSettingsEnd()); |
| 4504 } | 4046 } |
| 4505 | 4047 |
| 4506 framer.ProcessInput(frame->data(), frame->size()); | 4048 framer.ProcessInput(frame->data(), frame->size()); |
| 4507 if (flags & ~SETTINGS_FLAG_ACK) { | 4049 if (flags & ~SETTINGS_FLAG_ACK) { |
| 4508 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4050 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4509 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4051 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4510 framer.error_code()) | 4052 framer.error_code()) |
| 4511 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4053 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4512 } else if (flags & SETTINGS_FLAG_ACK) { | 4054 } else if (flags & SETTINGS_FLAG_ACK) { |
| 4513 // The frame is invalid because ACK frames should have no payload. | 4055 // The frame is invalid because ACK frames should have no payload. |
| 4514 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4056 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4515 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, | 4057 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4516 framer.error_code()) | |
| 4517 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4058 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4518 } else { | 4059 } else { |
| 4519 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4060 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4520 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4061 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4521 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4062 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4522 } | 4063 } |
| 4523 } | 4064 } |
| 4524 } | 4065 } |
| 4525 | 4066 |
| 4526 TEST_P(SpdyFramerTest, GoawayFrameFlags) { | 4067 TEST_P(SpdyFramerTest, GoawayFrameFlags) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4567 SpdyFramer framer(spdy_version_); | 4108 SpdyFramer framer(spdy_version_); |
| 4568 framer.set_visitor(&visitor); | 4109 framer.set_visitor(&visitor); |
| 4569 | 4110 |
| 4570 SpdyHeadersIR headers_ir(57); | 4111 SpdyHeadersIR headers_ir(57); |
| 4571 headers_ir.SetHeader("foo", "bar"); | 4112 headers_ir.SetHeader("foo", "bar"); |
| 4572 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 4113 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 4573 SetFrameFlags(frame.get(), flags, spdy_version_); | 4114 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4574 | 4115 |
| 4575 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4116 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
| 4576 EXPECT_CALL(visitor, OnError(_)); | 4117 EXPECT_CALL(visitor, OnError(_)); |
| 4577 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4118 } else if (IsSpdy4() && |
| 4578 HEADERS_FLAG_END_HEADERS)) { | 4119 flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_END_HEADERS)) { |
| 4579 EXPECT_CALL(visitor, OnError(_)); | 4120 EXPECT_CALL(visitor, OnError(_)); |
| 4580 } else { | 4121 } else { |
| 4581 EXPECT_CALL(visitor, OnHeaders(57, | 4122 EXPECT_CALL(visitor, |
| 4582 flags & CONTROL_FLAG_FIN, | 4123 OnHeaders(57, |
| 4583 (flags & HEADERS_FLAG_END_HEADERS) || | 4124 flags & CONTROL_FLAG_FIN, |
| 4584 !IsSpdy4())); | 4125 (flags & HEADERS_FLAG_END_HEADERS) || !IsSpdy4())); |
| 4585 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) | 4126 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) |
| 4586 .WillRepeatedly(testing::Return(true)); | 4127 .WillRepeatedly(testing::Return(true)); |
| 4587 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || | 4128 if (flags & DATA_FLAG_FIN && |
| 4588 flags & HEADERS_FLAG_END_HEADERS)) { | 4129 (!IsSpdy4() || flags & HEADERS_FLAG_END_HEADERS)) { |
| 4589 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4130 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
| 4590 } else { | 4131 } else { |
| 4591 // Do not close the stream if we are expecting a CONTINUATION frame. | 4132 // Do not close the stream if we are expecting a CONTINUATION frame. |
| 4592 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 4133 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
| 4593 } | 4134 } |
| 4594 } | 4135 } |
| 4595 | 4136 |
| 4596 framer.ProcessInput(frame->data(), frame->size()); | 4137 framer.ProcessInput(frame->data(), frame->size()); |
| 4597 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4138 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
| 4598 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4139 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4599 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4140 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4600 framer.error_code()) | 4141 framer.error_code()) |
| 4601 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4142 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4602 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY | | 4143 } else if (IsSpdy4() && |
| 4603 HEADERS_FLAG_END_HEADERS)) { | 4144 flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY | |
| 4145 HEADERS_FLAG_END_HEADERS)) { |
| 4604 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4146 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4605 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4147 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4606 framer.error_code()) | 4148 framer.error_code()) |
| 4607 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4149 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4608 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { | 4150 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { |
| 4609 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4151 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4610 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4152 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4611 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4153 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4612 } else { | 4154 } else { |
| 4613 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4155 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4614 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4156 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4615 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4157 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4616 } | 4158 } |
| 4617 } | 4159 } |
| 4618 } | 4160 } |
| 4619 | 4161 |
| 4620 TEST_P(SpdyFramerTest, PingFrameFlags) { | 4162 TEST_P(SpdyFramerTest, PingFrameFlags) { |
| 4621 for (int flags = 0; flags < 256; ++flags) { | 4163 for (int flags = 0; flags < 256; ++flags) { |
| 4622 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4164 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4623 | 4165 |
| 4624 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4166 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4625 SpdyFramer framer(spdy_version_); | 4167 SpdyFramer framer(spdy_version_); |
| 4626 framer.set_visitor(&visitor); | 4168 framer.set_visitor(&visitor); |
| 4627 | 4169 |
| 4628 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); | 4170 scoped_ptr<SpdyFrame> frame(framer.SerializePing(SpdyPingIR(42))); |
| 4629 SetFrameFlags(frame.get(), flags, spdy_version_); | 4171 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4630 | 4172 |
| 4631 if (spdy_version_ > SPDY3 && | 4173 if (spdy_version_ > SPDY3 && flags == PING_FLAG_ACK) { |
| 4632 flags == PING_FLAG_ACK) { | |
| 4633 EXPECT_CALL(visitor, OnPing(42, true)); | 4174 EXPECT_CALL(visitor, OnPing(42, true)); |
| 4634 } else if (flags == 0) { | 4175 } else if (flags == 0) { |
| 4635 EXPECT_CALL(visitor, OnPing(42, false)); | 4176 EXPECT_CALL(visitor, OnPing(42, false)); |
| 4636 } else { | 4177 } else { |
| 4637 EXPECT_CALL(visitor, OnError(_)); | 4178 EXPECT_CALL(visitor, OnError(_)); |
| 4638 } | 4179 } |
| 4639 | 4180 |
| 4640 framer.ProcessInput(frame->data(), frame->size()); | 4181 framer.ProcessInput(frame->data(), frame->size()); |
| 4641 if ((spdy_version_ > SPDY3 && flags == PING_FLAG_ACK) || | 4182 if ((spdy_version_ > SPDY3 && flags == PING_FLAG_ACK) || flags == 0) { |
| 4642 flags == 0) { | |
| 4643 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4183 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4644 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4184 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4645 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4185 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4646 } else { | 4186 } else { |
| 4647 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4187 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4648 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4188 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4649 framer.error_code()) | 4189 framer.error_code()) |
| 4650 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4190 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4651 } | 4191 } |
| 4652 } | 4192 } |
| 4653 } | 4193 } |
| 4654 | 4194 |
| 4655 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { | 4195 TEST_P(SpdyFramerTest, WindowUpdateFrameFlags) { |
| 4656 for (int flags = 0; flags < 256; ++flags) { | 4196 for (int flags = 0; flags < 256; ++flags) { |
| 4657 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4197 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
| 4658 | 4198 |
| 4659 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4199 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4660 SpdyFramer framer(spdy_version_); | 4200 SpdyFramer framer(spdy_version_); |
| 4661 framer.set_visitor(&visitor); | 4201 framer.set_visitor(&visitor); |
| 4662 | 4202 |
| 4663 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 4203 scoped_ptr<SpdyFrame> frame( |
| 4664 SpdyWindowUpdateIR(4, 1024))); | 4204 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(4, 1024))); |
| 4665 SetFrameFlags(frame.get(), flags, spdy_version_); | 4205 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4666 | 4206 |
| 4667 if (flags != 0) { | 4207 if (flags != 0) { |
| 4668 EXPECT_CALL(visitor, OnError(_)); | 4208 EXPECT_CALL(visitor, OnError(_)); |
| 4669 } else { | 4209 } else { |
| 4670 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); | 4210 EXPECT_CALL(visitor, OnWindowUpdate(4, 1024)); |
| 4671 } | 4211 } |
| 4672 | 4212 |
| 4673 framer.ProcessInput(frame->data(), frame->size()); | 4213 framer.ProcessInput(frame->data(), frame->size()); |
| 4674 if (flags != 0) { | 4214 if (flags != 0) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4696 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 4236 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
| 4697 SpdyFramer framer(spdy_version_); | 4237 SpdyFramer framer(spdy_version_); |
| 4698 framer.set_visitor(&visitor); | 4238 framer.set_visitor(&visitor); |
| 4699 framer.set_debug_visitor(&debug_visitor); | 4239 framer.set_debug_visitor(&debug_visitor); |
| 4700 | 4240 |
| 4701 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); | 4241 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); |
| 4702 | 4242 |
| 4703 SpdyPushPromiseIR push_promise(42, 57); | 4243 SpdyPushPromiseIR push_promise(42, 57); |
| 4704 push_promise.SetHeader("foo", "bar"); | 4244 push_promise.SetHeader("foo", "bar"); |
| 4705 scoped_ptr<SpdySerializedFrame> frame( | 4245 scoped_ptr<SpdySerializedFrame> frame( |
| 4706 framer.SerializePushPromise(push_promise)); | 4246 framer.SerializePushPromise(push_promise)); |
| 4707 SetFrameFlags(frame.get(), flags, spdy_version_); | 4247 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4708 | 4248 |
| 4709 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { | 4249 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { |
| 4710 EXPECT_CALL(visitor, OnError(_)); | 4250 EXPECT_CALL(visitor, OnError(_)); |
| 4711 } else { | 4251 } else { |
| 4712 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); | 4252 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); |
| 4713 EXPECT_CALL(visitor, OnPushPromise(42, 57, | 4253 EXPECT_CALL( |
| 4714 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); | 4254 visitor, |
| 4255 OnPushPromise(42, 57, flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); |
| 4715 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4256 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
| 4716 .WillRepeatedly(testing::Return(true)); | 4257 .WillRepeatedly(testing::Return(true)); |
| 4717 } | 4258 } |
| 4718 | 4259 |
| 4719 framer.ProcessInput(frame->data(), frame->size()); | 4260 framer.ProcessInput(frame->data(), frame->size()); |
| 4720 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { | 4261 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { |
| 4721 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4262 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4722 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4263 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4723 framer.error_code()) | 4264 framer.error_code()) |
| 4724 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4265 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4741 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4282 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4742 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 4283 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
| 4743 SpdyFramer framer(spdy_version_); | 4284 SpdyFramer framer(spdy_version_); |
| 4744 framer.set_visitor(&visitor); | 4285 framer.set_visitor(&visitor); |
| 4745 framer.set_debug_visitor(&debug_visitor); | 4286 framer.set_debug_visitor(&debug_visitor); |
| 4746 | 4287 |
| 4747 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); | 4288 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); |
| 4748 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); | 4289 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); |
| 4749 EXPECT_CALL(visitor, OnHeaders(42, 0, false)); | 4290 EXPECT_CALL(visitor, OnHeaders(42, 0, false)); |
| 4750 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4291 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
| 4751 .WillRepeatedly(testing::Return(true)); | 4292 .WillRepeatedly(testing::Return(true)); |
| 4752 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, CONTINUATION, _, _)); | 4293 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, CONTINUATION, _, _)); |
| 4753 | 4294 |
| 4754 SpdyHeadersIR headers_ir(42); | 4295 SpdyHeadersIR headers_ir(42); |
| 4755 headers_ir.SetHeader("foo", "bar"); | 4296 headers_ir.SetHeader("foo", "bar"); |
| 4756 headers_ir.set_end_headers(false); | 4297 headers_ir.set_end_headers(false); |
| 4757 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); | 4298 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); |
| 4758 | 4299 |
| 4759 SpdyContinuationIR continuation(42); | 4300 SpdyContinuationIR continuation(42); |
| 4760 continuation.SetHeader("foo", "bar"); | 4301 continuation.SetHeader("foo", "bar"); |
| 4761 scoped_ptr<SpdySerializedFrame> frame( | 4302 scoped_ptr<SpdySerializedFrame> frame( |
| 4762 framer.SerializeContinuation(continuation)); | 4303 framer.SerializeContinuation(continuation)); |
| 4763 SetFrameFlags(frame.get(), flags, spdy_version_); | 4304 SetFrameFlags(frame.get(), flags, spdy_version_); |
| 4764 | 4305 |
| 4765 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 4306 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
| 4766 EXPECT_CALL(visitor, OnError(_)); | 4307 EXPECT_CALL(visitor, OnError(_)); |
| 4767 } else { | 4308 } else { |
| 4768 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); | 4309 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); |
| 4769 EXPECT_CALL(visitor, OnContinuation(42, | 4310 EXPECT_CALL(visitor, |
| 4770 flags & HEADERS_FLAG_END_HEADERS)); | 4311 OnContinuation(42, flags & HEADERS_FLAG_END_HEADERS)); |
| 4771 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4312 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
| 4772 .WillRepeatedly(testing::Return(true)); | 4313 .WillRepeatedly(testing::Return(true)); |
| 4773 } | 4314 } |
| 4774 | 4315 |
| 4775 framer.ProcessInput(frame0->data(), frame0->size()); | 4316 framer.ProcessInput(frame0->data(), frame0->size()); |
| 4776 framer.ProcessInput(frame->data(), frame->size()); | 4317 framer.ProcessInput(frame->data(), frame->size()); |
| 4777 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 4318 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
| 4778 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4319 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4779 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4320 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
| 4780 framer.error_code()) | 4321 framer.error_code()) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4825 EXPECT_EQ(kId, id_and_flags.id()); | 4366 EXPECT_EQ(kId, id_and_flags.id()); |
| 4826 EXPECT_EQ(kFlags, id_and_flags.flags()); | 4367 EXPECT_EQ(kFlags, id_and_flags.flags()); |
| 4827 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); | 4368 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); |
| 4828 } | 4369 } |
| 4829 | 4370 |
| 4830 // Test handling of a RST_STREAM with out-of-bounds status codes. | 4371 // Test handling of a RST_STREAM with out-of-bounds status codes. |
| 4831 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { | 4372 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { |
| 4832 const unsigned char kRstStreamStatusTooLow = 0x00; | 4373 const unsigned char kRstStreamStatusTooLow = 0x00; |
| 4833 const unsigned char kRstStreamStatusTooHigh = 0xff; | 4374 const unsigned char kRstStreamStatusTooHigh = 0xff; |
| 4834 const unsigned char kV3RstStreamInvalid[] = { | 4375 const unsigned char kV3RstStreamInvalid[] = { |
| 4835 0x80, spdy_version_ch_, 0x00, 0x03, | 4376 0x80, spdy_version_ch_, 0x00, 0x03, 0x00, 0x00, |
| 4836 0x00, 0x00, 0x00, 0x08, | 4377 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, |
| 4837 0x00, 0x00, 0x00, 0x01, | 4378 0x00, 0x00, 0x00, kRstStreamStatusTooLow}; |
| 4838 0x00, 0x00, 0x00, kRstStreamStatusTooLow | |
| 4839 }; | |
| 4840 const unsigned char kV4RstStreamInvalid[] = { | 4379 const unsigned char kV4RstStreamInvalid[] = { |
| 4841 0x00, 0x04, 0x03, 0x00, | 4380 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, |
| 4842 0x00, 0x00, 0x00, 0x01, | 4381 0x00, 0x01, 0x00, 0x00, 0x00, kRstStreamStatusTooLow}; |
| 4843 0x00, 0x00, 0x00, kRstStreamStatusTooLow | |
| 4844 }; | |
| 4845 | 4382 |
| 4846 const unsigned char kV3RstStreamNumStatusCodes[] = { | 4383 const unsigned char kV3RstStreamNumStatusCodes[] = { |
| 4847 0x80, spdy_version_ch_, 0x00, 0x03, | 4384 0x80, spdy_version_ch_, 0x00, 0x03, 0x00, 0x00, |
| 4848 0x00, 0x00, 0x00, 0x08, | 4385 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, |
| 4849 0x00, 0x00, 0x00, 0x01, | 4386 0x00, 0x00, 0x00, kRstStreamStatusTooHigh}; |
| 4850 0x00, 0x00, 0x00, kRstStreamStatusTooHigh | |
| 4851 }; | |
| 4852 const unsigned char kV4RstStreamNumStatusCodes[] = { | 4387 const unsigned char kV4RstStreamNumStatusCodes[] = { |
| 4853 0x00, 0x04, 0x03, 0x00, | 4388 0x00, 0x04, 0x03, 0x00, 0x00, 0x00, |
| 4854 0x00, 0x00, 0x00, 0x01, | 4389 0x00, 0x01, 0x00, 0x00, 0x00, kRstStreamStatusTooHigh}; |
| 4855 0x00, 0x00, 0x00, kRstStreamStatusTooHigh | |
| 4856 }; | |
| 4857 | 4390 |
| 4858 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4391 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4859 SpdyFramer framer(spdy_version_); | 4392 SpdyFramer framer(spdy_version_); |
| 4860 framer.set_visitor(&visitor); | 4393 framer.set_visitor(&visitor); |
| 4861 | 4394 |
| 4862 if (IsSpdy4()) { | 4395 if (IsSpdy4()) { |
| 4863 EXPECT_CALL(visitor, OnError(_)); | 4396 EXPECT_CALL(visitor, OnError(_)); |
| 4864 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), | 4397 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), |
| 4865 arraysize(kV4RstStreamInvalid)); | 4398 arraysize(kV4RstStreamInvalid)); |
| 4866 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4399 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4867 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 4400 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4868 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4401 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4869 } else { | 4402 } else { |
| 4870 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); | 4403 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 4871 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), | 4404 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), |
| 4872 arraysize(kV3RstStreamInvalid)); | 4405 arraysize(kV3RstStreamInvalid)); |
| 4873 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4406 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4874 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4407 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4875 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4408 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4876 } | 4409 } |
| 4877 | 4410 |
| 4878 | |
| 4879 framer.Reset(); | 4411 framer.Reset(); |
| 4880 | 4412 |
| 4881 if (IsSpdy4()) { | 4413 if (IsSpdy4()) { |
| 4882 EXPECT_CALL(visitor, OnError(_)); | 4414 EXPECT_CALL(visitor, OnError(_)); |
| 4883 framer.ProcessInput( | 4415 framer.ProcessInput( |
| 4884 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), | 4416 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), |
| 4885 arraysize(kV4RstStreamNumStatusCodes)); | 4417 arraysize(kV4RstStreamNumStatusCodes)); |
| 4886 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4418 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
| 4887 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) | 4419 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code()) |
| 4888 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4420 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4889 } else { | 4421 } else { |
| 4890 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); | 4422 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); |
| 4891 framer.ProcessInput( | 4423 framer.ProcessInput( |
| 4892 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), | 4424 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), |
| 4893 arraysize(kV3RstStreamNumStatusCodes)); | 4425 arraysize(kV3RstStreamNumStatusCodes)); |
| 4894 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4426 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4895 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4427 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4896 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4428 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4897 } | 4429 } |
| 4898 } | 4430 } |
| 4899 | 4431 |
| 4900 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. | 4432 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. |
| 4901 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { | 4433 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { |
| 4902 const unsigned char kV2FrameData[] = { | 4434 const unsigned char kV2FrameData[] = { |
| 4903 0x80, spdy_version_ch_, 0x00, 0x07, | 4435 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, |
| 4904 0x00, 0x00, 0x00, 0x04, | 4436 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, |
| 4905 0xff, 0xff, 0xff, 0xff, | |
| 4906 }; | 4437 }; |
| 4907 const unsigned char kV3FrameData[] = { | 4438 const unsigned char kV3FrameData[] = { |
| 4908 0x80, spdy_version_ch_, 0x00, 0x07, | 4439 0x80, spdy_version_ch_, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, |
| 4909 0x00, 0x00, 0x00, 0x08, | 4440 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, |
| 4910 0xff, 0xff, 0xff, 0xff, | |
| 4911 0x00, 0x00, 0x00, 0x00, | |
| 4912 }; | 4441 }; |
| 4913 const unsigned char kV4FrameData[] = { | 4442 const unsigned char kV4FrameData[] = { |
| 4914 0x00, 0x08, 0x07, 0x00, | 4443 0x00, 0x08, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 4915 0x00, 0x00, 0x00, 0x00, | 4444 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, |
| 4916 0xff, 0xff, 0xff, 0xff, | |
| 4917 0x00, 0x00, 0x00, 0x00, | |
| 4918 }; | 4445 }; |
| 4919 | 4446 |
| 4920 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4447 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 4921 SpdyFramer framer(spdy_version_); | 4448 SpdyFramer framer(spdy_version_); |
| 4922 framer.set_visitor(&visitor); | 4449 framer.set_visitor(&visitor); |
| 4923 | 4450 |
| 4924 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); | 4451 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); |
| 4925 if (IsSpdy2()) { | 4452 if (IsSpdy2()) { |
| 4926 framer.ProcessInput(reinterpret_cast<const char*>(kV2FrameData), | 4453 framer.ProcessInput(reinterpret_cast<const char*>(kV2FrameData), |
| 4927 arraysize(kV2FrameData)); | 4454 arraysize(kV2FrameData)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4953 SpdyBlockedIR blocked_ir(0); | 4480 SpdyBlockedIR blocked_ir(0); |
| 4954 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 4481 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
| 4955 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 4482 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
| 4956 | 4483 |
| 4957 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4484 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 4958 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4485 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 4959 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4486 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 4960 } | 4487 } |
| 4961 | 4488 |
| 4962 } // namespace net | 4489 } // namespace net |
| OLD | NEW |