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 173 matching lines...) Loading... |
184 scoped_ptr<SpdyFrame> frame(framer.SerializePushPromise(push_promise)); | 184 scoped_ptr<SpdyFrame> frame(framer.SerializePushPromise(push_promise)); |
185 ResetBuffer(); | 185 ResetBuffer(); |
186 memcpy(buffer_.get(), frame->data(), framer.GetPushPromiseMinimumSize()); | 186 memcpy(buffer_.get(), frame->data(), framer.GetPushPromiseMinimumSize()); |
187 size_ += framer.GetPushPromiseMinimumSize(); | 187 size_ += framer.GetPushPromiseMinimumSize(); |
188 } | 188 } |
189 | 189 |
190 virtual void OnContinuation(SpdyStreamId stream_id, bool end) OVERRIDE { | 190 virtual void OnContinuation(SpdyStreamId stream_id, bool end) OVERRIDE { |
191 LOG(FATAL); | 191 LOG(FATAL); |
192 } | 192 } |
193 | 193 |
| 194 virtual void OnPriority(SpdyStreamId stream_id, |
| 195 SpdyStreamId parent_stream_id, |
| 196 uint8 weight, |
| 197 bool exclusive) OVERRIDE { |
| 198 // Do nothing. |
| 199 } |
| 200 |
194 char* ReleaseBuffer() { | 201 char* ReleaseBuffer() { |
195 CHECK(finished_); | 202 CHECK(finished_); |
196 return buffer_.release(); | 203 return buffer_.release(); |
197 } | 204 } |
198 | 205 |
199 virtual void OnWindowUpdate(SpdyStreamId stream_id, | 206 virtual void OnWindowUpdate(SpdyStreamId stream_id, |
200 uint32 delta_window_size) OVERRIDE { | 207 uint32 delta_window_size) OVERRIDE { |
201 LOG(FATAL); | 208 LOG(FATAL); |
202 } | 209 } |
203 | 210 |
(...skipping 16 matching lines...) Loading... |
220 }; | 227 }; |
221 | 228 |
222 class TestSpdyVisitor : public SpdyFramerVisitorInterface, | 229 class TestSpdyVisitor : public SpdyFramerVisitorInterface, |
223 public SpdyFramerDebugVisitorInterface { | 230 public SpdyFramerDebugVisitorInterface { |
224 public: | 231 public: |
225 // This is larger than our max frame size because header blocks that | 232 // This is larger than our max frame size because header blocks that |
226 // are too long can spill over into CONTINUATION frames. | 233 // are too long can spill over into CONTINUATION frames. |
227 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; | 234 static const size_t kDefaultHeaderBufferSize = 16 * 1024 * 1024; |
228 | 235 |
229 explicit TestSpdyVisitor(SpdyMajorVersion version) | 236 explicit TestSpdyVisitor(SpdyMajorVersion version) |
230 : framer_(version), | 237 : framer_(version), |
231 use_compression_(false), | 238 use_compression_(false), |
232 error_count_(0), | 239 error_count_(0), |
233 syn_frame_count_(0), | 240 syn_frame_count_(0), |
234 syn_reply_frame_count_(0), | 241 syn_reply_frame_count_(0), |
235 headers_frame_count_(0), | 242 headers_frame_count_(0), |
236 push_promise_frame_count_(0), | 243 push_promise_frame_count_(0), |
237 goaway_count_(0), | 244 goaway_count_(0), |
238 setting_count_(0), | 245 setting_count_(0), |
239 settings_ack_sent_(0), | 246 settings_ack_sent_(0), |
240 settings_ack_received_(0), | 247 settings_ack_received_(0), |
241 continuation_count_(0), | 248 continuation_count_(0), |
242 altsvc_count_(0), | 249 altsvc_count_(0), |
243 test_altsvc_ir_(0), | 250 priority_count_(0), |
244 last_window_update_stream_(0), | 251 test_altsvc_ir_(0), |
245 last_window_update_delta_(0), | 252 last_window_update_stream_(0), |
246 last_push_promise_stream_(0), | 253 last_window_update_delta_(0), |
247 last_push_promise_promised_stream_(0), | 254 last_push_promise_stream_(0), |
248 data_bytes_(0), | 255 last_push_promise_promised_stream_(0), |
249 fin_frame_count_(0), | 256 data_bytes_(0), |
250 fin_opaque_data_(), | 257 fin_frame_count_(0), |
251 fin_flag_count_(0), | 258 fin_opaque_data_(), |
252 zero_length_data_frame_count_(0), | 259 fin_flag_count_(0), |
253 control_frame_header_data_count_(0), | 260 zero_length_data_frame_count_(0), |
254 zero_length_control_frame_header_data_count_(0), | 261 control_frame_header_data_count_(0), |
255 data_frame_count_(0), | 262 zero_length_control_frame_header_data_count_(0), |
256 last_payload_len_(0), | 263 data_frame_count_(0), |
257 last_frame_len_(0), | 264 last_payload_len_(0), |
258 header_buffer_(new char[kDefaultHeaderBufferSize]), | 265 last_frame_len_(0), |
259 header_buffer_length_(0), | 266 header_buffer_(new char[kDefaultHeaderBufferSize]), |
260 header_buffer_size_(kDefaultHeaderBufferSize), | 267 header_buffer_length_(0), |
261 header_stream_id_(-1), | 268 header_buffer_size_(kDefaultHeaderBufferSize), |
262 header_control_type_(DATA), | 269 header_stream_id_(-1), |
263 header_buffer_valid_(false) { | 270 header_control_type_(DATA), |
264 } | 271 header_buffer_valid_(false) {} |
265 | 272 |
266 virtual void OnError(SpdyFramer* f) OVERRIDE { | 273 virtual void OnError(SpdyFramer* f) OVERRIDE { |
267 LOG(INFO) << "SpdyFramer Error: " | 274 LOG(INFO) << "SpdyFramer Error: " |
268 << SpdyFramer::ErrorCodeToString(f->error_code()); | 275 << SpdyFramer::ErrorCodeToString(f->error_code()); |
269 ++error_count_; | 276 ++error_count_; |
270 } | 277 } |
271 | 278 |
272 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 279 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
273 size_t length, | 280 size_t length, |
274 bool fin) OVERRIDE { | 281 bool fin) OVERRIDE { |
(...skipping 45 matching lines...) Loading... |
320 header_buffer_length_ += len; | 327 header_buffer_length_ += len; |
321 return true; | 328 return true; |
322 } | 329 } |
323 | 330 |
324 virtual void OnSynStream(SpdyStreamId stream_id, | 331 virtual void OnSynStream(SpdyStreamId stream_id, |
325 SpdyStreamId associated_stream_id, | 332 SpdyStreamId associated_stream_id, |
326 SpdyPriority priority, | 333 SpdyPriority priority, |
327 bool fin, | 334 bool fin, |
328 bool unidirectional) OVERRIDE { | 335 bool unidirectional) OVERRIDE { |
329 ++syn_frame_count_; | 336 ++syn_frame_count_; |
330 InitHeaderStreaming(SYN_STREAM, stream_id); | 337 if (framer_.protocol_version() > SPDY3) { |
| 338 InitHeaderStreaming(HEADERS, stream_id); |
| 339 } else { |
| 340 InitHeaderStreaming(SYN_STREAM, stream_id); |
| 341 } |
331 if (fin) { | 342 if (fin) { |
332 ++fin_flag_count_; | 343 ++fin_flag_count_; |
333 } | 344 } |
334 } | 345 } |
335 | 346 |
336 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE { | 347 virtual void OnSynReply(SpdyStreamId stream_id, bool fin) OVERRIDE { |
337 ++syn_reply_frame_count_; | 348 ++syn_reply_frame_count_; |
338 InitHeaderStreaming(SYN_REPLY, stream_id); | 349 if (framer_.protocol_version() > SPDY3) { |
| 350 InitHeaderStreaming(HEADERS, stream_id); |
| 351 } else { |
| 352 InitHeaderStreaming(SYN_REPLY, stream_id); |
| 353 } |
339 if (fin) { | 354 if (fin) { |
340 ++fin_flag_count_; | 355 ++fin_flag_count_; |
341 } | 356 } |
342 } | 357 } |
343 | 358 |
344 virtual void OnRstStream(SpdyStreamId stream_id, | 359 virtual void OnRstStream(SpdyStreamId stream_id, |
345 SpdyRstStreamStatus status) OVERRIDE { | 360 SpdyRstStreamStatus status) OVERRIDE { |
346 ++fin_frame_count_; | 361 ++fin_frame_count_; |
347 } | 362 } |
348 | 363 |
(...skipping 75 matching lines...) Loading... |
424 } | 439 } |
425 | 440 |
426 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, | 441 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, |
427 SpdyFrameType type, | 442 SpdyFrameType type, |
428 size_t payload_len, | 443 size_t payload_len, |
429 size_t frame_len) OVERRIDE { | 444 size_t frame_len) OVERRIDE { |
430 last_payload_len_ = payload_len; | 445 last_payload_len_ = payload_len; |
431 last_frame_len_ = frame_len; | 446 last_frame_len_ = frame_len; |
432 } | 447 } |
433 | 448 |
| 449 virtual void OnPriority(SpdyStreamId stream_id, |
| 450 SpdyStreamId parent_stream_id, |
| 451 uint8 weight, |
| 452 bool exclusive) OVERRIDE { |
| 453 ++priority_count_; |
| 454 } |
| 455 |
434 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, | 456 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, |
435 SpdyFrameType type, | 457 SpdyFrameType type, |
436 size_t frame_len) OVERRIDE { | 458 size_t frame_len) OVERRIDE { |
437 last_frame_len_ = frame_len; | 459 last_frame_len_ = frame_len; |
438 } | 460 } |
439 | 461 |
440 // Convenience function which runs a framer simulation with particular input. | 462 // Convenience function which runs a framer simulation with particular input. |
441 void SimulateInFramer(const unsigned char* input, size_t size) { | 463 void SimulateInFramer(const unsigned char* input, size_t size) { |
442 framer_.set_enable_compression(use_compression_); | 464 framer_.set_enable_compression(use_compression_); |
443 framer_.set_visitor(this); | 465 framer_.set_visitor(this); |
444 size_t input_remaining = size; | 466 size_t input_remaining = size; |
445 const char* input_ptr = reinterpret_cast<const char*>(input); | 467 const char* input_ptr = reinterpret_cast<const char*>(input); |
446 while (input_remaining > 0 && | 468 while (input_remaining > 0 && |
447 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { | 469 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { |
448 // To make the tests more interesting, we feed random (amd small) chunks | 470 // To make the tests more interesting, we feed random (amd small) chunks |
449 // into the framer. This simulates getting strange-sized reads from | 471 // into the framer. This simulates getting strange-sized reads from |
450 // the socket. | 472 // the socket. |
451 const size_t kMaxReadSize = 32; | 473 const size_t kMaxReadSize = 32; |
452 size_t bytes_read = | 474 size_t bytes_read = |
453 (rand() % min(input_remaining, kMaxReadSize)) + 1; | 475 (rand() % min(input_remaining, kMaxReadSize)) + 1; |
454 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); | 476 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); |
455 input_remaining -= bytes_processed; | 477 input_remaining -= bytes_processed; |
456 input_ptr += bytes_processed; | 478 input_ptr += bytes_processed; |
457 } | 479 } |
458 } | 480 } |
459 | 481 |
460 void InitHeaderStreaming(SpdyFrameType header_control_type, | 482 void InitHeaderStreaming(SpdyFrameType header_control_type, |
461 SpdyStreamId stream_id) { | 483 SpdyStreamId stream_id) { |
462 DCHECK_GE(header_control_type, FIRST_CONTROL_TYPE); | 484 if (!SpdyConstants::IsValidFrameType(framer_.protocol_version(), |
463 DCHECK_LE(header_control_type, LAST_CONTROL_TYPE); | 485 SpdyConstants::SerializeFrameType(framer_.protocol_version(), |
| 486 header_control_type))) { |
| 487 DLOG(FATAL) << "Attempted to init header streaming with " |
| 488 << "invalid control frame type: " |
| 489 << header_control_type; |
| 490 } |
464 memset(header_buffer_.get(), 0, header_buffer_size_); | 491 memset(header_buffer_.get(), 0, header_buffer_size_); |
465 header_buffer_length_ = 0; | 492 header_buffer_length_ = 0; |
466 header_stream_id_ = stream_id; | 493 header_stream_id_ = stream_id; |
467 header_control_type_ = header_control_type; | 494 header_control_type_ = header_control_type; |
468 header_buffer_valid_ = true; | 495 header_buffer_valid_ = true; |
469 DCHECK_NE(header_stream_id_, SpdyFramer::kInvalidStream); | 496 DCHECK_NE(header_stream_id_, SpdyFramer::kInvalidStream); |
470 } | 497 } |
471 | 498 |
472 // Override the default buffer size (16K). Call before using the framer! | 499 // Override the default buffer size (16K). Call before using the framer! |
473 void set_header_buffer_size(size_t header_buffer_size) { | 500 void set_header_buffer_size(size_t header_buffer_size) { |
(...skipping 13 matching lines...) Loading... |
487 int syn_frame_count_; | 514 int syn_frame_count_; |
488 int syn_reply_frame_count_; | 515 int syn_reply_frame_count_; |
489 int headers_frame_count_; | 516 int headers_frame_count_; |
490 int push_promise_frame_count_; | 517 int push_promise_frame_count_; |
491 int goaway_count_; | 518 int goaway_count_; |
492 int setting_count_; | 519 int setting_count_; |
493 int settings_ack_sent_; | 520 int settings_ack_sent_; |
494 int settings_ack_received_; | 521 int settings_ack_received_; |
495 int continuation_count_; | 522 int continuation_count_; |
496 int altsvc_count_; | 523 int altsvc_count_; |
| 524 int priority_count_; |
497 SpdyAltSvcIR test_altsvc_ir_; | 525 SpdyAltSvcIR test_altsvc_ir_; |
498 SpdyStreamId last_window_update_stream_; | 526 SpdyStreamId last_window_update_stream_; |
499 uint32 last_window_update_delta_; | 527 uint32 last_window_update_delta_; |
500 SpdyStreamId last_push_promise_stream_; | 528 SpdyStreamId last_push_promise_stream_; |
501 SpdyStreamId last_push_promise_promised_stream_; | 529 SpdyStreamId last_push_promise_promised_stream_; |
502 int data_bytes_; | 530 int data_bytes_; |
503 int fin_frame_count_; // The count of RST_STREAM type frames received. | 531 int fin_frame_count_; // The count of RST_STREAM type frames received. |
504 std::string fin_opaque_data_; | 532 std::string fin_opaque_data_; |
505 int fin_flag_count_; // The count of frames with the FIN flag set. | 533 int fin_flag_count_; // The count of frames with the FIN flag set. |
506 int zero_length_data_frame_count_; // The count of zero-length data frames. | 534 int zero_length_data_frame_count_; // The count of zero-length data frames. |
(...skipping 131 matching lines...) Loading... |
638 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. | 666 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. |
639 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | 667 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, |
640 SpdyFramerTest, | 668 SpdyFramerTest, |
641 ::testing::Values(SPDY2, SPDY3, SPDY4)); | 669 ::testing::Values(SPDY2, SPDY3, SPDY4)); |
642 | 670 |
643 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. | 671 // Test that we can encode and decode a SpdyHeaderBlock in serialized form. |
644 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { | 672 TEST_P(SpdyFramerTest, HeaderBlockInBuffer) { |
645 SpdyFramer framer(spdy_version_); | 673 SpdyFramer framer(spdy_version_); |
646 framer.set_enable_compression(false); | 674 framer.set_enable_compression(false); |
647 | 675 |
648 // Encode the header block into a SynStream frame. | 676 // Encode the header block into a Headers frame. |
649 SpdySynStreamIR syn_stream(1); | 677 SpdyHeadersIR headers(1); |
650 syn_stream.set_priority(1); | 678 headers.set_priority(1); |
651 syn_stream.SetHeader("alpha", "beta"); | 679 headers.SetHeader("alpha", "beta"); |
652 syn_stream.SetHeader("gamma", "charlie"); | 680 headers.SetHeader("gamma", "charlie"); |
653 syn_stream.SetHeader("cookie", "key1=value1; key2=value2"); | 681 headers.SetHeader("cookie", "key1=value1; key2=value2"); |
654 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 682 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers)); |
655 EXPECT_TRUE(frame.get() != NULL); | 683 EXPECT_TRUE(frame.get() != NULL); |
656 | 684 |
657 TestSpdyVisitor visitor(spdy_version_); | 685 TestSpdyVisitor visitor(spdy_version_); |
658 visitor.use_compression_ = false; | 686 visitor.use_compression_ = false; |
659 visitor.SimulateInFramer( | 687 visitor.SimulateInFramer( |
660 reinterpret_cast<unsigned char*>(frame->data()), | 688 reinterpret_cast<unsigned char*>(frame->data()), |
661 frame->size()); | 689 frame->size()); |
662 | 690 |
663 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 691 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
664 EXPECT_TRUE(CompareHeaderBlocks(&syn_stream.name_value_block(), | 692 EXPECT_TRUE(CompareHeaderBlocks(&headers.name_value_block(), |
665 &visitor.headers_)); | 693 &visitor.headers_)); |
666 } | 694 } |
667 | 695 |
668 // Test that if there's not a full frame, we fail to parse it. | 696 // Test that if there's not a full frame, we fail to parse it. |
669 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { | 697 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { |
670 SpdyFramer framer(spdy_version_); | 698 SpdyFramer framer(spdy_version_); |
671 framer.set_enable_compression(false); | 699 framer.set_enable_compression(false); |
672 | 700 |
673 // Encode the header block into a SynStream frame. | 701 // Encode the header block into a Headers frame. |
674 SpdySynStreamIR syn_stream(1); | 702 SpdyHeadersIR headers(1); |
675 syn_stream.set_priority(1); | 703 headers.set_priority(1); |
676 syn_stream.SetHeader("alpha", "beta"); | 704 headers.SetHeader("alpha", "beta"); |
677 syn_stream.SetHeader("gamma", "charlie"); | 705 headers.SetHeader("gamma", "charlie"); |
678 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 706 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers)); |
679 EXPECT_TRUE(frame.get() != NULL); | 707 EXPECT_TRUE(frame.get() != NULL); |
680 | 708 |
681 TestSpdyVisitor visitor(spdy_version_); | 709 TestSpdyVisitor visitor(spdy_version_); |
682 visitor.use_compression_ = false; | 710 visitor.use_compression_ = false; |
683 visitor.SimulateInFramer( | 711 visitor.SimulateInFramer( |
684 reinterpret_cast<unsigned char*>(frame->data()), | 712 reinterpret_cast<unsigned char*>(frame->data()), |
685 frame->size() - 2); | 713 frame->size() - 2); |
686 | 714 |
687 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); | 715 EXPECT_EQ(0, visitor.zero_length_control_frame_header_data_count_); |
688 EXPECT_EQ(0u, visitor.headers_.size()); | 716 EXPECT_EQ(0u, visitor.headers_.size()); |
689 } | 717 } |
690 | 718 |
691 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error | 719 // Test that if we receive a SYN_REPLY with stream ID zero, we signal an error |
692 // (but don't crash). | 720 // (but don't crash). |
693 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { | 721 TEST_P(SpdyFramerTest, SynReplyWithStreamIdZero) { |
| 722 if (spdy_version_ > SPDY3) { |
| 723 return; |
| 724 } |
694 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 725 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
695 SpdyFramer framer(spdy_version_); | 726 SpdyFramer framer(spdy_version_); |
696 framer.set_visitor(&visitor); | 727 framer.set_visitor(&visitor); |
697 | 728 |
698 SpdySynReplyIR syn_reply(0); | 729 SpdySynReplyIR syn_reply(0); |
699 syn_reply.SetHeader("alpha", "beta"); | 730 syn_reply.SetHeader("alpha", "beta"); |
700 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeSynReply(syn_reply)); | 731 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeSynReply(syn_reply)); |
701 ASSERT_TRUE(frame.get() != NULL); | 732 ASSERT_TRUE(frame.get() != NULL); |
702 | 733 |
703 // We shouldn't have to read the whole frame before we signal an error. | 734 // We shouldn't have to read the whole frame before we signal an error. |
(...skipping 210 matching lines...) Loading... |
914 } | 945 } |
915 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); | 946 scoped_ptr<SpdyFrame> frame2(framer.SerializeSynStream(syn_stream)); |
916 size_t uncompressed_size2 = visitor->last_payload_len_; | 947 size_t uncompressed_size2 = visitor->last_payload_len_; |
917 size_t compressed_size2 = | 948 size_t compressed_size2 = |
918 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 949 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
919 | 950 |
920 // Expect the second frame to be more compact than the first. | 951 // Expect the second frame to be more compact than the first. |
921 EXPECT_LE(frame2->size(), frame1->size()); | 952 EXPECT_LE(frame2->size(), frame1->size()); |
922 | 953 |
923 // Decompress the first frame | 954 // Decompress the first frame |
924 scoped_ptr<SpdyFrame> frame3(SpdyFramerTestUtil::DecompressFrame( | 955 scoped_ptr<SpdyFrame> frame3( |
925 &framer, *frame1.get())); | 956 SpdyFramerTestUtil::DecompressFrame(&framer, *frame1)); |
926 | 957 |
927 // Decompress the second frame | 958 // Decompress the second frame |
928 visitor.reset(new TestSpdyVisitor(spdy_version_)); | 959 visitor.reset(new TestSpdyVisitor(spdy_version_)); |
929 framer.set_debug_visitor(visitor.get()); | 960 framer.set_debug_visitor(visitor.get()); |
930 scoped_ptr<SpdyFrame> frame4(SpdyFramerTestUtil::DecompressFrame( | 961 scoped_ptr<SpdyFrame> frame4( |
931 &framer, *frame2.get())); | 962 SpdyFramerTestUtil::DecompressFrame(&framer, *frame2)); |
932 size_t uncompressed_size4 = | 963 size_t uncompressed_size4 = |
933 frame4->size() - framer.GetSynStreamMinimumSize(); | 964 frame4->size() - framer.GetSynStreamMinimumSize(); |
934 size_t compressed_size4 = | 965 size_t compressed_size4 = |
935 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); | 966 visitor->last_frame_len_ - framer.GetSynStreamMinimumSize(); |
936 if (IsSpdy2()) { | 967 if (IsSpdy2()) { |
937 EXPECT_EQ(139u, uncompressed_size4); | 968 EXPECT_EQ(139u, uncompressed_size4); |
938 #if defined(USE_SYSTEM_ZLIB) | 969 #if defined(USE_SYSTEM_ZLIB) |
939 EXPECT_EQ(149u, compressed_size4); | 970 EXPECT_EQ(149u, compressed_size4); |
940 #else // !defined(USE_SYSTEM_ZLIB) | 971 #else // !defined(USE_SYSTEM_ZLIB) |
941 EXPECT_EQ(101u, compressed_size4); | 972 EXPECT_EQ(101u, compressed_size4); |
(...skipping 17 matching lines...) Loading... |
959 // Expect frames 3 to be the same as a uncompressed frame created | 990 // Expect frames 3 to be the same as a uncompressed frame created |
960 // from scratch. | 991 // from scratch. |
961 framer.set_enable_compression(false); | 992 framer.set_enable_compression(false); |
962 scoped_ptr<SpdyFrame> uncompressed_frame( | 993 scoped_ptr<SpdyFrame> uncompressed_frame( |
963 framer.SerializeSynStream(syn_stream)); | 994 framer.SerializeSynStream(syn_stream)); |
964 CompareFrames("Uncompressed SYN_STREAM", *frame3, *uncompressed_frame); | 995 CompareFrames("Uncompressed SYN_STREAM", *frame3, *uncompressed_frame); |
965 } | 996 } |
966 | 997 |
967 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { | 998 TEST_P(SpdyFramerTest, CompressEmptyHeaders) { |
968 // See crbug.com/172383 | 999 // See crbug.com/172383 |
969 SpdySynStreamIR syn_stream(1); | 1000 SpdyHeadersIR headers(1); |
970 syn_stream.SetHeader("server", "SpdyServer 1.0"); | 1001 headers.SetHeader("server", "SpdyServer 1.0"); |
971 syn_stream.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); | 1002 headers.SetHeader("date", "Mon 12 Jan 2009 12:12:12 PST"); |
972 syn_stream.SetHeader("status", "200"); | 1003 headers.SetHeader("status", "200"); |
973 syn_stream.SetHeader("version", "HTTP/1.1"); | 1004 headers.SetHeader("version", "HTTP/1.1"); |
974 syn_stream.SetHeader("content-type", "text/html"); | 1005 headers.SetHeader("content-type", "text/html"); |
975 syn_stream.SetHeader("content-length", "12"); | 1006 headers.SetHeader("content-length", "12"); |
976 syn_stream.SetHeader("x-empty-header", ""); | 1007 headers.SetHeader("x-empty-header", ""); |
977 | 1008 |
978 SpdyFramer framer(spdy_version_); | 1009 SpdyFramer framer(spdy_version_); |
979 framer.set_enable_compression(true); | 1010 framer.set_enable_compression(true); |
980 scoped_ptr<SpdyFrame> frame1(framer.SerializeSynStream(syn_stream)); | 1011 scoped_ptr<SpdyFrame> frame1(framer.SerializeHeaders(headers)); |
981 } | 1012 } |
982 | 1013 |
983 TEST_P(SpdyFramerTest, Basic) { | 1014 TEST_P(SpdyFramerTest, Basic) { |
984 const unsigned char kV2Input[] = { | 1015 const unsigned char kV2Input[] = { |
985 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 | 1016 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 |
986 0x00, 0x00, 0x00, 0x14, | 1017 0x00, 0x00, 0x00, 0x14, |
987 0x00, 0x00, 0x00, 0x01, | 1018 0x00, 0x00, 0x00, 0x01, |
988 0x00, 0x00, 0x00, 0x00, | 1019 0x00, 0x00, 0x00, 0x00, |
989 0x00, 0x00, 0x00, 0x01, | 1020 0x00, 0x00, 0x00, 0x01, |
990 0x00, 0x02, 'h', 'h', | 1021 0x00, 0x02, 'h', 'h', |
(...skipping 395 matching lines...) Loading... |
1386 scoped_ptr<SpdyFrame> syn_frame_2(send_framer.SerializeSynStream(syn_stream)); | 1417 scoped_ptr<SpdyFrame> syn_frame_2(send_framer.SerializeSynStream(syn_stream)); |
1387 EXPECT_TRUE(syn_frame_2.get() != NULL); | 1418 EXPECT_TRUE(syn_frame_2.get() != NULL); |
1388 | 1419 |
1389 // Now start decompressing | 1420 // Now start decompressing |
1390 scoped_ptr<SpdyFrame> decompressed; | 1421 scoped_ptr<SpdyFrame> decompressed; |
1391 scoped_ptr<SpdyFrame> uncompressed; | 1422 scoped_ptr<SpdyFrame> uncompressed; |
1392 base::StringPiece serialized_headers; | 1423 base::StringPiece serialized_headers; |
1393 SpdyHeaderBlock decompressed_headers; | 1424 SpdyHeaderBlock decompressed_headers; |
1394 | 1425 |
1395 // Decompress SYN_STREAM #1 | 1426 // Decompress SYN_STREAM #1 |
1396 decompressed.reset(SpdyFramerTestUtil::DecompressFrame( | 1427 decompressed.reset( |
1397 &recv_framer, *syn_frame_1.get())); | 1428 SpdyFramerTestUtil::DecompressFrame(&recv_framer, *syn_frame_1)); |
1398 EXPECT_TRUE(decompressed.get() != NULL); | 1429 EXPECT_TRUE(decompressed.get() != NULL); |
1399 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); | 1430 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); |
1400 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 1431 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
1401 serialized_headers.size(), | 1432 serialized_headers.size(), |
1402 &decompressed_headers)); | 1433 &decompressed_headers)); |
1403 EXPECT_EQ(2u, decompressed_headers.size()); | 1434 EXPECT_EQ(2u, decompressed_headers.size()); |
1404 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); | 1435 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); |
1405 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); | 1436 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); |
1406 | 1437 |
1407 // Decompress SYN_STREAM #2 | 1438 // Decompress SYN_STREAM #2 |
1408 decompressed.reset(SpdyFramerTestUtil::DecompressFrame( | 1439 decompressed.reset( |
1409 &recv_framer, *syn_frame_2.get())); | 1440 SpdyFramerTestUtil::DecompressFrame(&recv_framer, *syn_frame_2)); |
1410 EXPECT_TRUE(decompressed.get() != NULL); | 1441 EXPECT_TRUE(decompressed.get() != NULL); |
1411 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); | 1442 serialized_headers = GetSerializedHeaders(decompressed.get(), send_framer); |
1412 decompressed_headers.clear(); | 1443 decompressed_headers.clear(); |
1413 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), | 1444 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers.data(), |
1414 serialized_headers.size(), | 1445 serialized_headers.size(), |
1415 &decompressed_headers)); | 1446 &decompressed_headers)); |
1416 EXPECT_EQ(3u, decompressed_headers.size()); | 1447 EXPECT_EQ(3u, decompressed_headers.size()); |
1417 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); | 1448 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); |
1418 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); | 1449 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); |
1419 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); | 1450 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); |
1420 } | 1451 } |
1421 | 1452 |
1422 // Verify we don't leak when we leave streams unclosed | |
1423 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressors) { | |
1424 SpdyFramer send_framer(spdy_version_); | |
1425 | |
1426 send_framer.set_enable_compression(true); | |
1427 | |
1428 const char kHeader1[] = "header1"; | |
1429 const char kHeader2[] = "header2"; | |
1430 const char kValue1[] = "value1"; | |
1431 const char kValue2[] = "value2"; | |
1432 | |
1433 SpdySynStreamIR syn_stream(1); | |
1434 syn_stream.SetHeader(kHeader1, kValue1); | |
1435 syn_stream.SetHeader(kHeader2, kValue2); | |
1436 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); | |
1437 EXPECT_TRUE(syn_frame.get() != NULL); | |
1438 | |
1439 StringPiece bytes = "this is a test test test test test!"; | |
1440 SpdyDataIR data_ir(1, bytes); | |
1441 data_ir.set_fin(true); | |
1442 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); | |
1443 EXPECT_TRUE(send_frame.get() != NULL); | |
1444 | |
1445 // Run the inputs through the framer. | |
1446 TestSpdyVisitor visitor(spdy_version_); | |
1447 visitor.use_compression_ = true; | |
1448 const unsigned char* data; | |
1449 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); | |
1450 visitor.SimulateInFramer(data, syn_frame->size()); | |
1451 data = reinterpret_cast<const unsigned char*>(send_frame->data()); | |
1452 visitor.SimulateInFramer(data, send_frame->size()); | |
1453 | |
1454 EXPECT_EQ(0, visitor.error_count_); | |
1455 EXPECT_EQ(1, visitor.syn_frame_count_); | |
1456 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | |
1457 EXPECT_EQ(0, visitor.headers_frame_count_); | |
1458 EXPECT_EQ(bytes.size(), static_cast<unsigned>(visitor.data_bytes_)); | |
1459 EXPECT_EQ(0, visitor.fin_frame_count_); | |
1460 EXPECT_EQ(0, visitor.fin_flag_count_); | |
1461 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | |
1462 EXPECT_EQ(1, visitor.data_frame_count_); | |
1463 } | |
1464 | |
1465 // Verify we can decompress the stream even if handed over to the | 1453 // Verify we can decompress the stream even if handed over to the |
1466 // framer 1 byte at a time. | 1454 // framer 1 byte at a time. |
1467 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { | 1455 TEST_P(SpdyFramerTest, UnclosedStreamDataCompressorsOneByteAtATime) { |
1468 SpdyFramer send_framer(spdy_version_); | 1456 SpdyFramer send_framer(spdy_version_); |
1469 | 1457 |
1470 send_framer.set_enable_compression(true); | 1458 send_framer.set_enable_compression(true); |
1471 | 1459 |
1472 const char kHeader1[] = "header1"; | 1460 const char kHeader1[] = "header1"; |
1473 const char kHeader2[] = "header2"; | 1461 const char kHeader2[] = "header2"; |
1474 const char kValue1[] = "value1"; | 1462 const char kValue1[] = "value1"; |
1475 const char kValue2[] = "value2"; | 1463 const char kValue2[] = "value2"; |
1476 | 1464 |
1477 SpdySynStreamIR syn_stream(1); | 1465 SpdyHeadersIR headers(1); |
1478 syn_stream.SetHeader(kHeader1, kValue1); | 1466 headers.SetHeader(kHeader1, kValue1); |
1479 syn_stream.SetHeader(kHeader2, kValue2); | 1467 headers.SetHeader(kHeader2, kValue2); |
1480 scoped_ptr<SpdyFrame> syn_frame(send_framer.SerializeSynStream(syn_stream)); | 1468 scoped_ptr<SpdyFrame> headers_frame(send_framer.SerializeHeaders(headers)); |
1481 EXPECT_TRUE(syn_frame.get() != NULL); | 1469 EXPECT_TRUE(headers_frame.get() != NULL); |
1482 | 1470 |
1483 const char bytes[] = "this is a test test test test test!"; | 1471 const char bytes[] = "this is a test test test test test!"; |
1484 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); | 1472 SpdyDataIR data_ir(1, StringPiece(bytes, arraysize(bytes))); |
1485 data_ir.set_fin(true); | 1473 data_ir.set_fin(true); |
1486 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); | 1474 scoped_ptr<SpdyFrame> send_frame(send_framer.SerializeData(data_ir)); |
1487 EXPECT_TRUE(send_frame.get() != NULL); | 1475 EXPECT_TRUE(send_frame.get() != NULL); |
1488 | 1476 |
1489 // Run the inputs through the framer. | 1477 // Run the inputs through the framer. |
1490 TestSpdyVisitor visitor(spdy_version_); | 1478 TestSpdyVisitor visitor(spdy_version_); |
1491 visitor.use_compression_ = true; | 1479 visitor.use_compression_ = true; |
1492 const unsigned char* data; | 1480 const unsigned char* data; |
1493 data = reinterpret_cast<const unsigned char*>(syn_frame->data()); | 1481 data = reinterpret_cast<const unsigned char*>(headers_frame->data()); |
1494 for (size_t idx = 0; idx < syn_frame->size(); ++idx) { | 1482 for (size_t idx = 0; idx < headers_frame->size(); ++idx) { |
1495 visitor.SimulateInFramer(data + idx, 1); | 1483 visitor.SimulateInFramer(data + idx, 1); |
1496 ASSERT_EQ(0, visitor.error_count_); | 1484 ASSERT_EQ(0, visitor.error_count_); |
1497 } | 1485 } |
1498 data = reinterpret_cast<const unsigned char*>(send_frame->data()); | 1486 data = reinterpret_cast<const unsigned char*>(send_frame->data()); |
1499 for (size_t idx = 0; idx < send_frame->size(); ++idx) { | 1487 for (size_t idx = 0; idx < send_frame->size(); ++idx) { |
1500 visitor.SimulateInFramer(data + idx, 1); | 1488 visitor.SimulateInFramer(data + idx, 1); |
1501 ASSERT_EQ(0, visitor.error_count_); | 1489 ASSERT_EQ(0, visitor.error_count_); |
1502 } | 1490 } |
1503 | 1491 |
1504 EXPECT_EQ(0, visitor.error_count_); | 1492 EXPECT_EQ(0, visitor.error_count_); |
1505 EXPECT_EQ(1, visitor.syn_frame_count_); | 1493 EXPECT_EQ(0, visitor.syn_frame_count_); |
1506 EXPECT_EQ(0, visitor.syn_reply_frame_count_); | 1494 EXPECT_EQ(0, visitor.syn_reply_frame_count_); |
1507 EXPECT_EQ(0, visitor.headers_frame_count_); | 1495 EXPECT_EQ(1, visitor.headers_frame_count_); |
1508 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); | 1496 EXPECT_EQ(arraysize(bytes), static_cast<unsigned>(visitor.data_bytes_)); |
1509 EXPECT_EQ(0, visitor.fin_frame_count_); | 1497 EXPECT_EQ(0, visitor.fin_frame_count_); |
1510 EXPECT_EQ(0, visitor.fin_flag_count_); | 1498 EXPECT_EQ(0, visitor.fin_flag_count_); |
1511 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 1499 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
1512 EXPECT_EQ(1, visitor.data_frame_count_); | 1500 EXPECT_EQ(1, visitor.data_frame_count_); |
1513 } | 1501 } |
1514 | 1502 |
1515 TEST_P(SpdyFramerTest, WindowUpdateFrame) { | 1503 TEST_P(SpdyFramerTest, WindowUpdateFrame) { |
1516 SpdyFramer framer(spdy_version_); | 1504 SpdyFramer framer(spdy_version_); |
1517 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( | 1505 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( |
(...skipping 63 matching lines...) Loading... |
1581 { | 1569 { |
1582 const char kDescription[] = "'hello' data frame with more padding, no FIN"; | 1570 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
1583 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1571 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1584 0x00, 0x00, 0x00, 0x01, | 1572 0x00, 0x00, 0x00, 0x01, |
1585 0x00, 0x00, 0x00, 0x05, | 1573 0x00, 0x00, 0x00, 0x05, |
1586 'h', 'e', 'l', 'l', | 1574 'h', 'e', 'l', 'l', |
1587 'o' | 1575 'o' |
1588 }; | 1576 }; |
1589 | 1577 |
1590 const unsigned char kV4FrameData[] = { | 1578 const unsigned char kV4FrameData[] = { |
1591 0x01, 0x0b, 0x00, 0x18, // Length = 267. PAD_HIGH and PAD_LOW set. | 1579 0x00, 0xfd, 0x00, 0x08, // Length = 253. PADDED set. |
1592 0x00, 0x00, 0x00, 0x01, | 1580 0x00, 0x00, 0x00, 0x01, |
1593 0x01, 0x04, // Pad Low and Pad High fields. | 1581 0xf7, // Pad length field. |
1594 'h', 'e', 'l', 'l', // Data | 1582 'h', 'e', 'l', 'l', // Data |
1595 'o', | 1583 'o', |
1596 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). | 1584 // Padding of 247 zeros. |
1597 '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', |
1598 '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', |
1599 '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', |
1600 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | |
1601 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1588 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1602 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1589 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1603 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1590 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1604 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1591 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1605 '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', |
1606 '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', |
1607 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1594 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1608 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1595 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1609 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1596 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1610 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1597 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1611 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1598 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1612 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1599 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1613 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1600 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1614 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1601 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1615 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1602 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1616 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1603 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1617 }; | 1604 }; |
1618 const char bytes[] = "hello"; | 1605 const char bytes[] = "hello"; |
1619 | 1606 |
1620 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1607 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1621 // 260 zeros and the pad low/high fields make the overall padding to be 262 | 1608 // 247 zeros and the pad length field make the overall padding to be 248 |
1622 // bytes. | 1609 // bytes. |
1623 data_ir.set_padding_len(262); | 1610 data_ir.set_padding_len(248); |
1624 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1611 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1625 if (IsSpdy4()) { | 1612 if (IsSpdy4()) { |
1626 CompareFrame( | 1613 CompareFrame( |
1627 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1614 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
1628 } else { | 1615 } else { |
1629 CompareFrame( | 1616 CompareFrame( |
1630 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1617 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1631 } | 1618 } |
1632 | 1619 |
1633 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); | 1620 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); |
1634 CompareCharArraysWithHexError( | 1621 CompareCharArraysWithHexError( |
1635 kDescription, | 1622 kDescription, |
1636 reinterpret_cast<const unsigned char*>(frame->data()), | 1623 reinterpret_cast<const unsigned char*>(frame->data()), |
1637 framer.GetDataFrameMinimumSize(), | 1624 framer.GetDataFrameMinimumSize(), |
1638 IsSpdy4() ? kV4FrameData : kV3FrameData, | 1625 IsSpdy4() ? kV4FrameData : kV3FrameData, |
1639 framer.GetDataFrameMinimumSize()); | 1626 framer.GetDataFrameMinimumSize()); |
1640 } | 1627 } |
1641 | 1628 |
1642 { | 1629 { |
1643 const char kDescription[] = "'hello' data frame with few padding, no FIN"; | 1630 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
1644 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1631 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1645 0x00, 0x00, 0x00, 0x01, | 1632 0x00, 0x00, 0x00, 0x01, |
1646 0x00, 0x00, 0x00, 0x05, | 1633 0x00, 0x00, 0x00, 0x05, |
1647 'h', 'e', 'l', 'l', | 1634 'h', 'e', 'l', 'l', |
1648 'o' | 1635 'o' |
1649 }; | 1636 }; |
1650 | 1637 |
1651 const unsigned char kV4FrameData[] = { | 1638 const unsigned char kV4FrameData[] = { |
1652 0x00, 0x0d, 0x00, 0x08, // Length = 13. PAD_LOW set. | 1639 0x00, 0x0d, 0x00, 0x08, // Length = 13. PADDED set. |
1653 0x00, 0x00, 0x00, 0x01, | 1640 0x00, 0x00, 0x00, 0x01, |
1654 0x07, // Pad Low field. | 1641 0x07, // Pad length field. |
1655 'h', 'e', 'l', 'l', // Data | 1642 'h', 'e', 'l', 'l', // Data |
1656 'o', | 1643 'o', |
1657 '0', '0', '0', '0', // Padding | 1644 '0', '0', '0', '0', // Padding |
1658 '0', '0', '0' | 1645 '0', '0', '0' |
1659 }; | 1646 }; |
1660 const char bytes[] = "hello"; | 1647 const char bytes[] = "hello"; |
1661 | 1648 |
1662 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1649 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1663 // 7 zeros and the pad low field make the overall padding to be 8 bytes. | 1650 // 7 zeros and the pad length field make the overall padding to be 8 bytes. |
1664 data_ir.set_padding_len(8); | 1651 data_ir.set_padding_len(8); |
1665 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1652 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1666 if (IsSpdy4()) { | 1653 if (IsSpdy4()) { |
1667 CompareFrame( | 1654 CompareFrame( |
1668 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1655 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
1669 } else { | 1656 } else { |
1670 CompareFrame( | 1657 CompareFrame( |
1671 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1658 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1672 } | 1659 } |
1673 } | 1660 } |
1674 | 1661 |
1675 { | 1662 { |
1676 const char kDescription[] = | 1663 const char kDescription[] = |
1677 "'hello' data frame with 1 byte padding, no FIN"; | 1664 "'hello' data frame with 1 byte padding, no FIN"; |
1678 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1665 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1679 0x00, 0x00, 0x00, 0x01, | 1666 0x00, 0x00, 0x00, 0x01, |
1680 0x00, 0x00, 0x00, 0x05, | 1667 0x00, 0x00, 0x00, 0x05, |
1681 'h', 'e', 'l', 'l', | 1668 'h', 'e', 'l', 'l', |
1682 'o' | 1669 'o' |
1683 }; | 1670 }; |
1684 | 1671 |
1685 const unsigned char kV4FrameData[] = { | 1672 const unsigned char kV4FrameData[] = { |
1686 0x00, 0x06, 0x00, 0x08, // Length = 6. PAD_LOW set. | 1673 0x00, 0x06, 0x00, 0x08, // Length = 6. PADDED set. |
1687 0x00, 0x00, 0x00, 0x01, | 1674 0x00, 0x00, 0x00, 0x01, |
1688 0x00, // Pad Low field. | 1675 0x00, // Pad length field. |
1689 'h', 'e', 'l', 'l', // Data | 1676 'h', 'e', 'l', 'l', // Data |
1690 'o', | 1677 'o', |
1691 }; | 1678 }; |
1692 const char bytes[] = "hello"; | 1679 const char bytes[] = "hello"; |
1693 | 1680 |
1694 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1681 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1695 // The pad low field itself is used for the 1-byte padding and no padding | 1682 // The pad length field itself is used for the 1-byte padding and no padding |
1696 // payload is needed. | 1683 // payload is needed. |
1697 data_ir.set_padding_len(1); | 1684 data_ir.set_padding_len(1); |
1698 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1685 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1699 if (IsSpdy4()) { | 1686 if (IsSpdy4()) { |
1700 CompareFrame( | 1687 CompareFrame( |
1701 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1688 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
1702 } else { | 1689 } else { |
1703 CompareFrame( | 1690 CompareFrame( |
1704 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1691 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1705 } | 1692 } |
(...skipping 129 matching lines...) Loading... |
1835 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); | 1822 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); |
1836 | 1823 |
1837 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); | 1824 SpdyDataIR data_ir(1, StringPiece(kData.data(), kData.size())); |
1838 data_ir.set_fin(true); | 1825 data_ir.set_fin(true); |
1839 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 1826 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
1840 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); | 1827 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); |
1841 } | 1828 } |
1842 } | 1829 } |
1843 | 1830 |
1844 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { | 1831 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { |
| 1832 if (!IsSpdy2() && !IsSpdy3()) { |
| 1833 // SYN_STREAM unsupported in SPDY>3 |
| 1834 return; |
| 1835 } |
1845 SpdyFramer framer(spdy_version_); | 1836 SpdyFramer framer(spdy_version_); |
1846 framer.set_enable_compression(false); | 1837 framer.set_enable_compression(false); |
1847 | 1838 |
1848 { | 1839 { |
1849 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; | 1840 const char kDescription[] = "SYN_STREAM frame, lowest pri, no FIN"; |
1850 | 1841 |
1851 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; | 1842 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0; |
1852 const unsigned char kV2FrameData[] = { | 1843 const unsigned char kV2FrameData[] = { |
1853 0x80, spdy_version_ch_, 0x00, 0x01, | 1844 0x80, spdy_version_ch_, 0x00, 0x01, |
1854 0x00, 0x00, 0x00, 0x20, | 1845 0x00, 0x00, 0x00, 0x20, |
(...skipping 14 matching lines...) Loading... |
1869 kPri, 0x00, 0x00, 0x00, | 1860 kPri, 0x00, 0x00, 0x00, |
1870 0x00, 0x02, 0x00, 0x00, | 1861 0x00, 0x02, 0x00, 0x00, |
1871 0x00, 0x03, 'b', 'a', | 1862 0x00, 0x03, 'b', 'a', |
1872 'r', 0x00, 0x00, 0x00, | 1863 'r', 0x00, 0x00, 0x00, |
1873 0x03, 'f', 'o', 'o', | 1864 0x03, 'f', 'o', 'o', |
1874 0x00, 0x00, 0x00, 0x03, | 1865 0x00, 0x00, 0x00, 0x03, |
1875 'f', 'o', 'o', 0x00, | 1866 'f', 'o', 'o', 0x00, |
1876 0x00, 0x00, 0x03, 'b', | 1867 0x00, 0x00, 0x03, 'b', |
1877 'a', 'r' | 1868 'a', 'r' |
1878 }; | 1869 }; |
1879 const unsigned char kV4FrameData[] = { | |
1880 0x00, 0x17, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS | |
1881 0x00, 0x00, 0x00, 0x01, // Stream 1 | |
1882 0x00, 0x00, 0x00, 0x00, // Non-exclusive dependency 0. Weight 0. | |
1883 0x00, 0x00, 0x03, 0x62, | |
1884 0x61, 0x72, 0x03, 0x66, | |
1885 0x6f, 0x6f, 0x00, 0x03, | |
1886 0x66, 0x6f, 0x6f, 0x03, | |
1887 0x62, 0x61, 0x72, | |
1888 }; | |
1889 SpdySynStreamIR syn_stream(1); | 1870 SpdySynStreamIR syn_stream(1); |
1890 syn_stream.set_priority(framer.GetLowestPriority()); | 1871 syn_stream.set_priority(framer.GetLowestPriority()); |
1891 syn_stream.SetHeader("bar", "foo"); | 1872 syn_stream.SetHeader("bar", "foo"); |
1892 syn_stream.SetHeader("foo", "bar"); | 1873 syn_stream.SetHeader("foo", "bar"); |
1893 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1874 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
1894 if (IsSpdy2()) { | 1875 if (IsSpdy2()) { |
1895 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1876 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
1896 } else if (IsSpdy3()) { | 1877 } else if (IsSpdy3()) { |
1897 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1878 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1898 } else { | 1879 } else { |
1899 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1880 LOG(FATAL) << "Unsupported version in test."; |
1900 } | 1881 } |
1901 } | 1882 } |
1902 | 1883 |
1903 { | 1884 { |
1904 const char kDescription[] = | 1885 const char kDescription[] = |
1905 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " | 1886 "SYN_STREAM frame with a 0-length header name, highest pri, FIN, " |
1906 "max stream ID"; | 1887 "max stream ID"; |
1907 | 1888 |
1908 const unsigned char kV2FrameData[] = { | 1889 const unsigned char kV2FrameData[] = { |
1909 0x80, spdy_version_ch_, 0x00, 0x01, | 1890 0x80, spdy_version_ch_, 0x00, 0x01, |
(...skipping 14 matching lines...) Loading... |
1924 0x7f, 0xff, 0xff, 0xff, | 1905 0x7f, 0xff, 0xff, 0xff, |
1925 0x00, 0x00, 0x00, 0x00, | 1906 0x00, 0x00, 0x00, 0x00, |
1926 0x00, 0x02, 0x00, 0x00, | 1907 0x00, 0x02, 0x00, 0x00, |
1927 0x00, 0x00, 0x00, 0x00, | 1908 0x00, 0x00, 0x00, 0x00, |
1928 0x00, 0x03, 'f', 'o', | 1909 0x00, 0x03, 'f', 'o', |
1929 'o', 0x00, 0x00, 0x00, | 1910 'o', 0x00, 0x00, 0x00, |
1930 0x03, 'f', 'o', 'o', | 1911 0x03, 'f', 'o', 'o', |
1931 0x00, 0x00, 0x00, 0x03, | 1912 0x00, 0x00, 0x00, 0x03, |
1932 'b', 'a', 'r' | 1913 'b', 'a', 'r' |
1933 }; | 1914 }; |
1934 const unsigned char kV4FrameData[] = { | |
1935 0x00, 0x14, 0x01, 0x25, // HEADERS: PRIORITY | FIN | END_HEADERS | |
1936 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | |
1937 0x00, 0x00, 0x00, 0x00, // Non-exclusive dependency 0. Weight 255. | |
1938 0xff, 0x00, 0x00, 0x03, | |
1939 0x66, 0x6f, 0x6f, 0x00, | |
1940 0x03, 0x66, 0x6f, 0x6f, | |
1941 0x03, 0x62, 0x61, 0x72, | |
1942 }; | |
1943 SpdySynStreamIR syn_stream(0x7fffffff); | 1915 SpdySynStreamIR syn_stream(0x7fffffff); |
1944 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1916 syn_stream.set_associated_to_stream_id(0x7fffffff); |
1945 syn_stream.set_priority(framer.GetHighestPriority()); | 1917 syn_stream.set_priority(framer.GetHighestPriority()); |
1946 syn_stream.set_fin(true); | 1918 syn_stream.set_fin(true); |
1947 syn_stream.SetHeader("", "foo"); | 1919 syn_stream.SetHeader("", "foo"); |
1948 syn_stream.SetHeader("foo", "bar"); | 1920 syn_stream.SetHeader("foo", "bar"); |
1949 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1921 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
1950 if (IsSpdy2()) { | 1922 if (IsSpdy2()) { |
1951 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1923 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
1952 } else if (IsSpdy3()) { | 1924 } else if (IsSpdy3()) { |
1953 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1925 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
1954 } else { | 1926 } else { |
1955 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1927 LOG(FATAL) << "Unsupported version in test."; |
1956 } | 1928 } |
1957 } | 1929 } |
1958 | 1930 |
1959 { | 1931 { |
1960 const char kDescription[] = | 1932 const char kDescription[] = |
1961 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " | 1933 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " |
1962 "max stream ID"; | 1934 "max stream ID"; |
1963 | 1935 |
1964 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20; | 1936 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20; |
1965 const unsigned char kV2FrameData[] = { | 1937 const unsigned char kV2FrameData[] = { |
(...skipping 15 matching lines...) Loading... |
1981 0x7f, 0xff, 0xff, 0xff, | 1953 0x7f, 0xff, 0xff, 0xff, |
1982 kPri, 0x00, 0x00, 0x00, | 1954 kPri, 0x00, 0x00, 0x00, |
1983 0x00, 0x02, 0x00, 0x00, | 1955 0x00, 0x02, 0x00, 0x00, |
1984 0x00, 0x03, 'b', 'a', | 1956 0x00, 0x03, 'b', 'a', |
1985 'r', 0x00, 0x00, 0x00, | 1957 'r', 0x00, 0x00, 0x00, |
1986 0x03, 'f', 'o', 'o', | 1958 0x03, 'f', 'o', 'o', |
1987 0x00, 0x00, 0x00, 0x03, | 1959 0x00, 0x00, 0x00, 0x03, |
1988 'f', 'o', 'o', 0x00, | 1960 'f', 'o', 'o', 0x00, |
1989 0x00, 0x00, 0x00 | 1961 0x00, 0x00, 0x00 |
1990 }; | 1962 }; |
1991 const unsigned char kV4FrameData[] = { | |
1992 0x00, 0x14, 0x01, 0x25, // HEADERS: PRIORITY | FIN | END_HEADERS | |
1993 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | |
1994 0x00, 0x00, 0x00, 0x00, // Non-exclusive dependency 0. Weight 219. | |
1995 0xdb, 0x00, 0x03, 0x62, | |
1996 0x61, 0x72, 0x03, 0x66, | |
1997 0x6f, 0x6f, 0x00, 0x03, | |
1998 0x66, 0x6f, 0x6f, 0x00, | |
1999 }; | |
2000 SpdySynStreamIR syn_stream(0x7fffffff); | 1963 SpdySynStreamIR syn_stream(0x7fffffff); |
2001 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1964 syn_stream.set_associated_to_stream_id(0x7fffffff); |
2002 syn_stream.set_priority(1); | 1965 syn_stream.set_priority(1); |
2003 syn_stream.set_fin(true); | 1966 syn_stream.set_fin(true); |
2004 syn_stream.SetHeader("bar", "foo"); | 1967 syn_stream.SetHeader("bar", "foo"); |
2005 syn_stream.SetHeader("foo", ""); | 1968 syn_stream.SetHeader("foo", ""); |
2006 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 1969 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
2007 if (IsSpdy2()) { | 1970 if (IsSpdy2()) { |
2008 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 1971 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2009 } else if (IsSpdy3()) { | 1972 } else if (IsSpdy3()) { |
2010 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 1973 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2011 } else { | 1974 } else { |
2012 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 1975 LOG(FATAL) << "Unsupported version in test."; |
2013 } | 1976 } |
2014 } | 1977 } |
2015 } | 1978 } |
2016 | 1979 |
2017 // TODO(phajdan.jr): Clean up after we no longer need | 1980 // TODO(phajdan.jr): Clean up after we no longer need |
2018 // to workaround http://crbug.com/139744. | 1981 // to workaround http://crbug.com/139744. |
2019 #if !defined(USE_SYSTEM_ZLIB) | 1982 #if !defined(USE_SYSTEM_ZLIB) |
2020 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { | 1983 TEST_P(SpdyFramerTest, CreateSynStreamCompressed) { |
| 1984 if (!IsSpdy2() && !IsSpdy3()) { |
| 1985 // SYN_STREAM not supported for SPDY>3 |
| 1986 return; |
| 1987 } |
2021 SpdyFramer framer(spdy_version_); | 1988 SpdyFramer framer(spdy_version_); |
2022 framer.set_enable_compression(true); | 1989 framer.set_enable_compression(true); |
2023 | 1990 |
2024 { | 1991 { |
2025 const char kDescription[] = | 1992 const char kDescription[] = |
2026 "SYN_STREAM frame, low pri, no FIN"; | 1993 "SYN_STREAM frame, low pri, no FIN"; |
2027 | 1994 |
2028 const SpdyPriority priority = IsSpdy2() ? 2 : 4; | 1995 const SpdyPriority priority = IsSpdy2() ? 2 : 4; |
2029 const unsigned char kV2FrameData[] = { | 1996 const unsigned char kV2FrameData[] = { |
2030 0x80, spdy_version_ch_, 0x00, 0x01, | 1997 0x80, spdy_version_ch_, 0x00, 0x01, |
(...skipping 34 matching lines...) Loading... |
2065 SpdySynStreamIR syn_stream(1); | 2032 SpdySynStreamIR syn_stream(1); |
2066 syn_stream.set_priority(priority); | 2033 syn_stream.set_priority(priority); |
2067 syn_stream.SetHeader("bar", "foo"); | 2034 syn_stream.SetHeader("bar", "foo"); |
2068 syn_stream.SetHeader("foo", "bar"); | 2035 syn_stream.SetHeader("foo", "bar"); |
2069 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 2036 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
2070 if (IsSpdy2()) { | 2037 if (IsSpdy2()) { |
2071 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2038 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2072 } else if (IsSpdy3()) { | 2039 } else if (IsSpdy3()) { |
2073 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2040 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2074 } else { | 2041 } else { |
2075 // Deflate compression doesn't apply to HPACK. | 2042 LOG(FATAL) << "Unsupported version in test."; |
2076 } | 2043 } |
2077 } | 2044 } |
2078 } | 2045 } |
2079 #endif // !defined(USE_SYSTEM_ZLIB) | 2046 #endif // !defined(USE_SYSTEM_ZLIB) |
2080 | 2047 |
2081 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { | 2048 TEST_P(SpdyFramerTest, CreateSynReplyUncompressed) { |
| 2049 if (spdy_version_ > SPDY3) { |
| 2050 // SYN_REPLY unsupported in SPDY>3 |
| 2051 return; |
| 2052 } |
2082 SpdyFramer framer(spdy_version_); | 2053 SpdyFramer framer(spdy_version_); |
2083 framer.set_enable_compression(false); | 2054 framer.set_enable_compression(false); |
2084 | 2055 |
2085 { | 2056 { |
2086 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 2057 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2087 | 2058 |
2088 const unsigned char kV2FrameData[] = { | 2059 const unsigned char kV2FrameData[] = { |
2089 0x80, spdy_version_ch_, 0x00, 0x02, | 2060 0x80, spdy_version_ch_, 0x00, 0x02, |
2090 0x00, 0x00, 0x00, 0x1C, | 2061 0x00, 0x00, 0x00, 0x1C, |
2091 0x00, 0x00, 0x00, 0x01, | 2062 0x00, 0x00, 0x00, 0x01, |
(...skipping 10 matching lines...) Loading... |
2102 0x00, 0x00, 0x00, 0x01, | 2073 0x00, 0x00, 0x00, 0x01, |
2103 0x00, 0x00, 0x00, 0x02, | 2074 0x00, 0x00, 0x00, 0x02, |
2104 0x00, 0x00, 0x00, 0x03, | 2075 0x00, 0x00, 0x00, 0x03, |
2105 'b', 'a', 'r', 0x00, | 2076 'b', 'a', 'r', 0x00, |
2106 0x00, 0x00, 0x03, 'f', | 2077 0x00, 0x00, 0x03, 'f', |
2107 'o', 'o', 0x00, 0x00, | 2078 'o', 'o', 0x00, 0x00, |
2108 0x00, 0x03, 'f', 'o', | 2079 0x00, 0x03, 'f', 'o', |
2109 'o', 0x00, 0x00, 0x00, | 2080 'o', 0x00, 0x00, 0x00, |
2110 0x03, 'b', 'a', 'r' | 2081 0x03, 'b', 'a', 'r' |
2111 }; | 2082 }; |
2112 const unsigned char kV4FrameData[] = { | |
2113 0x00, 0x12, 0x01, 0x04, // HEADER: END_HEADERS | |
2114 0x00, 0x00, 0x00, 0x01, // Stream 1 | |
2115 0x00, 0x03, 0x62, 0x61, // @.ba | |
2116 0x72, 0x03, 0x66, 0x6f, // r.fo | |
2117 0x6f, 0x00, 0x03, 0x66, // o@.f | |
2118 0x6f, 0x6f, 0x03, 0x62, // oo.b | |
2119 0x61, 0x72, // ar | |
2120 }; | |
2121 SpdySynReplyIR syn_reply(1); | 2083 SpdySynReplyIR syn_reply(1); |
2122 syn_reply.SetHeader("bar", "foo"); | 2084 syn_reply.SetHeader("bar", "foo"); |
2123 syn_reply.SetHeader("foo", "bar"); | 2085 syn_reply.SetHeader("foo", "bar"); |
2124 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2086 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2125 if (IsSpdy2()) { | 2087 if (IsSpdy2()) { |
2126 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2088 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2127 } else if (IsSpdy3()) { | 2089 } else if (IsSpdy3()) { |
2128 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2090 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2129 } else { | 2091 } else { |
2130 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2092 LOG(FATAL) << "Unsupported version in test."; |
2131 } | 2093 } |
2132 } | 2094 } |
2133 | 2095 |
2134 { | 2096 { |
2135 const char kDescription[] = | 2097 const char kDescription[] = |
2136 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; | 2098 "SYN_REPLY frame with a 0-length header name, FIN, max stream ID"; |
2137 | 2099 |
2138 const unsigned char kV2FrameData[] = { | 2100 const unsigned char kV2FrameData[] = { |
2139 0x80, spdy_version_ch_, 0x00, 0x02, | 2101 0x80, spdy_version_ch_, 0x00, 0x02, |
2140 0x01, 0x00, 0x00, 0x19, | 2102 0x01, 0x00, 0x00, 0x19, |
(...skipping 11 matching lines...) Loading... |
2152 0x7f, 0xff, 0xff, 0xff, | 2114 0x7f, 0xff, 0xff, 0xff, |
2153 0x00, 0x00, 0x00, 0x02, | 2115 0x00, 0x00, 0x00, 0x02, |
2154 0x00, 0x00, 0x00, 0x00, | 2116 0x00, 0x00, 0x00, 0x00, |
2155 0x00, 0x00, 0x00, 0x03, | 2117 0x00, 0x00, 0x00, 0x03, |
2156 'f', 'o', 'o', 0x00, | 2118 'f', 'o', 'o', 0x00, |
2157 0x00, 0x00, 0x03, 'f', | 2119 0x00, 0x00, 0x03, 'f', |
2158 'o', 'o', 0x00, 0x00, | 2120 'o', 'o', 0x00, 0x00, |
2159 0x00, 0x03, 'b', 'a', | 2121 0x00, 0x03, 'b', 'a', |
2160 'r' | 2122 'r' |
2161 }; | 2123 }; |
2162 const unsigned char kV4FrameData[] = { | |
2163 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS | |
2164 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | |
2165 0x00, 0x00, 0x03, 0x66, // @..f | |
2166 0x6f, 0x6f, 0x00, 0x03, // oo@. | |
2167 0x66, 0x6f, 0x6f, 0x03, // foo. | |
2168 0x62, 0x61, 0x72, // bar | |
2169 }; | |
2170 SpdySynReplyIR syn_reply(0x7fffffff); | 2124 SpdySynReplyIR syn_reply(0x7fffffff); |
2171 syn_reply.set_fin(true); | 2125 syn_reply.set_fin(true); |
2172 syn_reply.SetHeader("", "foo"); | 2126 syn_reply.SetHeader("", "foo"); |
2173 syn_reply.SetHeader("foo", "bar"); | 2127 syn_reply.SetHeader("foo", "bar"); |
2174 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2128 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2175 if (IsSpdy2()) { | 2129 if (IsSpdy2()) { |
2176 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2130 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2177 } else if (IsSpdy3()) { | 2131 } else if (IsSpdy3()) { |
2178 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2132 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2179 } else { | 2133 } else { |
2180 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2134 LOG(FATAL) << "Unsupported version in test."; |
2181 } | 2135 } |
2182 } | 2136 } |
2183 | 2137 |
2184 { | 2138 { |
2185 const char kDescription[] = | 2139 const char kDescription[] = |
2186 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; | 2140 "SYN_REPLY frame with a 0-length header val, FIN, max stream ID"; |
2187 | 2141 |
2188 const unsigned char kV2FrameData[] = { | 2142 const unsigned char kV2FrameData[] = { |
2189 0x80, spdy_version_ch_, 0x00, 0x02, | 2143 0x80, spdy_version_ch_, 0x00, 0x02, |
2190 0x01, 0x00, 0x00, 0x19, | 2144 0x01, 0x00, 0x00, 0x19, |
(...skipping 11 matching lines...) Loading... |
2202 0x7f, 0xff, 0xff, 0xff, | 2156 0x7f, 0xff, 0xff, 0xff, |
2203 0x00, 0x00, 0x00, 0x02, | 2157 0x00, 0x00, 0x00, 0x02, |
2204 0x00, 0x00, 0x00, 0x03, | 2158 0x00, 0x00, 0x00, 0x03, |
2205 'b', 'a', 'r', 0x00, | 2159 'b', 'a', 'r', 0x00, |
2206 0x00, 0x00, 0x03, 'f', | 2160 0x00, 0x00, 0x03, 'f', |
2207 'o', 'o', 0x00, 0x00, | 2161 'o', 'o', 0x00, 0x00, |
2208 0x00, 0x03, 'f', 'o', | 2162 0x00, 0x03, 'f', 'o', |
2209 'o', 0x00, 0x00, 0x00, | 2163 'o', 0x00, 0x00, 0x00, |
2210 0x00 | 2164 0x00 |
2211 }; | 2165 }; |
2212 const unsigned char kV4FrameData[] = { | |
2213 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS | |
2214 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | |
2215 0x00, 0x03, 0x62, 0x61, // @.ba | |
2216 0x72, 0x03, 0x66, 0x6f, // r.fo | |
2217 0x6f, 0x00, 0x03, 0x66, // o@.f | |
2218 0x6f, 0x6f, 0x00, // oo. | |
2219 }; | |
2220 SpdySynReplyIR syn_reply(0x7fffffff); | 2166 SpdySynReplyIR syn_reply(0x7fffffff); |
2221 syn_reply.set_fin(true); | 2167 syn_reply.set_fin(true); |
2222 syn_reply.SetHeader("bar", "foo"); | 2168 syn_reply.SetHeader("bar", "foo"); |
2223 syn_reply.SetHeader("foo", ""); | 2169 syn_reply.SetHeader("foo", ""); |
2224 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2170 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2225 if (IsSpdy2()) { | 2171 if (IsSpdy2()) { |
2226 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2172 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2227 } else if (IsSpdy3()) { | 2173 } else if (IsSpdy3()) { |
2228 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2174 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2229 } else { | 2175 } else { |
2230 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2176 LOG(FATAL) << "Unsupported version in test."; |
2231 } | 2177 } |
2232 } | 2178 } |
2233 } | 2179 } |
2234 | 2180 |
2235 // TODO(phajdan.jr): Clean up after we no longer need | 2181 // TODO(phajdan.jr): Clean up after we no longer need |
2236 // to workaround http://crbug.com/139744. | 2182 // to workaround http://crbug.com/139744. |
2237 #if !defined(USE_SYSTEM_ZLIB) | 2183 #if !defined(USE_SYSTEM_ZLIB) |
2238 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { | 2184 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { |
| 2185 if (spdy_version_ > SPDY3) { |
| 2186 // SYN_REPLY unsupported in SPDY>3 |
| 2187 return; |
| 2188 } |
2239 SpdyFramer framer(spdy_version_); | 2189 SpdyFramer framer(spdy_version_); |
2240 framer.set_enable_compression(true); | 2190 framer.set_enable_compression(true); |
2241 | 2191 |
2242 { | 2192 { |
2243 const char kDescription[] = "SYN_REPLY frame, no FIN"; | 2193 const char kDescription[] = "SYN_REPLY frame, no FIN"; |
2244 | 2194 |
2245 const unsigned char kV2FrameData[] = { | 2195 const unsigned char kV2FrameData[] = { |
2246 0x80, spdy_version_ch_, 0x00, 0x02, | 2196 0x80, spdy_version_ch_, 0x00, 0x02, |
2247 0x00, 0x00, 0x00, 0x32, | 2197 0x00, 0x00, 0x00, 0x32, |
2248 0x00, 0x00, 0x00, 0x01, | 2198 0x00, 0x00, 0x00, 0x01, |
(...skipping 29 matching lines...) Loading... |
2278 }; | 2228 }; |
2279 SpdySynReplyIR syn_reply(1); | 2229 SpdySynReplyIR syn_reply(1); |
2280 syn_reply.SetHeader("bar", "foo"); | 2230 syn_reply.SetHeader("bar", "foo"); |
2281 syn_reply.SetHeader("foo", "bar"); | 2231 syn_reply.SetHeader("foo", "bar"); |
2282 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); | 2232 scoped_ptr<SpdyFrame> frame(framer.SerializeSynReply(syn_reply)); |
2283 if (IsSpdy2()) { | 2233 if (IsSpdy2()) { |
2284 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2234 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2285 } else if (IsSpdy3()) { | 2235 } else if (IsSpdy3()) { |
2286 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2236 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2287 } else { | 2237 } else { |
2288 // Deflate compression doesn't apply to HPACK. | 2238 LOG(FATAL) << "Unsupported version in test."; |
2289 } | 2239 } |
2290 } | 2240 } |
2291 } | 2241 } |
2292 #endif // !defined(USE_SYSTEM_ZLIB) | 2242 #endif // !defined(USE_SYSTEM_ZLIB) |
2293 | 2243 |
2294 TEST_P(SpdyFramerTest, CreateRstStream) { | 2244 TEST_P(SpdyFramerTest, CreateRstStream) { |
2295 SpdyFramer framer(spdy_version_); | 2245 SpdyFramer framer(spdy_version_); |
2296 | 2246 |
2297 { | 2247 { |
2298 const char kDescription[] = "RST_STREAM frame"; | 2248 const char kDescription[] = "RST_STREAM frame"; |
(...skipping 81 matching lines...) Loading... |
2380 0x0a, 0x0b, 0x0c, 0x0d, | 2330 0x0a, 0x0b, 0x0c, 0x0d, |
2381 }; | 2331 }; |
2382 const unsigned char kV3FrameData[] = { | 2332 const unsigned char kV3FrameData[] = { |
2383 0x80, spdy_version_ch_, 0x00, 0x04, | 2333 0x80, spdy_version_ch_, 0x00, 0x04, |
2384 0x00, 0x00, 0x00, 0x0c, | 2334 0x00, 0x00, 0x00, 0x0c, |
2385 0x00, 0x00, 0x00, 0x01, | 2335 0x00, 0x00, 0x00, 0x01, |
2386 0x01, 0x00, 0x00, 0x07, | 2336 0x01, 0x00, 0x00, 0x07, |
2387 0x0a, 0x0b, 0x0c, 0x0d, | 2337 0x0a, 0x0b, 0x0c, 0x0d, |
2388 }; | 2338 }; |
2389 const unsigned char kV4FrameData[] = { | 2339 const unsigned char kV4FrameData[] = { |
2390 0x00, 0x05, 0x04, 0x00, | 2340 0x00, 0x06, 0x04, 0x00, |
2391 0x00, 0x00, 0x00, 0x00, | 2341 0x00, 0x00, 0x00, 0x00, |
2392 0x04, 0x0a, 0x0b, 0x0c, | 2342 0x00, 0x04, 0x0a, 0x0b, |
2393 0x0d, | 2343 0x0c, 0x0d, |
2394 }; | 2344 }; |
2395 | 2345 |
2396 uint32 kValue = 0x0a0b0c0d; | 2346 uint32 kValue = 0x0a0b0c0d; |
2397 SpdySettingsIR settings_ir; | 2347 SpdySettingsIR settings_ir; |
2398 | 2348 |
2399 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); | 2349 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); |
2400 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; | 2350 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; |
2401 SettingsMap settings; | 2351 SettingsMap settings; |
2402 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); | 2352 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); |
2403 EXPECT_EQ(kFlags, settings[kId].first); | 2353 EXPECT_EQ(kFlags, settings[kId].first); |
(...skipping 39 matching lines...) Loading... |
2443 0x00, 0x00, 0x00, 0x06, | 2393 0x00, 0x00, 0x00, 0x06, |
2444 0x00, 0x00, 0x00, 0x03, // 3rd Setting | 2394 0x00, 0x00, 0x00, 0x03, // 3rd Setting |
2445 0x00, 0x00, 0x00, 0x07, | 2395 0x00, 0x00, 0x00, 0x07, |
2446 0x00, 0x00, 0x00, 0x04, // 4th Setting | 2396 0x00, 0x00, 0x00, 0x04, // 4th Setting |
2447 0x00, 0x00, 0x00, 0x08, | 2397 0x00, 0x00, 0x00, 0x08, |
2448 }; | 2398 }; |
2449 // These end up seemingly out of order because of the way that our internal | 2399 // These end up seemingly out of order because of the way that our internal |
2450 // ordering for settings_ir works. HTTP2 has no requirement on ordering on | 2400 // ordering for settings_ir works. HTTP2 has no requirement on ordering on |
2451 // the wire. | 2401 // the wire. |
2452 const unsigned char kV4FrameData[] = { | 2402 const unsigned char kV4FrameData[] = { |
2453 0x00, 0x14, 0x04, 0x00, | 2403 0x00, 0x18, 0x04, 0x00, |
2454 0x00, 0x00, 0x00, 0x00, | 2404 0x00, 0x00, 0x00, 0x00, |
2455 0x03, // 3rd Setting | 2405 0x00, 0x03, // 3rd Setting |
2456 0x00, 0x00, 0x00, 0x07, | 2406 0x00, 0x00, 0x00, 0x07, |
2457 0x04, // 4th Setting | 2407 0x00, 0x04, // 4th Setting |
2458 0x00, 0x00, 0x00, 0x08, | 2408 0x00, 0x00, 0x00, 0x08, |
2459 0x01, // 1st Setting | 2409 0x00, 0x01, // 1st Setting |
2460 0x00, 0x00, 0x00, 0x05, | 2410 0x00, 0x00, 0x00, 0x05, |
2461 0x02, // 2nd Setting | 2411 0x00, 0x02, // 2nd Setting |
2462 0x00, 0x00, 0x00, 0x06, | 2412 0x00, 0x00, 0x00, 0x06, |
2463 }; | 2413 }; |
2464 | 2414 |
2465 SpdySettingsIR settings_ir; | 2415 SpdySettingsIR settings_ir; |
2466 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), | 2416 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1), |
2467 false, // persist | 2417 false, // persist |
2468 false, // persisted | 2418 false, // persisted |
2469 5); | 2419 5); |
2470 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), | 2420 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 2), |
2471 false, // persist | 2421 false, // persist |
(...skipping 295 matching lines...) Loading... |
2767 headers_ir.SetHeader("foo", ""); | 2717 headers_ir.SetHeader("foo", ""); |
2768 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 2718 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
2769 if (IsSpdy2()) { | 2719 if (IsSpdy2()) { |
2770 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); | 2720 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); |
2771 } else if (IsSpdy3()) { | 2721 } else if (IsSpdy3()) { |
2772 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2722 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2773 } else { | 2723 } else { |
2774 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2724 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2775 } | 2725 } |
2776 } | 2726 } |
| 2727 |
| 2728 { |
| 2729 const char kDescription[] = |
| 2730 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; |
| 2731 |
| 2732 const unsigned char kV4FrameData[] = { |
| 2733 0x00, 0x14, 0x01, 0x25, // Headers: FIN | END_HEADERS | PRIORITY |
| 2734 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
| 2735 0x00, 0x00, 0x00, 0x00, // parent stream |
| 2736 0xdb, // weight |
| 2737 0x00, 0x03, 0x62, 0x61, // @.ba |
| 2738 0x72, 0x03, 0x66, 0x6f, // r.fo |
| 2739 0x6f, 0x00, 0x03, 0x66, // o@.f |
| 2740 0x6f, 0x6f, 0x00, // oo. |
| 2741 }; |
| 2742 SpdyHeadersIR headers_ir(0x7fffffff); |
| 2743 headers_ir.set_fin(true); |
| 2744 headers_ir.set_priority(1); |
| 2745 headers_ir.set_has_priority(true); |
| 2746 headers_ir.SetHeader("bar", "foo"); |
| 2747 headers_ir.SetHeader("foo", ""); |
| 2748 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
| 2749 if (IsSpdy2() || IsSpdy3()) { |
| 2750 // HEADERS with priority not supported. |
| 2751 } else { |
| 2752 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
| 2753 } |
| 2754 } |
2777 } | 2755 } |
2778 | 2756 |
2779 // TODO(phajdan.jr): Clean up after we no longer need | 2757 // TODO(phajdan.jr): Clean up after we no longer need |
2780 // to workaround http://crbug.com/139744. | 2758 // to workaround http://crbug.com/139744. |
2781 #if !defined(USE_SYSTEM_ZLIB) | 2759 #if !defined(USE_SYSTEM_ZLIB) |
2782 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { | 2760 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { |
2783 SpdyFramer framer(spdy_version_); | 2761 SpdyFramer framer(spdy_version_); |
2784 framer.set_enable_compression(true); | 2762 framer.set_enable_compression(true); |
2785 | 2763 |
2786 { | 2764 { |
(...skipping 207 matching lines...) Loading... |
2994 SpdyAltSvcIR altsvc_ir(3); | 2972 SpdyAltSvcIR altsvc_ir(3); |
2995 altsvc_ir.set_max_age(5); | 2973 altsvc_ir.set_max_age(5); |
2996 altsvc_ir.set_port(443); | 2974 altsvc_ir.set_port(443); |
2997 altsvc_ir.set_protocol_id("pid1"); | 2975 altsvc_ir.set_protocol_id("pid1"); |
2998 altsvc_ir.set_host("host"); | 2976 altsvc_ir.set_host("host"); |
2999 altsvc_ir.set_origin("origin"); | 2977 altsvc_ir.set_origin("origin"); |
3000 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); | 2978 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
3001 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2979 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
3002 } | 2980 } |
3003 | 2981 |
| 2982 TEST_P(SpdyFramerTest, CreatePriority) { |
| 2983 if (spdy_version_ <= SPDY3) { |
| 2984 return; |
| 2985 } |
| 2986 |
| 2987 SpdyFramer framer(spdy_version_); |
| 2988 |
| 2989 const char kDescription[] = "PRIORITY frame"; |
| 2990 const char kType = static_cast<unsigned char>( |
| 2991 SpdyConstants::SerializeFrameType(spdy_version_, PRIORITY)); |
| 2992 const unsigned char kFrameData[] = { |
| 2993 0x00, 0x05, kType, 0x00, |
| 2994 0x00, 0x00, 0x00, 0x02, // Stream ID = 2 |
| 2995 0x80, 0x00, 0x00, 0x01, // Exclusive dependency, parent stream ID = 1 |
| 2996 0x10, // Weight = 16 |
| 2997 }; |
| 2998 SpdyPriorityIR priority_ir(2, 1, 16, true); |
| 2999 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(priority_ir)); |
| 3000 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 3001 } |
| 3002 |
3004 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { | 3003 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { |
| 3004 if (spdy_version_ > SPDY3) { |
| 3005 // SYN_STREAM not supported in SPDY>3 |
| 3006 return; |
| 3007 } |
3005 SpdyFramer framer(spdy_version_); | 3008 SpdyFramer framer(spdy_version_); |
3006 SpdySynStreamIR syn_stream(1); | 3009 SpdySynStreamIR syn_stream(1); |
3007 syn_stream.set_priority(1); | 3010 syn_stream.set_priority(1); |
3008 syn_stream.SetHeader("aa", "vv"); | 3011 syn_stream.SetHeader("aa", "vv"); |
3009 syn_stream.SetHeader("bb", "ww"); | 3012 syn_stream.SetHeader("bb", "ww"); |
3010 SpdyHeaderBlock headers = syn_stream.name_value_block(); | 3013 SpdyHeaderBlock headers = syn_stream.name_value_block(); |
3011 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3014 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
3012 EXPECT_TRUE(control_frame.get() != NULL); | 3015 EXPECT_TRUE(control_frame.get() != NULL); |
3013 TestSpdyVisitor visitor(spdy_version_); | 3016 TestSpdyVisitor visitor(spdy_version_); |
3014 visitor.use_compression_ = true; | 3017 visitor.use_compression_ = true; |
3015 visitor.SimulateInFramer( | 3018 visitor.SimulateInFramer( |
3016 reinterpret_cast<unsigned char*>(control_frame->data()), | 3019 reinterpret_cast<unsigned char*>(control_frame->data()), |
3017 control_frame->size()); | 3020 control_frame->size()); |
3018 EXPECT_EQ(1, visitor.syn_frame_count_); | 3021 EXPECT_EQ(1, visitor.syn_frame_count_); |
3019 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3022 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
3020 } | 3023 } |
3021 | 3024 |
3022 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { | 3025 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { |
| 3026 if (spdy_version_ > SPDY3) { |
| 3027 return; |
| 3028 } |
3023 SpdyFramer framer(spdy_version_); | 3029 SpdyFramer framer(spdy_version_); |
3024 SpdySynReplyIR syn_reply(1); | 3030 SpdySynReplyIR syn_reply(1); |
3025 syn_reply.SetHeader("alpha", "beta"); | 3031 syn_reply.SetHeader("alpha", "beta"); |
3026 syn_reply.SetHeader("gamma", "delta"); | 3032 syn_reply.SetHeader("gamma", "delta"); |
3027 SpdyHeaderBlock headers = syn_reply.name_value_block(); | 3033 SpdyHeaderBlock headers = syn_reply.name_value_block(); |
3028 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynReply(syn_reply)); | 3034 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynReply(syn_reply)); |
3029 EXPECT_TRUE(control_frame.get() != NULL); | 3035 EXPECT_TRUE(control_frame.get() != NULL); |
3030 TestSpdyVisitor visitor(spdy_version_); | 3036 TestSpdyVisitor visitor(spdy_version_); |
3031 visitor.use_compression_ = true; | 3037 visitor.use_compression_ = true; |
3032 visitor.SimulateInFramer( | 3038 visitor.SimulateInFramer( |
(...skipping 194 matching lines...) Loading... |
3227 // Check that the framer stops delivering header data chunks once the visitor | 3233 // Check that the framer stops delivering header data chunks once the visitor |
3228 // declares it doesn't want any more. This is important to guard against | 3234 // declares it doesn't want any more. This is important to guard against |
3229 // "zip bomb" types of attacks. | 3235 // "zip bomb" types of attacks. |
3230 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { | 3236 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { |
3231 const size_t kHeaderBufferChunks = 4; | 3237 const size_t kHeaderBufferChunks = 4; |
3232 const size_t kHeaderBufferSize = | 3238 const size_t kHeaderBufferSize = |
3233 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 3239 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
3234 const size_t kBigValueSize = kHeaderBufferSize * 2; | 3240 const size_t kBigValueSize = kHeaderBufferSize * 2; |
3235 string big_value(kBigValueSize, 'x'); | 3241 string big_value(kBigValueSize, 'x'); |
3236 SpdyFramer framer(spdy_version_); | 3242 SpdyFramer framer(spdy_version_); |
3237 SpdySynStreamIR syn_stream(1); | 3243 SpdyHeadersIR headers(1); |
3238 syn_stream.set_priority(1); | 3244 headers.set_priority(1); |
3239 syn_stream.set_fin(true); | 3245 headers.set_fin(true); |
3240 syn_stream.SetHeader("aa", big_value); | 3246 headers.SetHeader("aa", big_value); |
3241 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3247 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); |
3242 EXPECT_TRUE(control_frame.get() != NULL); | 3248 EXPECT_TRUE(control_frame.get() != NULL); |
3243 TestSpdyVisitor visitor(spdy_version_); | 3249 TestSpdyVisitor visitor(spdy_version_); |
3244 visitor.set_header_buffer_size(kHeaderBufferSize); | 3250 visitor.set_header_buffer_size(kHeaderBufferSize); |
3245 visitor.use_compression_ = true; | 3251 visitor.use_compression_ = true; |
3246 visitor.SimulateInFramer( | 3252 visitor.SimulateInFramer( |
3247 reinterpret_cast<unsigned char*>(control_frame->data()), | 3253 reinterpret_cast<unsigned char*>(control_frame->data()), |
3248 control_frame->size()); | 3254 control_frame->size()); |
3249 EXPECT_FALSE(visitor.header_buffer_valid_); | 3255 EXPECT_FALSE(visitor.header_buffer_valid_); |
3250 EXPECT_EQ(1, visitor.error_count_); | 3256 EXPECT_EQ(1, visitor.error_count_); |
3251 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, | 3257 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, |
(...skipping 200 matching lines...) Loading... |
3452 0x00, 0x00, 0x00, 0x1C, | 3458 0x00, 0x00, 0x00, 0x1C, |
3453 0x00, 0x00, 0x00, 0x03, | 3459 0x00, 0x00, 0x00, 0x03, |
3454 0x00, 0x00, 0x00, 0x01, // 1st Setting | 3460 0x00, 0x00, 0x00, 0x01, // 1st Setting |
3455 0x00, 0x00, 0x00, 0x02, | 3461 0x00, 0x00, 0x00, 0x02, |
3456 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting | 3462 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting |
3457 0x00, 0x00, 0x00, 0x03, | 3463 0x00, 0x00, 0x00, 0x03, |
3458 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting | 3464 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting |
3459 0x00, 0x00, 0x00, 0x03, | 3465 0x00, 0x00, 0x00, 0x03, |
3460 }; | 3466 }; |
3461 const unsigned char kV4FrameData[] = { | 3467 const unsigned char kV4FrameData[] = { |
3462 0x00, 0x0f, 0x04, 0x00, | 3468 0x00, 0x12, 0x04, 0x00, |
3463 0x00, 0x00, 0x00, 0x00, | 3469 0x00, 0x00, 0x00, 0x00, |
3464 0x01, // 1st Setting | 3470 0x00, 0x01, // 1st Setting |
3465 0x00, 0x00, 0x00, 0x02, | 3471 0x00, 0x00, 0x00, 0x02, |
3466 0x01, // 2nd (duplicate) Setting | 3472 0x00, 0x01, // 2nd (duplicate) Setting |
3467 0x00, 0x00, 0x00, 0x03, | 3473 0x00, 0x00, 0x00, 0x03, |
3468 0x03, // 3rd (unprocessed) Setting | 3474 0x00, 0x03, // 3rd (unprocessed) Setting |
3469 0x00, 0x00, 0x00, 0x03, | 3475 0x00, 0x00, 0x00, 0x03, |
3470 }; | 3476 }; |
3471 | 3477 |
3472 TestSpdyVisitor visitor(spdy_version_); | 3478 TestSpdyVisitor visitor(spdy_version_); |
3473 visitor.use_compression_ = false; | 3479 visitor.use_compression_ = false; |
3474 if (IsSpdy2()) { | 3480 if (IsSpdy2()) { |
3475 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | 3481 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
3476 } else if (IsSpdy3()) { | 3482 } else if (IsSpdy3()) { |
3477 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3483 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
3478 } else { | 3484 } else { |
3479 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); | 3485 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); |
3480 } | 3486 } |
3481 | 3487 |
3482 if (!IsSpdy4()) { | 3488 if (!IsSpdy4()) { |
3483 EXPECT_EQ(1, visitor.setting_count_); | 3489 EXPECT_EQ(1, visitor.setting_count_); |
3484 EXPECT_EQ(1, visitor.error_count_); | 3490 EXPECT_EQ(1, visitor.error_count_); |
3485 } else { | 3491 } else { |
3486 // In SPDY 4+, duplicate settings are allowed; | 3492 // In SPDY 4+, duplicate settings are allowed; |
3487 // each setting replaces the previous value for that setting. | 3493 // each setting replaces the previous value for that setting. |
3488 EXPECT_EQ(3, visitor.setting_count_); | 3494 EXPECT_EQ(3, visitor.setting_count_); |
3489 EXPECT_EQ(0, visitor.error_count_); | 3495 EXPECT_EQ(0, visitor.error_count_); |
3490 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3496 EXPECT_EQ(1, visitor.settings_ack_sent_); |
3491 } | 3497 } |
3492 } | 3498 } |
3493 | 3499 |
3494 // Tests handling of SETTINGS_COMPRESS_DATA. | |
3495 TEST_P(SpdyFramerTest, AcceptSettingsCompressData) { | |
3496 if (!IsSpdy4()) { return; } | |
3497 SpdyFramer framer(spdy_version_); | |
3498 | |
3499 const unsigned char kFrameData[] = { | |
3500 0x00, 0x05, 0x04, 0x00, | |
3501 0x00, 0x00, 0x00, 0x00, | |
3502 0x05, 0x00, 0x00, 0x00, | |
3503 0x01, | |
3504 }; | |
3505 | |
3506 TestSpdyVisitor visitor(spdy_version_); | |
3507 visitor.use_compression_ = false; | |
3508 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | |
3509 EXPECT_EQ(1, visitor.setting_count_); | |
3510 EXPECT_EQ(0, visitor.error_count_); | |
3511 } | |
3512 | |
3513 // Tests handling of SETTINGS frame with entries out of order. | 3500 // Tests handling of SETTINGS frame with entries out of order. |
3514 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 3501 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
3515 SpdyFramer framer(spdy_version_); | 3502 SpdyFramer framer(spdy_version_); |
3516 | 3503 |
3517 const unsigned char kV2FrameData[] = { | 3504 const unsigned char kV2FrameData[] = { |
3518 0x80, spdy_version_ch_, 0x00, 0x04, | 3505 0x80, spdy_version_ch_, 0x00, 0x04, |
3519 0x00, 0x00, 0x00, 0x1C, | 3506 0x00, 0x00, 0x00, 0x1C, |
3520 0x00, 0x00, 0x00, 0x03, | 3507 0x00, 0x00, 0x00, 0x03, |
3521 0x02, 0x00, 0x00, 0x00, // 1st Setting | 3508 0x02, 0x00, 0x00, 0x00, // 1st Setting |
3522 0x00, 0x00, 0x00, 0x02, | 3509 0x00, 0x00, 0x00, 0x02, |
3523 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting | 3510 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting |
3524 0x00, 0x00, 0x00, 0x03, | 3511 0x00, 0x00, 0x00, 0x03, |
3525 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting | 3512 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting |
3526 0x00, 0x00, 0x00, 0x03, | 3513 0x00, 0x00, 0x00, 0x03, |
3527 }; | 3514 }; |
3528 const unsigned char kV3FrameData[] = { | 3515 const unsigned char kV3FrameData[] = { |
3529 0x80, spdy_version_ch_, 0x00, 0x04, | 3516 0x80, spdy_version_ch_, 0x00, 0x04, |
3530 0x00, 0x00, 0x00, 0x1C, | 3517 0x00, 0x00, 0x00, 0x1C, |
3531 0x00, 0x00, 0x00, 0x03, | 3518 0x00, 0x00, 0x00, 0x03, |
3532 0x00, 0x00, 0x00, 0x02, // 1st Setting | 3519 0x00, 0x00, 0x00, 0x02, // 1st Setting |
3533 0x00, 0x00, 0x00, 0x02, | 3520 0x00, 0x00, 0x00, 0x02, |
3534 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting | 3521 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting |
3535 0x00, 0x00, 0x00, 0x03, | 3522 0x00, 0x00, 0x00, 0x03, |
3536 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting | 3523 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting |
3537 0x00, 0x00, 0x00, 0x03, | 3524 0x00, 0x00, 0x00, 0x03, |
3538 }; | 3525 }; |
3539 const unsigned char kV4FrameData[] = { | 3526 const unsigned char kV4FrameData[] = { |
3540 0x00, 0x0f, 0x04, 0x00, | 3527 0x00, 0x12, 0x04, 0x00, |
3541 0x00, 0x00, 0x00, 0x00, | 3528 0x00, 0x00, 0x00, 0x00, |
3542 0x02, // 1st Setting | 3529 0x00, 0x02, // 1st Setting |
3543 0x00, 0x00, 0x00, 0x02, | 3530 0x00, 0x00, 0x00, 0x02, |
3544 0x01, // 2nd (out of order) Setting | 3531 0x00, 0x01, // 2nd (out of order) Setting |
3545 0x00, 0x00, 0x00, 0x03, | 3532 0x00, 0x00, 0x00, 0x03, |
3546 0x03, // 3rd (unprocessed) Setting | 3533 0x00, 0x03, // 3rd (unprocessed) Setting |
3547 0x00, 0x00, 0x00, 0x03, | 3534 0x00, 0x00, 0x00, 0x03, |
3548 }; | 3535 }; |
3549 | 3536 |
3550 TestSpdyVisitor visitor(spdy_version_); | 3537 TestSpdyVisitor visitor(spdy_version_); |
3551 visitor.use_compression_ = false; | 3538 visitor.use_compression_ = false; |
3552 if (IsSpdy2()) { | 3539 if (IsSpdy2()) { |
3553 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); | 3540 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); |
3554 } else if (IsSpdy3()) { | 3541 } else if (IsSpdy3()) { |
3555 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); | 3542 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); |
3556 } else { | 3543 } else { |
(...skipping 24 matching lines...) Loading... |
3581 | 3568 |
3582 TestSpdyVisitor visitor(spdy_version_); | 3569 TestSpdyVisitor visitor(spdy_version_); |
3583 visitor.use_compression_ = false; | 3570 visitor.use_compression_ = false; |
3584 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | 3571 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
3585 | 3572 |
3586 EXPECT_EQ(0, visitor.error_count_); | 3573 EXPECT_EQ(0, visitor.error_count_); |
3587 EXPECT_EQ(0, visitor.setting_count_); | 3574 EXPECT_EQ(0, visitor.setting_count_); |
3588 EXPECT_EQ(1, visitor.settings_ack_received_); | 3575 EXPECT_EQ(1, visitor.settings_ack_received_); |
3589 } | 3576 } |
3590 | 3577 |
3591 | |
3592 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { | 3578 TEST_P(SpdyFramerTest, ProcessDataFrameWithPadding) { |
3593 if (spdy_version_ <= SPDY3) { | 3579 if (spdy_version_ <= SPDY3) { |
3594 return; | 3580 return; |
3595 } | 3581 } |
3596 | 3582 |
3597 const int kPaddingLen = 512; // So we get two bytes for padding length field. | 3583 const int kPaddingLen = 119; |
3598 const char data_payload[] = "hello"; | 3584 const char data_payload[] = "hello"; |
3599 | 3585 |
3600 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 3586 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
3601 SpdyFramer framer(spdy_version_); | 3587 SpdyFramer framer(spdy_version_); |
3602 framer.set_visitor(&visitor); | 3588 framer.set_visitor(&visitor); |
3603 | 3589 |
3604 SpdyDataIR data_ir(1, StringPiece(data_payload, strlen(data_payload))); | 3590 SpdyDataIR data_ir(1, StringPiece(data_payload, strlen(data_payload))); |
3605 data_ir.set_padding_len(kPaddingLen); | 3591 data_ir.set_padding_len(kPaddingLen); |
3606 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 3592 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
3607 ASSERT_TRUE(frame.get() != NULL); | 3593 ASSERT_TRUE(frame.get() != NULL); |
3608 | 3594 |
3609 int bytes_consumed = 0; | 3595 int bytes_consumed = 0; |
3610 | 3596 |
3611 // Send the frame header. | 3597 // Send the frame header. |
3612 EXPECT_CALL(visitor, OnDataFrameHeader(1, | 3598 EXPECT_CALL(visitor, OnDataFrameHeader(1, |
3613 kPaddingLen + strlen(data_payload), | 3599 kPaddingLen + strlen(data_payload), |
3614 false)); | 3600 false)); |
3615 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); | 3601 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); |
3616 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); | 3602 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); |
3617 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3603 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3618 bytes_consumed += 8; | 3604 bytes_consumed += 8; |
3619 | 3605 |
3620 // Send the first byte of the padding length field. | 3606 // Send the padding length field. |
3621 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); | |
3622 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); | |
3623 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | |
3624 bytes_consumed += 1; | |
3625 | |
3626 // Send the second byte of the padding length field. | |
3627 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); | 3607 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); |
3628 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); | 3608 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); |
3629 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3609 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3630 bytes_consumed += 1; | 3610 bytes_consumed += 1; |
3631 | 3611 |
3632 // Send the first two bytes of the data payload. | 3612 // Send the first two bytes of the data payload, i.e., "he". |
3633 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 2, false)); | 3613 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 2, false)); |
3634 CHECK_EQ(2u, framer.ProcessInput(frame->data() + bytes_consumed, 2)); | 3614 CHECK_EQ(2u, framer.ProcessInput(frame->data() + bytes_consumed, 2)); |
3635 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); | 3615 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); |
3636 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3616 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3637 bytes_consumed += 2; | 3617 bytes_consumed += 2; |
3638 | 3618 |
3639 // Send the rest three bytes of the data payload. | 3619 // Send the rest three bytes of the data payload, i.e., "llo". |
3640 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 3, false)); | 3620 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 3, false)); |
3641 CHECK_EQ(3u, framer.ProcessInput(frame->data() + bytes_consumed, 3)); | 3621 CHECK_EQ(3u, framer.ProcessInput(frame->data() + bytes_consumed, 3)); |
3642 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); | 3622 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); |
3643 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3623 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3644 bytes_consumed += 3; | 3624 bytes_consumed += 3; |
3645 | 3625 |
3646 // Send the first 100 bytes of the padding payload. | 3626 // Send the first 100 bytes of the padding payload. |
3647 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 100, false)); | 3627 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 100, false)); |
3648 CHECK_EQ(100u, framer.ProcessInput(frame->data() + bytes_consumed, 100)); | 3628 CHECK_EQ(100u, framer.ProcessInput(frame->data() + bytes_consumed, 100)); |
3649 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); | 3629 CHECK_EQ(framer.state(), SpdyFramer::SPDY_CONSUME_PADDING); |
3650 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3630 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3651 bytes_consumed += 100; | 3631 bytes_consumed += 100; |
3652 | 3632 |
3653 // Send rest of the padding payload. | 3633 // Send rest of the padding payload. |
3654 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 410, false)); | 3634 EXPECT_CALL(visitor, OnStreamFrameData(1, NULL, 18, false)); |
3655 CHECK_EQ(410u, framer.ProcessInput(frame->data() + bytes_consumed, 410)); | 3635 CHECK_EQ(18u, framer.ProcessInput(frame->data() + bytes_consumed, 18)); |
3656 CHECK_EQ(framer.state(), SpdyFramer::SPDY_RESET); | 3636 CHECK_EQ(framer.state(), SpdyFramer::SPDY_RESET); |
3657 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); | 3637 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); |
3658 } | 3638 } |
3659 | 3639 |
3660 TEST_P(SpdyFramerTest, ReadWindowUpdate) { | 3640 TEST_P(SpdyFramerTest, ReadWindowUpdate) { |
3661 SpdyFramer framer(spdy_version_); | 3641 SpdyFramer framer(spdy_version_); |
3662 scoped_ptr<SpdyFrame> control_frame( | 3642 scoped_ptr<SpdyFrame> control_frame( |
3663 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); | 3643 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 2))); |
3664 TestSpdyVisitor visitor(spdy_version_); | 3644 TestSpdyVisitor visitor(spdy_version_); |
3665 visitor.SimulateInFramer( | 3645 visitor.SimulateInFramer( |
(...skipping 112 matching lines...) Loading... |
3778 TestSpdyVisitor visitor(spdy_version_); | 3758 TestSpdyVisitor visitor(spdy_version_); |
3779 visitor.use_compression_ = true; | 3759 visitor.use_compression_ = true; |
3780 visitor.SimulateInFramer( | 3760 visitor.SimulateInFramer( |
3781 reinterpret_cast<unsigned char*>(frame->data()), | 3761 reinterpret_cast<unsigned char*>(frame->data()), |
3782 frame->size()); | 3762 frame->size()); |
3783 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3763 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
3784 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3764 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
3785 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3765 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
3786 } | 3766 } |
3787 | 3767 |
3788 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndPadding) { | 3768 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { |
3789 if (spdy_version_ <= SPDY3) { | 3769 if (spdy_version_ <= SPDY3) { |
3790 return; | 3770 return; |
3791 } | 3771 } |
3792 | 3772 |
3793 const unsigned char kInput[] = { | 3773 const unsigned char kInput[] = { |
3794 0x00, 0x14, 0x01, 0x08, // HEADERS: PAD_LOW | 3774 0x00, 0x14, 0x01, 0x08, // HEADERS: PADDED |
3795 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3775 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3796 0x03, // Padding of 3. | 3776 0x03, // Padding of 3. |
3797 0x00, 0x06, 0x63, 0x6f, | 3777 0x00, 0x06, 0x63, 0x6f, |
3798 0x6f, 0x6b, 0x69, 0x65, | 3778 0x6f, 0x6b, 0x69, 0x65, |
3799 0x07, 0x66, 0x6f, 0x6f, | 3779 0x07, 0x66, 0x6f, 0x6f, |
3800 0x3d, 0x62, 0x61, 0x72, | 3780 0x3d, 0x62, 0x61, 0x72, |
3801 0x00, 0x00, 0x00, | 3781 0x00, 0x00, 0x00, |
3802 | 3782 |
3803 0x00, 0x1a, 0x09, 0x18, // CONTINUATION: PAD_LOW & PAD_HIGH | 3783 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
3804 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3784 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3805 0x00, 0x04, // Padding of 4. | |
3806 0x00, 0x06, 0x63, 0x6f, | 3785 0x00, 0x06, 0x63, 0x6f, |
3807 0x6f, 0x6b, 0x69, 0x65, | 3786 0x6f, 0x6b, 0x69, 0x65, |
3808 0x08, 0x62, 0x61, 0x7a, | 3787 0x08, 0x62, 0x61, 0x7a, |
3809 0x3d, 0x62, 0x69, 0x6e, | 3788 0x3d, 0x62, 0x69, 0x6e, |
3810 0x67, 0x00, 0x06, 0x63, | 3789 0x67, 0x00, 0x06, 0x63, |
3811 0x00, 0x00, 0x00, 0x00, | |
3812 | 3790 |
3813 0x00, 0x13, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS | 3791 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS |
3814 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3792 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3815 0x00, // Padding of 0. | |
3816 0x6f, 0x6f, 0x6b, 0x69, | 3793 0x6f, 0x6f, 0x6b, 0x69, |
3817 0x65, 0x00, 0x00, 0x04, | 3794 0x65, 0x00, 0x00, 0x04, |
3818 0x6e, 0x61, 0x6d, 0x65, | 3795 0x6e, 0x61, 0x6d, 0x65, |
3819 0x05, 0x76, 0x61, 0x6c, | 3796 0x05, 0x76, 0x61, 0x6c, |
3820 0x75, 0x65, | 3797 0x75, 0x65, |
3821 }; | 3798 }; |
3822 | 3799 |
3823 TestSpdyVisitor visitor(spdy_version_); | 3800 TestSpdyVisitor visitor(spdy_version_); |
3824 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3801 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
3825 | 3802 |
(...skipping 47 matching lines...) Loading... |
3873 EXPECT_EQ(2, visitor.continuation_count_); | 3850 EXPECT_EQ(2, visitor.continuation_count_); |
3874 EXPECT_EQ(1, visitor.fin_flag_count_); | 3851 EXPECT_EQ(1, visitor.fin_flag_count_); |
3875 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3852 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3876 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3853 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
3877 | 3854 |
3878 EXPECT_THAT(visitor.headers_, ElementsAre( | 3855 EXPECT_THAT(visitor.headers_, ElementsAre( |
3879 Pair("cookie", "foo=bar; baz=bing; "), | 3856 Pair("cookie", "foo=bar; baz=bing; "), |
3880 Pair("name", "value"))); | 3857 Pair("name", "value"))); |
3881 } | 3858 } |
3882 | 3859 |
3883 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuationAndPadding) { | 3860 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { |
3884 if (spdy_version_ <= SPDY3) { | 3861 if (spdy_version_ <= SPDY3) { |
3885 return; | 3862 return; |
3886 } | 3863 } |
3887 | 3864 |
3888 const unsigned char kInput[] = { | 3865 const unsigned char kInput[] = { |
3889 0x00, 0x18, 0x05, 0x18, // PUSH_PROMISE: PAD_LOW & PAD_HIGH | 3866 0x00, 0x17, 0x05, 0x08, // PUSH_PROMISE: PADDED |
3890 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3867 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3891 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3868 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
3892 0x00, 0x02, // Padding of 2. | 3869 0x02, // Padding of 2. |
3893 0x00, 0x06, 0x63, 0x6f, | 3870 0x00, 0x06, 0x63, 0x6f, |
3894 0x6f, 0x6b, 0x69, 0x65, | 3871 0x6f, 0x6b, 0x69, 0x65, |
3895 0x07, 0x66, 0x6f, 0x6f, | 3872 0x07, 0x66, 0x6f, 0x6f, |
3896 0x3d, 0x62, 0x61, 0x72, | 3873 0x3d, 0x62, 0x61, 0x72, |
3897 0x00, 0x00, | 3874 0x00, 0x00, |
3898 | 3875 |
3899 0x00, 0x14, 0x09, 0x00, // CONTINUATION: | 3876 0x00, 0x14, 0x09, 0x00, // CONTINUATION |
3900 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3877 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3901 0x00, 0x06, 0x63, 0x6f, | 3878 0x00, 0x06, 0x63, 0x6f, |
3902 0x6f, 0x6b, 0x69, 0x65, | 3879 0x6f, 0x6b, 0x69, 0x65, |
3903 0x08, 0x62, 0x61, 0x7a, | 3880 0x08, 0x62, 0x61, 0x7a, |
3904 0x3d, 0x62, 0x69, 0x6e, | 3881 0x3d, 0x62, 0x69, 0x6e, |
3905 0x67, 0x00, 0x06, 0x63, | 3882 0x67, 0x00, 0x06, 0x63, |
3906 | 3883 |
3907 0x00, 0x17, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS | 3884 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS |
3908 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3885 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3909 0x04, // Padding of 4. | |
3910 0x6f, 0x6f, 0x6b, 0x69, | 3886 0x6f, 0x6f, 0x6b, 0x69, |
3911 0x65, 0x00, 0x00, 0x04, | 3887 0x65, 0x00, 0x00, 0x04, |
3912 0x6e, 0x61, 0x6d, 0x65, | 3888 0x6e, 0x61, 0x6d, 0x65, |
3913 0x05, 0x76, 0x61, 0x6c, | 3889 0x05, 0x76, 0x61, 0x6c, |
3914 0x75, 0x65, 0x00, 0x00, | 3890 0x75, 0x65, |
3915 0x00, 0x00, | |
3916 }; | 3891 }; |
3917 | 3892 |
3918 SpdyFramer framer(spdy_version_); | 3893 SpdyFramer framer(spdy_version_); |
3919 TestSpdyVisitor visitor(spdy_version_); | 3894 TestSpdyVisitor visitor(spdy_version_); |
3920 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3895 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
3921 | 3896 |
3922 EXPECT_EQ(0, visitor.error_count_); | 3897 EXPECT_EQ(0, visitor.error_count_); |
3923 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3898 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
3924 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3899 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
3925 EXPECT_EQ(2, visitor.continuation_count_); | 3900 EXPECT_EQ(2, visitor.continuation_count_); |
(...skipping 372 matching lines...) Loading... |
4298 EXPECT_STREQ("DATA", | 4273 EXPECT_STREQ("DATA", |
4299 SpdyFramer::FrameTypeToString(DATA)); | 4274 SpdyFramer::FrameTypeToString(DATA)); |
4300 EXPECT_STREQ("SYN_STREAM", | 4275 EXPECT_STREQ("SYN_STREAM", |
4301 SpdyFramer::FrameTypeToString(SYN_STREAM)); | 4276 SpdyFramer::FrameTypeToString(SYN_STREAM)); |
4302 EXPECT_STREQ("SYN_REPLY", | 4277 EXPECT_STREQ("SYN_REPLY", |
4303 SpdyFramer::FrameTypeToString(SYN_REPLY)); | 4278 SpdyFramer::FrameTypeToString(SYN_REPLY)); |
4304 EXPECT_STREQ("RST_STREAM", | 4279 EXPECT_STREQ("RST_STREAM", |
4305 SpdyFramer::FrameTypeToString(RST_STREAM)); | 4280 SpdyFramer::FrameTypeToString(RST_STREAM)); |
4306 EXPECT_STREQ("SETTINGS", | 4281 EXPECT_STREQ("SETTINGS", |
4307 SpdyFramer::FrameTypeToString(SETTINGS)); | 4282 SpdyFramer::FrameTypeToString(SETTINGS)); |
4308 EXPECT_STREQ("NOOP", | |
4309 SpdyFramer::FrameTypeToString(NOOP)); | |
4310 EXPECT_STREQ("PING", | 4283 EXPECT_STREQ("PING", |
4311 SpdyFramer::FrameTypeToString(PING)); | 4284 SpdyFramer::FrameTypeToString(PING)); |
4312 EXPECT_STREQ("GOAWAY", | 4285 EXPECT_STREQ("GOAWAY", |
4313 SpdyFramer::FrameTypeToString(GOAWAY)); | 4286 SpdyFramer::FrameTypeToString(GOAWAY)); |
4314 EXPECT_STREQ("HEADERS", | 4287 EXPECT_STREQ("HEADERS", |
4315 SpdyFramer::FrameTypeToString(HEADERS)); | 4288 SpdyFramer::FrameTypeToString(HEADERS)); |
4316 EXPECT_STREQ("WINDOW_UPDATE", | 4289 EXPECT_STREQ("WINDOW_UPDATE", |
4317 SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); | 4290 SpdyFramer::FrameTypeToString(WINDOW_UPDATE)); |
4318 EXPECT_STREQ("PUSH_PROMISE", | 4291 EXPECT_STREQ("PUSH_PROMISE", |
4319 SpdyFramer::FrameTypeToString(PUSH_PROMISE)); | 4292 SpdyFramer::FrameTypeToString(PUSH_PROMISE)); |
(...skipping 73 matching lines...) Loading... |
4393 } | 4366 } |
4394 } | 4367 } |
4395 } | 4368 } |
4396 | 4369 |
4397 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { | 4370 TEST_P(SpdyFramerTest, DataFrameFlagsV4) { |
4398 if (spdy_version_ <= SPDY3) { | 4371 if (spdy_version_ <= SPDY3) { |
4399 return; | 4372 return; |
4400 } | 4373 } |
4401 | 4374 |
4402 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | | 4375 uint8 valid_data_flags = DATA_FLAG_FIN | DATA_FLAG_END_SEGMENT | |
4403 DATA_FLAG_PAD_LOW | DATA_FLAG_PAD_HIGH; | 4376 DATA_FLAG_PADDED; |
4404 | 4377 |
4405 for (int flags = 0; flags < 256; ++flags) { | 4378 for (int flags = 0; flags < 256; ++flags) { |
4406 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4379 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4407 | 4380 |
4408 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4381 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4409 SpdyFramer framer(spdy_version_); | 4382 SpdyFramer framer(spdy_version_); |
4410 framer.set_visitor(&visitor); | 4383 framer.set_visitor(&visitor); |
4411 | 4384 |
4412 SpdyDataIR data_ir(1, StringPiece("hello", 5)); | 4385 SpdyDataIR data_ir(1, StringPiece("hello", 5)); |
4413 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); | 4386 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); |
4414 SetFrameFlags(frame.get(), flags, spdy_version_); | 4387 SetFrameFlags(frame.get(), flags, spdy_version_); |
4415 | 4388 |
4416 if (flags & ~valid_data_flags) { | 4389 if (flags & ~valid_data_flags) { |
4417 EXPECT_CALL(visitor, OnError(_)); | 4390 EXPECT_CALL(visitor, OnError(_)); |
4418 } else { | 4391 } else { |
4419 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); | 4392 EXPECT_CALL(visitor, OnDataFrameHeader(1, 5, flags & DATA_FLAG_FIN)); |
4420 if ((flags & DATA_FLAG_PAD_LOW) || (flags & DATA_FLAG_PAD_HIGH)) { | 4393 if (flags & DATA_FLAG_PADDED) { |
4421 // Expect Error since we don't set pad_high and pad_low in payload. | 4394 // Expect Error since we don't set padded in payload. |
4422 EXPECT_CALL(visitor, OnError(_)); | 4395 EXPECT_CALL(visitor, OnError(_)); |
4423 } else { | 4396 } else { |
4424 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); | 4397 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 5, false)); |
4425 if (flags & DATA_FLAG_FIN) { | 4398 if (flags & DATA_FLAG_FIN) { |
4426 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4399 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
4427 } | 4400 } |
4428 } | 4401 } |
4429 } | 4402 } |
4430 | 4403 |
4431 framer.ProcessInput(frame->data(), frame->size()); | 4404 framer.ProcessInput(frame->data(), frame->size()); |
4432 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PAD_LOW) || | 4405 if ((flags & ~valid_data_flags) || (flags & DATA_FLAG_PADDED)) { |
4433 (flags & DATA_FLAG_PAD_HIGH)) { | |
4434 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4406 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4435 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, | 4407 EXPECT_EQ(SpdyFramer::SPDY_INVALID_DATA_FRAME_FLAGS, |
4436 framer.error_code()) | 4408 framer.error_code()) |
4437 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4409 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4438 } else { | 4410 } else { |
4439 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4411 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4440 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4412 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4441 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4413 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4442 } | 4414 } |
4443 } | 4415 } |
4444 } | 4416 } |
4445 | 4417 |
4446 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { | 4418 TEST_P(SpdyFramerTest, SynStreamFrameFlags) { |
| 4419 if (!IsSpdy2() && !IsSpdy3()) { |
| 4420 // SYN_STREAM not supported in SPDY>3 |
| 4421 return; |
| 4422 } |
4447 for (int flags = 0; flags < 256; ++flags) { | 4423 for (int flags = 0; flags < 256; ++flags) { |
4448 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4424 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4449 | 4425 |
4450 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4426 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4451 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4427 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
4452 SpdyFramer framer(spdy_version_); | 4428 SpdyFramer framer(spdy_version_); |
4453 framer.set_visitor(&visitor); | 4429 framer.set_visitor(&visitor); |
4454 framer.set_debug_visitor(&debug_visitor); | 4430 framer.set_debug_visitor(&debug_visitor); |
4455 | 4431 |
4456 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _)); | 4432 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(8, SYN_STREAM, _, _)); |
4457 | 4433 |
4458 SpdySynStreamIR syn_stream(8); | 4434 SpdySynStreamIR syn_stream(8); |
4459 syn_stream.set_associated_to_stream_id(3); | 4435 syn_stream.set_associated_to_stream_id(3); |
4460 syn_stream.set_priority(1); | 4436 syn_stream.set_priority(1); |
4461 syn_stream.SetHeader("foo", "bar"); | 4437 syn_stream.SetHeader("foo", "bar"); |
4462 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 4438 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
4463 int set_flags = flags; | 4439 int set_flags = flags; |
4464 if (IsSpdy4()) { | |
4465 // PRIORITY required for SYN_STREAM simulation. | |
4466 set_flags |= HEADERS_FLAG_PRIORITY; | |
4467 | |
4468 // TODO(jgraettinger): Add padding to SynStreamIR, and implement framing. | |
4469 set_flags &= ~HEADERS_FLAG_PAD_LOW; | |
4470 set_flags &= ~HEADERS_FLAG_PAD_HIGH; | |
4471 } | |
4472 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4440 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4473 | 4441 |
4474 if (!IsSpdy4() && | 4442 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
4475 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | |
4476 EXPECT_CALL(visitor, OnError(_)); | |
4477 } else if (IsSpdy4() && | |
4478 flags & ~(CONTROL_FLAG_FIN | | |
4479 HEADERS_FLAG_PRIORITY | | |
4480 HEADERS_FLAG_END_HEADERS | | |
4481 HEADERS_FLAG_END_SEGMENT | | |
4482 HEADERS_FLAG_PAD_LOW | | |
4483 HEADERS_FLAG_PAD_HIGH)) { | |
4484 EXPECT_CALL(visitor, OnError(_)); | 4443 EXPECT_CALL(visitor, OnError(_)); |
4485 } else { | 4444 } else { |
4486 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); | 4445 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); |
4487 if (IsSpdy4()) { | 4446 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, |
4488 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, | 4447 flags & CONTROL_FLAG_UNIDIRECTIONAL)); |
4489 false)); | |
4490 } else { | |
4491 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, | |
4492 flags & CONTROL_FLAG_UNIDIRECTIONAL)); | |
4493 } | |
4494 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) | 4448 EXPECT_CALL(visitor, OnControlFrameHeaderData(8, _, _)) |
4495 .WillRepeatedly(testing::Return(true)); | 4449 .WillRepeatedly(testing::Return(true)); |
4496 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || | 4450 if (flags & DATA_FLAG_FIN) { |
4497 flags & HEADERS_FLAG_END_HEADERS)) { | |
4498 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4451 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
4499 } else { | 4452 } else { |
4500 // Do not close the stream if we are expecting a CONTINUATION frame. | 4453 // Do not close the stream if we are expecting a CONTINUATION frame. |
4501 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 4454 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
4502 } | 4455 } |
4503 } | 4456 } |
4504 | 4457 |
4505 framer.ProcessInput(frame->data(), frame->size()); | 4458 framer.ProcessInput(frame->data(), frame->size()); |
4506 if (!IsSpdy4() && | 4459 if (flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
4507 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | |
4508 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4460 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4509 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4461 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4510 framer.error_code()) | 4462 framer.error_code()) |
4511 << SpdyFramer::ErrorCodeToString(framer.error_code()); | |
4512 } else if (IsSpdy4() && | |
4513 flags & ~(CONTROL_FLAG_FIN | | |
4514 HEADERS_FLAG_PRIORITY | | |
4515 HEADERS_FLAG_END_HEADERS | | |
4516 HEADERS_FLAG_END_SEGMENT | | |
4517 HEADERS_FLAG_PAD_LOW | | |
4518 HEADERS_FLAG_PAD_HIGH)) { | |
4519 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | |
4520 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | |
4521 framer.error_code()) | |
4522 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4463 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4523 } else { | 4464 } else { |
4524 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4465 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4525 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4466 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4526 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4467 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4527 } | 4468 } |
4528 } | 4469 } |
4529 } | 4470 } |
4530 | 4471 |
4531 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { | 4472 TEST_P(SpdyFramerTest, SynReplyFrameFlags) { |
4532 if (IsSpdy4()) { | 4473 if (!IsSpdy2() && !IsSpdy3()) { |
4533 // Covered by HEADERS case. | 4474 // SYN_REPLY not supported in SPDY>3 |
4534 return; | 4475 return; |
4535 } | 4476 } |
4536 for (int flags = 0; flags < 256; ++flags) { | 4477 for (int flags = 0; flags < 256; ++flags) { |
4537 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4478 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4538 | 4479 |
4539 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4480 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4540 SpdyFramer framer(spdy_version_); | 4481 SpdyFramer framer(spdy_version_); |
4541 framer.set_visitor(&visitor); | 4482 framer.set_visitor(&visitor); |
4542 | 4483 |
4543 SpdySynReplyIR syn_reply(37); | 4484 SpdySynReplyIR syn_reply(37); |
(...skipping 168 matching lines...) Loading... |
4712 } else { | 4653 } else { |
4713 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4654 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4714 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4655 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4715 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4656 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4716 } | 4657 } |
4717 } | 4658 } |
4718 } | 4659 } |
4719 | 4660 |
4720 TEST_P(SpdyFramerTest, HeadersFrameFlags) { | 4661 TEST_P(SpdyFramerTest, HeadersFrameFlags) { |
4721 for (int flags = 0; flags < 256; ++flags) { | 4662 for (int flags = 0; flags < 256; ++flags) { |
4722 if (IsSpdy4() && flags & HEADERS_FLAG_PRIORITY) { | |
4723 // Covered by SYN_STREAM case. | |
4724 continue; | |
4725 } | |
4726 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4663 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4727 | 4664 |
4728 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4665 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4729 SpdyFramer framer(spdy_version_); | 4666 SpdyFramer framer(spdy_version_); |
4730 framer.set_visitor(&visitor); | 4667 framer.set_visitor(&visitor); |
4731 | 4668 |
4732 SpdyHeadersIR headers_ir(57); | 4669 SpdyHeadersIR headers_ir(57); |
| 4670 if (IsSpdy4() && (flags & HEADERS_FLAG_PRIORITY)) { |
| 4671 headers_ir.set_priority(3); |
| 4672 headers_ir.set_has_priority(true); |
| 4673 } |
4733 headers_ir.SetHeader("foo", "bar"); | 4674 headers_ir.SetHeader("foo", "bar"); |
4734 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 4675 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
4735 int set_flags = flags; | 4676 int set_flags = flags; |
4736 if (IsSpdy4()) { | 4677 if (IsSpdy4()) { |
4737 // TODO(jgraettinger): Add padding to SpdyHeadersIR, | 4678 // TODO(jgraettinger): Add padding to SpdyHeadersIR, |
4738 // and implement framing. | 4679 // and implement framing. |
4739 set_flags &= ~HEADERS_FLAG_PAD_LOW; | 4680 set_flags &= ~HEADERS_FLAG_PADDED; |
4740 set_flags &= ~HEADERS_FLAG_PAD_HIGH; | |
4741 } | 4681 } |
4742 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4682 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4743 | 4683 |
4744 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4684 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4745 EXPECT_CALL(visitor, OnError(_)); | 4685 EXPECT_CALL(visitor, OnError(_)); |
4746 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4686 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4747 HEADERS_FLAG_END_HEADERS | | 4687 HEADERS_FLAG_END_HEADERS | |
4748 HEADERS_FLAG_END_SEGMENT | | 4688 HEADERS_FLAG_END_SEGMENT | |
4749 HEADERS_FLAG_PAD_LOW | | 4689 HEADERS_FLAG_PADDED | |
4750 HEADERS_FLAG_PAD_HIGH)) { | 4690 HEADERS_FLAG_PRIORITY)) { |
4751 EXPECT_CALL(visitor, OnError(_)); | 4691 EXPECT_CALL(visitor, OnError(_)); |
4752 } else { | 4692 } else { |
4753 EXPECT_CALL(visitor, OnHeaders(57, | 4693 if (spdy_version_ > SPDY3 && flags & HEADERS_FLAG_PRIORITY) { |
4754 flags & CONTROL_FLAG_FIN, | 4694 EXPECT_CALL(visitor, OnSynStream(57, // stream id |
4755 (flags & HEADERS_FLAG_END_HEADERS) || | 4695 0, // associated stream id |
4756 !IsSpdy4())); | 4696 3, // priority |
| 4697 flags & CONTROL_FLAG_FIN, |
| 4698 false)); // unidirectional |
| 4699 } else { |
| 4700 EXPECT_CALL(visitor, OnHeaders(57, |
| 4701 flags & CONTROL_FLAG_FIN, |
| 4702 (flags & HEADERS_FLAG_END_HEADERS) || |
| 4703 !IsSpdy4())); |
| 4704 } |
4757 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) | 4705 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) |
4758 .WillRepeatedly(testing::Return(true)); | 4706 .WillRepeatedly(testing::Return(true)); |
4759 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || | 4707 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || |
4760 flags & HEADERS_FLAG_END_HEADERS)) { | 4708 flags & HEADERS_FLAG_END_HEADERS)) { |
4761 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4709 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
4762 } else { | 4710 } else { |
4763 // Do not close the stream if we are expecting a CONTINUATION frame. | 4711 // Do not close the stream if we are expecting a CONTINUATION frame. |
4764 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 4712 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
4765 } | 4713 } |
4766 } | 4714 } |
4767 | 4715 |
4768 framer.ProcessInput(frame->data(), frame->size()); | 4716 framer.ProcessInput(frame->data(), frame->size()); |
4769 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4717 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4770 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4718 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4771 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4719 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4772 framer.error_code()) | 4720 framer.error_code()) |
4773 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4721 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4774 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4722 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4775 HEADERS_FLAG_END_HEADERS | | 4723 HEADERS_FLAG_END_HEADERS | |
4776 HEADERS_FLAG_END_SEGMENT | | 4724 HEADERS_FLAG_END_SEGMENT | |
4777 HEADERS_FLAG_PAD_LOW | | 4725 HEADERS_FLAG_PADDED | |
4778 HEADERS_FLAG_PAD_HIGH)) { | 4726 HEADERS_FLAG_PRIORITY)) { |
4779 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4727 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4780 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4728 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4781 framer.error_code()) | 4729 framer.error_code()) |
4782 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4730 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4783 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { | 4731 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { |
4784 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4732 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4785 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4733 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4786 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4734 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4787 } else { | 4735 } else { |
4788 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4736 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
(...skipping 85 matching lines...) Loading... |
4874 framer.set_debug_visitor(&debug_visitor); | 4822 framer.set_debug_visitor(&debug_visitor); |
4875 | 4823 |
4876 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); | 4824 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); |
4877 | 4825 |
4878 SpdyPushPromiseIR push_promise(42, 57); | 4826 SpdyPushPromiseIR push_promise(42, 57); |
4879 push_promise.SetHeader("foo", "bar"); | 4827 push_promise.SetHeader("foo", "bar"); |
4880 scoped_ptr<SpdySerializedFrame> frame( | 4828 scoped_ptr<SpdySerializedFrame> frame( |
4881 framer.SerializePushPromise(push_promise)); | 4829 framer.SerializePushPromise(push_promise)); |
4882 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, | 4830 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
4883 // and implement framing. | 4831 // and implement framing. |
4884 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; | 4832 int set_flags = flags & ~HEADERS_FLAG_PADDED; |
4885 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4833 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4886 | 4834 |
4887 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | | 4835 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { |
4888 HEADERS_FLAG_PAD_LOW | | |
4889 HEADERS_FLAG_PAD_HIGH)) { | |
4890 EXPECT_CALL(visitor, OnError(_)); | 4836 EXPECT_CALL(visitor, OnError(_)); |
4891 } else { | 4837 } else { |
4892 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); | 4838 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); |
4893 EXPECT_CALL(visitor, OnPushPromise(42, 57, | 4839 EXPECT_CALL(visitor, OnPushPromise(42, 57, |
4894 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); | 4840 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); |
4895 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4841 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4896 .WillRepeatedly(testing::Return(true)); | 4842 .WillRepeatedly(testing::Return(true)); |
4897 } | 4843 } |
4898 | 4844 |
4899 framer.ProcessInput(frame->data(), frame->size()); | 4845 framer.ProcessInput(frame->data(), frame->size()); |
4900 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | | 4846 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | HEADERS_FLAG_PADDED)) { |
4901 HEADERS_FLAG_PAD_LOW | | |
4902 HEADERS_FLAG_PAD_HIGH)) { | |
4903 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4847 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4904 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4848 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4905 framer.error_code()) | 4849 framer.error_code()) |
4906 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4850 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4907 } else { | 4851 } else { |
4908 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4852 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4909 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4853 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4910 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4854 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4911 } | 4855 } |
4912 } | 4856 } |
(...skipping 22 matching lines...) Loading... |
4935 | 4879 |
4936 SpdyHeadersIR headers_ir(42); | 4880 SpdyHeadersIR headers_ir(42); |
4937 headers_ir.SetHeader("foo", "bar"); | 4881 headers_ir.SetHeader("foo", "bar"); |
4938 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); | 4882 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); |
4939 SetFrameFlags(frame0.get(), 0, spdy_version_); | 4883 SetFrameFlags(frame0.get(), 0, spdy_version_); |
4940 | 4884 |
4941 SpdyContinuationIR continuation(42); | 4885 SpdyContinuationIR continuation(42); |
4942 continuation.SetHeader("foo", "bar"); | 4886 continuation.SetHeader("foo", "bar"); |
4943 scoped_ptr<SpdySerializedFrame> frame( | 4887 scoped_ptr<SpdySerializedFrame> frame( |
4944 framer.SerializeContinuation(continuation)); | 4888 framer.SerializeContinuation(continuation)); |
4945 // TODO(jgraettinger): Add padding to the eventual continuation | 4889 SetFrameFlags(frame.get(), flags, spdy_version_); |
4946 // serialization implementation. | |
4947 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; | |
4948 SetFrameFlags(frame.get(), set_flags, spdy_version_); | |
4949 | 4890 |
4950 if (flags & ~(HEADERS_FLAG_END_HEADERS | | 4891 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
4951 HEADERS_FLAG_PAD_LOW | | |
4952 HEADERS_FLAG_PAD_HIGH)) { | |
4953 EXPECT_CALL(visitor, OnError(_)); | 4892 EXPECT_CALL(visitor, OnError(_)); |
4954 } else { | 4893 } else { |
4955 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); | 4894 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); |
4956 EXPECT_CALL(visitor, OnContinuation(42, | 4895 EXPECT_CALL(visitor, OnContinuation(42, |
4957 flags & HEADERS_FLAG_END_HEADERS)); | 4896 flags & HEADERS_FLAG_END_HEADERS)); |
4958 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4897 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4959 .WillRepeatedly(testing::Return(true)); | 4898 .WillRepeatedly(testing::Return(true)); |
4960 } | 4899 } |
4961 | 4900 |
4962 framer.ProcessInput(frame0->data(), frame0->size()); | 4901 framer.ProcessInput(frame0->data(), frame0->size()); |
4963 framer.ProcessInput(frame->data(), frame->size()); | 4902 framer.ProcessInput(frame->data(), frame->size()); |
4964 if (flags & ~(HEADERS_FLAG_END_HEADERS | | 4903 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { |
4965 HEADERS_FLAG_PAD_LOW | | |
4966 HEADERS_FLAG_PAD_HIGH)) { | |
4967 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4904 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4968 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4905 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4969 framer.error_code()) | 4906 framer.error_code()) |
4970 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4907 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4971 } else { | 4908 } else { |
4972 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4909 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4973 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4910 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4974 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4911 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4975 } | 4912 } |
4976 } | 4913 } |
4977 } | 4914 } |
4978 | 4915 |
4979 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) | 4916 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
4980 | 4917 |
4981 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) | 4918 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) |
4982 | 4919 |
4983 TEST_P(SpdyFramerTest, EmptySynStream) { | 4920 TEST_P(SpdyFramerTest, EmptySynStream) { |
| 4921 if (!IsSpdy2() && !IsSpdy3()) { |
| 4922 // SYN_STREAM not supported in SPDY>3. |
| 4923 return; |
| 4924 } |
4984 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4925 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4985 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4926 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
4986 SpdyFramer framer(spdy_version_); | 4927 SpdyFramer framer(spdy_version_); |
4987 framer.set_visitor(&visitor); | 4928 framer.set_visitor(&visitor); |
4988 framer.set_debug_visitor(&debug_visitor); | 4929 framer.set_debug_visitor(&debug_visitor); |
4989 | 4930 |
4990 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); | 4931 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); |
4991 | 4932 |
4992 SpdySynStreamIR syn_stream(1); | 4933 SpdySynStreamIR syn_stream(1); |
4993 syn_stream.set_priority(1); | 4934 syn_stream.set_priority(1); |
(...skipping 358 matching lines...) Loading... |
5352 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); | 5293 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); |
5353 EXPECT_EQ("protocolid", visitor.test_altsvc_ir_.protocol_id()); | 5294 EXPECT_EQ("protocolid", visitor.test_altsvc_ir_.protocol_id()); |
5354 EXPECT_EQ("hostname", visitor.test_altsvc_ir_.host()); | 5295 EXPECT_EQ("hostname", visitor.test_altsvc_ir_.host()); |
5355 } | 5296 } |
5356 | 5297 |
5357 // Tests handling of PRIORITY frames. | 5298 // Tests handling of PRIORITY frames. |
5358 TEST_P(SpdyFramerTest, ReadPriority) { | 5299 TEST_P(SpdyFramerTest, ReadPriority) { |
5359 if (spdy_version_ <= SPDY3) { | 5300 if (spdy_version_ <= SPDY3) { |
5360 return; | 5301 return; |
5361 } | 5302 } |
| 5303 SpdyFramer framer(spdy_version_); |
| 5304 SpdyPriorityIR priority(3, 1, 255, false); |
| 5305 scoped_ptr<SpdySerializedFrame> frame(framer.SerializePriority(priority)); |
| 5306 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5307 framer.set_visitor(&visitor); |
| 5308 EXPECT_CALL(visitor, OnPriority(3, 1, 255, false)); |
| 5309 framer.ProcessInput(frame->data(), frame->size()); |
5362 | 5310 |
5363 const unsigned char kFrameData[] = { | 5311 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
5364 0x00, 0x05, 0x02, 0x00, // PRIORITY frame | 5312 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
5365 0x00, 0x00, 0x00, 0x03, // stream ID 3 | 5313 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
5366 0x00, 0x00, 0x00, 0x01, // dependent on stream id 1 | 5314 // TODO(mlavan): once we actually maintain a priority tree, |
5367 0x00 // weight 0 | 5315 // check that state is adjusted correctly. |
5368 }; | |
5369 | |
5370 TestSpdyVisitor visitor(spdy_version_); | |
5371 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); | |
5372 | |
5373 EXPECT_EQ(SpdyFramer::SPDY_RESET, visitor.framer_.state()); | |
5374 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, visitor.framer_.error_code()) | |
5375 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); | |
5376 } | 5316 } |
5377 | 5317 |
5378 // Tests handling of PRIORITY frame with incorrect size. | 5318 // Tests handling of PRIORITY frame with incorrect size. |
5379 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { | 5319 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
5380 if (spdy_version_ <= SPDY3) { | 5320 if (spdy_version_ <= SPDY3) { |
5381 return; | 5321 return; |
5382 } | 5322 } |
5383 | 5323 |
5384 // PRIORITY frame of size 4, which isn't correct. | 5324 // PRIORITY frame of size 4, which isn't correct. |
5385 const unsigned char kFrameData[] = { | 5325 const unsigned char kFrameData[] = { |
(...skipping 37 matching lines...) Loading... |
5423 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); | 5363 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); |
5424 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); | 5364 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); |
5425 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); | 5365 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); |
5426 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); | 5366 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); |
5427 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); | 5367 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); |
5428 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); | 5368 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); |
5429 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); | 5369 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); |
5430 } | 5370 } |
5431 | 5371 |
5432 } // namespace net | 5372 } // namespace net |
OLD | NEW |