Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: net/spdy/spdy_framer_test.cc

Issue 10207001: Clean up a raft of SPDY files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: no ssize_t :( Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 8
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "net/spdy/spdy_framer.h" 10 #include "net/spdy/spdy_framer.h"
10 #include "net/spdy/spdy_protocol.h" 11 #include "net/spdy/spdy_protocol.h"
11 #include "net/spdy/spdy_frame_builder.h" 12 #include "net/spdy/spdy_frame_builder.h"
12 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
14 15
16 using std::string;
17 using std::max;
18 using std::min;
19 using std::numeric_limits;
15 using testing::_; 20 using testing::_;
16 21
17 namespace net { 22 namespace net {
18 23
19 namespace test { 24 namespace test {
20 25
21 static const size_t kMaxDecompressedSize = 1024; 26 static const size_t kMaxDecompressedSize = 1024;
22 27
23 class MockVisitor : public SpdyFramerVisitorInterface { 28 class MockVisitor : public SpdyFramerVisitorInterface {
24 public: 29 public:
25 MOCK_METHOD1(OnError, void(SpdyFramer* framer)); 30 MOCK_METHOD1(OnError, void(SpdyFramer* framer));
26 MOCK_METHOD1(OnControl, void(const SpdyControlFrame* frame)); 31 MOCK_METHOD1(OnControl, void(const SpdyControlFrame* frame));
27 MOCK_METHOD3(OnControlFrameHeaderData, bool(SpdyStreamId stream_id, 32 MOCK_METHOD3(OnControlFrameHeaderData, bool(SpdyStreamId stream_id,
28 const char* header_data, 33 const char* header_data,
29 size_t len)); 34 size_t len));
30 MOCK_METHOD2(OnCredentialFrameData, bool(const char* header_data, 35 MOCK_METHOD2(OnCredentialFrameData, bool(const char* header_data,
31 size_t len)); 36 size_t len));
32 MOCK_METHOD1(OnDataFrameHeader, void(const SpdyDataFrame* frame)); 37 MOCK_METHOD1(OnDataFrameHeader, void(const SpdyDataFrame* frame));
33 MOCK_METHOD3(OnStreamFrameData, void(SpdyStreamId stream_id, 38 MOCK_METHOD3(OnStreamFrameData, void(SpdyStreamId stream_id,
34 const char* data, 39 const char* data,
35 size_t len)); 40 size_t len));
36 MOCK_METHOD3(OnSetting, void(SpdySettingsIds id, uint8 flags, uint32 value)); 41 MOCK_METHOD3(OnSetting, void(SpdySettingsIds id, uint8 flags, uint32 value));
37 }; 42 };
38 43
39 class SpdyFramerTestUtil { 44 class SpdyFramerTestUtil {
40 public: 45 public:
41 // Decompress a single frame using the decompression context held by 46 // Decompress a single frame using the decompression context held by
42 // the SpdyFramer. The implemention will CHECK fail if the input is anything 47 // the SpdyFramer. The implemention is meant for use only in tests
ramant (doing other things) 2012/04/24 20:53:37 nit: two spaces after period. As you are cleaning
43 // other than a single, well-formed compressed frame. 48 // and will CHECK fail if the input is anything other than a single,
49 // well-formed compressed frame.
44 // 50 //
45 // Returns a new decompressed SpdyFrame. 51 // Returns a new decompressed SpdyFrame.
46 template<class SpdyFrameType> static SpdyFrame* DecompressFrame( 52 template<class SpdyFrameType> static SpdyFrame* DecompressFrame(
47 SpdyFramer* framer, const SpdyFrameType& frame) { 53 SpdyFramer* framer, const SpdyFrameType& frame) {
48 DecompressionVisitor visitor; 54 DecompressionVisitor visitor;
49 framer->set_visitor(&visitor); 55 framer->set_visitor(&visitor);
50 size_t input_size = frame.length() + SpdyFrame::kHeaderSize; 56 size_t input_size = frame.length() + SpdyFrame::kHeaderSize;
51 CHECK_EQ(input_size, framer->ProcessInput(frame.data(), input_size)); 57 CHECK_EQ(input_size, framer->ProcessInput(frame.data(), input_size));
52 CHECK_EQ(SpdyFramer::SPDY_RESET, framer->state()); 58 CHECK_EQ(SpdyFramer::SPDY_RESET, framer->state());
53 framer->set_visitor(NULL); 59 framer->set_visitor(NULL);
54 60
55 char* buffer = visitor.ReleaseBuffer(); 61 char* buffer = visitor.ReleaseBuffer();
56 CHECK(buffer); 62 CHECK(buffer != NULL);
57 SpdyFrame* decompressed_frame = new SpdyFrame(buffer, true); 63 SpdyFrame* decompressed_frame = new SpdyFrame(buffer, true);
58 decompressed_frame->set_length(visitor.size() - SpdyFrame::kHeaderSize); 64 decompressed_frame->set_length(visitor.size() - SpdyFrame::kHeaderSize);
59 return decompressed_frame; 65 return decompressed_frame;
60 } 66 }
61 67
62 class DecompressionVisitor : public SpdyFramerVisitorInterface { 68 class DecompressionVisitor : public SpdyFramerVisitorInterface {
63 public: 69 public:
64 DecompressionVisitor() 70 DecompressionVisitor()
65 : buffer_(NULL), size_(0), finished_(false) { 71 : buffer_(NULL), size_(0), finished_(false) {
66 } 72 }
67 73
68 virtual void OnControl(const SpdyControlFrame* frame) { 74 virtual void OnControl(const SpdyControlFrame* frame) {
69 CHECK(frame->has_header_block()); 75 CHECK(frame->has_header_block());
70 CHECK(!buffer_.get()); 76 CHECK(buffer_.get() == NULL);
71 CHECK_EQ(size_, 0u); 77 CHECK_EQ(0u, size_);
72 CHECK(!finished_); 78 CHECK(!finished_);
73 79
74 int32 control_frame_header_size = 0; 80 int32 control_frame_header_size = 0;
75 switch (frame->type()) { 81 switch (frame->type()) {
76 case SYN_STREAM: 82 case SYN_STREAM:
77 control_frame_header_size = SpdySynStreamControlFrame::size(); 83 control_frame_header_size = SpdySynStreamControlFrame::size();
78 break; 84 break;
79 case SYN_REPLY: 85 case SYN_REPLY:
80 control_frame_header_size = SpdySynReplyControlFrame::size(); 86 control_frame_header_size = SpdySynReplyControlFrame::size();
81 break; 87 break;
82 case HEADERS: 88 case HEADERS:
83 control_frame_header_size = SpdyHeadersControlFrame::size(); 89 control_frame_header_size = SpdyHeadersControlFrame::size();
84 break; 90 break;
85 default: 91 default:
86 LOG(FATAL); 92 LOG(FATAL);
87 return;
88 } 93 }
89 94
90 // Allocate space for the frame, and the copy header over. 95 // Allocate space for the frame, and the copy header over.
91 buffer_.reset(new char[kMaxDecompressedSize]); 96 buffer_.reset(new char[kMaxDecompressedSize]);
92 memcpy(buffer_.get(), frame->data(), control_frame_header_size); 97 memcpy(buffer_.get(), frame->data(), control_frame_header_size);
93 size_ += control_frame_header_size; 98 size_ += control_frame_header_size;
94 } 99 }
95 100
96 virtual bool OnControlFrameHeaderData(SpdyStreamId stream_id, 101 virtual bool OnControlFrameHeaderData(SpdyStreamId stream_id,
97 const char* header_data, 102 const char* header_data,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 scoped_array<char> buffer_; 147 scoped_array<char> buffer_;
143 size_t size_; 148 size_t size_;
144 bool finished_; 149 bool finished_;
145 150
146 DISALLOW_COPY_AND_ASSIGN(DecompressionVisitor); 151 DISALLOW_COPY_AND_ASSIGN(DecompressionVisitor);
147 }; 152 };
148 153
149 DISALLOW_COPY_AND_ASSIGN(SpdyFramerTestUtil); 154 DISALLOW_COPY_AND_ASSIGN(SpdyFramerTestUtil);
150 }; 155 };
151 156
152 std::string HexDumpWithMarks(const unsigned char* data, int length, 157 string HexDumpWithMarks(const unsigned char* data, int length,
153 const bool* marks, int mark_length) { 158 const bool* marks, int mark_length) {
154 static const char kHexChars[] = "0123456789abcdef"; 159 static const char kHexChars[] = "0123456789abcdef";
155 static const int kColumns = 4; 160 static const int kColumns = 4;
156 161
157 const int kSizeLimit = 1024; 162 const int kSizeLimit = 1024;
158 if (length > kSizeLimit || mark_length > kSizeLimit) { 163 if (length > kSizeLimit || mark_length > kSizeLimit) {
159 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes."; 164 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
160 length = std::min(length, kSizeLimit); 165 length = min(length, kSizeLimit);
161 mark_length = std::min(mark_length, kSizeLimit); 166 mark_length = min(mark_length, kSizeLimit);
162 } 167 }
163 168
164 std::string hex; 169 string hex;
165 for (const unsigned char* row = data; length > 0; 170 for (const unsigned char* row = data; length > 0;
166 row += kColumns, length -= kColumns) { 171 row += kColumns, length -= kColumns) {
167 for (const unsigned char *p = row; p < row + 4; ++p) { 172 for (const unsigned char *p = row; p < row + 4; ++p) {
168 if (p < row + length) { 173 if (p < row + length) {
169 const bool mark = 174 const bool mark =
170 (marks && (p - data) < mark_length && marks[p - data]); 175 (marks && (p - data) < mark_length && marks[p - data]);
171 hex += mark ? '*' : ' '; 176 hex += mark ? '*' : ' ';
172 hex += kHexChars[(*p & 0xf0) >> 4]; 177 hex += kHexChars[(*p & 0xf0) >> 4];
173 hex += kHexChars[*p & 0x0f]; 178 hex += kHexChars[*p & 0x0f];
174 hex += mark ? '*' : ' '; 179 hex += mark ? '*' : ' ';
175 } else { 180 } else {
176 hex += " "; 181 hex += " ";
177 } 182 }
178 } 183 }
179 hex = hex + " "; 184 hex = hex + " ";
180 185
181 for (const unsigned char *p = row; p < row + 4 && p < row + length; ++p) 186 for (const unsigned char *p = row; p < row + 4 && p < row + length; ++p)
182 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.'; 187 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
183 188
184 hex = hex + '\n'; 189 hex = hex + '\n';
185 } 190 }
186 return hex; 191 return hex;
187 } 192 }
188 193
189 void CompareCharArraysWithHexError( 194 void CompareCharArraysWithHexError(
190 const std::string& description, 195 const string& description,
191 const unsigned char* actual, 196 const unsigned char* actual,
192 const int actual_len, 197 const int actual_len,
193 const unsigned char* expected, 198 const unsigned char* expected,
194 const int expected_len) { 199 const int expected_len) {
195 const int min_len = std::min(actual_len, expected_len); 200 const int min_len = min(actual_len, expected_len);
196 const int max_len = std::max(actual_len, expected_len); 201 const int max_len = max(actual_len, expected_len);
197 scoped_array<bool> marks(new bool[max_len]); 202 scoped_array<bool> marks(new bool[max_len]);
198 bool identical = (actual_len == expected_len); 203 bool identical = (actual_len == expected_len);
199 for (int i = 0; i < min_len; ++i) { 204 for (int i = 0; i < min_len; ++i) {
200 if (actual[i] != expected[i]) { 205 if (actual[i] != expected[i]) {
201 marks[i] = true; 206 marks[i] = true;
202 identical = false; 207 identical = false;
203 } else { 208 } else {
204 marks[i] = false; 209 marks[i] = false;
205 } 210 }
206 } 211 }
207 for (int i = min_len; i < max_len; ++i) { 212 for (int i = min_len; i < max_len; ++i) {
208 marks[i] = true; 213 marks[i] = true;
209 } 214 }
210 if (identical) return; 215 if (identical) return;
211 ADD_FAILURE() 216 ADD_FAILURE()
212 << "Description:\n" 217 << "Description:\n"
213 << description 218 << description
214 << "\n\nExpected:\n" 219 << "\n\nExpected:\n"
215 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len) 220 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len)
216 << "\nActual:\n" 221 << "\nActual:\n"
217 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len); 222 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
218 } 223 }
219 224
220 class TestSpdyVisitor : public SpdyFramerVisitorInterface { 225 class TestSpdyVisitor : public SpdyFramerVisitorInterface {
221 public: 226 public:
222 static const size_t kDefaultHeaderBufferSize = 64 * 1024; 227 static const size_t kDefaultHeaderBufferSize = 16 * 1024;
223 static const size_t kDefaultCredentialBufferSize = 16 * 1024; 228 static const size_t kDefaultCredentialBufferSize = 16 * 1024;
224 229
225 TestSpdyVisitor(int version) 230 explicit TestSpdyVisitor(int version)
226 : framer_(version), 231 : framer_(version),
227 use_compression_(false), 232 use_compression_(false),
228 error_count_(0), 233 error_count_(0),
229 syn_frame_count_(0), 234 syn_frame_count_(0),
230 syn_reply_frame_count_(0), 235 syn_reply_frame_count_(0),
231 headers_frame_count_(0), 236 headers_frame_count_(0),
232 goaway_count_(0), 237 goaway_count_(0),
233 credential_count_(0), 238 credential_count_(0),
234 settings_frame_count_(0), 239 settings_frame_count_(0),
235 setting_count_(0), 240 setting_count_(0),
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 framer_.set_visitor(this); 373 framer_.set_visitor(this);
369 size_t input_remaining = size; 374 size_t input_remaining = size;
370 const char* input_ptr = reinterpret_cast<const char*>(input); 375 const char* input_ptr = reinterpret_cast<const char*>(input);
371 while (input_remaining > 0 && 376 while (input_remaining > 0 &&
372 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) { 377 framer_.error_code() == SpdyFramer::SPDY_NO_ERROR) {
373 // To make the tests more interesting, we feed random (amd small) chunks 378 // To make the tests more interesting, we feed random (amd small) chunks
374 // into the framer. This simulates getting strange-sized reads from 379 // into the framer. This simulates getting strange-sized reads from
375 // the socket. 380 // the socket.
376 const size_t kMaxReadSize = 32; 381 const size_t kMaxReadSize = 32;
377 size_t bytes_read = 382 size_t bytes_read =
378 (rand() % std::min(input_remaining, kMaxReadSize)) + 1; 383 (rand() % min(input_remaining, kMaxReadSize)) + 1;
379 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read); 384 size_t bytes_processed = framer_.ProcessInput(input_ptr, bytes_read);
380 input_remaining -= bytes_processed; 385 input_remaining -= bytes_processed;
381 input_ptr += bytes_processed; 386 input_ptr += bytes_processed;
382 if (framer_.state() == SpdyFramer::SPDY_DONE) 387 if (framer_.state() == SpdyFramer::SPDY_DONE)
383 framer_.Reset(); 388 framer_.Reset();
384 } 389 }
385 } 390 }
386 391
387 void InitHeaderStreaming(const SpdyControlFrame* frame) { 392 void InitHeaderStreaming(const SpdyControlFrame* frame) {
388 memset(header_buffer_.get(), 0, header_buffer_size_); 393 memset(header_buffer_.get(), 0, header_buffer_size_);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 SpdyControlType header_control_type_; 442 SpdyControlType header_control_type_;
438 bool header_buffer_valid_; 443 bool header_buffer_valid_;
439 SpdyHeaderBlock headers_; 444 SpdyHeaderBlock headers_;
440 445
441 scoped_array<char> credential_buffer_; 446 scoped_array<char> credential_buffer_;
442 size_t credential_buffer_length_; 447 size_t credential_buffer_length_;
443 size_t credential_buffer_size_; 448 size_t credential_buffer_size_;
444 SpdyCredential credential_; 449 SpdyCredential credential_;
445 }; 450 };
446 451
447 } // namespace test 452 } // namespace net
448 453
449 using test::CompareCharArraysWithHexError; 454 using test::CompareCharArraysWithHexError;
450 using test::SpdyFramerTestUtil; 455 using test::SpdyFramerTestUtil;
451 using test::TestSpdyVisitor; 456 using test::TestSpdyVisitor;
452 457
453 TEST(SpdyFrameBuilderTest, WriteLimits) { 458 TEST(SpdyFrameBuilderTest, WriteLimits) {
454 SpdyFrameBuilder builder(1, DATA_FLAG_NONE, kLengthMask + 8); 459 SpdyFrameBuilder builder(1, DATA_FLAG_NONE, kLengthMask + 8);
455 // Data frame header is 8 bytes 460 // Data frame header is 8 bytes
456 EXPECT_EQ(8u, builder.length()); 461 EXPECT_EQ(8u, builder.length());
457 const std::string kLargeData(kLengthMask, 'A'); 462 const string kLargeData(kLengthMask, 'A');
458 builder.WriteUInt32(kLengthMask); 463 builder.WriteUInt32(kLengthMask);
459 EXPECT_EQ(12u, builder.length()); 464 EXPECT_EQ(12u, builder.length());
460 EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask - 4)); 465 EXPECT_TRUE(builder.WriteBytes(kLargeData.data(), kLengthMask - 4));
461 EXPECT_EQ(kLengthMask + 8, builder.length()); 466 EXPECT_EQ(kLengthMask + 8u, builder.length());
462 } 467 }
463 468
464 enum SpdyFramerTestTypes { 469 enum SpdyFramerTestTypes {
465 SPDY2, 470 SPDY2 = 2,
466 SPDY3, 471 SPDY3 = 3,
467 }; 472 };
468 473
469 class SpdyFramerTest 474 class SpdyFramerTest
470 : public ::testing::TestWithParam<SpdyFramerTestTypes> { 475 : public ::testing::TestWithParam<SpdyFramerTestTypes> {
471 protected: 476 protected:
472 virtual void SetUp() { 477 virtual void SetUp() {
473 spdy_version_ = (GetParam() == SPDY2) ? 2 : 3; 478 spdy_version_ = GetParam();
474 } 479 }
475 480
476 virtual void TearDown() {} 481 void CompareFrame(const string& description,
477
478 void CompareFrame(const std::string& description,
479 const SpdyFrame& actual_frame, 482 const SpdyFrame& actual_frame,
480 const unsigned char* expected, 483 const unsigned char* expected,
481 const int expected_len) { 484 const int expected_len) {
482 const unsigned char* actual = 485 const unsigned char* actual =
483 reinterpret_cast<const unsigned char*>(actual_frame.data()); 486 reinterpret_cast<const unsigned char*>(actual_frame.data());
484 int actual_len = actual_frame.length() + SpdyFrame::kHeaderSize; 487 int actual_len = actual_frame.length() + SpdyFrame::kHeaderSize;
485 CompareCharArraysWithHexError( 488 CompareCharArraysWithHexError(
486 description, actual, actual_len, expected, expected_len); 489 description, actual, actual_len, expected, expected_len);
487 } 490 }
488 491
489 // Returns true if the two header blocks have equivalent content. 492 // Returns true if the two header blocks have equivalent content.
490 bool CompareHeaderBlocks(const SpdyHeaderBlock* expected, 493 bool CompareHeaderBlocks(const SpdyHeaderBlock* expected,
491 const SpdyHeaderBlock* actual) { 494 const SpdyHeaderBlock* actual) {
492 if (expected->size() != actual->size()) { 495 if (expected->size() != actual->size()) {
493 LOG(ERROR) << "Expected " << expected->size() << " headers; actually got " 496 LOG(ERROR) << "Expected " << expected->size() << " headers; actually got "
494 << actual->size() << "." << std::endl; 497 << actual->size() << ".";
495 return false; 498 return false;
496 } 499 }
497 for (SpdyHeaderBlock::const_iterator it = expected->begin(); 500 for (SpdyHeaderBlock::const_iterator it = expected->begin();
498 it != expected->end(); 501 it != expected->end();
499 ++it) { 502 ++it) {
500 SpdyHeaderBlock::const_iterator it2 = actual->find(it->first); 503 SpdyHeaderBlock::const_iterator it2 = actual->find(it->first);
501 if (it2 == actual->end()) { 504 if (it2 == actual->end()) {
502 LOG(ERROR) << "Expected header name '" << it->first << "'." 505 LOG(ERROR) << "Expected header name '" << it->first << "'.";
503 << std::endl;
504 return false; 506 return false;
505 } 507 }
506 if (it->second.compare(it2->second) != 0) { 508 if (it->second.compare(it2->second) != 0) {
507 LOG(ERROR) << "Expected header named '" << it->first 509 LOG(ERROR) << "Expected header named '" << it->first
508 << "' to have a value of '" << it->second 510 << "' to have a value of '" << it->second
509 << "'. The actual value received was '" << it2->second 511 << "'. The actual value received was '" << it2->second
510 << "'." << std::endl; 512 << "'.";
511 return false; 513 return false;
512 } 514 }
513 } 515 }
514 return true; 516 return true;
515 } 517 }
516 518
517 void AddSpdySettingFromWireFormat(SettingsMap* settings, 519 void AddSpdySettingFromWireFormat(SettingsMap* settings,
518 uint32 key, 520 uint32 key,
519 uint32 value) { 521 uint32 value) {
520 SettingsFlagsAndId flags_and_id = 522 SettingsFlagsAndId flags_and_id =
521 SettingsFlagsAndId::FromWireFormat(spdy_version_, key); 523 SettingsFlagsAndId::FromWireFormat(spdy_version_, key);
522 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id()); 524 SpdySettingsIds id = static_cast<SpdySettingsIds>(flags_and_id.id());
523 SpdySettingsFlags flags = 525 SpdySettingsFlags flags =
524 static_cast<SpdySettingsFlags>(flags_and_id.flags()); 526 static_cast<SpdySettingsFlags>(flags_and_id.flags());
525 settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value))); 527 settings->insert(std::make_pair(id, SettingsFlagsAndValue(flags, value)));
526 } 528 }
527 529
528 bool IsSpdy2() { return spdy_version_ < 3; } 530 bool IsSpdy2() { return spdy_version_ == SPDY2; }
529 531
530 // Version of SPDY protocol to be used. 532 // Version of SPDY protocol to be used.
531 int spdy_version_; 533 unsigned char spdy_version_;
532 }; 534 };
533 535
534
535 //-----------------------------------------------------------------------------
536 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3. 536 // All tests are run with two different SPDY versions: SPDY/2 and SPDY/3.
537 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, 537 INSTANTIATE_TEST_CASE_P(SpdyFramerTests,
538 SpdyFramerTest, 538 SpdyFramerTest,
539 ::testing::Values(SPDY2, SPDY3)); 539 ::testing::Values(SPDY2, SPDY3));
540 540
541 TEST_P(SpdyFramerTest, IsCompressible) { 541 TEST_P(SpdyFramerTest, IsCompressible) {
542 SpdyFramer framer(spdy_version_); 542 SpdyFramer framer(spdy_version_);
543 for (SpdyControlType type = SYN_STREAM; 543 for (SpdyControlType type = SYN_STREAM;
544 type < NUM_CONTROL_FRAME_TYPES; 544 type < NUM_CONTROL_FRAME_TYPES;
545 type = static_cast<SpdyControlType>(type + 1)) { 545 type = static_cast<SpdyControlType>(type + 1)) {
(...skipping 16 matching lines...) Expand all
562 // Encode the header block into a SynStream frame. 562 // Encode the header block into a SynStream frame.
563 scoped_ptr<SpdySynStreamControlFrame> frame( 563 scoped_ptr<SpdySynStreamControlFrame> frame(
564 framer.CreateSynStream(1, // stream id 564 framer.CreateSynStream(1, // stream id
565 0, // associated stream id 565 0, // associated stream id
566 1, // priority 566 1, // priority
567 0, // credential slot 567 0, // credential slot
568 CONTROL_FLAG_NONE, 568 CONTROL_FLAG_NONE,
569 false, // compress 569 false, // compress
570 &headers)); 570 &headers));
571 EXPECT_TRUE(frame.get() != NULL); 571 EXPECT_TRUE(frame.get() != NULL);
572 std::string serialized_headers(frame->header_block(), 572 string serialized_headers(frame->header_block(), frame->header_block_len());
573 frame->header_block_len());
574 SpdyHeaderBlock new_headers; 573 SpdyHeaderBlock new_headers;
575 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), 574 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
576 serialized_headers.size(), 575 serialized_headers.size(),
577 &new_headers)); 576 &new_headers));
578 577
579 EXPECT_EQ(headers.size(), new_headers.size()); 578 EXPECT_EQ(headers.size(), new_headers.size());
580 EXPECT_EQ(headers["alpha"], new_headers["alpha"]); 579 EXPECT_EQ(headers["alpha"], new_headers["alpha"]);
581 EXPECT_EQ(headers["gamma"], new_headers["gamma"]); 580 EXPECT_EQ(headers["gamma"], new_headers["gamma"]);
582 } 581 }
583 582
584 // Test that if there's not a full frame, we fail to parse it. 583 // Test that if there's not a full frame, we fail to parse it.
585 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) { 584 TEST_P(SpdyFramerTest, UndersizedHeaderBlockInBuffer) {
586 SpdyHeaderBlock headers; 585 SpdyHeaderBlock headers;
587 headers["alpha"] = "beta"; 586 headers["alpha"] = "beta";
588 headers["gamma"] = "charlie"; 587 headers["gamma"] = "charlie";
589 SpdyFramer framer(spdy_version_); 588 SpdyFramer framer(spdy_version_);
590 589
591 // Encode the header block into a SynStream frame. 590 // Encode the header block into a SynStream frame.
592 scoped_ptr<SpdySynStreamControlFrame> frame( 591 scoped_ptr<SpdySynStreamControlFrame> frame(
593 framer.CreateSynStream(1, // stream id 592 framer.CreateSynStream(1, // stream id
594 0, // associated stream id 593 0, // associated stream id
595 1, // priority 594 1, // priority
596 0, // credential slot 595 0, // credential slot
597 CONTROL_FLAG_NONE, 596 CONTROL_FLAG_NONE,
598 false, // compress 597 false, // compress
599 &headers)); 598 &headers));
600 EXPECT_TRUE(frame.get() != NULL); 599 EXPECT_TRUE(frame.get() != NULL);
601 600
602 std::string serialized_headers(frame->header_block(), 601 string serialized_headers(frame->header_block(), frame->header_block_len());
603 frame->header_block_len());
604 SpdyHeaderBlock new_headers; 602 SpdyHeaderBlock new_headers;
605 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), 603 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
606 serialized_headers.size() - 2, 604 serialized_headers.size() - 2,
607 &new_headers)); 605 &new_headers));
608 } 606 }
609 607
610 TEST_P(SpdyFramerTest, OutOfOrderHeaders) { 608 TEST_P(SpdyFramerTest, OutOfOrderHeaders) {
611 // Frame builder with plentiful buffer size. 609 // Frame builder with plentiful buffer size.
612 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024); 610 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024);
613 611
(...skipping 13 matching lines...) Expand all
627 frame.WriteStringPiece32("gamma"); 625 frame.WriteStringPiece32("gamma");
628 frame.WriteStringPiece32("alpha"); 626 frame.WriteStringPiece32("alpha");
629 frame.WriteStringPiece32("alpha"); 627 frame.WriteStringPiece32("alpha");
630 } 628 }
631 // write the length 629 // write the length
632 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); 630 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize);
633 631
634 SpdyHeaderBlock new_headers; 632 SpdyHeaderBlock new_headers;
635 scoped_ptr<SpdyFrame> control_frame(frame.take()); 633 scoped_ptr<SpdyFrame> control_frame(frame.take());
636 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); 634 SpdySynStreamControlFrame syn_frame(control_frame->data(), false);
637 std::string serialized_headers(syn_frame.header_block(), 635 string serialized_headers(syn_frame.header_block(),
638 syn_frame.header_block_len()); 636 syn_frame.header_block_len());
639 SpdyFramer framer(spdy_version_); 637 SpdyFramer framer(spdy_version_);
640 framer.set_enable_compression(false); 638 framer.set_enable_compression(false);
641 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), 639 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
642 serialized_headers.size(), 640 serialized_headers.size(),
643 &new_headers)); 641 &new_headers));
644 } 642 }
645 643
646 TEST_P(SpdyFramerTest, CreateCredential) { 644 TEST_P(SpdyFramerTest, CreateCredential) {
647 SpdyFramer framer(spdy_version_); 645 SpdyFramer framer(spdy_version_);
648 646
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 frame.WriteStringPiece32("value1"); 732 frame.WriteStringPiece32("value1");
735 frame.WriteStringPiece32("name"); 733 frame.WriteStringPiece32("name");
736 frame.WriteStringPiece32("value2"); 734 frame.WriteStringPiece32("value2");
737 } 735 }
738 // write the length 736 // write the length
739 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); 737 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize);
740 738
741 SpdyHeaderBlock new_headers; 739 SpdyHeaderBlock new_headers;
742 scoped_ptr<SpdyFrame> control_frame(frame.take()); 740 scoped_ptr<SpdyFrame> control_frame(frame.take());
743 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); 741 SpdySynStreamControlFrame syn_frame(control_frame->data(), false);
744 std::string serialized_headers(syn_frame.header_block(), 742 string serialized_headers(syn_frame.header_block(),
745 syn_frame.header_block_len()); 743 syn_frame.header_block_len());
746 SpdyFramer framer(spdy_version_); 744 SpdyFramer framer(spdy_version_);
747 framer.set_enable_compression(false); 745 framer.set_enable_compression(false);
748 // This should fail because duplicate headers are verboten by the spec. 746 // This should fail because duplicate headers are verboten by the spec.
749 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), 747 EXPECT_FALSE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
750 serialized_headers.size(), 748 serialized_headers.size(),
751 &new_headers)); 749 &new_headers));
752 } 750 }
753 751
754 TEST_P(SpdyFramerTest, MultiValueHeader) { 752 TEST_P(SpdyFramerTest, MultiValueHeader) {
755 // Frame builder with plentiful buffer size. 753 // Frame builder with plentiful buffer size.
756 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024); 754 SpdyFrameBuilder frame(SYN_STREAM, CONTROL_FLAG_NONE, 1, 1024);
757 755
758 frame.WriteUInt32(3); // stream_id 756 frame.WriteUInt32(3); // stream_id
759 frame.WriteUInt32(0); // associated stream id 757 frame.WriteUInt32(0); // associated stream id
760 frame.WriteUInt16(0); // Priority. 758 frame.WriteUInt16(0); // Priority.
761 759
762 std::string value("value1\0value2"); 760 string value("value1\0value2");
763 if (IsSpdy2()) { 761 if (IsSpdy2()) {
764 frame.WriteUInt16(1); // Number of headers. 762 frame.WriteUInt16(1); // Number of headers.
765 frame.WriteString("name"); 763 frame.WriteString("name");
766 frame.WriteString(value); 764 frame.WriteString(value);
767 } else { 765 } else {
768 frame.WriteUInt32(1); // Number of headers. 766 frame.WriteUInt32(1); // Number of headers.
769 frame.WriteStringPiece32("name"); 767 frame.WriteStringPiece32("name");
770 frame.WriteStringPiece32(value); 768 frame.WriteStringPiece32(value);
771 } 769 }
772 // write the length 770 // write the length
773 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize); 771 frame.WriteUInt32ToOffset(4, frame.length() - SpdyFrame::kHeaderSize);
774 772
775 SpdyHeaderBlock new_headers; 773 SpdyHeaderBlock new_headers;
776 scoped_ptr<SpdyFrame> control_frame(frame.take()); 774 scoped_ptr<SpdyFrame> control_frame(frame.take());
777 SpdySynStreamControlFrame syn_frame(control_frame->data(), false); 775 SpdySynStreamControlFrame syn_frame(control_frame->data(), false);
778 std::string serialized_headers(syn_frame.header_block(), 776 string serialized_headers(syn_frame.header_block(),
779 syn_frame.header_block_len()); 777 syn_frame.header_block_len());
780 SpdyFramer framer(spdy_version_); 778 SpdyFramer framer(spdy_version_);
781 framer.set_enable_compression(false); 779 framer.set_enable_compression(false);
782 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(), 780 EXPECT_TRUE(framer.ParseHeaderBlockInBuffer(serialized_headers.c_str(),
783 serialized_headers.size(), 781 serialized_headers.size(),
784 &new_headers)); 782 &new_headers));
785 EXPECT_TRUE(new_headers.find("name") != new_headers.end()); 783 EXPECT_TRUE(new_headers.find("name") != new_headers.end());
786 EXPECT_EQ(value, new_headers.find("name")->second); 784 EXPECT_EQ(value, new_headers.find("name")->second);
787 } 785 }
788 786
789 TEST_P(SpdyFramerTest, BasicCompression) { 787 TEST_P(SpdyFramerTest, BasicCompression) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 false, // compress 840 false, // compress
843 &headers)); 841 &headers));
844 EXPECT_EQ(frame3->length(), uncompressed_frame->length()); 842 EXPECT_EQ(frame3->length(), uncompressed_frame->length());
845 EXPECT_EQ(0, 843 EXPECT_EQ(0,
846 memcmp(frame3->data(), uncompressed_frame->data(), 844 memcmp(frame3->data(), uncompressed_frame->data(),
847 SpdyFrame::kHeaderSize + uncompressed_frame->length())); 845 SpdyFrame::kHeaderSize + uncompressed_frame->length()));
848 } 846 }
849 847
850 TEST_P(SpdyFramerTest, Basic) { 848 TEST_P(SpdyFramerTest, Basic) {
851 const unsigned char kV2Input[] = { 849 const unsigned char kV2Input[] = {
852 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1 850 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1
853 0x00, 0x00, 0x00, 0x14, 851 0x00, 0x00, 0x00, 0x14,
854 0x00, 0x00, 0x00, 0x01, 852 0x00, 0x00, 0x00, 0x01,
855 0x00, 0x00, 0x00, 0x00, 853 0x00, 0x00, 0x00, 0x00,
856 0x00, 0x00, 0x00, 0x01, 854 0x00, 0x00, 0x00, 0x01,
857 0x00, 0x02, 'h', 'h', 855 0x00, 0x02, 'h', 'h',
858 0x00, 0x02, 'v', 'v', 856 0x00, 0x02, 'v', 'v',
859 857
860 0x80, spdy_version_, 0x00, 0x08, // HEADERS on Stream #1 858 0x80, spdy_version_, 0x00, 0x08, // HEADERS on Stream #1
861 0x00, 0x00, 0x00, 0x18, 859 0x00, 0x00, 0x00, 0x18,
862 0x00, 0x00, 0x00, 0x01, 860 0x00, 0x00, 0x00, 0x01,
863 0x00, 0x00, 0x00, 0x02, 861 0x00, 0x00, 0x00, 0x02,
864 0x00, 0x02, 'h', '2', 862 0x00, 0x02, 'h', '2',
865 0x00, 0x02, 'v', '2', 863 0x00, 0x02, 'v', '2',
866 0x00, 0x02, 'h', '3', 864 0x00, 0x02, 'h', '3',
867 0x00, 0x02, 'v', '3', 865 0x00, 0x02, 'v', '3',
868 866
869 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 867 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
870 0x00, 0x00, 0x00, 0x0c, 868 0x00, 0x00, 0x00, 0x0c,
871 0xde, 0xad, 0xbe, 0xef, 869 0xde, 0xad, 0xbe, 0xef,
872 0xde, 0xad, 0xbe, 0xef, 870 0xde, 0xad, 0xbe, 0xef,
873 0xde, 0xad, 0xbe, 0xef, 871 0xde, 0xad, 0xbe, 0xef,
874 872
875 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #3 873 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #3
876 0x00, 0x00, 0x00, 0x0c, 874 0x00, 0x00, 0x00, 0x0c,
877 0x00, 0x00, 0x00, 0x03, 875 0x00, 0x00, 0x00, 0x03,
878 0x00, 0x00, 0x00, 0x00, 876 0x00, 0x00, 0x00, 0x00,
879 0x00, 0x00, 0x00, 0x00, 877 0x00, 0x00, 0x00, 0x00,
880 878
881 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 879 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3
882 0x00, 0x00, 0x00, 0x08, 880 0x00, 0x00, 0x00, 0x08,
883 0xde, 0xad, 0xbe, 0xef, 881 0xde, 0xad, 0xbe, 0xef,
884 0xde, 0xad, 0xbe, 0xef, 882 0xde, 0xad, 0xbe, 0xef,
885 883
886 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 884 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
887 0x00, 0x00, 0x00, 0x04, 885 0x00, 0x00, 0x00, 0x04,
888 0xde, 0xad, 0xbe, 0xef, 886 0xde, 0xad, 0xbe, 0xef,
889 887
890 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #1 888 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #1
891 0x00, 0x00, 0x00, 0x08, 889 0x00, 0x00, 0x00, 0x08,
892 0x00, 0x00, 0x00, 0x01, 890 0x00, 0x00, 0x00, 0x01,
893 0x00, 0x00, 0x00, 0x00, 891 0x00, 0x00, 0x00, 0x00,
894 892
895 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 893 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3
896 0x00, 0x00, 0x00, 0x00, 894 0x00, 0x00, 0x00, 0x00,
897 895
898 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #3 896 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #3
899 0x00, 0x00, 0x00, 0x08, 897 0x00, 0x00, 0x00, 0x08,
900 0x00, 0x00, 0x00, 0x03, 898 0x00, 0x00, 0x00, 0x03,
901 0x00, 0x00, 0x00, 0x00, 899 0x00, 0x00, 0x00, 0x00,
902 }; 900 };
903 901
904 const unsigned char kV3Input[] = { 902 const unsigned char kV3Input[] = {
905 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1 903 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1
906 0x00, 0x00, 0x00, 0x1a, 904 0x00, 0x00, 0x00, 0x1a,
907 0x00, 0x00, 0x00, 0x01, 905 0x00, 0x00, 0x00, 0x01,
908 0x00, 0x00, 0x00, 0x00, 906 0x00, 0x00, 0x00, 0x00,
909 0x00, 0x00, 0x00, 0x00, 907 0x00, 0x00, 0x00, 0x00,
910 0x00, 0x01, 0x00, 0x00, 908 0x00, 0x01, 0x00, 0x00,
911 0x00, 0x02, 'h', 'h', 909 0x00, 0x02, 'h', 'h',
912 0x00, 0x00, 0x00, 0x02, 910 0x00, 0x00, 0x00, 0x02,
913 'v', 'v', 911 'v', 'v',
914 912
915 0x80, spdy_version_, 0x00, 0x08, // HEADERS on Stream #1 913 0x80, spdy_version_, 0x00, 0x08, // HEADERS on Stream #1
916 0x00, 0x00, 0x00, 0x22, 914 0x00, 0x00, 0x00, 0x22,
917 0x00, 0x00, 0x00, 0x01, 915 0x00, 0x00, 0x00, 0x01,
918 0x00, 0x00, 0x00, 0x00, 916 0x00, 0x00, 0x00, 0x00,
919 0x00, 0x02, 0x00, 0x00, 917 0x00, 0x02, 0x00, 0x00,
920 0x00, 0x02, 'h', '2', 918 0x00, 0x02, 'h', '2',
921 0x00, 0x00, 0x00, 0x02, 919 0x00, 0x00, 0x00, 0x02,
922 'v', '2', 0x00, 0x00, 920 'v', '2', 0x00, 0x00,
923 0x00, 0x02, 'h', '3', 921 0x00, 0x02, 'h', '3',
924 0x00, 0x00, 0x00, 0x02, 922 0x00, 0x00, 0x00, 0x02,
925 'v', '3', 923 'v', '3',
926 924
927 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 925 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
928 0x00, 0x00, 0x00, 0x0c, 926 0x00, 0x00, 0x00, 0x0c,
929 0xde, 0xad, 0xbe, 0xef, 927 0xde, 0xad, 0xbe, 0xef,
930 0xde, 0xad, 0xbe, 0xef, 928 0xde, 0xad, 0xbe, 0xef,
931 0xde, 0xad, 0xbe, 0xef, 929 0xde, 0xad, 0xbe, 0xef,
932 930
933 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #3 931 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #3
934 0x00, 0x00, 0x00, 0x0e, 932 0x00, 0x00, 0x00, 0x0e,
935 0x00, 0x00, 0x00, 0x03, 933 0x00, 0x00, 0x00, 0x03,
936 0x00, 0x00, 0x00, 0x00, 934 0x00, 0x00, 0x00, 0x00,
937 0x00, 0x00, 0x00, 0x00, 935 0x00, 0x00, 0x00, 0x00,
938 0x00, 0x00, 936 0x00, 0x00,
939 937
940 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 938 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3
941 0x00, 0x00, 0x00, 0x08, 939 0x00, 0x00, 0x00, 0x08,
942 0xde, 0xad, 0xbe, 0xef, 940 0xde, 0xad, 0xbe, 0xef,
943 0xde, 0xad, 0xbe, 0xef, 941 0xde, 0xad, 0xbe, 0xef,
944 942
945 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 943 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
946 0x00, 0x00, 0x00, 0x04, 944 0x00, 0x00, 0x00, 0x04,
947 0xde, 0xad, 0xbe, 0xef, 945 0xde, 0xad, 0xbe, 0xef,
948 946
949 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #1 947 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #1
950 0x00, 0x00, 0x00, 0x08, 948 0x00, 0x00, 0x00, 0x08,
951 0x00, 0x00, 0x00, 0x01, 949 0x00, 0x00, 0x00, 0x01,
952 0x00, 0x00, 0x00, 0x00, 950 0x00, 0x00, 0x00, 0x00,
953 951
954 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3 952 0x00, 0x00, 0x00, 0x03, // DATA on Stream #3
955 0x00, 0x00, 0x00, 0x00, 953 0x00, 0x00, 0x00, 0x00,
956 954
957 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #3 955 0x80, spdy_version_, 0x00, 0x03, // RST_STREAM on Stream #3
958 0x00, 0x00, 0x00, 0x08, 956 0x00, 0x00, 0x00, 0x08,
959 0x00, 0x00, 0x00, 0x03, 957 0x00, 0x00, 0x00, 0x03,
960 0x00, 0x00, 0x00, 0x00, 958 0x00, 0x00, 0x00, 0x00,
961 }; 959 };
962 960
963 TestSpdyVisitor visitor(spdy_version_); 961 TestSpdyVisitor visitor(spdy_version_);
964 if (IsSpdy2()) { 962 if (IsSpdy2()) {
965 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); 963 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
966 } else { 964 } else {
967 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 965 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
968 } 966 }
969 967
970 EXPECT_EQ(0, visitor.error_count_); 968 EXPECT_EQ(0, visitor.error_count_);
971 EXPECT_EQ(2, visitor.syn_frame_count_); 969 EXPECT_EQ(2, visitor.syn_frame_count_);
972 EXPECT_EQ(0, visitor.syn_reply_frame_count_); 970 EXPECT_EQ(0, visitor.syn_reply_frame_count_);
973 EXPECT_EQ(1, visitor.headers_frame_count_); 971 EXPECT_EQ(1, visitor.headers_frame_count_);
974 EXPECT_EQ(24, visitor.data_bytes_); 972 EXPECT_EQ(24, visitor.data_bytes_);
975 EXPECT_EQ(2, visitor.fin_frame_count_); 973 EXPECT_EQ(2, visitor.fin_frame_count_);
976 EXPECT_EQ(0, visitor.fin_flag_count_); 974 EXPECT_EQ(0, visitor.fin_flag_count_);
977 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); 975 EXPECT_EQ(0, visitor.zero_length_data_frame_count_);
978 EXPECT_EQ(4, visitor.data_frame_count_); 976 EXPECT_EQ(4, visitor.data_frame_count_);
979 } 977 }
980 978
981 // Test that the FIN flag on a data frame signifies EOF. 979 // Test that the FIN flag on a data frame signifies EOF.
982 TEST_P(SpdyFramerTest, FinOnDataFrame) { 980 TEST_P(SpdyFramerTest, FinOnDataFrame) {
983 const unsigned char kV2Input[] = { 981 const unsigned char kV2Input[] = {
984 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1 982 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1
985 0x00, 0x00, 0x00, 0x14, 983 0x00, 0x00, 0x00, 0x14,
986 0x00, 0x00, 0x00, 0x01, 984 0x00, 0x00, 0x00, 0x01,
987 0x00, 0x00, 0x00, 0x00, 985 0x00, 0x00, 0x00, 0x00,
988 0x00, 0x00, 0x00, 0x01, 986 0x00, 0x00, 0x00, 0x01,
989 0x00, 0x02, 'h', 'h', 987 0x00, 0x02, 'h', 'h',
990 0x00, 0x02, 'v', 'v', 988 0x00, 0x02, 'v', 'v',
991 989
992 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1 990 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1
993 0x00, 0x00, 0x00, 0x10, 991 0x00, 0x00, 0x00, 0x10,
994 0x00, 0x00, 0x00, 0x01, 992 0x00, 0x00, 0x00, 0x01,
995 0x00, 0x00, 0x00, 0x01, 993 0x00, 0x00, 0x00, 0x01,
996 0x00, 0x02, 'a', 'a', 994 0x00, 0x02, 'a', 'a',
997 0x00, 0x02, 'b', 'b', 995 0x00, 0x02, 'b', 'b',
998 996
999 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 997 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
1000 0x00, 0x00, 0x00, 0x0c, 998 0x00, 0x00, 0x00, 0x0c,
1001 0xde, 0xad, 0xbe, 0xef, 999 0xde, 0xad, 0xbe, 0xef,
1002 0xde, 0xad, 0xbe, 0xef, 1000 0xde, 0xad, 0xbe, 0xef,
1003 0xde, 0xad, 0xbe, 0xef, 1001 0xde, 0xad, 0xbe, 0xef,
1004 1002
1005 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF 1003 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF
1006 0x01, 0x00, 0x00, 0x04, 1004 0x01, 0x00, 0x00, 0x04,
1007 0xde, 0xad, 0xbe, 0xef, 1005 0xde, 0xad, 0xbe, 0xef,
1008 }; 1006 };
1009 const unsigned char kV3Input[] = { 1007 const unsigned char kV3Input[] = {
1010 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1 1008 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1
1011 0x00, 0x00, 0x00, 0x1a, 1009 0x00, 0x00, 0x00, 0x1a,
1012 0x00, 0x00, 0x00, 0x01, 1010 0x00, 0x00, 0x00, 0x01,
1013 0x00, 0x00, 0x00, 0x00, 1011 0x00, 0x00, 0x00, 0x00,
1014 0x00, 0x00, 0x00, 0x00, 1012 0x00, 0x00, 0x00, 0x00,
1015 0x00, 0x01, 0x00, 0x00, 1013 0x00, 0x01, 0x00, 0x00,
1016 0x00, 0x02, 'h', 'h', 1014 0x00, 0x02, 'h', 'h',
1017 0x00, 0x00, 0x00, 0x02, 1015 0x00, 0x00, 0x00, 0x02,
1018 'v', 'v', 1016 'v', 'v',
1019 1017
1020 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1 1018 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1
1021 0x00, 0x00, 0x00, 0x16, 1019 0x00, 0x00, 0x00, 0x16,
1022 0x00, 0x00, 0x00, 0x01, 1020 0x00, 0x00, 0x00, 0x01,
1023 0x00, 0x00, 0x00, 0x00, 1021 0x00, 0x00, 0x00, 0x00,
1024 0x00, 0x01, 0x00, 0x00, 1022 0x00, 0x01, 0x00, 0x00,
1025 0x00, 0x02, 'a', 'a', 1023 0x00, 0x02, 'a', 'a',
1026 0x00, 0x00, 0x00, 0x02, 1024 0x00, 0x00, 0x00, 0x02,
1027 'b', 'b', 1025 'b', 'b',
1028 1026
1029 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 1027 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
1030 0x00, 0x00, 0x00, 0x0c, 1028 0x00, 0x00, 0x00, 0x0c,
1031 0xde, 0xad, 0xbe, 0xef, 1029 0xde, 0xad, 0xbe, 0xef,
1032 0xde, 0xad, 0xbe, 0xef, 1030 0xde, 0xad, 0xbe, 0xef,
1033 0xde, 0xad, 0xbe, 0xef, 1031 0xde, 0xad, 0xbe, 0xef,
1034 1032
1035 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF 1033 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF
1036 0x01, 0x00, 0x00, 0x04, 1034 0x01, 0x00, 0x00, 0x04,
1037 0xde, 0xad, 0xbe, 0xef, 1035 0xde, 0xad, 0xbe, 0xef,
1038 }; 1036 };
1039 1037
1040 TestSpdyVisitor visitor(spdy_version_); 1038 TestSpdyVisitor visitor(spdy_version_);
1041 if (IsSpdy2()) { 1039 if (IsSpdy2()) {
1042 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); 1040 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1043 } else { 1041 } else {
1044 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1042 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1045 } 1043 }
1046 1044
1047 EXPECT_EQ(0, visitor.error_count_); 1045 EXPECT_EQ(0, visitor.error_count_);
1048 EXPECT_EQ(1, visitor.syn_frame_count_); 1046 EXPECT_EQ(1, visitor.syn_frame_count_);
1049 EXPECT_EQ(1, visitor.syn_reply_frame_count_); 1047 EXPECT_EQ(1, visitor.syn_reply_frame_count_);
1050 EXPECT_EQ(0, visitor.headers_frame_count_); 1048 EXPECT_EQ(0, visitor.headers_frame_count_);
1051 EXPECT_EQ(16, visitor.data_bytes_); 1049 EXPECT_EQ(16, visitor.data_bytes_);
1052 EXPECT_EQ(0, visitor.fin_frame_count_); 1050 EXPECT_EQ(0, visitor.fin_frame_count_);
1053 EXPECT_EQ(0, visitor.fin_flag_count_); 1051 EXPECT_EQ(0, visitor.fin_flag_count_);
1054 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); 1052 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
1055 EXPECT_EQ(2, visitor.data_frame_count_); 1053 EXPECT_EQ(2, visitor.data_frame_count_);
1056 } 1054 }
1057 1055
1058 // Test that the FIN flag on a SYN reply frame signifies EOF. 1056 // Test that the FIN flag on a SYN reply frame signifies EOF.
1059 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { 1057 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) {
1060 const unsigned char kV2Input[] = { 1058 const unsigned char kV2Input[] = {
1061 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1 1059 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1
1062 0x00, 0x00, 0x00, 0x14, 1060 0x00, 0x00, 0x00, 0x14,
1063 0x00, 0x00, 0x00, 0x01, 1061 0x00, 0x00, 0x00, 0x01,
1064 0x00, 0x00, 0x00, 0x00, 1062 0x00, 0x00, 0x00, 0x00,
1065 0x00, 0x00, 0x00, 0x01, 1063 0x00, 0x00, 0x00, 0x01,
1066 0x00, 0x02, 'h', 'h', 1064 0x00, 0x02, 'h', 'h',
1067 0x00, 0x02, 'v', 'v', 1065 0x00, 0x02, 'v', 'v',
1068 1066
1069 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1 1067 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1
1070 0x01, 0x00, 0x00, 0x14, 1068 0x01, 0x00, 0x00, 0x14,
1071 0x00, 0x00, 0x00, 0x01, 1069 0x00, 0x00, 0x00, 0x01,
1072 0x00, 0x00, 0x00, 0x00, 1070 0x00, 0x00, 0x00, 0x00,
1073 0x00, 0x00, 0x00, 0x01, 1071 0x00, 0x00, 0x00, 0x01,
1074 0x00, 0x02, 'a', 'a', 1072 0x00, 0x02, 'a', 'a',
1075 0x00, 0x02, 'b', 'b', 1073 0x00, 0x02, 'b', 'b',
1076 }; 1074 };
1077 const unsigned char kV3Input[] = { 1075 const unsigned char kV3Input[] = {
1078 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1 1076 0x80, spdy_version_, 0x00, 0x01, // SYN Stream #1
1079 0x00, 0x00, 0x00, 0x1a, 1077 0x00, 0x00, 0x00, 0x1a,
1080 0x00, 0x00, 0x00, 0x01, 1078 0x00, 0x00, 0x00, 0x01,
1081 0x00, 0x00, 0x00, 0x00, 1079 0x00, 0x00, 0x00, 0x00,
1082 0x00, 0x00, 0x00, 0x00, 1080 0x00, 0x00, 0x00, 0x00,
1083 0x00, 0x01, 0x00, 0x00, 1081 0x00, 0x01, 0x00, 0x00,
1084 0x00, 0x02, 'h', 'h', 1082 0x00, 0x02, 'h', 'h',
1085 0x00, 0x00, 0x00, 0x02, 1083 0x00, 0x00, 0x00, 0x02,
1086 'v', 'v', 1084 'v', 'v',
1087 1085
1088 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1 1086 0x80, spdy_version_, 0x00, 0x02, // SYN REPLY Stream #1
1089 0x01, 0x00, 0x00, 0x1a, 1087 0x01, 0x00, 0x00, 0x1a,
1090 0x00, 0x00, 0x00, 0x01, 1088 0x00, 0x00, 0x00, 0x01,
1091 0x00, 0x00, 0x00, 0x00, 1089 0x00, 0x00, 0x00, 0x00,
1092 0x00, 0x00, 0x00, 0x00, 1090 0x00, 0x00, 0x00, 0x00,
1093 0x00, 0x01, 0x00, 0x00, 1091 0x00, 0x01, 0x00, 0x00,
1094 0x00, 0x02, 'a', 'a', 1092 0x00, 0x02, 'a', 'a',
1095 0x00, 0x00, 0x00, 0x02, 1093 0x00, 0x00, 0x00, 0x02,
1096 'b', 'b', 1094 'b', 'b',
1097 }; 1095 };
1098 1096
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 0, // priority 1149 0, // priority
1152 0, // credential slot 1150 0, // credential slot
1153 flags, 1151 flags,
1154 true, // compress 1152 true, // compress
1155 &block)); 1153 &block));
1156 EXPECT_TRUE(syn_frame_2.get() != NULL); 1154 EXPECT_TRUE(syn_frame_2.get() != NULL);
1157 1155
1158 // Now start decompressing 1156 // Now start decompressing
1159 scoped_ptr<SpdyFrame> decompressed; 1157 scoped_ptr<SpdyFrame> decompressed;
1160 scoped_ptr<SpdySynStreamControlFrame> syn_frame; 1158 scoped_ptr<SpdySynStreamControlFrame> syn_frame;
1161 scoped_ptr<std::string> serialized_headers; 1159 scoped_ptr<string> serialized_headers;
1162 SpdyHeaderBlock decompressed_headers; 1160 SpdyHeaderBlock decompressed_headers;
1163 1161
1164 // Decompress SYN_STREAM #1 1162 // Decompress SYN_STREAM #1
1165 decompressed.reset(SpdyFramerTestUtil::DecompressFrame( 1163 decompressed.reset(SpdyFramerTestUtil::DecompressFrame(
1166 &recv_framer, *syn_frame_1.get())); 1164 &recv_framer, *syn_frame_1.get()));
1167 EXPECT_TRUE(decompressed.get() != NULL); 1165 EXPECT_TRUE(decompressed.get() != NULL);
1168 EXPECT_TRUE(decompressed->is_control_frame()); 1166 EXPECT_TRUE(decompressed->is_control_frame());
1169 EXPECT_EQ(SYN_STREAM, 1167 EXPECT_EQ(SYN_STREAM,
1170 reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type()); 1168 reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type());
1171 syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false)); 1169 syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false));
1172 serialized_headers.reset(new std::string(syn_frame->header_block(), 1170 serialized_headers.reset(new string(syn_frame->header_block(),
1173 syn_frame->header_block_len())); 1171 syn_frame->header_block_len()));
1174 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(), 1172 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(),
1175 serialized_headers->size(), 1173 serialized_headers->size(),
1176 &decompressed_headers)); 1174 &decompressed_headers));
1177 EXPECT_EQ(2u, decompressed_headers.size()); 1175 EXPECT_EQ(2u, decompressed_headers.size());
1178 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); 1176 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]);
1179 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); 1177 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]);
1180 1178
1181 // Decompress SYN_STREAM #2 1179 // Decompress SYN_STREAM #2
1182 decompressed.reset(SpdyFramerTestUtil::DecompressFrame( 1180 decompressed.reset(SpdyFramerTestUtil::DecompressFrame(
1183 &recv_framer, *syn_frame_2.get())); 1181 &recv_framer, *syn_frame_2.get()));
1184 EXPECT_TRUE(decompressed.get() != NULL); 1182 EXPECT_TRUE(decompressed.get() != NULL);
1185 EXPECT_TRUE(decompressed->is_control_frame()); 1183 EXPECT_TRUE(decompressed->is_control_frame());
1186 EXPECT_EQ(SYN_STREAM, 1184 EXPECT_EQ(SYN_STREAM,
1187 reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type()); 1185 reinterpret_cast<SpdyControlFrame*>(decompressed.get())->type());
1188 syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false)); 1186 syn_frame.reset(new SpdySynStreamControlFrame(decompressed->data(), false));
1189 serialized_headers.reset(new std::string(syn_frame->header_block(), 1187 serialized_headers.reset(new string(syn_frame->header_block(),
1190 syn_frame->header_block_len())); 1188 syn_frame->header_block_len()));
1191 decompressed_headers.clear(); 1189 decompressed_headers.clear();
1192 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(), 1190 EXPECT_TRUE(recv_framer.ParseHeaderBlockInBuffer(serialized_headers->c_str(),
1193 serialized_headers->size(), 1191 serialized_headers->size(),
1194 &decompressed_headers)); 1192 &decompressed_headers));
1195 EXPECT_EQ(3u, decompressed_headers.size()); 1193 EXPECT_EQ(3u, decompressed_headers.size());
1196 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]); 1194 EXPECT_EQ(kValue1, decompressed_headers[kHeader1]);
1197 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]); 1195 EXPECT_EQ(kValue2, decompressed_headers[kHeader2]);
1198 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]); 1196 EXPECT_EQ(kValue3, decompressed_headers[kHeader3]);
1199 } 1197 }
1200 1198
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 { 1334 {
1337 const char kDescription[] = "'hello' data frame, no FIN"; 1335 const char kDescription[] = "'hello' data frame, no FIN";
1338 const unsigned char kFrameData[] = { 1336 const unsigned char kFrameData[] = {
1339 0x00, 0x00, 0x00, 0x01, 1337 0x00, 0x00, 0x00, 0x01,
1340 0x00, 0x00, 0x00, 0x05, 1338 0x00, 0x00, 0x00, 0x05,
1341 'h', 'e', 'l', 'l', 1339 'h', 'e', 'l', 'l',
1342 'o' 1340 'o'
1343 }; 1341 };
1344 const char bytes[] = "hello"; 1342 const char bytes[] = "hello";
1345 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame( 1343 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame(
1346 1, bytes, arraysize(bytes) - 1, DATA_FLAG_NONE)); 1344 1, bytes, strlen(bytes), DATA_FLAG_NONE));
1347 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 1345 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
1348 } 1346 }
1349 1347
1350 { 1348 {
1351 const char kDescription[] = "Data frame with negative data byte, no FIN"; 1349 const char kDescription[] = "Data frame with negative data byte, no FIN";
1352 const unsigned char kFrameData[] = { 1350 const unsigned char kFrameData[] = {
1353 0x00, 0x00, 0x00, 0x01, 1351 0x00, 0x00, 0x00, 0x01,
1354 0x00, 0x00, 0x00, 0x01, 1352 0x00, 0x00, 0x00, 0x01,
1355 0xff 1353 0xff
1356 }; 1354 };
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 'o' 1390 'o'
1393 }; 1391 };
1394 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame( 1392 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame(
1395 0x7fffffff, "hello", 5, DATA_FLAG_FIN)); 1393 0x7fffffff, "hello", 5, DATA_FLAG_FIN));
1396 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 1394 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
1397 } 1395 }
1398 1396
1399 { 1397 {
1400 const char kDescription[] = "Large data frame"; 1398 const char kDescription[] = "Large data frame";
1401 const int kDataSize = 4 * 1024 * 1024; // 4 MB 1399 const int kDataSize = 4 * 1024 * 1024; // 4 MB
1402 const std::string kData(kDataSize, 'A'); 1400 const string kData(kDataSize, 'A');
1403 const unsigned char kFrameHeader[] = { 1401 const unsigned char kFrameHeader[] = {
1404 0x00, 0x00, 0x00, 0x01, 1402 0x00, 0x00, 0x00, 0x01,
1405 0x01, 0x40, 0x00, 0x00, 1403 0x01, 0x40, 0x00, 0x00,
1406 }; 1404 };
1407 1405
1408 const int kFrameSize = arraysize(kFrameHeader) + kDataSize; 1406 const int kFrameSize = arraysize(kFrameHeader) + kDataSize;
1409 scoped_array<unsigned char> expected_frame_data( 1407 scoped_array<unsigned char> expected_frame_data(
1410 new unsigned char[kFrameSize]); 1408 new unsigned char[kFrameSize]);
1411 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader)); 1409 memcpy(expected_frame_data.get(), kFrameHeader, arraysize(kFrameHeader));
1412 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize); 1410 memset(expected_frame_data.get() + arraysize(kFrameHeader), 'A', kDataSize);
1413 1411
1414 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame( 1412 scoped_ptr<SpdyFrame> frame(framer.CreateDataFrame(
1415 1, kData.data(), kData.size(), DATA_FLAG_FIN)); 1413 1, kData.data(), kData.size(), DATA_FLAG_FIN));
1416 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize); 1414 CompareFrame(kDescription, *frame, expected_frame_data.get(), kFrameSize);
1417 } 1415 }
1418 } 1416 }
1419 1417
1420 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) { 1418 TEST_P(SpdyFramerTest, CreateSynStreamUncompressed) {
1421 SpdyFramer framer(spdy_version_); 1419 SpdyFramer framer(spdy_version_);
1422 framer.set_enable_compression(false); 1420 framer.set_enable_compression(false);
1423 1421
1424 { 1422 {
1425 const char kDescription[] = "SYN_STREAM frame, lowest pri, slot 2, no FIN"; 1423 const char kDescription[] = "SYN_STREAM frame, lowest pri, slot 2, no FIN";
1426 1424
1427 SpdyHeaderBlock headers; 1425 SpdyHeaderBlock headers;
1428 headers["bar"] = "foo"; 1426 headers["bar"] = "foo";
1429 headers["foo"] = "bar"; 1427 headers["foo"] = "bar";
1430 1428
1431 const unsigned char kPri = (IsSpdy2()) ? 0xC0 : 0xE0; 1429 const unsigned char kPri = IsSpdy2() ? 0xC0 : 0xE0;
1432 const unsigned char kCre = (IsSpdy2()) ? 0 : 2; 1430 const unsigned char kCre = IsSpdy2() ? 0 : 2;
1433 const unsigned char kV2FrameData[] = { 1431 const unsigned char kV2FrameData[] = {
1434 0x80, spdy_version_, 0x00, 0x01, 1432 0x80, spdy_version_, 0x00, 0x01,
1435 0x00, 0x00, 0x00, 0x20, 1433 0x00, 0x00, 0x00, 0x20,
1436 0x00, 0x00, 0x00, 0x01, 1434 0x00, 0x00, 0x00, 0x01,
1437 0x00, 0x00, 0x00, 0x00, 1435 0x00, 0x00, 0x00, 0x00,
1438 kPri, 0x00, 0x00, 0x02, 1436 kPri, 0x00, 0x00, 0x02,
1439 0x00, 0x03, 'b', 'a', 1437 0x00, 0x03, 'b', 'a',
1440 'r', 0x00, 0x03, 'f', 1438 'r', 0x00, 0x03, 'f',
1441 'o', 'o', 0x00, 0x03, 1439 'o', 'o', 0x00, 0x03,
1442 'f', 'o', 'o', 0x00, 1440 'f', 'o', 'o', 0x00,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 1521
1524 { 1522 {
1525 const char kDescription[] = 1523 const char kDescription[] =
1526 "SYN_STREAM frame with a 0-length header val, high pri, FIN, " 1524 "SYN_STREAM frame with a 0-length header val, high pri, FIN, "
1527 "max stream ID"; 1525 "max stream ID";
1528 1526
1529 SpdyHeaderBlock headers; 1527 SpdyHeaderBlock headers;
1530 headers["bar"] = "foo"; 1528 headers["bar"] = "foo";
1531 headers["foo"] = ""; 1529 headers["foo"] = "";
1532 1530
1533 const unsigned char kPri = (spdy_version_ != 2) ? 0x20 : 0x40; 1531 const unsigned char kPri = IsSpdy2() ? 0x40 : 0x20;
1534 const unsigned char kV2FrameData[] = { 1532 const unsigned char kV2FrameData[] = {
1535 0x80, spdy_version_, 0x00, 0x01, 1533 0x80, spdy_version_, 0x00, 0x01,
1536 0x01, 0x00, 0x00, 0x1D, 1534 0x01, 0x00, 0x00, 0x1D,
1537 0x7f, 0xff, 0xff, 0xff, 1535 0x7f, 0xff, 0xff, 0xff,
1538 0x7f, 0xff, 0xff, 0xff, 1536 0x7f, 0xff, 0xff, 0xff,
1539 kPri, 0x00, 0x00, 0x02, 1537 kPri, 0x00, 0x00, 0x02,
1540 0x00, 0x03, 'b', 'a', 1538 0x00, 0x03, 'b', 'a',
1541 'r', 0x00, 0x03, 'f', 1539 'r', 0x00, 0x03, 'f',
1542 'o', 'o', 0x00, 0x03, 1540 'o', 'o', 0x00, 0x03,
1543 'f', 'o', 'o', 0x00, 1541 'f', 'o', 'o', 0x00,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 framer.set_enable_compression(true); 1575 framer.set_enable_compression(true);
1578 1576
1579 { 1577 {
1580 const char kDescription[] = 1578 const char kDescription[] =
1581 "SYN_STREAM frame, low pri, no FIN"; 1579 "SYN_STREAM frame, low pri, no FIN";
1582 1580
1583 SpdyHeaderBlock headers; 1581 SpdyHeaderBlock headers;
1584 headers["bar"] = "foo"; 1582 headers["bar"] = "foo";
1585 headers["foo"] = "bar"; 1583 headers["foo"] = "bar";
1586 1584
1587 const SpdyPriority priority = (spdy_version_ != 2) ? 4 : 2; 1585 const SpdyPriority priority = IsSpdy2() ? 2 : 4;
1588 const unsigned char kV2FrameData[] = { 1586 const unsigned char kV2FrameData[] = {
1589 0x80, spdy_version_, 0x00, 0x01, 1587 0x80, spdy_version_, 0x00, 0x01,
1590 0x00, 0x00, 0x00, 0x25, 1588 0x00, 0x00, 0x00, 0x25,
1591 0x00, 0x00, 0x00, 0x01, 1589 0x00, 0x00, 0x00, 0x01,
1592 0x00, 0x00, 0x00, 0x00, 1590 0x00, 0x00, 0x00, 0x00,
1593 0x80, 0x00, 0x38, 0xea, 1591 0x80, 0x00, 0x38, 0xea,
1594 0xdf, 0xa2, 0x51, 0xb2, 1592 0xdf, 0xa2, 0x51, 0xb2,
1595 0x62, 0x60, 0x62, 0x60, 1593 0x62, 0x60, 0x62, 0x60,
1596 0x4e, 0x4a, 0x2c, 0x62, 1594 0x4e, 0x4a, 0x2c, 0x62,
1597 0x60, 0x4e, 0xcb, 0xcf, 1595 0x60, 0x4e, 0xcb, 0xcf,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 0x00, 0x00, 0x03, 'f', 1738 0x00, 0x00, 0x03, 'f',
1741 'o', 'o', 0x00, 0x00, 1739 'o', 'o', 0x00, 0x00,
1742 0x00, 0x03, 'f', 'o', 1740 0x00, 0x03, 'f', 'o',
1743 'o', 0x00, 0x00, 0x00, 1741 'o', 0x00, 0x00, 0x00,
1744 0x00 1742 0x00
1745 }; 1743 };
1746 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( 1744 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply(
1747 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); 1745 0x7fffffff, CONTROL_FLAG_FIN, false, &headers));
1748 CompareFrame(kDescription, 1746 CompareFrame(kDescription,
1749 *frame, 1747 *frame,
1750 (IsSpdy2()) ? kV2FrameData : kV3FrameData, 1748 IsSpdy2() ? kV2FrameData : kV3FrameData,
1751 (IsSpdy2()) ? arraysize(kV2FrameData) 1749 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
1752 : arraysize(kV3FrameData));
1753 } 1750 }
1754 } 1751 }
1755 1752
1756 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) { 1753 TEST_P(SpdyFramerTest, CreateSynReplyCompressed) {
1757 SpdyFramer framer(spdy_version_); 1754 SpdyFramer framer(spdy_version_);
1758 framer.set_enable_compression(true); 1755 framer.set_enable_compression(true);
1759 1756
1760 { 1757 {
1761 const char kDescription[] = "SYN_REPLY frame, no FIN"; 1758 const char kDescription[] = "SYN_REPLY frame, no FIN";
1762 1759
(...skipping 24 matching lines...) Expand all
1787 0x4a, 0x04, 0xe5, 0x0b, 1784 0x4a, 0x04, 0xe5, 0x0b,
1788 0xe6, 0xb4, 0xfc, 0x7c, 1785 0xe6, 0xb4, 0xfc, 0x7c,
1789 0x24, 0x0a, 0x28, 0x08, 1786 0x24, 0x0a, 0x28, 0x08,
1790 0x00, 0x00, 0x00, 0xff, 1787 0x00, 0x00, 0x00, 0xff,
1791 0xff 1788 0xff
1792 }; 1789 };
1793 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply( 1790 scoped_ptr<SpdyFrame> frame(framer.CreateSynReply(
1794 1, CONTROL_FLAG_NONE, true, &headers)); 1791 1, CONTROL_FLAG_NONE, true, &headers));
1795 CompareFrame(kDescription, 1792 CompareFrame(kDescription,
1796 *frame, 1793 *frame,
1797 (IsSpdy2()) ? kV2FrameData : kV3FrameData, 1794 IsSpdy2() ? kV2FrameData : kV3FrameData,
1798 (IsSpdy2()) ? arraysize(kV2FrameData) 1795 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
1799 : arraysize(kV3FrameData));
1800 } 1796 }
1801 } 1797 }
1802 1798
1803 TEST_P(SpdyFramerTest, CreateRstStream) { 1799 TEST_P(SpdyFramerTest, CreateRstStream) {
1804 SpdyFramer framer(spdy_version_); 1800 SpdyFramer framer(spdy_version_);
1805 1801
1806 { 1802 {
1807 const char kDescription[] = "RST_STREAM frame"; 1803 const char kDescription[] = "RST_STREAM frame";
1808 const unsigned char kFrameData[] = { 1804 const unsigned char kFrameData[] = {
1809 0x80, spdy_version_, 0x00, 0x03, 1805 0x80, spdy_version_, 0x00, 0x03,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 0x80, spdy_version_, 0x00, 0x04, 1868 0x80, spdy_version_, 0x00, 0x04,
1873 0x00, 0x00, 0x00, 0x0c, 1869 0x00, 0x00, 0x00, 0x0c,
1874 0x00, 0x00, 0x00, 0x01, 1870 0x00, 0x00, 0x00, 0x01,
1875 0x04, 0x03, 0x02, 0x01, 1871 0x04, 0x03, 0x02, 0x01,
1876 0x0a, 0x0b, 0x0c, 0x0d, 1872 0x0a, 0x0b, 0x0c, 0x0d,
1877 }; 1873 };
1878 1874
1879 scoped_ptr<SpdySettingsControlFrame> frame(framer.CreateSettings(settings)); 1875 scoped_ptr<SpdySettingsControlFrame> frame(framer.CreateSettings(settings));
1880 CompareFrame(kDescription, 1876 CompareFrame(kDescription,
1881 *frame, 1877 *frame,
1882 (IsSpdy2()) ? kFrameDatav2 : kFrameDatav3, 1878 IsSpdy2() ? kFrameDatav2 : kFrameDatav3,
1883 arraysize(kFrameDatav3)); // Size is unchanged among versions. 1879 arraysize(kFrameDatav3)); // Size is unchanged among versions.
1884 EXPECT_EQ(SpdyFramer::kInvalidStream, 1880 EXPECT_EQ(SpdyFramer::kInvalidStream,
1885 SpdyFramer::GetControlFrameStreamId(frame.get())); 1881 SpdyFramer::GetControlFrameStreamId(frame.get()));
1886 1882
1887 // Make sure that ParseSettings also works as advertised. 1883 // Make sure that ParseSettings also works as advertised.
1888 SettingsMap parsed_settings; 1884 SettingsMap parsed_settings;
1889 EXPECT_TRUE(framer.ParseSettings(frame.get(), &parsed_settings)); 1885 EXPECT_TRUE(framer.ParseSettings(frame.get(), &parsed_settings));
1890 EXPECT_EQ(settings.size(), parsed_settings.size()); 1886 EXPECT_EQ(settings.size(), parsed_settings.size());
1891 EXPECT_EQ(kFlags, parsed_settings[kId].first); 1887 EXPECT_EQ(kFlags, parsed_settings[kId].first);
1892 EXPECT_EQ(kValue, parsed_settings[kId].second); 1888 EXPECT_EQ(kValue, parsed_settings[kId].second);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 const unsigned char kV3FrameData[] = { 1976 const unsigned char kV3FrameData[] = {
1981 0x80, spdy_version_, 0x00, 0x07, 1977 0x80, spdy_version_, 0x00, 0x07,
1982 0x00, 0x00, 0x00, 0x08, 1978 0x00, 0x00, 0x00, 0x08,
1983 0x00, 0x00, 0x00, 0x00, 1979 0x00, 0x00, 0x00, 0x00,
1984 0x00, 0x00, 0x00, 0x00, 1980 0x00, 0x00, 0x00, 0x00,
1985 }; 1981 };
1986 scoped_ptr<SpdyGoAwayControlFrame> frame(framer.CreateGoAway(0, GOAWAY_OK)); 1982 scoped_ptr<SpdyGoAwayControlFrame> frame(framer.CreateGoAway(0, GOAWAY_OK));
1987 CompareFrame(kDescription, 1983 CompareFrame(kDescription,
1988 *frame, 1984 *frame,
1989 IsSpdy2() ? kV2FrameData : kV3FrameData, 1985 IsSpdy2() ? kV2FrameData : kV3FrameData,
1990 IsSpdy2() ? arraysize(kV2FrameData) 1986 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
1991 : arraysize(kV3FrameData));
1992 EXPECT_EQ(SpdyFramer::kInvalidStream, 1987 EXPECT_EQ(SpdyFramer::kInvalidStream,
1993 SpdyFramer::GetControlFrameStreamId(frame.get())); 1988 SpdyFramer::GetControlFrameStreamId(frame.get()));
1994 } 1989 }
1995 1990
1996 { 1991 {
1997 const char kDescription[] = "GOAWAY frame with max stream ID, status"; 1992 const char kDescription[] = "GOAWAY frame with max stream ID, status";
1998 const unsigned char kV2FrameData[] = { 1993 const unsigned char kV2FrameData[] = {
1999 0x80, spdy_version_, 0x00, 0x07, 1994 0x80, spdy_version_, 0x00, 0x07,
2000 0x00, 0x00, 0x00, 0x04, 1995 0x00, 0x00, 0x00, 0x04,
2001 0x7f, 0xff, 0xff, 0xff, 1996 0x7f, 0xff, 0xff, 0xff,
2002 }; 1997 };
2003 const unsigned char kV3FrameData[] = { 1998 const unsigned char kV3FrameData[] = {
2004 0x80, spdy_version_, 0x00, 0x07, 1999 0x80, spdy_version_, 0x00, 0x07,
2005 0x00, 0x00, 0x00, 0x08, 2000 0x00, 0x00, 0x00, 0x08,
2006 0x7f, 0xff, 0xff, 0xff, 2001 0x7f, 0xff, 0xff, 0xff,
2007 0x00, 0x00, 0x00, 0x02, 2002 0x00, 0x00, 0x00, 0x02,
2008 }; 2003 };
2009 scoped_ptr<SpdyFrame> frame(framer.CreateGoAway(0x7FFFFFFF, 2004 scoped_ptr<SpdyFrame> frame(framer.CreateGoAway(0x7FFFFFFF,
2010 GOAWAY_INTERNAL_ERROR)); 2005 GOAWAY_INTERNAL_ERROR));
2011 CompareFrame(kDescription, 2006 CompareFrame(kDescription,
2012 *frame, 2007 *frame,
2013 IsSpdy2() ? kV2FrameData : kV3FrameData, 2008 IsSpdy2() ? kV2FrameData : kV3FrameData,
2014 IsSpdy2() ? arraysize(kV2FrameData) 2009 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
2015 : arraysize(kV3FrameData));
2016 } 2010 }
2017 } 2011 }
2018 2012
2019 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) { 2013 TEST_P(SpdyFramerTest, CreateHeadersUncompressed) {
2020 SpdyFramer framer(spdy_version_); 2014 SpdyFramer framer(spdy_version_);
2021 framer.set_enable_compression(false); 2015 framer.set_enable_compression(false);
2022 2016
2023 { 2017 {
2024 const char kDescription[] = "HEADERS frame, no FIN"; 2018 const char kDescription[] = "HEADERS frame, no FIN";
2025 2019
(...skipping 22 matching lines...) Expand all
2048 0x00, 0x00, 0x03, 'f', 2042 0x00, 0x00, 0x03, 'f',
2049 'o', 'o', 0x00, 0x00, 2043 'o', 'o', 0x00, 0x00,
2050 0x00, 0x03, 'f', 'o', 2044 0x00, 0x03, 'f', 'o',
2051 'o', 0x00, 0x00, 0x00, 2045 'o', 0x00, 0x00, 0x00,
2052 0x03, 'b', 'a', 'r' 2046 0x03, 'b', 'a', 'r'
2053 }; 2047 };
2054 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( 2048 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders(
2055 1, CONTROL_FLAG_NONE, false, &headers)); 2049 1, CONTROL_FLAG_NONE, false, &headers));
2056 CompareFrame(kDescription, 2050 CompareFrame(kDescription,
2057 *frame, 2051 *frame,
2058 (IsSpdy2()) ? kV2FrameData : kV3FrameData, 2052 IsSpdy2() ? kV2FrameData : kV3FrameData,
2059 (IsSpdy2()) ? arraysize(kV2FrameData) 2053 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
2060 : arraysize(kV3FrameData));
2061 } 2054 }
2062 2055
2063 { 2056 {
2064 const char kDescription[] = 2057 const char kDescription[] =
2065 "HEADERS frame with a 0-length header name, FIN, max stream ID"; 2058 "HEADERS frame with a 0-length header name, FIN, max stream ID";
2066 2059
2067 SpdyHeaderBlock headers; 2060 SpdyHeaderBlock headers;
2068 headers[""] = "foo"; 2061 headers[""] = "foo";
2069 headers["foo"] = "bar"; 2062 headers["foo"] = "bar";
2070 2063
(...skipping 19 matching lines...) Expand all
2090 0x00, 0x00, 0x03, 'f', 2083 0x00, 0x00, 0x03, 'f',
2091 'o', 'o', 0x00, 0x00, 2084 'o', 'o', 0x00, 0x00,
2092 0x00, 0x03, 'b', 'a', 2085 0x00, 0x03, 'b', 'a',
2093 'r' 2086 'r'
2094 }; 2087 };
2095 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( 2088 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders(
2096 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); 2089 0x7fffffff, CONTROL_FLAG_FIN, false, &headers));
2097 CompareFrame(kDescription, 2090 CompareFrame(kDescription,
2098 *frame, 2091 *frame,
2099 IsSpdy2() ? kV2FrameData : kV3FrameData, 2092 IsSpdy2() ? kV2FrameData : kV3FrameData,
2100 IsSpdy2() ? arraysize(kV2FrameData) 2093 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
2101 : arraysize(kV3FrameData));
2102 } 2094 }
2103 2095
2104 { 2096 {
2105 const char kDescription[] = 2097 const char kDescription[] =
2106 "HEADERS frame with a 0-length header val, FIN, max stream ID"; 2098 "HEADERS frame with a 0-length header val, FIN, max stream ID";
2107 2099
2108 SpdyHeaderBlock headers; 2100 SpdyHeaderBlock headers;
2109 headers["bar"] = "foo"; 2101 headers["bar"] = "foo";
2110 headers["foo"] = ""; 2102 headers["foo"] = "";
2111 2103
(...skipping 19 matching lines...) Expand all
2131 'o', 'o', 0x00, 0x00, 2123 'o', 'o', 0x00, 0x00,
2132 0x00, 0x03, 'f', 'o', 2124 0x00, 0x03, 'f', 'o',
2133 'o', 0x00, 0x00, 0x00, 2125 'o', 0x00, 0x00, 0x00,
2134 0x00 2126 0x00
2135 }; 2127 };
2136 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( 2128 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders(
2137 0x7fffffff, CONTROL_FLAG_FIN, false, &headers)); 2129 0x7fffffff, CONTROL_FLAG_FIN, false, &headers));
2138 CompareFrame(kDescription, 2130 CompareFrame(kDescription,
2139 *frame, 2131 *frame,
2140 IsSpdy2() ? kV2FrameData : kV3FrameData, 2132 IsSpdy2() ? kV2FrameData : kV3FrameData,
2141 IsSpdy2() ? arraysize(kV2FrameData) 2133 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
2142 : arraysize(kV3FrameData));
2143 } 2134 }
2144 } 2135 }
2145 2136
2146 TEST_P(SpdyFramerTest, CreateHeadersCompressed) { 2137 TEST_P(SpdyFramerTest, CreateHeadersCompressed) {
2147 SpdyFramer framer(spdy_version_); 2138 SpdyFramer framer(spdy_version_);
2148 framer.set_enable_compression(true); 2139 framer.set_enable_compression(true);
2149 2140
2150 { 2141 {
2151 const char kDescription[] = "HEADERS frame, no FIN"; 2142 const char kDescription[] = "HEADERS frame, no FIN";
2152 2143
(...skipping 25 matching lines...) Expand all
2178 0xe6, 0xb4, 0xfc, 0x7c, 2169 0xe6, 0xb4, 0xfc, 0x7c,
2179 0x24, 0x0a, 0x28, 0x08, 2170 0x24, 0x0a, 0x28, 0x08,
2180 0x00, 0x00, 0x00, 0xff, 2171 0x00, 0x00, 0x00, 0xff,
2181 0xff 2172 0xff
2182 }; 2173 };
2183 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders( 2174 scoped_ptr<SpdyFrame> frame(framer.CreateHeaders(
2184 1, CONTROL_FLAG_NONE, true, &headers)); 2175 1, CONTROL_FLAG_NONE, true, &headers));
2185 CompareFrame(kDescription, 2176 CompareFrame(kDescription,
2186 *frame, 2177 *frame,
2187 IsSpdy2() ? kV2FrameData : kV3FrameData, 2178 IsSpdy2() ? kV2FrameData : kV3FrameData,
2188 IsSpdy2() ? arraysize(kV2FrameData) 2179 IsSpdy2() ? arraysize(kV2FrameData) : arraysize(kV3FrameData));
2189 : arraysize(kV3FrameData));
2190 } 2180 }
2191 } 2181 }
2192 2182
2193 TEST_P(SpdyFramerTest, CreateWindowUpdate) { 2183 TEST_P(SpdyFramerTest, CreateWindowUpdate) {
2194 SpdyFramer framer(spdy_version_); 2184 SpdyFramer framer(spdy_version_);
2195 2185
2196 { 2186 {
2197 const char kDescription[] = "WINDOW_UPDATE frame"; 2187 const char kDescription[] = "WINDOW_UPDATE frame";
2198 const unsigned char kFrameData[] = { 2188 const unsigned char kFrameData[] = {
2199 0x80, spdy_version_, 0x00, 0x09, 2189 0x80, spdy_version_, 0x00, 0x09,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 1, // priority 2251 1, // priority
2262 0, // credential_slot 2252 0, // credential_slot
2263 CONTROL_FLAG_NONE, 2253 CONTROL_FLAG_NONE,
2264 true, // compress 2254 true, // compress
2265 &headers)); 2255 &headers));
2266 EXPECT_TRUE(control_frame.get() != NULL); 2256 EXPECT_TRUE(control_frame.get() != NULL);
2267 TestSpdyVisitor visitor(spdy_version_); 2257 TestSpdyVisitor visitor(spdy_version_);
2268 visitor.use_compression_ = true; 2258 visitor.use_compression_ = true;
2269 visitor.SimulateInFramer( 2259 visitor.SimulateInFramer(
2270 reinterpret_cast<unsigned char*>(control_frame->data()), 2260 reinterpret_cast<unsigned char*>(control_frame->data()),
2271 control_frame->length() + SpdyControlFrame::kHeaderSize); 2261 control_frame->length() + SpdyControlFrame::kHeaderSize);
2272 EXPECT_EQ(1, visitor.syn_frame_count_); 2262 EXPECT_EQ(1, visitor.syn_frame_count_);
2273 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 2263 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
2274 } 2264 }
2275 2265
2276 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) { 2266 TEST_P(SpdyFramerTest, ReadCompressedSynReplyHeaderBlock) {
2277 SpdyHeaderBlock headers; 2267 SpdyHeaderBlock headers;
2278 headers["alpha"] = "beta"; 2268 headers["alpha"] = "beta";
2279 headers["gamma"] = "delta"; 2269 headers["gamma"] = "delta";
2280 SpdyFramer framer(spdy_version_); 2270 SpdyFramer framer(spdy_version_);
2281 scoped_ptr<SpdySynReplyControlFrame> control_frame( 2271 scoped_ptr<SpdySynReplyControlFrame> control_frame(
2282 framer.CreateSynReply(1, // stream_id 2272 framer.CreateSynReply(1, // stream_id
2283 CONTROL_FLAG_NONE, 2273 CONTROL_FLAG_NONE,
2284 true, // compress 2274 true, // compress
2285 &headers)); 2275 &headers));
2286 EXPECT_TRUE(control_frame.get() != NULL); 2276 EXPECT_TRUE(control_frame.get() != NULL);
2287 TestSpdyVisitor visitor(spdy_version_); 2277 TestSpdyVisitor visitor(spdy_version_);
2288 visitor.use_compression_ = true; 2278 visitor.use_compression_ = true;
2289 visitor.SimulateInFramer( 2279 visitor.SimulateInFramer(
2290 reinterpret_cast<unsigned char*>(control_frame->data()), 2280 reinterpret_cast<unsigned char*>(control_frame->data()),
2291 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2281 control_frame->length() + SpdyControlFrame::kHeaderSize);
2292 EXPECT_EQ(1, visitor.syn_reply_frame_count_); 2282 EXPECT_EQ(1, visitor.syn_reply_frame_count_);
2293 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 2283 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
2294 } 2284 }
2295 2285
2296 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) { 2286 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlock) {
2297 SpdyHeaderBlock headers; 2287 SpdyHeaderBlock headers;
2298 headers["alpha"] = "beta"; 2288 headers["alpha"] = "beta";
2299 headers["gamma"] = "delta"; 2289 headers["gamma"] = "delta";
2300 SpdyFramer framer(spdy_version_); 2290 SpdyFramer framer(spdy_version_);
2301 scoped_ptr<SpdyHeadersControlFrame> control_frame( 2291 scoped_ptr<SpdyHeadersControlFrame> control_frame(
2302 framer.CreateHeaders(1, // stream_id 2292 framer.CreateHeaders(1, // stream_id
2303 CONTROL_FLAG_NONE, 2293 CONTROL_FLAG_NONE,
2304 true, // compress 2294 true, // compress
2305 &headers)); 2295 &headers));
2306 EXPECT_TRUE(control_frame.get() != NULL); 2296 EXPECT_TRUE(control_frame.get() != NULL);
2307 TestSpdyVisitor visitor(spdy_version_); 2297 TestSpdyVisitor visitor(spdy_version_);
2308 visitor.use_compression_ = true; 2298 visitor.use_compression_ = true;
2309 visitor.SimulateInFramer( 2299 visitor.SimulateInFramer(
2310 reinterpret_cast<unsigned char*>(control_frame->data()), 2300 reinterpret_cast<unsigned char*>(control_frame->data()),
2311 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2301 control_frame->length() + SpdyControlFrame::kHeaderSize);
2312 EXPECT_EQ(1, visitor.headers_frame_count_); 2302 EXPECT_EQ(1, visitor.headers_frame_count_);
2313 // control_frame_header_data_count_ depends on the random sequence 2303 // control_frame_header_data_count_ depends on the random sequence
2314 // produced by rand(), so adding, removing or running single tests 2304 // produced by rand(), so adding, removing or running single tests
2315 // alters this value. The best we can do is assert that it happens 2305 // alters this value. The best we can do is assert that it happens
2316 // at least twice. 2306 // at least twice.
2317 EXPECT_LE(2, visitor.control_frame_header_data_count_); 2307 EXPECT_LE(2, visitor.control_frame_header_data_count_);
2318 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); 2308 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_);
2319 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); 2309 EXPECT_EQ(0, visitor.zero_length_data_frame_count_);
2320 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 2310 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
2321 } 2311 }
2322 2312
2323 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) { 2313 TEST_P(SpdyFramerTest, ReadCompressedHeadersHeaderBlockWithHalfClose) {
2324 SpdyHeaderBlock headers; 2314 SpdyHeaderBlock headers;
2325 headers["alpha"] = "beta"; 2315 headers["alpha"] = "beta";
2326 headers["gamma"] = "delta"; 2316 headers["gamma"] = "delta";
2327 SpdyFramer framer(spdy_version_); 2317 SpdyFramer framer(spdy_version_);
2328 scoped_ptr<SpdyHeadersControlFrame> control_frame( 2318 scoped_ptr<SpdyHeadersControlFrame> control_frame(
2329 framer.CreateHeaders(1, // stream_id 2319 framer.CreateHeaders(1, // stream_id
2330 CONTROL_FLAG_FIN, 2320 CONTROL_FLAG_FIN,
2331 true, // compress 2321 true, // compress
2332 &headers)); 2322 &headers));
2333 EXPECT_TRUE(control_frame.get() != NULL); 2323 EXPECT_TRUE(control_frame.get() != NULL);
2334 TestSpdyVisitor visitor(spdy_version_); 2324 TestSpdyVisitor visitor(spdy_version_);
2335 visitor.use_compression_ = true; 2325 visitor.use_compression_ = true;
2336 visitor.SimulateInFramer( 2326 visitor.SimulateInFramer(
2337 reinterpret_cast<unsigned char*>(control_frame->data()), 2327 reinterpret_cast<unsigned char*>(control_frame->data()),
2338 control_frame->length() + SpdyControlFrame::kHeaderSize); 2328 control_frame->length() + SpdyControlFrame::kHeaderSize);
2339 EXPECT_EQ(1, visitor.headers_frame_count_); 2329 EXPECT_EQ(1, visitor.headers_frame_count_);
2340 // control_frame_header_data_count_ depends on the random sequence 2330 // control_frame_header_data_count_ depends on the random sequence
2341 // produced by rand(), so adding, removing or running single tests 2331 // produced by rand(), so adding, removing or running single tests
2342 // alters this value. The best we can do is assert that it happens 2332 // alters this value. The best we can do is assert that it happens
2343 // at least twice. 2333 // at least twice.
2344 EXPECT_LE(2, visitor.control_frame_header_data_count_); 2334 EXPECT_LE(2, visitor.control_frame_header_data_count_);
2345 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); 2335 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_);
2346 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); 2336 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
2347 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 2337 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
2348 } 2338 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 0, // associated_stream_id 2391 0, // associated_stream_id
2402 1, // priority 2392 1, // priority
2403 0, // credential_slot 2393 0, // credential_slot
2404 CONTROL_FLAG_NONE, 2394 CONTROL_FLAG_NONE,
2405 false, // compress 2395 false, // compress
2406 &headers)); 2396 &headers));
2407 EXPECT_TRUE(control_frame.get() != NULL); 2397 EXPECT_TRUE(control_frame.get() != NULL);
2408 TestSpdyVisitor visitor(spdy_version_); 2398 TestSpdyVisitor visitor(spdy_version_);
2409 visitor.SimulateInFramer( 2399 visitor.SimulateInFramer(
2410 reinterpret_cast<unsigned char*>(control_frame->data()), 2400 reinterpret_cast<unsigned char*>(control_frame->data()),
2411 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2401 control_frame->length() + SpdyControlFrame::kHeaderSize);
2412 EXPECT_FALSE(visitor.header_buffer_valid_); 2402 EXPECT_FALSE(visitor.header_buffer_valid_);
2413 EXPECT_EQ(1, visitor.error_count_); 2403 EXPECT_EQ(1, visitor.error_count_);
2414 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, 2404 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE,
2415 visitor.framer_.error_code()); 2405 visitor.framer_.error_code());
2416 EXPECT_EQ(0, visitor.syn_frame_count_); 2406 EXPECT_EQ(0, visitor.syn_frame_count_);
2417 EXPECT_EQ(0u, visitor.header_buffer_length_); 2407 EXPECT_EQ(0u, visitor.header_buffer_length_);
2418 } 2408 }
2419 2409
2420 // Check that the framer stops delivering header data chunks once the visitor 2410 // Check that the framer stops delivering header data chunks once the visitor
2421 // declares it doesn't want any more. This is important to guard against 2411 // declares it doesn't want any more. This is important to guard against
(...skipping 14 matching lines...) Expand all
2436 0, // credential_slot 2426 0, // credential_slot
2437 CONTROL_FLAG_FIN, // half close 2427 CONTROL_FLAG_FIN, // half close
2438 true, // compress 2428 true, // compress
2439 &headers)); 2429 &headers));
2440 EXPECT_TRUE(control_frame.get() != NULL); 2430 EXPECT_TRUE(control_frame.get() != NULL);
2441 TestSpdyVisitor visitor(spdy_version_); 2431 TestSpdyVisitor visitor(spdy_version_);
2442 visitor.set_header_buffer_size(kHeaderBufferSize); 2432 visitor.set_header_buffer_size(kHeaderBufferSize);
2443 visitor.use_compression_ = true; 2433 visitor.use_compression_ = true;
2444 visitor.SimulateInFramer( 2434 visitor.SimulateInFramer(
2445 reinterpret_cast<unsigned char*>(control_frame->data()), 2435 reinterpret_cast<unsigned char*>(control_frame->data()),
2446 control_frame->length() + SpdyControlFrame::kHeaderSize); 2436 control_frame->length() + SpdyControlFrame::kHeaderSize);
2447 EXPECT_FALSE(visitor.header_buffer_valid_); 2437 EXPECT_FALSE(visitor.header_buffer_valid_);
2448 EXPECT_EQ(1, visitor.error_count_); 2438 EXPECT_EQ(1, visitor.error_count_);
2449 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, 2439 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE,
2450 visitor.framer_.error_code()); 2440 visitor.framer_.error_code());
2451 2441
2452 // The framer should have stoped delivering chunks after the visitor 2442 // The framer should have stoped delivering chunks after the visitor
2453 // signaled "stop" by returning false from OnControlFrameHeaderData(). 2443 // signaled "stop" by returning false from OnControlFrameHeaderData().
2454 // 2444 //
2455 // control_frame_header_data_count_ depends on the random sequence 2445 // control_frame_header_data_count_ depends on the random sequence
2456 // produced by rand(), so adding, removing or running single tests 2446 // produced by rand(), so adding, removing or running single tests
(...skipping 19 matching lines...) Expand all
2476 0, // associated_stream_id 2466 0, // associated_stream_id
2477 1, // priority 2467 1, // priority
2478 0, // credential_slot 2468 0, // credential_slot
2479 CONTROL_FLAG_NONE, 2469 CONTROL_FLAG_NONE,
2480 false, // compress 2470 false, // compress
2481 &headers)); 2471 &headers));
2482 TestSpdyVisitor visitor(spdy_version_); 2472 TestSpdyVisitor visitor(spdy_version_);
2483 visitor.use_compression_ = true; 2473 visitor.use_compression_ = true;
2484 visitor.SimulateInFramer( 2474 visitor.SimulateInFramer(
2485 reinterpret_cast<unsigned char*>(control_frame->data()), 2475 reinterpret_cast<unsigned char*>(control_frame->data()),
2486 control_frame->length() + SpdyControlFrame::kHeaderSize); 2476 control_frame->length() + SpdyControlFrame::kHeaderSize);
2487 EXPECT_EQ(1, visitor.error_count_); 2477 EXPECT_EQ(1, visitor.error_count_);
2488 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code()); 2478 EXPECT_EQ(SpdyFramer::SPDY_DECOMPRESS_FAILURE, visitor.framer_.error_code());
2489 EXPECT_EQ(0u, visitor.header_buffer_length_); 2479 EXPECT_EQ(0u, visitor.header_buffer_length_);
2490 } 2480 }
2491 2481
2492 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) { 2482 TEST_P(SpdyFramerTest, ControlFrameSizesAreValidated) {
2493 // Create a GoAway frame that has a few extra bytes at the end. 2483 // Create a GoAway frame that has a few extra bytes at the end.
2494 // We create enough overhead to overflow the framer's control frame buffer. 2484 // We create enough overhead to overflow the framer's control frame buffer.
2495 size_t overhead = SpdyFramer::kControlFrameBufferSize; 2485 size_t overhead = SpdyFramer::kControlFrameBufferSize;
2496
2497 SpdyFramer framer(spdy_version_); 2486 SpdyFramer framer(spdy_version_);
2498 scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1, GOAWAY_OK)); 2487 scoped_ptr<SpdyGoAwayControlFrame> goaway(framer.CreateGoAway(1, GOAWAY_OK));
2499 goaway->set_length(goaway->length() + overhead); 2488 goaway->set_length(goaway->length() + overhead);
2500 std::string pad('A', overhead); 2489 string pad('A', overhead);
2501 TestSpdyVisitor visitor(spdy_version_); 2490 TestSpdyVisitor visitor(spdy_version_);
2502 2491
2503 visitor.SimulateInFramer( 2492 visitor.SimulateInFramer(
2504 reinterpret_cast<unsigned char*>(goaway->data()), 2493 reinterpret_cast<unsigned char*>(goaway->data()),
2505 goaway->length() - overhead + SpdyControlFrame::kHeaderSize); 2494 goaway->length() - overhead + SpdyControlFrame::kHeaderSize);
2506 visitor.SimulateInFramer( 2495 visitor.SimulateInFramer(
2507 reinterpret_cast<const unsigned char*>(pad.c_str()), 2496 reinterpret_cast<const unsigned char*>(pad.c_str()),
2508 overhead); 2497 overhead);
2498
2509 EXPECT_EQ(1, visitor.error_count_); // This generated an error. 2499 EXPECT_EQ(1, visitor.error_count_); // This generated an error.
2510 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 2500 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
2511 visitor.framer_.error_code()); 2501 visitor.framer_.error_code());
2512 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed. 2502 EXPECT_EQ(0, visitor.goaway_count_); // Frame not parsed.
2513 } 2503 }
2514 2504
2515 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) { 2505 TEST_P(SpdyFramerTest, ReadZeroLenSettingsFrame) {
2516 SpdyFramer framer(spdy_version_); 2506 SpdyFramer framer(spdy_version_);
2517 SettingsMap settings; 2507 SettingsMap settings;
2518 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); 2508 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings));
2519 control_frame->set_length(0); 2509 control_frame->set_length(0);
2520 TestSpdyVisitor visitor(spdy_version_); 2510 TestSpdyVisitor visitor(spdy_version_);
2521 visitor.use_compression_ = false; 2511 visitor.use_compression_ = false;
2522 visitor.SimulateInFramer( 2512 visitor.SimulateInFramer(
2523 reinterpret_cast<unsigned char*>(control_frame->data()), 2513 reinterpret_cast<unsigned char*>(control_frame->data()),
2524 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2514 control_frame->length() + SpdyControlFrame::kHeaderSize);
2525 // Should generate an error, since zero-len settings frames are unsupported. 2515 // Should generate an error, since zero-len settings frames are unsupported.
2526 EXPECT_EQ(1, visitor.error_count_); 2516 EXPECT_EQ(1, visitor.error_count_);
2527 } 2517 }
2528 2518
2529 // Tests handling of SETTINGS frames with invalid length. 2519 // Tests handling of SETTINGS frames with invalid length.
2530 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) { 2520 TEST_P(SpdyFramerTest, ReadBogusLenSettingsFrame) {
2531 SpdyFramer framer(spdy_version_); 2521 SpdyFramer framer(spdy_version_);
2532 SettingsMap settings; 2522 SettingsMap settings;
2533 // Add a setting to pad the frame so that we don't get a buffer overflow when 2523 // Add a setting to pad the frame so that we don't get a buffer overflow when
2534 // calling SimulateInFramer() below. 2524 // calling SimulateInFramer() below.
2535 settings[SETTINGS_UPLOAD_BANDWIDTH] = 2525 settings[SETTINGS_UPLOAD_BANDWIDTH] =
2536 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, 0x00000002); 2526 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, 0x00000002);
2537 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); 2527 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings));
2538 control_frame->set_length(5); 2528 control_frame->set_length(5);
2539 TestSpdyVisitor visitor(spdy_version_); 2529 TestSpdyVisitor visitor(spdy_version_);
2540 visitor.use_compression_ = false; 2530 visitor.use_compression_ = false;
2541 visitor.SimulateInFramer( 2531 visitor.SimulateInFramer(
2542 reinterpret_cast<unsigned char*>(control_frame->data()), 2532 reinterpret_cast<unsigned char*>(control_frame->data()),
2543 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2533 control_frame->length() + SpdyControlFrame::kHeaderSize);
2544 // Should generate an error, since zero-len settings frames are unsupported. 2534 // Should generate an error, since zero-len settings frames are unsupported.
2545 EXPECT_EQ(1, visitor.error_count_); 2535 EXPECT_EQ(1, visitor.error_count_);
2546 } 2536 }
2547 2537
2548 // Tests handling of SETTINGS frames larger than the frame buffer size. 2538 // Tests handling of SETTINGS frames larger than the frame buffer size.
2549 TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) { 2539 TEST_P(SpdyFramerTest, ReadLargeSettingsFrame) {
2550 SpdyFramer framer(spdy_version_); 2540 SpdyFramer framer(spdy_version_);
2551 SettingsMap settings; 2541 SettingsMap settings;
2552 SpdySettingsFlags flags = SETTINGS_FLAG_NONE; 2542 SpdySettingsFlags flags = SETTINGS_FLAG_PLEASE_PERSIST;
2553 settings[SETTINGS_UPLOAD_BANDWIDTH] = 2543 settings[SETTINGS_UPLOAD_BANDWIDTH] =
2554 SettingsFlagsAndValue(flags, 0x00000002); 2544 SettingsFlagsAndValue(flags, 0x00000002);
2555 settings[SETTINGS_DOWNLOAD_BANDWIDTH] = 2545 settings[SETTINGS_DOWNLOAD_BANDWIDTH] =
2556 SettingsFlagsAndValue(flags, 0x00000003); 2546 SettingsFlagsAndValue(flags, 0x00000003);
2557 settings[SETTINGS_ROUND_TRIP_TIME] = SettingsFlagsAndValue(flags, 0x00000004); 2547 settings[SETTINGS_ROUND_TRIP_TIME] = SettingsFlagsAndValue(flags, 0x00000004);
2558 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings)); 2548 scoped_ptr<SpdyFrame> control_frame(framer.CreateSettings(settings));
2559 EXPECT_LT(SpdyFramer::kControlFrameBufferSize, 2549 EXPECT_LT(SpdyFramer::kControlFrameBufferSize,
2560 control_frame->length() + SpdyControlFrame::kHeaderSize); 2550 control_frame->length() + SpdyControlFrame::kHeaderSize);
2561 TestSpdyVisitor visitor(spdy_version_); 2551 TestSpdyVisitor visitor(spdy_version_);
2562 visitor.use_compression_ = false; 2552 visitor.use_compression_ = false;
2563 2553
2564 // Read all at once. 2554 // Read all at once.
2565 visitor.SimulateInFramer( 2555 visitor.SimulateInFramer(
2566 reinterpret_cast<unsigned char*>(control_frame->data()), 2556 reinterpret_cast<unsigned char*>(control_frame->data()),
2567 control_frame->length() + SpdyControlFrame::kHeaderSize); 2557 control_frame->length() + SpdyControlFrame::kHeaderSize);
2568 EXPECT_EQ(0, visitor.error_count_); 2558 EXPECT_EQ(0, visitor.error_count_);
2569 EXPECT_EQ(settings.size(), static_cast<unsigned>(visitor.setting_count_)); 2559 EXPECT_EQ(settings.size(), static_cast<unsigned>(visitor.setting_count_));
2570 EXPECT_EQ(1, visitor.settings_frame_count_); 2560 EXPECT_EQ(1, visitor.settings_frame_count_);
2571 2561
2572 // Read data in small chunks. 2562 // Read data in small chunks.
2573 size_t framed_data = 0; 2563 size_t framed_data = 0;
2574 size_t unframed_data = control_frame->length() + 2564 size_t unframed_data = control_frame->length() +
2575 SpdyControlFrame::kHeaderSize; 2565 SpdyControlFrame::kHeaderSize;
2576 size_t kReadChunkSize = 5; // Read five bytes at a time. 2566 size_t kReadChunkSize = 5; // Read five bytes at a time.
2577 while (unframed_data > 0) { 2567 while (unframed_data > 0) {
2578 size_t to_read = std::min(kReadChunkSize, unframed_data); 2568 size_t to_read = min(kReadChunkSize, unframed_data);
2579 visitor.SimulateInFramer( 2569 visitor.SimulateInFramer(
2580 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), 2570 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data),
2581 to_read); 2571 to_read);
2582 unframed_data -= to_read; 2572 unframed_data -= to_read;
2583 framed_data += to_read; 2573 framed_data += to_read;
2584 } 2574 }
2585 EXPECT_EQ(0, visitor.error_count_); 2575 EXPECT_EQ(0, visitor.error_count_);
2586 EXPECT_EQ(settings.size() * 2, static_cast<unsigned>(visitor.setting_count_)); 2576 EXPECT_EQ(settings.size() * 2, static_cast<unsigned>(visitor.setting_count_));
2587 EXPECT_EQ(2, visitor.settings_frame_count_); 2577 EXPECT_EQ(2, visitor.settings_frame_count_);
2588 } 2578 }
2589 2579
2590 TEST_P(SpdyFramerTest, ReadCredentialFrame) { 2580 TEST_P(SpdyFramerTest, ReadCredentialFrame) {
2591 SpdyCredential credential; 2581 SpdyCredential credential;
2592 credential.slot = 3; 2582 credential.slot = 3;
2593 credential.proof = "proof"; 2583 credential.proof = "proof";
2594 credential.certs.push_back("a cert"); 2584 credential.certs.push_back("a cert");
2595 credential.certs.push_back("another cert"); 2585 credential.certs.push_back("another cert");
2596 credential.certs.push_back("final cert"); 2586 credential.certs.push_back("final cert");
2597 SpdyFramer framer(spdy_version_); 2587 SpdyFramer framer(spdy_version_);
2598 scoped_ptr<SpdyFrame> control_frame( 2588 scoped_ptr<SpdyFrame> control_frame(
2599 framer.CreateCredentialFrame(credential)); 2589 framer.CreateCredentialFrame(credential));
2600 EXPECT_TRUE(control_frame.get() != NULL); 2590 EXPECT_TRUE(control_frame.get() != NULL);
2601 TestSpdyVisitor visitor(spdy_version_); 2591 TestSpdyVisitor visitor(spdy_version_);
2602 visitor.use_compression_ = false; 2592 visitor.use_compression_ = false;
2603 visitor.SimulateInFramer( 2593 visitor.SimulateInFramer(
2604 reinterpret_cast<unsigned char*>(control_frame.get()->data()), 2594 reinterpret_cast<unsigned char*>(control_frame->data()),
2605 control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2595 control_frame->length() + SpdyControlFrame::kHeaderSize);
2606 EXPECT_EQ(0, visitor.error_count_); 2596 EXPECT_EQ(0, visitor.error_count_);
2607 EXPECT_EQ(1, visitor.credential_count_); 2597 EXPECT_EQ(1, visitor.credential_count_);
2608 EXPECT_EQ(control_frame->length(), visitor.credential_buffer_length_); 2598 EXPECT_EQ(control_frame->length(), visitor.credential_buffer_length_);
2609 EXPECT_EQ(credential.slot, visitor.credential_.slot); 2599 EXPECT_EQ(credential.slot, visitor.credential_.slot);
2610 EXPECT_EQ(credential.proof, visitor.credential_.proof); 2600 EXPECT_EQ(credential.proof, visitor.credential_.proof);
2611 EXPECT_EQ(credential.certs.size(), visitor.credential_.certs.size()); 2601 EXPECT_EQ(credential.certs.size(), visitor.credential_.certs.size());
2612 for (size_t i = 0; i < credential.certs.size(); i++) { 2602 for (size_t i = 0; i < credential.certs.size(); i++) {
2613 EXPECT_EQ(credential.certs[i], visitor.credential_.certs[i]); 2603 EXPECT_EQ(credential.certs[i], visitor.credential_.certs[i]);
2614 } 2604 }
2615 } 2605 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 credential.certs.push_back("a cert"); 2664 credential.certs.push_back("a cert");
2675 credential.certs.push_back("another cert"); 2665 credential.certs.push_back("another cert");
2676 credential.certs.push_back("final cert"); 2666 credential.certs.push_back("final cert");
2677 SpdyFramer framer(spdy_version_); 2667 SpdyFramer framer(spdy_version_);
2678 scoped_ptr<SpdyFrame> control_frame( 2668 scoped_ptr<SpdyFrame> control_frame(
2679 framer.CreateCredentialFrame(credential)); 2669 framer.CreateCredentialFrame(credential));
2680 EXPECT_TRUE(control_frame.get() != NULL); 2670 EXPECT_TRUE(control_frame.get() != NULL);
2681 TestSpdyVisitor visitor(spdy_version_); 2671 TestSpdyVisitor visitor(spdy_version_);
2682 visitor.use_compression_ = false; 2672 visitor.use_compression_ = false;
2683 unsigned char* data = 2673 unsigned char* data =
2684 reinterpret_cast<unsigned char*>(control_frame.get()->data()); 2674 reinterpret_cast<unsigned char*>(control_frame->data());
2685 size_t offset = SpdyControlFrame::kHeaderSize + 4; 2675 size_t offset = SpdyControlFrame::kHeaderSize + 4;
2686 data[offset] = 0xFF; // Proof length is past the end of the frame 2676 data[offset] = 0xFF; // Proof length is past the end of the frame
2687 visitor.SimulateInFramer( 2677 visitor.SimulateInFramer(
2688 data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2678 data, control_frame->length() + SpdyControlFrame::kHeaderSize);
2689 EXPECT_EQ(1, visitor.error_count_); 2679 EXPECT_EQ(1, visitor.error_count_);
2690 } 2680 }
2691 2681
2692 TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptCertificate) { 2682 TEST_P(SpdyFramerTest, ReadCredentialFrameWithCorruptCertificate) {
2693 SpdyCredential credential; 2683 SpdyCredential credential;
2694 credential.slot = 3; 2684 credential.slot = 3;
2695 credential.proof = "proof"; 2685 credential.proof = "proof";
2696 credential.certs.push_back("a cert"); 2686 credential.certs.push_back("a cert");
2697 credential.certs.push_back("another cert"); 2687 credential.certs.push_back("another cert");
2698 credential.certs.push_back("final cert"); 2688 credential.certs.push_back("final cert");
2699 SpdyFramer framer(spdy_version_); 2689 SpdyFramer framer(spdy_version_);
2700 scoped_ptr<SpdyFrame> control_frame( 2690 scoped_ptr<SpdyFrame> control_frame(
2701 framer.CreateCredentialFrame(credential)); 2691 framer.CreateCredentialFrame(credential));
2702 EXPECT_TRUE(control_frame.get() != NULL); 2692 EXPECT_TRUE(control_frame.get() != NULL);
2703 TestSpdyVisitor visitor(spdy_version_); 2693 TestSpdyVisitor visitor(spdy_version_);
2704 visitor.use_compression_ = false; 2694 visitor.use_compression_ = false;
2705 unsigned char* data = 2695 unsigned char* data =
2706 reinterpret_cast<unsigned char*>(control_frame.get()->data()); 2696 reinterpret_cast<unsigned char*>(control_frame->data());
2707 size_t offset = SpdyControlFrame::kHeaderSize + credential.proof.length(); 2697 size_t offset = SpdyControlFrame::kHeaderSize + credential.proof.length();
2708 data[offset] = 0xFF; // Certificate length is past the end of the frame 2698 data[offset] = 0xFF; // Certificate length is past the end of the frame
2709 visitor.SimulateInFramer( 2699 visitor.SimulateInFramer(
2710 data, control_frame.get()->length() + SpdyControlFrame::kHeaderSize); 2700 data, control_frame->length() + SpdyControlFrame::kHeaderSize);
2711 EXPECT_EQ(1, visitor.error_count_); 2701 EXPECT_EQ(1, visitor.error_count_);
2712 } 2702 }
2713 2703
2714 TEST_P(SpdyFramerTest, ReadGarbage) { 2704 TEST_P(SpdyFramerTest, ReadGarbage) {
2715 SpdyFramer framer(spdy_version_); 2705 SpdyFramer framer(spdy_version_);
2716 unsigned char garbage_frame[256]; 2706 unsigned char garbage_frame[256];
2717 memset(garbage_frame, ~0, sizeof(garbage_frame)); 2707 memset(garbage_frame, ~0, sizeof(garbage_frame));
2718 TestSpdyVisitor visitor(spdy_version_); 2708 TestSpdyVisitor visitor(spdy_version_);
2719 visitor.use_compression_ = false; 2709 visitor.use_compression_ = false;
2720 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); 2710 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame));
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 GOAWAY)); 2866 GOAWAY));
2877 EXPECT_EQ(SpdyHeadersControlFrame::size(), 2867 EXPECT_EQ(SpdyHeadersControlFrame::size(),
2878 SpdyFramer::GetMinimumControlFrameSize(spdy_version_, 2868 SpdyFramer::GetMinimumControlFrameSize(spdy_version_,
2879 HEADERS)); 2869 HEADERS));
2880 EXPECT_EQ(SpdyWindowUpdateControlFrame::size(), 2870 EXPECT_EQ(SpdyWindowUpdateControlFrame::size(),
2881 SpdyFramer::GetMinimumControlFrameSize(spdy_version_, 2871 SpdyFramer::GetMinimumControlFrameSize(spdy_version_,
2882 WINDOW_UPDATE)); 2872 WINDOW_UPDATE));
2883 EXPECT_EQ(SpdyCredentialControlFrame::size(), 2873 EXPECT_EQ(SpdyCredentialControlFrame::size(),
2884 SpdyFramer::GetMinimumControlFrameSize(spdy_version_, 2874 SpdyFramer::GetMinimumControlFrameSize(spdy_version_,
2885 CREDENTIAL)); 2875 CREDENTIAL));
2886 EXPECT_EQ(static_cast<size_t>(0x7FFFFFFF), 2876 EXPECT_EQ(numeric_limits<size_t>::max(),
2887 SpdyFramer::GetMinimumControlFrameSize(spdy_version_, 2877 SpdyFramer::GetMinimumControlFrameSize(spdy_version_,
2888 NUM_CONTROL_FRAME_TYPES)); 2878 NUM_CONTROL_FRAME_TYPES));
2889 } 2879 }
2890 2880
2891 TEST_P(SpdyFramerTest, CatchProbableHttpResponse) { 2881 TEST_P(SpdyFramerTest, CatchProbableHttpResponse) {
2892 { 2882 {
2893 testing::StrictMock<test::MockVisitor> visitor; 2883 testing::StrictMock<test::MockVisitor> visitor;
2894 SpdyFramer framer(spdy_version_); 2884 SpdyFramer framer(spdy_version_);
2895 framer.set_visitor(&visitor); 2885 framer.set_visitor(&visitor);
2896 2886
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2961 2951
2962 size_t frame_size = frame->length() + SpdyFrame::kHeaderSize; 2952 size_t frame_size = frame->length() + SpdyFrame::kHeaderSize;
2963 framer.ProcessInput(frame->data(), frame_size); 2953 framer.ProcessInput(frame->data(), frame_size);
2964 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 2954 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
2965 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()); 2955 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code());
2966 } 2956 }
2967 2957
2968 TEST_P(SpdyFramerTest, SettingsFlagsAndId) { 2958 TEST_P(SpdyFramerTest, SettingsFlagsAndId) {
2969 const uint32 kId = 0x020304; 2959 const uint32 kId = 0x020304;
2970 const uint32 kFlags = 0x01; 2960 const uint32 kFlags = 0x01;
2971 const uint32 kWireFormat = 2961 const uint32 kWireFormat = htonl(IsSpdy2() ? 0x04030201 : 0x01020304);
2972 htonl(IsSpdy2() ? 0x04030201 : 0x01020304);
2973 2962
2974 SettingsFlagsAndId id_and_flags = 2963 SettingsFlagsAndId id_and_flags =
2975 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat); 2964 SettingsFlagsAndId::FromWireFormat(spdy_version_, kWireFormat);
2976 EXPECT_EQ(kId, id_and_flags.id()); 2965 EXPECT_EQ(kId, id_and_flags.id());
2977 EXPECT_EQ(kFlags, id_and_flags.flags()); 2966 EXPECT_EQ(kFlags, id_and_flags.flags());
2978 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_)); 2967 EXPECT_EQ(kWireFormat, id_and_flags.GetWireFormat(spdy_version_));
2979 } 2968 }
2980 2969
2981 } // namespace net 2970 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698