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

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

Issue 485833002: HTTP2 draft 14 support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ignore_result(). Created 6 years, 4 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
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('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 #include <limits>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 LOG(FATAL); 191 LOG(FATAL);
192 } 192 }
193 193
194 virtual void OnPriority(SpdyStreamId stream_id, 194 virtual void OnPriority(SpdyStreamId stream_id,
195 SpdyStreamId parent_stream_id, 195 SpdyStreamId parent_stream_id,
196 uint8 weight, 196 uint8 weight,
197 bool exclusive) OVERRIDE { 197 bool exclusive) OVERRIDE {
198 // Do nothing. 198 // Do nothing.
199 } 199 }
200 200
201 virtual bool OnUnknownFrame(SpdyStreamId stream_id,
202 int frame_type) override {
203 LOG(FATAL);
204 return false;
205 }
206
201 char* ReleaseBuffer() { 207 char* ReleaseBuffer() {
202 CHECK(finished_); 208 CHECK(finished_);
203 return buffer_.release(); 209 return buffer_.release();
204 } 210 }
205 211
206 virtual void OnWindowUpdate(SpdyStreamId stream_id, 212 virtual void OnWindowUpdate(SpdyStreamId stream_id,
207 uint32 delta_window_size) OVERRIDE { 213 uint32 delta_window_size) OVERRIDE {
208 LOG(FATAL); 214 LOG(FATAL);
209 } 215 }
210 216
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 headers_frame_count_(0), 248 headers_frame_count_(0),
243 push_promise_frame_count_(0), 249 push_promise_frame_count_(0),
244 goaway_count_(0), 250 goaway_count_(0),
245 setting_count_(0), 251 setting_count_(0),
246 settings_ack_sent_(0), 252 settings_ack_sent_(0),
247 settings_ack_received_(0), 253 settings_ack_received_(0),
248 continuation_count_(0), 254 continuation_count_(0),
249 altsvc_count_(0), 255 altsvc_count_(0),
250 priority_count_(0), 256 priority_count_(0),
251 test_altsvc_ir_(0), 257 test_altsvc_ir_(0),
258 on_unknown_frame_result_(false),
252 last_window_update_stream_(0), 259 last_window_update_stream_(0),
253 last_window_update_delta_(0), 260 last_window_update_delta_(0),
254 last_push_promise_stream_(0), 261 last_push_promise_stream_(0),
255 last_push_promise_promised_stream_(0), 262 last_push_promise_promised_stream_(0),
256 data_bytes_(0), 263 data_bytes_(0),
257 fin_frame_count_(0), 264 fin_frame_count_(0),
258 fin_opaque_data_(), 265 fin_opaque_data_(),
259 fin_flag_count_(0), 266 fin_flag_count_(0),
260 zero_length_data_frame_count_(0), 267 zero_length_data_frame_count_(0),
261 control_frame_header_data_count_(0), 268 control_frame_header_data_count_(0),
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 test_altsvc_ir_.set_max_age(max_age); 438 test_altsvc_ir_.set_max_age(max_age);
432 test_altsvc_ir_.set_port(port); 439 test_altsvc_ir_.set_port(port);
433 test_altsvc_ir_.set_protocol_id(protocol_id.as_string()); 440 test_altsvc_ir_.set_protocol_id(protocol_id.as_string());
434 test_altsvc_ir_.set_host(host.as_string()); 441 test_altsvc_ir_.set_host(host.as_string());
435 if (origin.length() > 0) { 442 if (origin.length() > 0) {
436 test_altsvc_ir_.set_origin(origin.as_string()); 443 test_altsvc_ir_.set_origin(origin.as_string());
437 } 444 }
438 ++altsvc_count_; 445 ++altsvc_count_;
439 } 446 }
440 447
448 virtual void OnPriority(SpdyStreamId stream_id,
449 SpdyStreamId parent_stream_id,
450 uint8 weight,
451 bool exclusive) OVERRIDE {
452 ++priority_count_;
453 }
454
455 virtual bool OnUnknownFrame(SpdyStreamId stream_id, int frame_type) override {
456 DLOG(INFO) << "Unknown frame type " << frame_type;
457 return on_unknown_frame_result_;
458 }
459
441 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, 460 virtual void OnSendCompressedFrame(SpdyStreamId stream_id,
442 SpdyFrameType type, 461 SpdyFrameType type,
443 size_t payload_len, 462 size_t payload_len,
444 size_t frame_len) OVERRIDE { 463 size_t frame_len) OVERRIDE {
445 last_payload_len_ = payload_len; 464 last_payload_len_ = payload_len;
446 last_frame_len_ = frame_len; 465 last_frame_len_ = frame_len;
447 } 466 }
448 467
449 virtual void OnPriority(SpdyStreamId stream_id,
450 SpdyStreamId parent_stream_id,
451 uint8 weight,
452 bool exclusive) OVERRIDE {
453 ++priority_count_;
454 }
455
456 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, 468 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id,
457 SpdyFrameType type, 469 SpdyFrameType type,
458 size_t frame_len) OVERRIDE { 470 size_t frame_len) OVERRIDE {
459 last_frame_len_ = frame_len; 471 last_frame_len_ = frame_len;
460 } 472 }
461 473
462 // Convenience function which runs a framer simulation with particular input. 474 // Convenience function which runs a framer simulation with particular input.
463 void SimulateInFramer(const unsigned char* input, size_t size) { 475 void SimulateInFramer(const unsigned char* input, size_t size) {
464 framer_.set_enable_compression(use_compression_); 476 framer_.set_enable_compression(use_compression_);
465 framer_.set_visitor(this); 477 framer_.set_visitor(this);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 int headers_frame_count_; 528 int headers_frame_count_;
517 int push_promise_frame_count_; 529 int push_promise_frame_count_;
518 int goaway_count_; 530 int goaway_count_;
519 int setting_count_; 531 int setting_count_;
520 int settings_ack_sent_; 532 int settings_ack_sent_;
521 int settings_ack_received_; 533 int settings_ack_received_;
522 int continuation_count_; 534 int continuation_count_;
523 int altsvc_count_; 535 int altsvc_count_;
524 int priority_count_; 536 int priority_count_;
525 SpdyAltSvcIR test_altsvc_ir_; 537 SpdyAltSvcIR test_altsvc_ir_;
538 bool on_unknown_frame_result_;
526 SpdyStreamId last_window_update_stream_; 539 SpdyStreamId last_window_update_stream_;
527 uint32 last_window_update_delta_; 540 uint32 last_window_update_delta_;
528 SpdyStreamId last_push_promise_stream_; 541 SpdyStreamId last_push_promise_stream_;
529 SpdyStreamId last_push_promise_promised_stream_; 542 SpdyStreamId last_push_promise_promised_stream_;
530 int data_bytes_; 543 int data_bytes_;
531 int fin_frame_count_; // The count of RST_STREAM type frames received. 544 int fin_frame_count_; // The count of RST_STREAM type frames received.
532 std::string fin_opaque_data_; 545 std::string fin_opaque_data_;
533 int fin_flag_count_; // The count of frames with the FIN flag set. 546 int fin_flag_count_; // The count of frames with the FIN flag set.
534 int zero_length_data_frame_count_; // The count of zero-length data frames. 547 int zero_length_data_frame_count_; // The count of zero-length data frames.
535 int control_frame_header_data_count_; // The count of chunks received. 548 int control_frame_header_data_count_; // The count of chunks received.
(...skipping 10 matching lines...) Expand all
546 SpdyStreamId header_stream_id_; 559 SpdyStreamId header_stream_id_;
547 SpdyFrameType header_control_type_; 560 SpdyFrameType header_control_type_;
548 bool header_buffer_valid_; 561 bool header_buffer_valid_;
549 SpdyHeaderBlock headers_; 562 SpdyHeaderBlock headers_;
550 }; 563 };
551 564
552 // Retrieves serialized headers from a HEADERS or SYN_STREAM frame. 565 // Retrieves serialized headers from a HEADERS or SYN_STREAM frame.
553 base::StringPiece GetSerializedHeaders(const SpdyFrame* frame, 566 base::StringPiece GetSerializedHeaders(const SpdyFrame* frame,
554 const SpdyFramer& framer) { 567 const SpdyFramer& framer) {
555 SpdyFrameReader reader(frame->data(), frame->size()); 568 SpdyFrameReader reader(frame->data(), frame->size());
556 reader.Seek(2); // Seek past the frame length. 569 if (framer.protocol_version() > SPDY3) {
570 reader.Seek(3); // Seek past the frame length.
571 } else {
572 reader.Seek(2); // Seek past the frame length.
573 }
557 SpdyFrameType frame_type; 574 SpdyFrameType frame_type;
558 if (framer.protocol_version() > SPDY3) { 575 if (framer.protocol_version() > SPDY3) {
559 uint8 serialized_type; 576 uint8 serialized_type;
560 reader.ReadUInt8(&serialized_type); 577 reader.ReadUInt8(&serialized_type);
561 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(), 578 frame_type = SpdyConstants::ParseFrameType(framer.protocol_version(),
562 serialized_type); 579 serialized_type);
563 DCHECK_EQ(HEADERS, frame_type); 580 DCHECK_EQ(HEADERS, frame_type);
564 uint8 flags; 581 uint8 flags;
565 reader.ReadUInt8(&flags); 582 reader.ReadUInt8(&flags);
566 if (flags & HEADERS_FLAG_PRIORITY) { 583 if (flags & HEADERS_FLAG_PRIORITY) {
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 1166
1150 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 1167 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3
1151 0x00, 0x00, 0x00, 0x08, 1168 0x00, 0x00, 0x00, 0x08,
1152 0x00, 0x00, 0x00, 0x03, 1169 0x00, 0x00, 0x00, 0x03,
1153 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL 1170 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL
1154 }; 1171 };
1155 1172
1156 // SYN_STREAM doesn't exist in SPDY4, so instead we send 1173 // SYN_STREAM doesn't exist in SPDY4, so instead we send
1157 // HEADERS frames with PRIORITY and END_HEADERS set. 1174 // HEADERS frames with PRIORITY and END_HEADERS set.
1158 const unsigned char kV4Input[] = { 1175 const unsigned char kV4Input[] = {
1159 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS 1176 0x00, 0x00, 0x05, 0x01, // HEADERS: PRIORITY | END_HEADERS
1160 0x00, 0x00, 0x00, 0x01, // Stream 1 1177 0x24, 0x00, 0x00, 0x00,
1161 0x00, 0x00, 0x00, 0x00, // Priority 0 1178 0x01, 0x00, 0x00, 0x00, // Stream 1, Priority 0
1162 0x82, // :method: GET 1179 0x00, 0x82, // :method: GET
1163 1180
1164 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS 1181 0x00, 0x00, 0x01, 0x01, // HEADERS: END_HEADERS
1165 0x00, 0x00, 0x00, 0x01, // Stream 1 1182 0x04, 0x00, 0x00, 0x00, // Stream 1
1166 0x8c, // :status: 200 1183 0x01, 0x8c, // :status: 200
1167 1184
1168 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 1185 0x00, 0x00, 0x0c, 0x00, // DATA on Stream #1
1169 0x00, 0x00, 0x00, 0x01, 1186 0x00, 0x00, 0x00, 0x00,
1170 0xde, 0xad, 0xbe, 0xef, 1187 0x01, 0xde, 0xad, 0xbe,
1171 0xde, 0xad, 0xbe, 0xef, 1188 0xef, 0xde, 0xad, 0xbe,
1172 0xde, 0xad, 0xbe, 0xef, 1189 0xef, 0xde, 0xad, 0xbe,
1190 0xef,
1173 1191
1174 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS 1192 0x00, 0x00, 0x05, 0x01, // HEADERS: PRIORITY | END_HEADERS
1175 0x00, 0x00, 0x00, 0x03, // Stream 3 1193 0x24, 0x00, 0x00, 0x00,
1176 0x00, 0x00, 0x00, 0x00, // Priority 0 1194 0x03, 0x00, 0x00, 0x00, // Stream 3, Priority 0
1177 0x82, // :method: GET 1195 0x00, 0x82, // :method: GET
1178 1196
1179 0x00, 0x08, 0x00, 0x00, // DATA on Stream #3 1197 0x00, 0x00, 0x08, 0x00, // DATA on Stream #3
1180 0x00, 0x00, 0x00, 0x03, 1198 0x00, 0x00, 0x00, 0x00,
1181 0xde, 0xad, 0xbe, 0xef, 1199 0x03, 0xde, 0xad, 0xbe,
1182 0xde, 0xad, 0xbe, 0xef, 1200 0xef, 0xde, 0xad, 0xbe,
1201 0xef,
1183 1202
1184 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 1203 0x00, 0x00, 0x04, 0x00, // DATA on Stream #1
1185 0x00, 0x00, 0x00, 0x01, 1204 0x00, 0x00, 0x00, 0x00,
1186 0xde, 0xad, 0xbe, 0xef, 1205 0x01, 0xde, 0xad, 0xbe,
1206 0xef,
1187 1207
1188 0x00, 0x04, 0x03, 0x00, // RST_STREAM on Stream #1 1208 0x00, 0x00, 0x04, 0x03, // RST_STREAM on Stream #1
1189 0x00, 0x00, 0x00, 0x01, 1209 0x00, 0x00, 0x00, 0x00,
1190 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL 1210 0x01, 0x00, 0x00, 0x00,
1211 0x08, // RST_STREAM_CANCEL
1191 1212
1192 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3 1213 0x00, 0x00, 0x00, 0x00, // DATA on Stream #3
1193 0x00, 0x00, 0x00, 0x03, 1214 0x00, 0x00, 0x00, 0x00,
1215 0x03,
1194 1216
1195 0x00, 0x0f, 0x03, 0x00, // RST_STREAM on Stream #3 1217 0x00, 0x00, 0x0f, 0x03, // RST_STREAM on Stream #3
1196 0x00, 0x00, 0x00, 0x03, 1218 0x00, 0x00, 0x00, 0x00,
1197 0x00, 0x00, 0x00, 0x08, // RST_STREAM_CANCEL 1219 0x03, 0x00, 0x00, 0x00, // RST_STREAM_CANCEL
1198 0x52, 0x45, 0x53, 0x45, // opaque data 1220 0x08, 0x52, 0x45, 0x53, // opaque data
1199 0x54, 0x53, 0x54, 0x52, 1221 0x45, 0x54, 0x53, 0x54,
1200 0x45, 0x41, 0x4d, 1222 0x52, 0x45, 0x41, 0x4d,
1201 }; 1223 };
1202 1224
1203 TestSpdyVisitor visitor(spdy_version_); 1225 TestSpdyVisitor visitor(spdy_version_);
1204 if (IsSpdy2()) { 1226 if (IsSpdy2()) {
1205 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); 1227 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1206 } else if (IsSpdy3()) { 1228 } else if (IsSpdy3()) {
1207 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1229 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1208 } else { 1230 } else {
1209 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); 1231 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input));
1210 } 1232 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 0xde, 0xad, 0xbe, 0xef, 1306 0xde, 0xad, 0xbe, 0xef,
1285 1307
1286 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF 1308 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF
1287 0x01, 0x00, 0x00, 0x04, 1309 0x01, 0x00, 0x00, 0x04,
1288 0xde, 0xad, 0xbe, 0xef, 1310 0xde, 0xad, 0xbe, 0xef,
1289 }; 1311 };
1290 1312
1291 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send 1313 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send
1292 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. 1314 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set.
1293 const unsigned char kV4Input[] = { 1315 const unsigned char kV4Input[] = {
1294 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS 1316 0x00, 0x00, 0x05, 0x01, // HEADERS: PRIORITY | END_HEADERS
1295 0x00, 0x00, 0x00, 0x01, // Stream 1 1317 0x24, 0x00, 0x00, 0x00, // Stream 1
1296 0x00, 0x00, 0x00, 0x00, // Priority 0 1318 0x01, 0x00, 0x00, 0x00, // Priority 0
1297 0x82, // :method: GET 1319 0x00, 0x82, // :method: GET
1298 1320
1299 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS 1321 0x00, 0x00, 0x01, 0x01, // HEADERS: END_HEADERS
1300 0x00, 0x00, 0x00, 0x01, // Stream 1 1322 0x04, 0x00, 0x00, 0x00, // Stream 1
1301 0x8c, // :status: 200 1323 0x01, 0x8c, // :status: 200
1302 1324
1303 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 1325 0x00, 0x00, 0x0c, 0x00, // DATA on Stream #1
1304 0x00, 0x00, 0x00, 0x01, 1326 0x00, 0x00, 0x00, 0x00,
1305 0xde, 0xad, 0xbe, 0xef, 1327 0x01, 0xde, 0xad, 0xbe,
1306 0xde, 0xad, 0xbe, 0xef, 1328 0xef, 0xde, 0xad, 0xbe,
1307 0xde, 0xad, 0xbe, 0xef, 1329 0xef, 0xde, 0xad, 0xbe,
1330 0xef,
1308 1331
1309 0x00, 0x04, 0x00, 0x01, // DATA on Stream #1, with FIN 1332 0x00, 0x00, 0x04, 0x00, // DATA on Stream #1, with FIN
1310 0x00, 0x00, 0x00, 0x01, 1333 0x01, 0x00, 0x00, 0x00,
1311 0xde, 0xad, 0xbe, 0xef, 1334 0x01, 0xde, 0xad, 0xbe,
1335 0xef,
1312 }; 1336 };
1313 1337
1314 TestSpdyVisitor visitor(spdy_version_); 1338 TestSpdyVisitor visitor(spdy_version_);
1315 if (IsSpdy2()) { 1339 if (IsSpdy2()) {
1316 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); 1340 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1317 } else if (IsSpdy3()) { 1341 } else if (IsSpdy3()) {
1318 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1342 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1319 } else { 1343 } else {
1320 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); 1344 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input));
1321 } 1345 }
(...skipping 10 matching lines...) Expand all
1332 EXPECT_EQ(16, visitor.data_bytes_); 1356 EXPECT_EQ(16, visitor.data_bytes_);
1333 EXPECT_EQ(0, visitor.fin_frame_count_); 1357 EXPECT_EQ(0, visitor.fin_frame_count_);
1334 EXPECT_EQ(0, visitor.fin_flag_count_); 1358 EXPECT_EQ(0, visitor.fin_flag_count_);
1335 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); 1359 EXPECT_EQ(1, visitor.zero_length_data_frame_count_);
1336 EXPECT_EQ(2, visitor.data_frame_count_); 1360 EXPECT_EQ(2, visitor.data_frame_count_);
1337 } 1361 }
1338 1362
1339 // Test that the FIN flag on a SYN reply frame signifies EOF. 1363 // Test that the FIN flag on a SYN reply frame signifies EOF.
1340 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) { 1364 TEST_P(SpdyFramerTest, FinOnSynReplyFrame) {
1341 const unsigned char kV2Input[] = { 1365 const unsigned char kV2Input[] = {
1342 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 1366 0x80, spdy_version_ch_, 0x00, // SYN Stream #1
1343 0x00, 0x00, 0x00, 0x14, 1367 0x01, 0x00, 0x00, 0x00,
1344 0x00, 0x00, 0x00, 0x01, 1368 0x14, 0x00, 0x00, 0x00,
1369 0x01, 0x00, 0x00, 0x00,
1345 0x00, 0x00, 0x00, 0x00, 1370 0x00, 0x00, 0x00, 0x00,
1346 0x00, 0x00, 0x00, 0x01, 1371 0x01, 0x00, 0x02, 'h',
1347 0x00, 0x02, 'h', 'h', 1372 'h', 0x00, 0x02, 'v',
1348 0x00, 0x02, 'v', 'v', 1373 'v',
1349 1374
1350 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 1375 0x80, spdy_version_ch_, 0x00, // SYN REPLY Stream #1
1351 0x01, 0x00, 0x00, 0x10, 1376 0x02, 0x01, 0x00, 0x00,
1352 0x00, 0x00, 0x00, 0x01, 1377 0x10, 0x00, 0x00, 0x00,
1353 0x00, 0x00, 0x00, 0x01, 1378 0x01, 0x00, 0x00, 0x00,
1354 0x00, 0x02, 'a', 'a', 1379 0x01, 0x00, 0x02, 'a',
1355 0x00, 0x02, 'b', 'b', 1380 'a', 0x00, 0x02, 'b',
1381 'b',
1356 }; 1382 };
1357 const unsigned char kV3Input[] = { 1383 const unsigned char kV3Input[] = {
1358 0x80, spdy_version_ch_, 0x00, 0x01, // SYN Stream #1 1384 0x80, spdy_version_ch_, 0x00, // SYN Stream #1
1359 0x00, 0x00, 0x00, 0x1a, 1385 0x01, 0x00, 0x00, 0x00,
1360 0x00, 0x00, 0x00, 0x01, 1386 0x1a, 0x00, 0x00, 0x00,
1387 0x01, 0x00, 0x00, 0x00,
1361 0x00, 0x00, 0x00, 0x00, 1388 0x00, 0x00, 0x00, 0x00,
1362 0x00, 0x00, 0x00, 0x00, 1389 0x00, 0x00, 0x01, 0x00,
1363 0x00, 0x01, 0x00, 0x00, 1390 0x00, 0x00, 0x02, 'h',
1364 0x00, 0x02, 'h', 'h', 1391 'h', 0x00, 0x00, 0x00,
1365 0x00, 0x00, 0x00, 0x02, 1392 0x02, 'v', 'v',
1366 'v', 'v',
1367 1393
1368 0x80, spdy_version_ch_, 0x00, 0x02, // SYN REPLY Stream #1 1394 0x80, spdy_version_ch_, 0x00, // SYN REPLY Stream #1
1369 0x01, 0x00, 0x00, 0x14, 1395 0x02, 0x01, 0x00, 0x00,
1370 0x00, 0x00, 0x00, 0x01, 1396 0x14, 0x00, 0x00, 0x00,
1371 0x00, 0x00, 0x00, 0x01, 1397 0x01, 0x00, 0x00, 0x00,
1372 0x00, 0x00, 0x00, 0x02, 1398 0x01, 0x00, 0x00, 0x00,
1373 'a', 'a', 0x00, 0x00, 1399 0x02, 'a', 'a', 0x00,
1374 0x00, 0x02, 'b', 'b', 1400 0x00, 0x00, 0x02, 'b',
1401 'b',
1375 }; 1402 };
1376 1403
1377 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send 1404 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send
1378 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. 1405 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set.
1379 const unsigned char kV4Input[] = { 1406 const unsigned char kV4Input[] = {
1380 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS 1407 0x00, 0x00, 0x05, 0x01, // HEADERS: PRIORITY | END_HEADERS
1381 0x00, 0x00, 0x00, 0x01, // Stream 1 1408 0x24, 0x00, 0x00, 0x00,
1382 0x00, 0x00, 0x00, 0x00, // Priority 0 1409 0x01, 0x00, 0x00, 0x00, // Stream 1, Priority 0
1383 0x82, // :method: GET 1410 0x00, 0x82, // :method: GET
1384 1411
1385 0x00, 0x01, 0x01, 0x05, // HEADERS: FIN | END_HEADERS 1412 0x00, 0x00, 0x01, 0x01, // HEADERS: FIN | END_HEADERS
1386 0x00, 0x00, 0x00, 0x01, // Stream 1 1413 0x05, 0x00, 0x00, 0x00,
1387 0x8c, // :status: 200 1414 0x01, 0x8c, // Stream 1, :status: 200
1388 }; 1415 };
1389 1416
1390 TestSpdyVisitor visitor(spdy_version_); 1417 TestSpdyVisitor visitor(spdy_version_);
1391 if (IsSpdy2()) { 1418 if (IsSpdy2()) {
1392 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input)); 1419 visitor.SimulateInFramer(kV2Input, sizeof(kV2Input));
1393 } else if (IsSpdy3()) { 1420 } else if (IsSpdy3()) {
1394 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input)); 1421 visitor.SimulateInFramer(kV3Input, sizeof(kV3Input));
1395 } else { 1422 } else {
1396 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input)); 1423 visitor.SimulateInFramer(kV4Input, sizeof(kV4Input));
1397 } 1424 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 SpdyWindowUpdateIR(1, 0x12345678))); 1562 SpdyWindowUpdateIR(1, 0x12345678)));
1536 1563
1537 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678"; 1564 const char kDescription[] = "WINDOW_UPDATE frame, stream 1, delta 0x12345678";
1538 const unsigned char kV3FrameData[] = { // Also applies for V2. 1565 const unsigned char kV3FrameData[] = { // Also applies for V2.
1539 0x80, spdy_version_ch_, 0x00, 0x09, 1566 0x80, spdy_version_ch_, 0x00, 0x09,
1540 0x00, 0x00, 0x00, 0x08, 1567 0x00, 0x00, 0x00, 0x08,
1541 0x00, 0x00, 0x00, 0x01, 1568 0x00, 0x00, 0x00, 0x01,
1542 0x12, 0x34, 0x56, 0x78 1569 0x12, 0x34, 0x56, 0x78
1543 }; 1570 };
1544 const unsigned char kV4FrameData[] = { 1571 const unsigned char kV4FrameData[] = {
1545 0x00, 0x04, 0x08, 0x00, 1572 0x00, 0x00, 0x04, 0x08,
1546 0x00, 0x00, 0x00, 0x01, 1573 0x00, 0x00, 0x00, 0x00,
1547 0x12, 0x34, 0x56, 0x78 1574 0x01, 0x12, 0x34, 0x56,
1575 0x78
1548 }; 1576 };
1549 1577
1550 if (IsSpdy4()) { 1578 if (IsSpdy4()) {
1551 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1579 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1552 } else { 1580 } else {
1553 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1581 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1554 } 1582 }
1555 } 1583 }
1556 1584
1557 TEST_P(SpdyFramerTest, CreateDataFrame) { 1585 TEST_P(SpdyFramerTest, CreateDataFrame) {
1558 SpdyFramer framer(spdy_version_); 1586 SpdyFramer framer(spdy_version_);
1559 1587
1560 { 1588 {
1561 const char kDescription[] = "'hello' data frame, no FIN"; 1589 const char kDescription[] = "'hello' data frame, no FIN";
1562 const unsigned char kV3FrameData[] = { // Also applies for V2. 1590 const unsigned char kV3FrameData[] = { // Also applies for V2.
1563 0x00, 0x00, 0x00, 0x01, 1591 0x00, 0x00, 0x00, 0x01,
1564 0x00, 0x00, 0x00, 0x05, 1592 0x00, 0x00, 0x00, 0x05,
1565 'h', 'e', 'l', 'l', 1593 'h', 'e', 'l', 'l',
1566 'o' 1594 'o'
1567 }; 1595 };
1568 const unsigned char kV4FrameData[] = { 1596 const unsigned char kV4FrameData[] = {
1569 0x00, 0x05, 0x00, 0x00, 1597 0x00, 0x00, 0x05, 0x00,
1570 0x00, 0x00, 0x00, 0x01, 1598 0x00, 0x00, 0x00, 0x00,
1571 'h', 'e', 'l', 'l', 1599 0x01, 'h', 'e', 'l',
1572 'o' 1600 'l', 'o'
1573 }; 1601 };
1574 const char bytes[] = "hello"; 1602 const char bytes[] = "hello";
1575 1603
1576 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); 1604 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes)));
1577 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1605 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1578 if (IsSpdy4()) { 1606 if (IsSpdy4()) {
1579 CompareFrame( 1607 CompareFrame(
1580 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1608 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1581 } else { 1609 } else {
1582 CompareFrame( 1610 CompareFrame(
(...skipping 15 matching lines...) Expand all
1598 { 1626 {
1599 const char kDescription[] = "'hello' data frame with more padding, no FIN"; 1627 const char kDescription[] = "'hello' data frame with more padding, no FIN";
1600 const unsigned char kV3FrameData[] = { // Also applies for V2. 1628 const unsigned char kV3FrameData[] = { // Also applies for V2.
1601 0x00, 0x00, 0x00, 0x01, 1629 0x00, 0x00, 0x00, 0x01,
1602 0x00, 0x00, 0x00, 0x05, 1630 0x00, 0x00, 0x00, 0x05,
1603 'h', 'e', 'l', 'l', 1631 'h', 'e', 'l', 'l',
1604 'o' 1632 'o'
1605 }; 1633 };
1606 1634
1607 const unsigned char kV4FrameData[] = { 1635 const unsigned char kV4FrameData[] = {
1608 0x00, 0xfd, 0x00, 0x08, // Length = 253. PADDED set. 1636 0x00, 0x00, 0xfd, 0x00, // Length = 253. PADDED set.
1609 0x00, 0x00, 0x00, 0x01, 1637 0x08, 0x00, 0x00, 0x00,
1610 0xf7, // Pad length field. 1638 0x01, 0xf7, // Pad length field.
1611 'h', 'e', 'l', 'l', // Data 1639 'h', 'e', 'l', 'l', // Data
1612 'o', 1640 'o',
1613 // Padding of 247 zeros. 1641 // Padding of 247 zeros.
1614 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1642 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
1615 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1643 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
1616 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1644 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
1617 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1645 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
1618 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1646 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
1619 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1647 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
1620 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 1648 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 { 1686 {
1659 const char kDescription[] = "'hello' data frame with few padding, no FIN"; 1687 const char kDescription[] = "'hello' data frame with few padding, no FIN";
1660 const unsigned char kV3FrameData[] = { // Also applies for V2. 1688 const unsigned char kV3FrameData[] = { // Also applies for V2.
1661 0x00, 0x00, 0x00, 0x01, 1689 0x00, 0x00, 0x00, 0x01,
1662 0x00, 0x00, 0x00, 0x05, 1690 0x00, 0x00, 0x00, 0x05,
1663 'h', 'e', 'l', 'l', 1691 'h', 'e', 'l', 'l',
1664 'o' 1692 'o'
1665 }; 1693 };
1666 1694
1667 const unsigned char kV4FrameData[] = { 1695 const unsigned char kV4FrameData[] = {
1668 0x00, 0x0d, 0x00, 0x08, // Length = 13. PADDED set. 1696 0x00, 0x00, 0x0d, 0x00, // Length = 13. PADDED set.
1669 0x00, 0x00, 0x00, 0x01, 1697 0x08, 0x00, 0x00, 0x00,
1670 0x07, // Pad length field. 1698 0x01, 0x07, // Pad length field.
1671 'h', 'e', 'l', 'l', // Data 1699 'h', 'e', 'l', 'l', // Data
1672 'o', 1700 'o',
1673 '0', '0', '0', '0', // Padding 1701 '0', '0', '0', '0', // Padding
1674 '0', '0', '0' 1702 '0', '0', '0'
1675 }; 1703 };
1676 const char bytes[] = "hello"; 1704 const char bytes[] = "hello";
1677 1705
1678 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); 1706 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes)));
1679 // 7 zeros and the pad length field make the overall padding to be 8 bytes. 1707 // 7 zeros and the pad length field make the overall padding to be 8 bytes.
1680 data_ir.set_padding_len(8); 1708 data_ir.set_padding_len(8);
(...skipping 11 matching lines...) Expand all
1692 const char kDescription[] = 1720 const char kDescription[] =
1693 "'hello' data frame with 1 byte padding, no FIN"; 1721 "'hello' data frame with 1 byte padding, no FIN";
1694 const unsigned char kV3FrameData[] = { // Also applies for V2. 1722 const unsigned char kV3FrameData[] = { // Also applies for V2.
1695 0x00, 0x00, 0x00, 0x01, 1723 0x00, 0x00, 0x00, 0x01,
1696 0x00, 0x00, 0x00, 0x05, 1724 0x00, 0x00, 0x00, 0x05,
1697 'h', 'e', 'l', 'l', 1725 'h', 'e', 'l', 'l',
1698 'o' 1726 'o'
1699 }; 1727 };
1700 1728
1701 const unsigned char kV4FrameData[] = { 1729 const unsigned char kV4FrameData[] = {
1702 0x00, 0x06, 0x00, 0x08, // Length = 6. PADDED set. 1730 0x00, 0x00, 0x06, 0x00, // Length = 6. PADDED set.
1703 0x00, 0x00, 0x00, 0x01, 1731 0x08, 0x00, 0x00, 0x00,
1704 0x00, // Pad length field. 1732 0x01, 0x00, // Pad length field.
1705 'h', 'e', 'l', 'l', // Data 1733 'h', 'e', 'l', 'l', // Data
1706 'o', 1734 'o',
1707 }; 1735 };
1708 const char bytes[] = "hello"; 1736 const char bytes[] = "hello";
1709 1737
1710 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); 1738 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes)));
1711 // The pad length field itself is used for the 1-byte padding and no padding 1739 // The pad length field itself is used for the 1-byte padding and no padding
1712 // payload is needed. 1740 // payload is needed.
1713 data_ir.set_padding_len(1); 1741 data_ir.set_padding_len(1);
1714 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1742 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
(...skipping 15 matching lines...) Expand all
1730 } 1758 }
1731 1759
1732 { 1760 {
1733 const char kDescription[] = "Data frame with negative data byte, no FIN"; 1761 const char kDescription[] = "Data frame with negative data byte, no FIN";
1734 const unsigned char kV3FrameData[] = { // Also applies for V2. 1762 const unsigned char kV3FrameData[] = { // Also applies for V2.
1735 0x00, 0x00, 0x00, 0x01, 1763 0x00, 0x00, 0x00, 0x01,
1736 0x00, 0x00, 0x00, 0x01, 1764 0x00, 0x00, 0x00, 0x01,
1737 0xff 1765 0xff
1738 }; 1766 };
1739 const unsigned char kV4FrameData[] = { 1767 const unsigned char kV4FrameData[] = {
1740 0x00, 0x01, 0x00, 0x00, 1768 0x00, 0x00, 0x01, 0x00, 0x00,
1741 0x00, 0x00, 0x00, 0x01, 1769 0x00, 0x00, 0x00, 0x01,
1742 0xff 1770 0xff
1743 }; 1771 };
1744 SpdyDataIR data_ir(1, StringPiece("\xff", 1)); 1772 SpdyDataIR data_ir(1, StringPiece("\xff", 1));
1745 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1773 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1746 if (IsSpdy4()) { 1774 if (IsSpdy4()) {
1747 CompareFrame( 1775 CompareFrame(
1748 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1776 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1749 } else { 1777 } else {
1750 CompareFrame( 1778 CompareFrame(
1751 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1779 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1752 } 1780 }
1753 } 1781 }
1754 1782
1755 { 1783 {
1756 const char kDescription[] = "'hello' data frame, with FIN"; 1784 const char kDescription[] = "'hello' data frame, with FIN";
1757 const unsigned char kV3FrameData[] = { // Also applies for V2. 1785 const unsigned char kV3FrameData[] = { // Also applies for V2.
1758 0x00, 0x00, 0x00, 0x01, 1786 0x00, 0x00, 0x00, 0x01,
1759 0x01, 0x00, 0x00, 0x05, 1787 0x01, 0x00, 0x00, 0x05,
1760 'h', 'e', 'l', 'l', 1788 'h', 'e', 'l', 'l',
1761 'o' 1789 'o'
1762 }; 1790 };
1763 const unsigned char kV4FrameData[] = { 1791 const unsigned char kV4FrameData[] = {
1764 0x00, 0x05, 0x00, 0x01, 1792 0x00, 0x00, 0x05, 0x00,
1765 0x00, 0x00, 0x00, 0x01, 1793 0x01, 0x00, 0x00, 0x00,
1766 'h', 'e', 'l', 'l', 1794 0x01, 'h', 'e', 'l',
1767 'o' 1795 'l', 'o'
1768 }; 1796 };
1769 SpdyDataIR data_ir(1, StringPiece("hello", 5)); 1797 SpdyDataIR data_ir(1, StringPiece("hello", 5));
1770 data_ir.set_fin(true); 1798 data_ir.set_fin(true);
1771 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1799 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1772 if (IsSpdy4()) { 1800 if (IsSpdy4()) {
1773 CompareFrame( 1801 CompareFrame(
1774 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1802 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1775 } else { 1803 } else {
1776 CompareFrame( 1804 CompareFrame(
1777 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1805 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1778 } 1806 }
1779 } 1807 }
1780 1808
1781 { 1809 {
1782 const char kDescription[] = "Empty data frame"; 1810 const char kDescription[] = "Empty data frame";
1783 const unsigned char kV3FrameData[] = { // Also applies for V2. 1811 const unsigned char kV3FrameData[] = { // Also applies for V2.
1784 0x00, 0x00, 0x00, 0x01, 1812 0x00, 0x00, 0x00, 0x01,
1785 0x00, 0x00, 0x00, 0x00, 1813 0x00, 0x00, 0x00, 0x00,
1786 }; 1814 };
1787 const unsigned char kV4FrameData[] = { 1815 const unsigned char kV4FrameData[] = {
1788 0x00, 0x00, 0x00, 0x00, 1816 0x00, 0x00, 0x00, 0x00,
1789 0x00, 0x00, 0x00, 0x01, 1817 0x00, 0x00, 0x00, 0x00,
1818 0x01,
1790 }; 1819 };
1791 SpdyDataIR data_ir(1, StringPiece()); 1820 SpdyDataIR data_ir(1, StringPiece());
1792 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1821 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1793 if (IsSpdy4()) { 1822 if (IsSpdy4()) {
1794 CompareFrame( 1823 CompareFrame(
1795 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1824 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1796 } else { 1825 } else {
1797 CompareFrame( 1826 CompareFrame(
1798 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1827 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
1799 } 1828 }
1800 1829
1801 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir)); 1830 frame.reset(framer.SerializeDataFrameHeaderWithPaddingLengthField(data_ir));
1802 CompareCharArraysWithHexError( 1831 CompareCharArraysWithHexError(
1803 kDescription, 1832 kDescription,
1804 reinterpret_cast<const unsigned char*>(frame->data()), 1833 reinterpret_cast<const unsigned char*>(frame->data()),
1805 framer.GetDataFrameMinimumSize(), 1834 framer.GetDataFrameMinimumSize(),
1806 IsSpdy4() ? kV4FrameData : kV3FrameData, 1835 IsSpdy4() ? kV4FrameData : kV3FrameData,
1807 framer.GetDataFrameMinimumSize()); 1836 framer.GetDataFrameMinimumSize());
1808 } 1837 }
1809 1838
1810 { 1839 {
1811 const char kDescription[] = "Data frame with max stream ID"; 1840 const char kDescription[] = "Data frame with max stream ID";
1812 const unsigned char kV3FrameData[] = { // Also applies for V2. 1841 const unsigned char kV3FrameData[] = { // Also applies for V2.
1813 0x7f, 0xff, 0xff, 0xff, 1842 0x7f, 0xff, 0xff, 0xff,
1814 0x01, 0x00, 0x00, 0x05, 1843 0x01, 0x00, 0x00, 0x05,
1815 'h', 'e', 'l', 'l', 1844 'h', 'e', 'l', 'l',
1816 'o' 1845 'o'
1817 }; 1846 };
1818 const unsigned char kV4FrameData[] = { 1847 const unsigned char kV4FrameData[] = {
1819 0x00, 0x05, 0x00, 0x01, 1848 0x00, 0x00, 0x05, 0x00,
1820 0x7f, 0xff, 0xff, 0xff, 1849 0x01, 0x7f, 0xff, 0xff,
1821 'h', 'e', 'l', 'l', 1850 0xff, 'h', 'e', 'l',
1822 'o' 1851 'l', 'o'
1823 }; 1852 };
1824 SpdyDataIR data_ir(0x7fffffff, "hello"); 1853 SpdyDataIR data_ir(0x7fffffff, "hello");
1825 data_ir.set_fin(true); 1854 data_ir.set_fin(true);
1826 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 1855 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
1827 if (IsSpdy4()) { 1856 if (IsSpdy4()) {
1828 CompareFrame( 1857 CompareFrame(
1829 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 1858 kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
1830 } else { 1859 } else {
1831 CompareFrame( 1860 CompareFrame(
1832 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 1861 kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 2304
2276 { 2305 {
2277 const char kDescription[] = "RST_STREAM frame"; 2306 const char kDescription[] = "RST_STREAM frame";
2278 const unsigned char kV3FrameData[] = { // Also applies for V2. 2307 const unsigned char kV3FrameData[] = { // Also applies for V2.
2279 0x80, spdy_version_ch_, 0x00, 0x03, 2308 0x80, spdy_version_ch_, 0x00, 0x03,
2280 0x00, 0x00, 0x00, 0x08, 2309 0x00, 0x00, 0x00, 0x08,
2281 0x00, 0x00, 0x00, 0x01, 2310 0x00, 0x00, 0x00, 0x01,
2282 0x00, 0x00, 0x00, 0x01, 2311 0x00, 0x00, 0x00, 0x01,
2283 }; 2312 };
2284 const unsigned char kV4FrameData[] = { 2313 const unsigned char kV4FrameData[] = {
2285 0x00, 0x07, 0x03, 0x00, 2314 0x00, 0x00, 0x07, 0x03,
2286 0x00, 0x00, 0x00, 0x01, 2315 0x00, 0x00, 0x00, 0x00,
2287 0x00, 0x00, 0x00, 0x01, 2316 0x01, 0x00, 0x00, 0x00,
2288 0x52, 0x53, 0x54 2317 0x01, 0x52, 0x53, 0x54
2289 }; 2318 };
2290 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR, "RST"); 2319 SpdyRstStreamIR rst_stream(1, RST_STREAM_PROTOCOL_ERROR, "RST");
2291 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); 2320 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream));
2292 if (IsSpdy4()) { 2321 if (IsSpdy4()) {
2293 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2322 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2294 } else { 2323 } else {
2295 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2324 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2296 } 2325 }
2297 } 2326 }
2298 2327
2299 { 2328 {
2300 const char kDescription[] = "RST_STREAM frame with max stream ID"; 2329 const char kDescription[] = "RST_STREAM frame with max stream ID";
2301 const unsigned char kV3FrameData[] = { // Also applies for V2. 2330 const unsigned char kV3FrameData[] = { // Also applies for V2.
2302 0x80, spdy_version_ch_, 0x00, 0x03, 2331 0x80, spdy_version_ch_, 0x00, 0x03,
2303 0x00, 0x00, 0x00, 0x08, 2332 0x00, 0x00, 0x00, 0x08,
2304 0x7f, 0xff, 0xff, 0xff, 2333 0x7f, 0xff, 0xff, 0xff,
2305 0x00, 0x00, 0x00, 0x01, 2334 0x00, 0x00, 0x00, 0x01,
2306 }; 2335 };
2307 const unsigned char kV4FrameData[] = { 2336 const unsigned char kV4FrameData[] = {
2308 0x00, 0x04, 0x03, 0x00, 2337 0x00, 0x00, 0x04, 0x03,
2309 0x7f, 0xff, 0xff, 0xff, 2338 0x00, 0x7f, 0xff, 0xff,
2310 0x00, 0x00, 0x00, 0x01, 2339 0xff, 0x00, 0x00, 0x00,
2340 0x01,
2311 }; 2341 };
2312 SpdyRstStreamIR rst_stream(0x7FFFFFFF, 2342 SpdyRstStreamIR rst_stream(0x7FFFFFFF,
2313 RST_STREAM_PROTOCOL_ERROR, 2343 RST_STREAM_PROTOCOL_ERROR,
2314 ""); 2344 "");
2315 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); 2345 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream));
2316 if (IsSpdy4()) { 2346 if (IsSpdy4()) {
2317 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2347 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2318 } else { 2348 } else {
2319 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2349 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2320 } 2350 }
2321 } 2351 }
2322 2352
2323 { 2353 {
2324 const char kDescription[] = "RST_STREAM frame with max status code"; 2354 const char kDescription[] = "RST_STREAM frame with max status code";
2325 const unsigned char kV3FrameData[] = { // Also applies for V2. 2355 const unsigned char kV3FrameData[] = { // Also applies for V2.
2326 0x80, spdy_version_ch_, 0x00, 0x03, 2356 0x80, spdy_version_ch_, 0x00, 0x03,
2327 0x00, 0x00, 0x00, 0x08, 2357 0x00, 0x00, 0x00, 0x08,
2328 0x7f, 0xff, 0xff, 0xff, 2358 0x7f, 0xff, 0xff, 0xff,
2329 0x00, 0x00, 0x00, 0x06, 2359 0x00, 0x00, 0x00, 0x06,
2330 }; 2360 };
2331 const unsigned char kV4FrameData[] = { 2361 const unsigned char kV4FrameData[] = {
2332 0x00, 0x04, 0x03, 0x00, 2362 0x00, 0x00, 0x04, 0x03,
2333 0x7f, 0xff, 0xff, 0xff, 2363 0x00, 0x7f, 0xff, 0xff,
2334 0x00, 0x00, 0x00, 0x06, 2364 0xff, 0x00, 0x00, 0x00,
2365 0x06,
2335 }; 2366 };
2336 SpdyRstStreamIR rst_stream(0x7FFFFFFF, 2367 SpdyRstStreamIR rst_stream(0x7FFFFFFF,
2337 RST_STREAM_INTERNAL_ERROR, 2368 RST_STREAM_INTERNAL_ERROR,
2338 ""); 2369 "");
2339 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream)); 2370 scoped_ptr<SpdyFrame> frame(framer.SerializeRstStream(rst_stream));
2340 if (IsSpdy4()) { 2371 if (IsSpdy4()) {
2341 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2372 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2342 } else { 2373 } else {
2343 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2374 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2344 } 2375 }
(...skipping 14 matching lines...) Expand all
2359 0x0a, 0x0b, 0x0c, 0x0d, 2390 0x0a, 0x0b, 0x0c, 0x0d,
2360 }; 2391 };
2361 const unsigned char kV3FrameData[] = { 2392 const unsigned char kV3FrameData[] = {
2362 0x80, spdy_version_ch_, 0x00, 0x04, 2393 0x80, spdy_version_ch_, 0x00, 0x04,
2363 0x00, 0x00, 0x00, 0x0c, 2394 0x00, 0x00, 0x00, 0x0c,
2364 0x00, 0x00, 0x00, 0x01, 2395 0x00, 0x00, 0x00, 0x01,
2365 0x01, 0x00, 0x00, 0x07, 2396 0x01, 0x00, 0x00, 0x07,
2366 0x0a, 0x0b, 0x0c, 0x0d, 2397 0x0a, 0x0b, 0x0c, 0x0d,
2367 }; 2398 };
2368 const unsigned char kV4FrameData[] = { 2399 const unsigned char kV4FrameData[] = {
2369 0x00, 0x06, 0x04, 0x00, 2400 0x00, 0x00, 0x06, 0x04,
2370 0x00, 0x00, 0x00, 0x00, 2401 0x00, 0x00, 0x00, 0x00,
2371 0x00, 0x04, 0x0a, 0x0b, 2402 0x00, 0x00, 0x04, 0x0a,
2372 0x0c, 0x0d, 2403 0x0b, 0x0c, 0x0d,
2373 }; 2404 };
2374 2405
2375 uint32 kValue = 0x0a0b0c0d; 2406 uint32 kValue = 0x0a0b0c0d;
2376 SpdySettingsIR settings_ir; 2407 SpdySettingsIR settings_ir;
2377 2408
2378 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01); 2409 SpdySettingsFlags kFlags = static_cast<SpdySettingsFlags>(0x01);
2379 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE; 2410 SpdySettingsIds kId = SETTINGS_INITIAL_WINDOW_SIZE;
2380 SettingsMap settings; 2411 SettingsMap settings;
2381 settings[kId] = SettingsFlagsAndValue(kFlags, kValue); 2412 settings[kId] = SettingsFlagsAndValue(kFlags, kValue);
2382 EXPECT_EQ(kFlags, settings[kId].first); 2413 EXPECT_EQ(kFlags, settings[kId].first);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 0x00, 0x00, 0x00, 0x06, 2453 0x00, 0x00, 0x00, 0x06,
2423 0x00, 0x00, 0x00, 0x03, // 3rd Setting 2454 0x00, 0x00, 0x00, 0x03, // 3rd Setting
2424 0x00, 0x00, 0x00, 0x07, 2455 0x00, 0x00, 0x00, 0x07,
2425 0x00, 0x00, 0x00, 0x04, // 4th Setting 2456 0x00, 0x00, 0x00, 0x04, // 4th Setting
2426 0x00, 0x00, 0x00, 0x08, 2457 0x00, 0x00, 0x00, 0x08,
2427 }; 2458 };
2428 // These end up seemingly out of order because of the way that our internal 2459 // These end up seemingly out of order because of the way that our internal
2429 // ordering for settings_ir works. HTTP2 has no requirement on ordering on 2460 // ordering for settings_ir works. HTTP2 has no requirement on ordering on
2430 // the wire. 2461 // the wire.
2431 const unsigned char kV4FrameData[] = { 2462 const unsigned char kV4FrameData[] = {
2432 0x00, 0x18, 0x04, 0x00, 2463 0x00, 0x00, 0x18, 0x04,
2433 0x00, 0x00, 0x00, 0x00, 2464 0x00, 0x00, 0x00, 0x00,
2434 0x00, 0x03, // 3rd Setting 2465 0x00, 0x00, 0x03, // 3rd Setting
2435 0x00, 0x00, 0x00, 0x07, 2466 0x00, 0x00, 0x00, 0x07,
2436 0x00, 0x04, // 4th Setting 2467 0x00, 0x04, // 4th Setting
2437 0x00, 0x00, 0x00, 0x08, 2468 0x00, 0x00, 0x00, 0x08,
2438 0x00, 0x01, // 1st Setting 2469 0x00, 0x01, // 1st Setting
2439 0x00, 0x00, 0x00, 0x05, 2470 0x00, 0x00, 0x00, 0x05,
2440 0x00, 0x02, // 2nd Setting 2471 0x00, 0x02, // 2nd Setting
2441 0x00, 0x00, 0x00, 0x06, 2472 0x00, 0x00, 0x00, 0x06,
2442 }; 2473 };
2443 2474
2444 SpdySettingsIR settings_ir; 2475 SpdySettingsIR settings_ir;
(...skipping 26 matching lines...) Expand all
2471 2502
2472 { 2503 {
2473 const char kDescription[] = "Empty SETTINGS frame"; 2504 const char kDescription[] = "Empty SETTINGS frame";
2474 2505
2475 const unsigned char kV3FrameData[] = { // Also applies for V2. 2506 const unsigned char kV3FrameData[] = { // Also applies for V2.
2476 0x80, spdy_version_ch_, 0x00, 0x04, 2507 0x80, spdy_version_ch_, 0x00, 0x04,
2477 0x00, 0x00, 0x00, 0x04, 2508 0x00, 0x00, 0x00, 0x04,
2478 0x00, 0x00, 0x00, 0x00, 2509 0x00, 0x00, 0x00, 0x00,
2479 }; 2510 };
2480 const unsigned char kV4FrameData[] = { 2511 const unsigned char kV4FrameData[] = {
2481 0x00, 0x00, 0x04, 0x00, 2512 0x00, 0x00, 0x00, 0x04,
2482 0x00, 0x00, 0x00, 0x00, 2513 0x00, 0x00, 0x00, 0x00,
2514 0x00,
2483 }; 2515 };
2484 SpdySettingsIR settings_ir; 2516 SpdySettingsIR settings_ir;
2485 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir)); 2517 scoped_ptr<SpdyFrame> frame(framer.SerializeSettings(settings_ir));
2486 if (IsSpdy4()) { 2518 if (IsSpdy4()) {
2487 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2519 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2488 } else { 2520 } else {
2489 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2521 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2490 } 2522 }
2491 } 2523 }
2492 } 2524 }
2493 2525
2494 TEST_P(SpdyFramerTest, CreatePingFrame) { 2526 TEST_P(SpdyFramerTest, CreatePingFrame) {
2495 SpdyFramer framer(spdy_version_); 2527 SpdyFramer framer(spdy_version_);
2496 2528
2497 { 2529 {
2498 const char kDescription[] = "PING frame"; 2530 const char kDescription[] = "PING frame";
2499 const unsigned char kV3FrameData[] = { // Also applies for V2. 2531 const unsigned char kV3FrameData[] = { // Also applies for V2.
2500 0x80, spdy_version_ch_, 0x00, 0x06, 2532 0x80, spdy_version_ch_, 0x00, 0x06,
2501 0x00, 0x00, 0x00, 0x04, 2533 0x00, 0x00, 0x00, 0x04,
2502 0x12, 0x34, 0x56, 0x78, 2534 0x12, 0x34, 0x56, 0x78,
2503 }; 2535 };
2504 const unsigned char kV4FrameData[] = { 2536 const unsigned char kV4FrameData[] = {
2505 0x00, 0x08, 0x06, 0x00, 2537 0x00, 0x00, 0x08, 0x06,
2506 0x00, 0x00, 0x00, 0x00, 2538 0x00, 0x00, 0x00, 0x00,
2507 0x12, 0x34, 0x56, 0x78, 2539 0x00, 0x12, 0x34, 0x56,
2508 0x9a, 0xbc, 0xde, 0xff, 2540 0x78, 0x9a, 0xbc, 0xde,
2541 0xff,
2509 }; 2542 };
2510 const unsigned char kV4FrameDataWithAck[] = { 2543 const unsigned char kV4FrameDataWithAck[] = {
2511 0x00, 0x08, 0x06, 0x01, 2544 0x00, 0x00, 0x08, 0x06,
2512 0x00, 0x00, 0x00, 0x00, 2545 0x01, 0x00, 0x00, 0x00,
2513 0x12, 0x34, 0x56, 0x78, 2546 0x00, 0x12, 0x34, 0x56,
2514 0x9a, 0xbc, 0xde, 0xff, 2547 0x78, 0x9a, 0xbc, 0xde,
2548 0xff,
2515 }; 2549 };
2516 scoped_ptr<SpdyFrame> frame; 2550 scoped_ptr<SpdyFrame> frame;
2517 if (IsSpdy4()) { 2551 if (IsSpdy4()) {
2518 const SpdyPingId kPingId = 0x123456789abcdeffULL; 2552 const SpdyPingId kPingId = 0x123456789abcdeffULL;
2519 SpdyPingIR ping_ir(kPingId); 2553 SpdyPingIR ping_ir(kPingId);
2520 // Tests SpdyPingIR when the ping is not an ack. 2554 // Tests SpdyPingIR when the ping is not an ack.
2521 ASSERT_FALSE(ping_ir.is_ack()); 2555 ASSERT_FALSE(ping_ir.is_ack());
2522 frame.reset(framer.SerializePing(ping_ir)); 2556 frame.reset(framer.SerializePing(ping_ir));
2523 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2557 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2524 2558
(...skipping 20 matching lines...) Expand all
2545 0x00, 0x00, 0x00, 0x04, 2579 0x00, 0x00, 0x00, 0x04,
2546 0x00, 0x00, 0x00, 0x00, // Stream Id 2580 0x00, 0x00, 0x00, 0x00, // Stream Id
2547 }; 2581 };
2548 const unsigned char kV3FrameData[] = { 2582 const unsigned char kV3FrameData[] = {
2549 0x80, spdy_version_ch_, 0x00, 0x07, 2583 0x80, spdy_version_ch_, 0x00, 0x07,
2550 0x00, 0x00, 0x00, 0x08, 2584 0x00, 0x00, 0x00, 0x08,
2551 0x00, 0x00, 0x00, 0x00, // Stream Id 2585 0x00, 0x00, 0x00, 0x00, // Stream Id
2552 0x00, 0x00, 0x00, 0x00, // Status 2586 0x00, 0x00, 0x00, 0x00, // Status
2553 }; 2587 };
2554 const unsigned char kV4FrameData[] = { 2588 const unsigned char kV4FrameData[] = {
2555 0x00, 0x0a, 0x07, 0x00, 2589 0x00, 0x00, 0x0a, 0x07,
2556 0x00, 0x00, 0x00, 0x00, 2590 0x00, 0x00, 0x00, 0x00,
2557 0x00, 0x00, 0x00, 0x00, // Stream id 2591 0x00, 0x00, 0x00, 0x00, // Stream id
2558 0x00, 0x00, 0x00, 0x00, // Status 2592 0x00, 0x00, 0x00, 0x00, // Status
2559 0x47, 0x41, // Opaque Description 2593 0x00, 0x47, 0x41, // Opaque Description
2560 }; 2594 };
2561 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA"); 2595 SpdyGoAwayIR goaway_ir(0, GOAWAY_OK, "GA");
2562 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); 2596 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir));
2563 if (IsSpdy2()) { 2597 if (IsSpdy2()) {
2564 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2598 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2565 } else if (IsSpdy3()) { 2599 } else if (IsSpdy3()) {
2566 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2600 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2567 } else { 2601 } else {
2568 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2602 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2569 } 2603 }
2570 } 2604 }
2571 2605
2572 { 2606 {
2573 const char kDescription[] = "GOAWAY frame with max stream ID, status"; 2607 const char kDescription[] = "GOAWAY frame with max stream ID, status";
2574 const unsigned char kV2FrameData[] = { 2608 const unsigned char kV2FrameData[] = {
2575 0x80, spdy_version_ch_, 0x00, 0x07, 2609 0x80, spdy_version_ch_, 0x00, 0x07,
2576 0x00, 0x00, 0x00, 0x04, 2610 0x00, 0x00, 0x00, 0x04,
2577 0x7f, 0xff, 0xff, 0xff, // Stream Id 2611 0x7f, 0xff, 0xff, 0xff, // Stream Id
2578 }; 2612 };
2579 const unsigned char kV3FrameData[] = { 2613 const unsigned char kV3FrameData[] = {
2580 0x80, spdy_version_ch_, 0x00, 0x07, 2614 0x80, spdy_version_ch_, 0x00, 0x07,
2581 0x00, 0x00, 0x00, 0x08, 2615 0x00, 0x00, 0x00, 0x08,
2582 0x7f, 0xff, 0xff, 0xff, // Stream Id 2616 0x7f, 0xff, 0xff, 0xff, // Stream Id
2583 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR. 2617 0x00, 0x00, 0x00, 0x01, // Status: PROTOCOL_ERROR.
2584 }; 2618 };
2585 const unsigned char kV4FrameData[] = { 2619 const unsigned char kV4FrameData[] = {
2586 0x00, 0x0a, 0x07, 0x00, 2620 0x00, 0x00, 0x0a, 0x07,
2587 0x00, 0x00, 0x00, 0x00, 2621 0x00, 0x00, 0x00, 0x00,
2588 0x7f, 0xff, 0xff, 0xff, // Stream Id 2622 0x00, 0x7f, 0xff, 0xff, // Stream Id
2589 0x00, 0x00, 0x00, 0x02, // Status: INTERNAL_ERROR. 2623 0xff, 0x00, 0x00, 0x00, // Status: INTERNAL_ERROR.
2590 0x47, 0x41, // Opaque Description 2624 0x02, 0x47, 0x41, // Opaque Description
2591 }; 2625 };
2592 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA"); 2626 SpdyGoAwayIR goaway_ir(0x7FFFFFFF, GOAWAY_INTERNAL_ERROR, "GA");
2593 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir)); 2627 scoped_ptr<SpdyFrame> frame(framer.SerializeGoAway(goaway_ir));
2594 if (IsSpdy2()) { 2628 if (IsSpdy2()) {
2595 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2629 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2596 } else if (IsSpdy3()) { 2630 } else if (IsSpdy3()) {
2597 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2631 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2598 } else { 2632 } else {
2599 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2633 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2600 } 2634 }
(...skipping 25 matching lines...) Expand all
2626 0x00, 0x00, 0x00, 0x02, 2660 0x00, 0x00, 0x00, 0x02,
2627 0x00, 0x00, 0x00, 0x03, 2661 0x00, 0x00, 0x00, 0x03,
2628 'b', 'a', 'r', 0x00, 2662 'b', 'a', 'r', 0x00,
2629 0x00, 0x00, 0x03, 'f', 2663 0x00, 0x00, 0x03, 'f',
2630 'o', 'o', 0x00, 0x00, 2664 'o', 'o', 0x00, 0x00,
2631 0x00, 0x03, 'f', 'o', 2665 0x00, 0x03, 'f', 'o',
2632 'o', 0x00, 0x00, 0x00, 2666 'o', 0x00, 0x00, 0x00,
2633 0x03, 'b', 'a', 'r' 2667 0x03, 'b', 'a', 'r'
2634 }; 2668 };
2635 const unsigned char kV4FrameData[] = { 2669 const unsigned char kV4FrameData[] = {
2636 0x00, 0x12, 0x01, 0x04, // Headers: END_HEADERS 2670 0x00, 0x00, 0x12, 0x01, // Headers: END_HEADERS
2637 0x00, 0x00, 0x00, 0x01, // Stream 1 2671 0x04, 0x00, 0x00, 0x00, // Stream 1
2638 0x00, 0x03, 0x62, 0x61, // @.ba 2672 0x01, 0x00, 0x03, 0x62, // @.ba
2639 0x72, 0x03, 0x66, 0x6f, // r.fo 2673 0x61, 0x72, 0x03, 0x66, // r.fo
2640 0x6f, 0x00, 0x03, 0x66, // o@.f 2674 0x6f, 0x6f, 0x00, 0x03, // o@.f
2641 0x6f, 0x6f, 0x03, 0x62, // oo.b 2675 0x66, 0x6f, 0x6f, 0x03, // oo.b
2642 0x61, 0x72, // ar 2676 0x62, 0x61, 0x72, // ar
2643 }; 2677 };
2644 SpdyHeadersIR headers_ir(1); 2678 SpdyHeadersIR headers_ir(1);
2645 headers_ir.SetHeader("bar", "foo"); 2679 headers_ir.SetHeader("bar", "foo");
2646 headers_ir.SetHeader("foo", "bar"); 2680 headers_ir.SetHeader("foo", "bar");
2647 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2681 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2648 if (IsSpdy2()) { 2682 if (IsSpdy2()) {
2649 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2683 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2650 } else if (IsSpdy3()) { 2684 } else if (IsSpdy3()) {
2651 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2685 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2652 } else { 2686 } else {
(...skipping 23 matching lines...) Expand all
2676 0x00, 0x00, 0x00, 0x02, 2710 0x00, 0x00, 0x00, 0x02,
2677 0x00, 0x00, 0x00, 0x00, 2711 0x00, 0x00, 0x00, 0x00,
2678 0x00, 0x00, 0x00, 0x03, 2712 0x00, 0x00, 0x00, 0x03,
2679 'f', 'o', 'o', 0x00, 2713 'f', 'o', 'o', 0x00,
2680 0x00, 0x00, 0x03, 'f', 2714 0x00, 0x00, 0x03, 'f',
2681 'o', 'o', 0x00, 0x00, 2715 'o', 'o', 0x00, 0x00,
2682 0x00, 0x03, 'b', 'a', 2716 0x00, 0x03, 'b', 'a',
2683 'r' 2717 'r'
2684 }; 2718 };
2685 const unsigned char kV4FrameData[] = { 2719 const unsigned char kV4FrameData[] = {
2686 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS 2720 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS
2687 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff 2721 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff
2688 0x00, 0x00, 0x03, 0x66, // @..f 2722 0xff, 0x00, 0x00, 0x03, // @..
2689 0x6f, 0x6f, 0x00, 0x03, // oo@. 2723 0x66, 0x6f, 0x6f, 0x00, // foo@
2690 0x66, 0x6f, 0x6f, 0x03, // foo. 2724 0x03, 0x66, 0x6f, 0x6f, // .foo
2691 0x62, 0x61, 0x72, // bar 2725 0x03, 0x62, 0x61, 0x72, // .bar
2692 }; 2726 };
2693 SpdyHeadersIR headers_ir(0x7fffffff); 2727 SpdyHeadersIR headers_ir(0x7fffffff);
2694 headers_ir.set_fin(true); 2728 headers_ir.set_fin(true);
2695 headers_ir.SetHeader("", "foo"); 2729 headers_ir.SetHeader("", "foo");
2696 headers_ir.SetHeader("foo", "bar"); 2730 headers_ir.SetHeader("foo", "bar");
2697 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2731 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2698 if (IsSpdy2()) { 2732 if (IsSpdy2()) {
2699 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2733 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2700 } else if (IsSpdy3()) { 2734 } else if (IsSpdy3()) {
2701 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2735 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
(...skipping 24 matching lines...) Expand all
2726 0x00, 0x00, 0x00, 0x02, 2760 0x00, 0x00, 0x00, 0x02,
2727 0x00, 0x00, 0x00, 0x03, 2761 0x00, 0x00, 0x00, 0x03,
2728 'b', 'a', 'r', 0x00, 2762 'b', 'a', 'r', 0x00,
2729 0x00, 0x00, 0x03, 'f', 2763 0x00, 0x00, 0x03, 'f',
2730 'o', 'o', 0x00, 0x00, 2764 'o', 'o', 0x00, 0x00,
2731 0x00, 0x03, 'f', 'o', 2765 0x00, 0x03, 'f', 'o',
2732 'o', 0x00, 0x00, 0x00, 2766 'o', 0x00, 0x00, 0x00,
2733 0x00 2767 0x00
2734 }; 2768 };
2735 const unsigned char kV4FrameData[] = { 2769 const unsigned char kV4FrameData[] = {
2736 0x00, 0x0f, 0x01, 0x05, // HEADER: FIN | END_HEADERS 2770 0x00, 0x00, 0x0f, 0x01, // Headers: FIN | END_HEADERS
2737 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff 2771 0x05, 0x7f, 0xff, 0xff, // Stream 0x7fffffff
2738 0x00, 0x03, 0x62, 0x61, // @.ba 2772 0xff, 0x00, 0x03, 0x62, // @.b
2739 0x72, 0x03, 0x66, 0x6f, // r.fo 2773 0x61, 0x72, 0x03, 0x66, // ar.f
2740 0x6f, 0x00, 0x03, 0x66, // o@.f 2774 0x6f, 0x6f, 0x00, 0x03, // oo@.
2741 0x6f, 0x6f, 0x00, // oo. 2775 0x66, 0x6f, 0x6f, 0x00, // foo.
2742 }; 2776 };
2743 SpdyHeadersIR headers_ir(0x7fffffff); 2777 SpdyHeadersIR headers_ir(0x7fffffff);
2744 headers_ir.set_fin(true); 2778 headers_ir.set_fin(true);
2745 headers_ir.SetHeader("bar", "foo"); 2779 headers_ir.SetHeader("bar", "foo");
2746 headers_ir.SetHeader("foo", ""); 2780 headers_ir.SetHeader("foo", "");
2747 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); 2781 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir));
2748 if (IsSpdy2()) { 2782 if (IsSpdy2()) {
2749 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData)); 2783 CompareFrame(kDescription, *frame, kV2FrameData, arraysize(kV2FrameData));
2750 } else if (IsSpdy3()) { 2784 } else if (IsSpdy3()) {
2751 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2785 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2752 } else { 2786 } else {
2753 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2787 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2754 } 2788 }
2755 } 2789 }
2756 2790
2757 { 2791 {
2758 const char kDescription[] = 2792 const char kDescription[] =
2759 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri"; 2793 "HEADERS frame with a 0-length header val, FIN, max stream ID, pri";
2760 2794
2761 const unsigned char kV4FrameData[] = { 2795 const unsigned char kV4FrameData[] = {
2762 0x00, 0x14, 0x01, 0x25, // Headers: FIN | END_HEADERS | PRIORITY 2796 0x00, 0x00, 0x14, 0x01, // Headers: FIN | END_HEADERS | PRIORITY
2763 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff 2797 0x25, 0x7f, 0xff, 0xff, // Stream 0x7fffffff
2764 0x00, 0x00, 0x00, 0x00, // parent stream 2798 0xff, 0x00, 0x00, 0x00, // parent stream
2765 0xdb, // weight 2799 0x00, 0xdb, // weight
2766 0x00, 0x03, 0x62, 0x61, // @.ba 2800 0x00, 0x03, 0x62, 0x61, // @.ba
2767 0x72, 0x03, 0x66, 0x6f, // r.fo 2801 0x72, 0x03, 0x66, 0x6f, // r.fo
2768 0x6f, 0x00, 0x03, 0x66, // o@.f 2802 0x6f, 0x00, 0x03, 0x66, // o@.f
2769 0x6f, 0x6f, 0x00, // oo. 2803 0x6f, 0x6f, 0x00, // oo.
2770 }; 2804 };
2771 SpdyHeadersIR headers_ir(0x7fffffff); 2805 SpdyHeadersIR headers_ir(0x7fffffff);
2772 headers_ir.set_fin(true); 2806 headers_ir.set_fin(true);
2773 headers_ir.set_priority(1); 2807 headers_ir.set_priority(1);
2774 headers_ir.set_has_priority(true); 2808 headers_ir.set_has_priority(true);
2775 headers_ir.SetHeader("bar", "foo"); 2809 headers_ir.SetHeader("bar", "foo");
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2847 2881
2848 { 2882 {
2849 const char kDescription[] = "WINDOW_UPDATE frame"; 2883 const char kDescription[] = "WINDOW_UPDATE frame";
2850 const unsigned char kV3FrameData[] = { // Also applies for V2. 2884 const unsigned char kV3FrameData[] = { // Also applies for V2.
2851 0x80, spdy_version_ch_, 0x00, 0x09, 2885 0x80, spdy_version_ch_, 0x00, 0x09,
2852 0x00, 0x00, 0x00, 0x08, 2886 0x00, 0x00, 0x00, 0x08,
2853 0x00, 0x00, 0x00, 0x01, 2887 0x00, 0x00, 0x00, 0x01,
2854 0x00, 0x00, 0x00, 0x01, 2888 0x00, 0x00, 0x00, 0x01,
2855 }; 2889 };
2856 const unsigned char kV4FrameData[] = { 2890 const unsigned char kV4FrameData[] = {
2857 0x00, 0x04, 0x08, 0x00, 2891 0x00, 0x00, 0x04, 0x08,
2858 0x00, 0x00, 0x00, 0x01, 2892 0x00, 0x00, 0x00, 0x00,
2859 0x00, 0x00, 0x00, 0x01, 2893 0x01, 0x00, 0x00, 0x00,
2894 0x01,
2860 }; 2895 };
2861 scoped_ptr<SpdyFrame> frame( 2896 scoped_ptr<SpdyFrame> frame(
2862 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1))); 2897 framer.SerializeWindowUpdate(SpdyWindowUpdateIR(1, 1)));
2863 if (IsSpdy4()) { 2898 if (IsSpdy4()) {
2864 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2899 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2865 } else { 2900 } else {
2866 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2901 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2867 } 2902 }
2868 } 2903 }
2869 2904
2870 { 2905 {
2871 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID"; 2906 const char kDescription[] = "WINDOW_UPDATE frame with max stream ID";
2872 const unsigned char kV3FrameData[] = { // Also applies for V2. 2907 const unsigned char kV3FrameData[] = { // Also applies for V2.
2873 0x80, spdy_version_ch_, 0x00, 0x09, 2908 0x80, spdy_version_ch_, 0x00, 0x09,
2874 0x00, 0x00, 0x00, 0x08, 2909 0x00, 0x00, 0x00, 0x08,
2875 0x7f, 0xff, 0xff, 0xff, 2910 0x7f, 0xff, 0xff, 0xff,
2876 0x00, 0x00, 0x00, 0x01, 2911 0x00, 0x00, 0x00, 0x01,
2877 }; 2912 };
2878 const unsigned char kV4FrameData[] = { 2913 const unsigned char kV4FrameData[] = {
2879 0x00, 0x04, 0x08, 0x00, 2914 0x00, 0x00, 0x04, 0x08,
2880 0x7f, 0xff, 0xff, 0xff, 2915 0x00, 0x7f, 0xff, 0xff,
2881 0x00, 0x00, 0x00, 0x01, 2916 0xff, 0x00, 0x00, 0x00,
2917 0x01,
2882 }; 2918 };
2883 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( 2919 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate(
2884 SpdyWindowUpdateIR(0x7FFFFFFF, 1))); 2920 SpdyWindowUpdateIR(0x7FFFFFFF, 1)));
2885 if (IsSpdy4()) { 2921 if (IsSpdy4()) {
2886 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2922 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2887 } else { 2923 } else {
2888 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2924 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2889 } 2925 }
2890 } 2926 }
2891 2927
2892 { 2928 {
2893 const char kDescription[] = "WINDOW_UPDATE frame with max window delta"; 2929 const char kDescription[] = "WINDOW_UPDATE frame with max window delta";
2894 const unsigned char kV3FrameData[] = { // Also applies for V2. 2930 const unsigned char kV3FrameData[] = { // Also applies for V2.
2895 0x80, spdy_version_ch_, 0x00, 0x09, 2931 0x80, spdy_version_ch_, 0x00, 0x09,
2896 0x00, 0x00, 0x00, 0x08, 2932 0x00, 0x00, 0x00, 0x08,
2897 0x00, 0x00, 0x00, 0x01, 2933 0x00, 0x00, 0x00, 0x01,
2898 0x7f, 0xff, 0xff, 0xff, 2934 0x7f, 0xff, 0xff, 0xff,
2899 }; 2935 };
2900 const unsigned char kV4FrameData[] = { 2936 const unsigned char kV4FrameData[] = {
2901 0x00, 0x04, 0x08, 0x00, 2937 0x00, 0x00, 0x04, 0x08,
2902 0x00, 0x00, 0x00, 0x01, 2938 0x00, 0x00, 0x00, 0x00,
2903 0x7f, 0xff, 0xff, 0xff, 2939 0x01, 0x7f, 0xff, 0xff,
2940 0xff,
2904 }; 2941 };
2905 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate( 2942 scoped_ptr<SpdyFrame> frame(framer.SerializeWindowUpdate(
2906 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); 2943 SpdyWindowUpdateIR(1, 0x7FFFFFFF)));
2907 if (IsSpdy4()) { 2944 if (IsSpdy4()) {
2908 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); 2945 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData));
2909 } else { 2946 } else {
2910 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); 2947 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData));
2911 } 2948 }
2912 } 2949 }
2913 } 2950 }
2914 2951
2915 TEST_P(SpdyFramerTest, SerializeBlocked) { 2952 TEST_P(SpdyFramerTest, SerializeBlocked) {
2916 if (spdy_version_ <= SPDY3) { 2953 if (spdy_version_ <= SPDY3) {
2917 return; 2954 return;
2918 } 2955 }
2919 2956
2920 SpdyFramer framer(spdy_version_); 2957 SpdyFramer framer(spdy_version_);
2921 2958
2922 const char kDescription[] = "BLOCKED frame"; 2959 const char kDescription[] = "BLOCKED frame";
2923 const unsigned char kType = static_cast<unsigned char>( 2960 const unsigned char kType = static_cast<unsigned char>(
2924 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); 2961 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED));
2925 const unsigned char kFrameData[] = { 2962 const unsigned char kFrameData[] = {
2926 0x00, 0x00, kType, 0x00, 2963 0x00, 0x00, 0x00, kType, 0x00,
2927 0x00, 0x00, 0x00, 0x00, 2964 0x00, 0x00, 0x00, 0x00,
2928 }; 2965 };
2929 SpdyBlockedIR blocked_ir(0); 2966 SpdyBlockedIR blocked_ir(0);
2930 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); 2967 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir));
2931 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 2968 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
2932 } 2969 }
2933 2970
2934 TEST_P(SpdyFramerTest, CreateBlocked) { 2971 TEST_P(SpdyFramerTest, CreateBlocked) {
2935 if (spdy_version_ <= SPDY3) { 2972 if (spdy_version_ <= SPDY3) {
2936 return; 2973 return;
(...skipping 16 matching lines...) Expand all
2953 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { 2990 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) {
2954 if (spdy_version_ <= SPDY3) { 2991 if (spdy_version_ <= SPDY3) {
2955 return; 2992 return;
2956 } 2993 }
2957 2994
2958 SpdyFramer framer(spdy_version_); 2995 SpdyFramer framer(spdy_version_);
2959 framer.set_enable_compression(false); 2996 framer.set_enable_compression(false);
2960 const char kDescription[] = "PUSH_PROMISE frame"; 2997 const char kDescription[] = "PUSH_PROMISE frame";
2961 2998
2962 const unsigned char kFrameData[] = { 2999 const unsigned char kFrameData[] = {
2963 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS 3000 0x00, 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS
2964 0x00, 0x00, 0x00, 0x2a, // Stream 42 3001 0x00, 0x00, 0x00, 0x2a, // Stream 42
2965 0x00, 0x00, 0x00, 0x39, // Promised stream 57 3002 0x00, 0x00, 0x00, 0x39, // Promised stream 57
2966 0x00, 0x03, 0x62, 0x61, // @.ba 3003 0x00, 0x03, 0x62, 0x61, // @.ba
2967 0x72, 0x03, 0x66, 0x6f, // r.fo 3004 0x72, 0x03, 0x66, 0x6f, // r.fo
2968 0x6f, 0x00, 0x03, 0x66, // o@.f 3005 0x6f, 0x00, 0x03, 0x66, // o@.f
2969 0x6f, 0x6f, 0x03, 0x62, // oo.b 3006 0x6f, 0x6f, 0x03, 0x62, // oo.b
2970 0x61, 0x72, // ar 3007 0x61, 0x72, // ar
2971 }; 3008 };
2972 3009
2973 SpdyPushPromiseIR push_promise(42, 57); 3010 SpdyPushPromiseIR push_promise(42, 57);
2974 push_promise.SetHeader("bar", "foo"); 3011 push_promise.SetHeader("bar", "foo");
2975 push_promise.SetHeader("foo", "bar"); 3012 push_promise.SetHeader("foo", "bar");
2976 scoped_ptr<SpdySerializedFrame> frame( 3013 scoped_ptr<SpdySerializedFrame> frame(
2977 framer.SerializePushPromise(push_promise)); 3014 framer.SerializePushPromise(push_promise));
2978 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 3015 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
2979 } 3016 }
2980 3017
3018 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) {
3019 if (spdy_version_ <= SPDY3) {
3020 return;
3021 }
3022
3023 SpdyFramer framer(spdy_version_);
3024 framer.set_enable_compression(false);
3025 const char kDescription[] = "CONTINUATION frame";
3026
3027 const unsigned char kFrameData[] = {
3028 0x00, 0x00, 0x12, 0x09, 0x00, // CONTINUATION
3029 0x00, 0x00, 0x00, 0x2a, // Stream 42
3030 0x00, 0x03, 0x62, 0x61, // @.ba
3031 0x72, 0x03, 0x66, 0x6f, // r.fo
3032 0x6f, 0x00, 0x03, 0x66, // o@.f
3033 0x6f, 0x6f, 0x03, 0x62, // oo.b
3034 0x61, 0x72, // ar
3035 };
3036
3037 SpdyContinuationIR continuation(42);
3038 continuation.SetHeader("bar", "foo");
3039 continuation.SetHeader("foo", "bar");
3040 scoped_ptr<SpdySerializedFrame> frame(
3041 framer.SerializeContinuation(continuation));
3042 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3043 }
3044
2981 TEST_P(SpdyFramerTest, CreateAltSvc) { 3045 TEST_P(SpdyFramerTest, CreateAltSvc) {
2982 if (spdy_version_ <= SPDY3) { 3046 if (spdy_version_ <= SPDY3) {
2983 return; 3047 return;
2984 } 3048 }
2985 3049
2986 SpdyFramer framer(spdy_version_); 3050 SpdyFramer framer(spdy_version_);
2987 3051
2988 const char kDescription[] = "ALTSVC frame"; 3052 const char kDescription[] = "ALTSVC frame";
2989 const unsigned char kType = static_cast<unsigned char>( 3053 const unsigned char kType = static_cast<unsigned char>(
2990 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); 3054 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC));
2991 const unsigned char kFrameData[] = { 3055 const unsigned char kFrameData[] = {
2992 0x00, 0x17, kType, 0x00, 3056 0x00, 0x00, 0x17, kType, 0x00,
2993 0x00, 0x00, 0x00, 0x03, 3057 0x00, 0x00, 0x00, 0x03,
2994 0x00, 0x00, 0x00, 0x05, 3058 0x00, 0x00, 0x00, 0x05,
2995 0x01, 0xbb, 0x00, 0x04, // Port = 443 3059 0x01, 0xbb, 0x00, 0x04, // Port = 443
2996 'p', 'i', 'd', '1', // Protocol-ID 3060 'p', 'i', 'd', '1', // Protocol-ID
2997 0x04, 'h', 'o', 's', 3061 0x04, 'h', 'o', 's',
2998 't', 'o', 'r', 'i', 3062 't', 'o', 'r', 'i',
2999 'g', 'i', 'n', 3063 'g', 'i', 'n',
3000 }; 3064 };
3001 SpdyAltSvcIR altsvc_ir(3); 3065 SpdyAltSvcIR altsvc_ir(3);
3002 altsvc_ir.set_max_age(5); 3066 altsvc_ir.set_max_age(5);
3003 altsvc_ir.set_port(443); 3067 altsvc_ir.set_port(443);
3004 altsvc_ir.set_protocol_id("pid1"); 3068 altsvc_ir.set_protocol_id("pid1");
3005 altsvc_ir.set_host("host"); 3069 altsvc_ir.set_host("host");
3006 altsvc_ir.set_origin("origin"); 3070 altsvc_ir.set_origin("origin");
3007 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); 3071 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir));
3008 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 3072 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3009 } 3073 }
3010 3074
3011 TEST_P(SpdyFramerTest, CreatePriority) { 3075 TEST_P(SpdyFramerTest, CreatePriority) {
3012 if (spdy_version_ <= SPDY3) { 3076 if (spdy_version_ <= SPDY3) {
3013 return; 3077 return;
3014 } 3078 }
3015 3079
3016 SpdyFramer framer(spdy_version_); 3080 SpdyFramer framer(spdy_version_);
3017 3081
3018 const char kDescription[] = "PRIORITY frame"; 3082 const char kDescription[] = "PRIORITY frame";
3019 const unsigned char kType = static_cast<unsigned char>( 3083 const unsigned char kType = static_cast<unsigned char>(
3020 SpdyConstants::SerializeFrameType(spdy_version_, PRIORITY)); 3084 SpdyConstants::SerializeFrameType(spdy_version_, PRIORITY));
3021 const unsigned char kFrameData[] = { 3085 const unsigned char kFrameData[] = {
3022 0x00, 0x05, kType, 0x00, 3086 0x00, 0x00, 0x05, kType, 0x00,
3023 0x00, 0x00, 0x00, 0x02, // Stream ID = 2 3087 0x00, 0x00, 0x00, 0x02, // Stream ID = 2
3024 0x80, 0x00, 0x00, 0x01, // Exclusive dependency, parent stream ID = 1 3088 0x80, 0x00, 0x00, 0x01, // Exclusive dependency, parent stream ID = 1
3025 0x10, // Weight = 16 3089 0x10, // Weight = 16
3026 }; 3090 };
3027 SpdyPriorityIR priority_ir(2, 1, 16, true); 3091 SpdyPriorityIR priority_ir(2, 1, 16, true);
3028 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(priority_ir)); 3092 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(priority_ir));
3029 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); 3093 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3030 } 3094 }
3031 3095
3032 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { 3096 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) {
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
3338 0x00, 0x00, 0x00, length, 3402 0x00, 0x00, 0x00, length,
3339 0x00, 0x00, 0x00, 0x00, // Stream ID 3403 0x00, 0x00, 0x00, 0x00, // Stream ID
3340 0x00, 0x00, 0x00, 0x00, // Status 3404 0x00, 0x00, 0x00, 0x00, // Status
3341 }; 3405 };
3342 3406
3343 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length, 3407 // SPDY version 4 and up GOAWAY frames are only bound to a minimal length,
3344 // since it may carry opaque data. Verify that minimal length is tested. 3408 // since it may carry opaque data. Verify that minimal length is tested.
3345 const unsigned char less_than_min_length = 3409 const unsigned char less_than_min_length =
3346 framer.GetGoAwayMinimumSize() - framer.GetControlFrameHeaderSize() - 1; 3410 framer.GetGoAwayMinimumSize() - framer.GetControlFrameHeaderSize() - 1;
3347 const unsigned char kV4FrameData[] = { 3411 const unsigned char kV4FrameData[] = {
3348 0x00, static_cast<uint8>(less_than_min_length), 0x07, 0x00, 3412 0x00, 0x00, static_cast<uint8>(less_than_min_length), 0x07,
3349 0x00, 0x00, 0x00, 0x00, 3413 0x00, 0x00, 0x00, 0x00,
3350 0x00, 0x00, 0x00, 0x00, // Stream Id 3414 0x00, 0x00, 0x00, 0x00, // Stream Id
3351 0x00, 0x00, 0x00, 0x00, // Status 3415 0x00, 0x00, 0x00, 0x00, // Status
3416 0x00,
3352 }; 3417 };
3353 const size_t pad_length = 3418 const size_t pad_length =
3354 length + framer.GetControlFrameHeaderSize() - 3419 length + framer.GetControlFrameHeaderSize() -
3355 (IsSpdy4() ? sizeof(kV4FrameData) : sizeof(kV3FrameData)); 3420 (IsSpdy4() ? sizeof(kV4FrameData) : sizeof(kV3FrameData));
3356 string pad('A', pad_length); 3421 string pad('A', pad_length);
3357 TestSpdyVisitor visitor(spdy_version_); 3422 TestSpdyVisitor visitor(spdy_version_);
3358 3423
3359 if (IsSpdy4()) { 3424 if (IsSpdy4()) {
3360 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); 3425 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData));
3361 } else { 3426 } else {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 0x00, 0x00, 0x00, 0x1C, 3552 0x00, 0x00, 0x00, 0x1C,
3488 0x00, 0x00, 0x00, 0x03, 3553 0x00, 0x00, 0x00, 0x03,
3489 0x00, 0x00, 0x00, 0x01, // 1st Setting 3554 0x00, 0x00, 0x00, 0x01, // 1st Setting
3490 0x00, 0x00, 0x00, 0x02, 3555 0x00, 0x00, 0x00, 0x02,
3491 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting 3556 0x00, 0x00, 0x00, 0x01, // 2nd (duplicate) Setting
3492 0x00, 0x00, 0x00, 0x03, 3557 0x00, 0x00, 0x00, 0x03,
3493 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting 3558 0x00, 0x00, 0x00, 0x03, // 3rd (unprocessed) Setting
3494 0x00, 0x00, 0x00, 0x03, 3559 0x00, 0x00, 0x00, 0x03,
3495 }; 3560 };
3496 const unsigned char kV4FrameData[] = { 3561 const unsigned char kV4FrameData[] = {
3497 0x00, 0x12, 0x04, 0x00, 3562 0x00, 0x00, 0x12, 0x04,
3498 0x00, 0x00, 0x00, 0x00, 3563 0x00, 0x00, 0x00, 0x00,
3499 0x00, 0x01, // 1st Setting 3564 0x00, 0x00, 0x01, // 1st Setting
3500 0x00, 0x00, 0x00, 0x02, 3565 0x00, 0x00, 0x00, 0x02,
3501 0x00, 0x01, // 2nd (duplicate) Setting 3566 0x00, 0x01, // 2nd (duplicate) Setting
3502 0x00, 0x00, 0x00, 0x03, 3567 0x00, 0x00, 0x00, 0x03,
3503 0x00, 0x03, // 3rd (unprocessed) Setting 3568 0x00, 0x03, // 3rd (unprocessed) Setting
3504 0x00, 0x00, 0x00, 0x03, 3569 0x00, 0x00, 0x00, 0x03,
3505 }; 3570 };
3506 3571
3507 TestSpdyVisitor visitor(spdy_version_); 3572 TestSpdyVisitor visitor(spdy_version_);
3508 visitor.use_compression_ = false; 3573 visitor.use_compression_ = false;
3509 if (IsSpdy2()) { 3574 if (IsSpdy2()) {
3510 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); 3575 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData));
3511 } else if (IsSpdy3()) { 3576 } else if (IsSpdy3()) {
3512 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); 3577 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData));
3513 } else { 3578 } else {
3514 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); 3579 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData));
3515 } 3580 }
3516 3581
3517 if (!IsSpdy4()) { 3582 if (!IsSpdy4()) {
3518 EXPECT_EQ(1, visitor.setting_count_); 3583 EXPECT_EQ(1, visitor.setting_count_);
3519 EXPECT_EQ(1, visitor.error_count_); 3584 EXPECT_EQ(1, visitor.error_count_);
3520 } else { 3585 } else {
3521 // In SPDY 4+, duplicate settings are allowed; 3586 // In SPDY 4+, duplicate settings are allowed;
3522 // each setting replaces the previous value for that setting. 3587 // each setting replaces the previous value for that setting.
3523 EXPECT_EQ(3, visitor.setting_count_); 3588 EXPECT_EQ(3, visitor.setting_count_);
3524 EXPECT_EQ(0, visitor.error_count_); 3589 EXPECT_EQ(0, visitor.error_count_);
3525 EXPECT_EQ(1, visitor.settings_ack_sent_); 3590 EXPECT_EQ(1, visitor.settings_ack_sent_);
3526 } 3591 }
3527 } 3592 }
3528 3593
3594 // Tests handling of SETTINGS frame with a setting we don't recognize.
3595 TEST_P(SpdyFramerTest, ReadUnknownSettingsId) {
3596 SpdyFramer framer(spdy_version_);
3597
3598 const unsigned char kV2FrameData[] = {
3599 0x80, spdy_version_ch_, 0x00, 0x04,
3600 0x00, 0x00, 0x00, 0x1C,
3601 0x00, 0x00, 0x00, 0x01,
3602 0x10, 0x00, 0x00, 0x00, // 1st Setting
3603 0x00, 0x00, 0x00, 0x02,
3604 };
3605 const unsigned char kV3FrameData[] = {
3606 0x80, spdy_version_ch_, 0x00, 0x04,
3607 0x00, 0x00, 0x00, 0x1C,
3608 0x00, 0x00, 0x00, 0x01,
3609 0x00, 0x00, 0x00, 0x10, // 1st Setting
3610 0x00, 0x00, 0x00, 0x02,
3611 };
3612 const unsigned char kV4FrameData[] = {
3613 0x00, 0x00, 0x06, 0x04,
3614 0x00, 0x00, 0x00, 0x00,
3615 0x00, 0x00, 0x10, // 1st Setting
3616 0x00, 0x00, 0x00, 0x02,
3617 };
3618
3619 TestSpdyVisitor visitor(spdy_version_);
3620 visitor.use_compression_ = false;
3621 if (IsSpdy2()) {
3622 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData));
3623 } else if (IsSpdy3()) {
3624 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData));
3625 } else {
3626 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData));
3627 }
3628
3629 if (!IsSpdy4()) {
3630 EXPECT_EQ(0, visitor.setting_count_);
3631 EXPECT_EQ(1, visitor.error_count_);
3632 } else {
3633 // In SPDY 4+, we ignore unknown settings because of extensions.
3634 EXPECT_EQ(0, visitor.setting_count_);
3635 EXPECT_EQ(0, visitor.error_count_);
3636 }
3637 }
3638
3529 // Tests handling of SETTINGS frame with entries out of order. 3639 // Tests handling of SETTINGS frame with entries out of order.
3530 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { 3640 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) {
3531 SpdyFramer framer(spdy_version_); 3641 SpdyFramer framer(spdy_version_);
3532 3642
3533 const unsigned char kV2FrameData[] = { 3643 const unsigned char kV2FrameData[] = {
3534 0x80, spdy_version_ch_, 0x00, 0x04, 3644 0x80, spdy_version_ch_, 0x00, 0x04,
3535 0x00, 0x00, 0x00, 0x1C, 3645 0x00, 0x00, 0x00, 0x1C,
3536 0x00, 0x00, 0x00, 0x03, 3646 0x00, 0x00, 0x00, 0x03,
3537 0x02, 0x00, 0x00, 0x00, // 1st Setting 3647 0x02, 0x00, 0x00, 0x00, // 1st Setting
3538 0x00, 0x00, 0x00, 0x02, 3648 0x00, 0x00, 0x00, 0x02,
3539 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting 3649 0x01, 0x00, 0x00, 0x00, // 2nd (out of order) Setting
3540 0x00, 0x00, 0x00, 0x03, 3650 0x00, 0x00, 0x00, 0x03,
3541 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting 3651 0x03, 0x00, 0x00, 0x00, // 3rd (unprocessed) Setting
3542 0x00, 0x00, 0x00, 0x03, 3652 0x00, 0x00, 0x00, 0x03,
3543 }; 3653 };
3544 const unsigned char kV3FrameData[] = { 3654 const unsigned char kV3FrameData[] = {
3545 0x80, spdy_version_ch_, 0x00, 0x04, 3655 0x80, spdy_version_ch_, 0x00, 0x04,
3546 0x00, 0x00, 0x00, 0x1C, 3656 0x00, 0x00, 0x00, 0x1C,
3547 0x00, 0x00, 0x00, 0x03, 3657 0x00, 0x00, 0x00, 0x03,
3548 0x00, 0x00, 0x00, 0x02, // 1st Setting 3658 0x00, 0x00, 0x00, 0x02, // 1st Setting
3549 0x00, 0x00, 0x00, 0x02, 3659 0x00, 0x00, 0x00, 0x02,
3550 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting 3660 0x00, 0x00, 0x00, 0x01, // 2nd (out of order) Setting
3551 0x00, 0x00, 0x00, 0x03, 3661 0x00, 0x00, 0x00, 0x03,
3552 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting 3662 0x00, 0x00, 0x01, 0x03, // 3rd (unprocessed) Setting
3553 0x00, 0x00, 0x00, 0x03, 3663 0x00, 0x00, 0x00, 0x03,
3554 }; 3664 };
3555 const unsigned char kV4FrameData[] = { 3665 const unsigned char kV4FrameData[] = {
3556 0x00, 0x12, 0x04, 0x00, 3666 0x00, 0x00, 0x12, 0x04,
3557 0x00, 0x00, 0x00, 0x00, 3667 0x00, 0x00, 0x00, 0x00,
3558 0x00, 0x02, // 1st Setting 3668 0x00, 0x00, 0x02, // 1st Setting
3559 0x00, 0x00, 0x00, 0x02, 3669 0x00, 0x00, 0x00, 0x02,
3560 0x00, 0x01, // 2nd (out of order) Setting 3670 0x00, 0x01, // 2nd (out of order) Setting
3561 0x00, 0x00, 0x00, 0x03, 3671 0x00, 0x00, 0x00, 0x03,
3562 0x00, 0x03, // 3rd (unprocessed) Setting 3672 0x00, 0x03, // 3rd (unprocessed) Setting
3563 0x00, 0x00, 0x00, 0x03, 3673 0x00, 0x00, 0x00, 0x03,
3564 }; 3674 };
3565 3675
3566 TestSpdyVisitor visitor(spdy_version_); 3676 TestSpdyVisitor visitor(spdy_version_);
3567 visitor.use_compression_ = false; 3677 visitor.use_compression_ = false;
3568 if (IsSpdy2()) { 3678 if (IsSpdy2()) {
3569 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData)); 3679 visitor.SimulateInFramer(kV2FrameData, sizeof(kV2FrameData));
3570 } else if (IsSpdy3()) { 3680 } else if (IsSpdy3()) {
3571 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData)); 3681 visitor.SimulateInFramer(kV3FrameData, sizeof(kV3FrameData));
3572 } else { 3682 } else {
3573 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData)); 3683 visitor.SimulateInFramer(kV4FrameData, sizeof(kV4FrameData));
3574 } 3684 }
3575 3685
3576 if (!IsSpdy4()) { 3686 if (!IsSpdy4()) {
3577 EXPECT_EQ(1, visitor.setting_count_); 3687 EXPECT_EQ(1, visitor.setting_count_);
3578 EXPECT_EQ(1, visitor.error_count_); 3688 EXPECT_EQ(1, visitor.error_count_);
3579 } else { 3689 } else {
3580 // In SPDY 4+, settings are allowed in any order. 3690 // In SPDY 4+, settings are allowed in any order.
3581 EXPECT_EQ(3, visitor.setting_count_); 3691 EXPECT_EQ(3, visitor.setting_count_);
3582 EXPECT_EQ(0, visitor.error_count_); 3692 EXPECT_EQ(0, visitor.error_count_);
3583 // EXPECT_EQ(1, visitor.settings_ack_count_);
3584 } 3693 }
3585 } 3694 }
3586 3695
3587 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) { 3696 TEST_P(SpdyFramerTest, ProcessSettingsAckFrame) {
3588 if (spdy_version_ <= SPDY3) { 3697 if (spdy_version_ <= SPDY3) {
3589 return; 3698 return;
3590 } 3699 }
3591 SpdyFramer framer(spdy_version_); 3700 SpdyFramer framer(spdy_version_);
3592 3701
3593 const unsigned char kFrameData[] = { 3702 const unsigned char kFrameData[] = {
3594 0x00, 0x00, 0x04, 0x01, 3703 0x00, 0x00, 0x00, 0x04, 0x01,
3595 0x00, 0x00, 0x00, 0x00, 3704 0x00, 0x00, 0x00, 0x00,
3596 }; 3705 };
3597 3706
3598 TestSpdyVisitor visitor(spdy_version_); 3707 TestSpdyVisitor visitor(spdy_version_);
3599 visitor.use_compression_ = false; 3708 visitor.use_compression_ = false;
3600 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); 3709 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData));
3601 3710
3602 EXPECT_EQ(0, visitor.error_count_); 3711 EXPECT_EQ(0, visitor.error_count_);
3603 EXPECT_EQ(0, visitor.setting_count_); 3712 EXPECT_EQ(0, visitor.setting_count_);
3604 EXPECT_EQ(1, visitor.settings_ack_received_); 3713 EXPECT_EQ(1, visitor.settings_ack_received_);
(...skipping 15 matching lines...) Expand all
3620 data_ir.set_padding_len(kPaddingLen); 3729 data_ir.set_padding_len(kPaddingLen);
3621 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir)); 3730 scoped_ptr<SpdyFrame> frame(framer.SerializeData(data_ir));
3622 ASSERT_TRUE(frame.get() != NULL); 3731 ASSERT_TRUE(frame.get() != NULL);
3623 3732
3624 int bytes_consumed = 0; 3733 int bytes_consumed = 0;
3625 3734
3626 // Send the frame header. 3735 // Send the frame header.
3627 EXPECT_CALL(visitor, OnDataFrameHeader(1, 3736 EXPECT_CALL(visitor, OnDataFrameHeader(1,
3628 kPaddingLen + strlen(data_payload), 3737 kPaddingLen + strlen(data_payload),
3629 false)); 3738 false));
3630 CHECK_EQ(8u, framer.ProcessInput(frame->data(), 8)); 3739 CHECK_EQ(framer.GetDataFrameMinimumSize(),
3740 framer.ProcessInput(frame->data(),
3741 framer.GetDataFrameMinimumSize()));
3631 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH); 3742 CHECK_EQ(framer.state(), SpdyFramer::SPDY_READ_PADDING_LENGTH);
3632 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); 3743 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR);
3633 bytes_consumed += 8; 3744 bytes_consumed += framer.GetDataFrameMinimumSize();
3634 3745
3635 // Send the padding length field. 3746 // Send the padding length field.
3636 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1)); 3747 CHECK_EQ(1u, framer.ProcessInput(frame->data() + bytes_consumed, 1));
3637 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME); 3748 CHECK_EQ(framer.state(), SpdyFramer::SPDY_FORWARD_STREAM_FRAME);
3638 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR); 3749 CHECK_EQ(framer.error_code(), SpdyFramer::SPDY_NO_ERROR);
3639 bytes_consumed += 1; 3750 bytes_consumed += 1;
3640 3751
3641 // Send the first two bytes of the data payload, i.e., "he". 3752 // Send the first two bytes of the data payload, i.e., "he".
3642 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 2, false)); 3753 EXPECT_CALL(visitor, OnStreamFrameData(1, _, 2, false));
3643 CHECK_EQ(2u, framer.ProcessInput(frame->data() + bytes_consumed, 2)); 3754 CHECK_EQ(2u, framer.ProcessInput(frame->data() + bytes_consumed, 2));
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3737 multiple_frame_data.append(string(control_frame->data(), 3848 multiple_frame_data.append(string(control_frame->data(),
3738 control_frame->size())); 3849 control_frame->size()));
3739 visitor.SimulateInFramer( 3850 visitor.SimulateInFramer(
3740 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), 3851 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()),
3741 multiple_frame_data.length()); 3852 multiple_frame_data.length());
3742 EXPECT_EQ(0, visitor.error_count_); 3853 EXPECT_EQ(0, visitor.error_count_);
3743 EXPECT_EQ(1u, visitor.last_window_update_stream_); 3854 EXPECT_EQ(1u, visitor.last_window_update_stream_);
3744 EXPECT_EQ(2u, visitor.last_window_update_delta_); 3855 EXPECT_EQ(2u, visitor.last_window_update_delta_);
3745 } 3856 }
3746 3857
3747 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) {
3748 if (spdy_version_ <= SPDY3) {
3749 return;
3750 }
3751
3752 SpdyFramer framer(spdy_version_);
3753 framer.set_enable_compression(false);
3754 const char kDescription[] = "CONTINUATION frame";
3755
3756 const unsigned char kFrameData[] = {
3757 0x00, 0x12, 0x09, 0x00, // CONTINUATION
3758 0x00, 0x00, 0x00, 0x2a, // Stream 42
3759 0x00, 0x03, 0x62, 0x61, // @.ba
3760 0x72, 0x03, 0x66, 0x6f, // r.fo
3761 0x6f, 0x00, 0x03, 0x66, // o@.f
3762 0x6f, 0x6f, 0x03, 0x62, // oo.b
3763 0x61, 0x72, // ar
3764 };
3765
3766 SpdyContinuationIR continuation(42);
3767 continuation.SetHeader("bar", "foo");
3768 continuation.SetHeader("foo", "bar");
3769 scoped_ptr<SpdySerializedFrame> frame(
3770 framer.SerializeContinuation(continuation));
3771 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData));
3772 }
3773
3774 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) { 3858 TEST_P(SpdyFramerTest, ReadCompressedPushPromise) {
3775 if (spdy_version_ <= SPDY3) { 3859 if (spdy_version_ <= SPDY3) {
3776 return; 3860 return;
3777 } 3861 }
3778 3862
3779 SpdyFramer framer(spdy_version_); 3863 SpdyFramer framer(spdy_version_);
3780 SpdyPushPromiseIR push_promise(42, 57); 3864 SpdyPushPromiseIR push_promise(42, 57);
3781 push_promise.SetHeader("foo", "bar"); 3865 push_promise.SetHeader("foo", "bar");
3782 push_promise.SetHeader("bar", "foofoo"); 3866 push_promise.SetHeader("bar", "foofoo");
3783 SpdyHeaderBlock headers = push_promise.name_value_block(); 3867 SpdyHeaderBlock headers = push_promise.name_value_block();
3784 scoped_ptr<SpdySerializedFrame> frame( 3868 scoped_ptr<SpdySerializedFrame> frame(
3785 framer.SerializePushPromise(push_promise)); 3869 framer.SerializePushPromise(push_promise));
3786 EXPECT_TRUE(frame.get() != NULL); 3870 EXPECT_TRUE(frame.get() != NULL);
3787 TestSpdyVisitor visitor(spdy_version_); 3871 TestSpdyVisitor visitor(spdy_version_);
3788 visitor.use_compression_ = true; 3872 visitor.use_compression_ = true;
3789 visitor.SimulateInFramer( 3873 visitor.SimulateInFramer(
3790 reinterpret_cast<unsigned char*>(frame->data()), 3874 reinterpret_cast<unsigned char*>(frame->data()),
3791 frame->size()); 3875 frame->size());
3792 EXPECT_EQ(42u, visitor.last_push_promise_stream_); 3876 EXPECT_EQ(42u, visitor.last_push_promise_stream_);
3793 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); 3877 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_);
3794 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); 3878 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_));
3795 } 3879 }
3796 3880
3797 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { 3881 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) {
3798 if (spdy_version_ <= SPDY3) { 3882 if (spdy_version_ <= SPDY3) {
3799 return; 3883 return;
3800 } 3884 }
3801 3885
3802 const unsigned char kInput[] = { 3886 const unsigned char kInput[] = {
3803 0x00, 0x14, 0x01, 0x08, // HEADERS: PADDED 3887 0x00, 0x00, 0x14, 0x01, 0x08, // HEADERS: PADDED
3804 0x00, 0x00, 0x00, 0x01, // Stream 1 3888 0x00, 0x00, 0x00, 0x01, // Stream 1
3805 0x03, // Padding of 3. 3889 0x03, // Padding of 3.
3806 0x00, 0x06, 0x63, 0x6f, 3890 0x00, 0x06, 0x63, 0x6f,
3807 0x6f, 0x6b, 0x69, 0x65, 3891 0x6f, 0x6b, 0x69, 0x65,
3808 0x07, 0x66, 0x6f, 0x6f, 3892 0x07, 0x66, 0x6f, 0x6f,
3809 0x3d, 0x62, 0x61, 0x72, 3893 0x3d, 0x62, 0x61, 0x72,
3810 0x00, 0x00, 0x00, 3894 0x00, 0x00, 0x00,
3811 3895
3812 0x00, 0x14, 0x09, 0x00, // CONTINUATION 3896 0x00, 0x00, 0x14, 0x09, 0x00, // CONTINUATION
3813 0x00, 0x00, 0x00, 0x01, // Stream 1 3897 0x00, 0x00, 0x00, 0x01, // Stream 1
3814 0x00, 0x06, 0x63, 0x6f, 3898 0x00, 0x06, 0x63, 0x6f,
3815 0x6f, 0x6b, 0x69, 0x65, 3899 0x6f, 0x6b, 0x69, 0x65,
3816 0x08, 0x62, 0x61, 0x7a, 3900 0x08, 0x62, 0x61, 0x7a,
3817 0x3d, 0x62, 0x69, 0x6e, 3901 0x3d, 0x62, 0x69, 0x6e,
3818 0x67, 0x00, 0x06, 0x63, 3902 0x67, 0x00, 0x06, 0x63,
3819 3903
3820 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS 3904 0x00, 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS
3821 0x00, 0x00, 0x00, 0x01, // Stream 1 3905 0x00, 0x00, 0x00, 0x01, // Stream 1
3822 0x6f, 0x6f, 0x6b, 0x69, 3906 0x6f, 0x6f, 0x6b, 0x69,
3823 0x65, 0x00, 0x00, 0x04, 3907 0x65, 0x00, 0x00, 0x04,
3824 0x6e, 0x61, 0x6d, 0x65, 3908 0x6e, 0x61, 0x6d, 0x65,
3825 0x05, 0x76, 0x61, 0x6c, 3909 0x05, 0x76, 0x61, 0x6c,
3826 0x75, 0x65, 3910 0x75, 0x65,
3827 }; 3911 };
3828 3912
3829 TestSpdyVisitor visitor(spdy_version_); 3913 TestSpdyVisitor visitor(spdy_version_);
3830 visitor.SimulateInFramer(kInput, sizeof(kInput)); 3914 visitor.SimulateInFramer(kInput, sizeof(kInput));
3831 3915
3832 EXPECT_EQ(0, visitor.error_count_); 3916 EXPECT_EQ(0, visitor.error_count_);
3833 EXPECT_EQ(1, visitor.headers_frame_count_); 3917 EXPECT_EQ(1, visitor.headers_frame_count_);
3834 EXPECT_EQ(2, visitor.continuation_count_); 3918 EXPECT_EQ(2, visitor.continuation_count_);
3835 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); 3919 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_);
3836 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); 3920 EXPECT_EQ(0, visitor.zero_length_data_frame_count_);
3837 3921
3838 EXPECT_THAT(visitor.headers_, ElementsAre( 3922 EXPECT_THAT(visitor.headers_, ElementsAre(
3839 Pair("cookie", "foo=bar; baz=bing; "), 3923 Pair("cookie", "foo=bar; baz=bing; "),
3840 Pair("name", "value"))); 3924 Pair("name", "value")));
3841 } 3925 }
3842 3926
3843 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) { 3927 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndFin) {
3844 if (spdy_version_ <= SPDY3) { 3928 if (spdy_version_ <= SPDY3) {
3845 return; 3929 return;
3846 } 3930 }
3847 3931
3848 const unsigned char kInput[] = { 3932 const unsigned char kInput[] = {
3849 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN 3933 0x00, 0x00, 0x10, 0x01, 0x01, // HEADERS: FIN
3850 0x00, 0x00, 0x00, 0x01, // Stream 1 3934 0x00, 0x00, 0x00, 0x01, // Stream 1
3851 0x00, 0x06, 0x63, 0x6f, 3935 0x00, 0x06, 0x63, 0x6f,
3852 0x6f, 0x6b, 0x69, 0x65, 3936 0x6f, 0x6b, 0x69, 0x65,
3853 0x07, 0x66, 0x6f, 0x6f, 3937 0x07, 0x66, 0x6f, 0x6f,
3854 0x3d, 0x62, 0x61, 0x72, 3938 0x3d, 0x62, 0x61, 0x72,
3855 3939
3856 0x00, 0x14, 0x09, 0x00, // CONTINUATION 3940 0x00, 0x00, 0x14, 0x09, 0x00, // CONTINUATION
3857 0x00, 0x00, 0x00, 0x01, // Stream 1 3941 0x00, 0x00, 0x00, 0x01, // Stream 1
3858 0x00, 0x06, 0x63, 0x6f, 3942 0x00, 0x06, 0x63, 0x6f,
3859 0x6f, 0x6b, 0x69, 0x65, 3943 0x6f, 0x6b, 0x69, 0x65,
3860 0x08, 0x62, 0x61, 0x7a, 3944 0x08, 0x62, 0x61, 0x7a,
3861 0x3d, 0x62, 0x69, 0x6e, 3945 0x3d, 0x62, 0x69, 0x6e,
3862 0x67, 0x00, 0x06, 0x63, 3946 0x67, 0x00, 0x06, 0x63,
3863 3947
3864 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS 3948 0x00, 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS
3865 0x00, 0x00, 0x00, 0x01, // Stream 1 3949 0x00, 0x00, 0x00, 0x01, // Stream 1
3866 0x6f, 0x6f, 0x6b, 0x69, 3950 0x6f, 0x6f, 0x6b, 0x69,
3867 0x65, 0x00, 0x00, 0x04, 3951 0x65, 0x00, 0x00, 0x04,
3868 0x6e, 0x61, 0x6d, 0x65, 3952 0x6e, 0x61, 0x6d, 0x65,
3869 0x05, 0x76, 0x61, 0x6c, 3953 0x05, 0x76, 0x61, 0x6c,
3870 0x75, 0x65, 3954 0x75, 0x65,
3871 }; 3955 };
3872 3956
3873 SpdyFramer framer(spdy_version_); 3957 SpdyFramer framer(spdy_version_);
3874 TestSpdyVisitor visitor(spdy_version_); 3958 TestSpdyVisitor visitor(spdy_version_);
(...skipping 10 matching lines...) Expand all
3885 Pair("cookie", "foo=bar; baz=bing; "), 3969 Pair("cookie", "foo=bar; baz=bing; "),
3886 Pair("name", "value"))); 3970 Pair("name", "value")));
3887 } 3971 }
3888 3972
3889 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { 3973 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) {
3890 if (spdy_version_ <= SPDY3) { 3974 if (spdy_version_ <= SPDY3) {
3891 return; 3975 return;
3892 } 3976 }
3893 3977
3894 const unsigned char kInput[] = { 3978 const unsigned char kInput[] = {
3895 0x00, 0x17, 0x05, 0x08, // PUSH_PROMISE: PADDED 3979 0x00, 0x00, 0x17, 0x05, 0x08, // PUSH_PROMISE: PADDED
3896 0x00, 0x00, 0x00, 0x01, // Stream 1 3980 0x00, 0x00, 0x00, 0x01, // Stream 1
3897 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 3981 0x00, 0x00, 0x00, 0x2A, // Promised stream 42
3898 0x02, // Padding of 2. 3982 0x02, // Padding of 2.
3899 0x00, 0x06, 0x63, 0x6f, 3983 0x00, 0x06, 0x63, 0x6f,
3900 0x6f, 0x6b, 0x69, 0x65, 3984 0x6f, 0x6b, 0x69, 0x65,
3901 0x07, 0x66, 0x6f, 0x6f, 3985 0x07, 0x66, 0x6f, 0x6f,
3902 0x3d, 0x62, 0x61, 0x72, 3986 0x3d, 0x62, 0x61, 0x72,
3903 0x00, 0x00, 3987 0x00, 0x00,
3904 3988
3905 0x00, 0x14, 0x09, 0x00, // CONTINUATION 3989 0x00, 0x00, 0x14, 0x09, 0x00, // CONTINUATION
3906 0x00, 0x00, 0x00, 0x01, // Stream 1 3990 0x00, 0x00, 0x00, 0x01, // Stream 1
3907 0x00, 0x06, 0x63, 0x6f, 3991 0x00, 0x06, 0x63, 0x6f,
3908 0x6f, 0x6b, 0x69, 0x65, 3992 0x6f, 0x6b, 0x69, 0x65,
3909 0x08, 0x62, 0x61, 0x7a, 3993 0x08, 0x62, 0x61, 0x7a,
3910 0x3d, 0x62, 0x69, 0x6e, 3994 0x3d, 0x62, 0x69, 0x6e,
3911 0x67, 0x00, 0x06, 0x63, 3995 0x67, 0x00, 0x06, 0x63,
3912 3996
3913 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS 3997 0x00, 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS
3914 0x00, 0x00, 0x00, 0x01, // Stream 1 3998 0x00, 0x00, 0x00, 0x01, // Stream 1
3915 0x6f, 0x6f, 0x6b, 0x69, 3999 0x6f, 0x6f, 0x6b, 0x69,
3916 0x65, 0x00, 0x00, 0x04, 4000 0x65, 0x00, 0x00, 0x04,
3917 0x6e, 0x61, 0x6d, 0x65, 4001 0x6e, 0x61, 0x6d, 0x65,
3918 0x05, 0x76, 0x61, 0x6c, 4002 0x05, 0x76, 0x61, 0x6c,
3919 0x75, 0x65, 4003 0x75, 0x65,
3920 }; 4004 };
3921 4005
3922 SpdyFramer framer(spdy_version_); 4006 SpdyFramer framer(spdy_version_);
3923 TestSpdyVisitor visitor(spdy_version_); 4007 TestSpdyVisitor visitor(spdy_version_);
(...skipping 10 matching lines...) Expand all
3934 Pair("cookie", "foo=bar; baz=bing; "), 4018 Pair("cookie", "foo=bar; baz=bing; "),
3935 Pair("name", "value"))); 4019 Pair("name", "value")));
3936 } 4020 }
3937 4021
3938 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) { 4022 TEST_P(SpdyFramerTest, ReadContinuationWithWrongStreamId) {
3939 if (spdy_version_ <= SPDY3) { 4023 if (spdy_version_ <= SPDY3) {
3940 return; 4024 return;
3941 } 4025 }
3942 4026
3943 const unsigned char kInput[] = { 4027 const unsigned char kInput[] = {
3944 0x00, 0x10, 0x01, 0x00, // HEADERS 4028 0x00, 0x00, 0x10, 0x01, 0x00, // HEADERS
3945 0x00, 0x00, 0x00, 0x01, // Stream 1 4029 0x00, 0x00, 0x00, 0x01, // Stream 1
3946 0x00, 0x06, 0x63, 0x6f, 4030 0x00, 0x06, 0x63, 0x6f,
3947 0x6f, 0x6b, 0x69, 0x65, 4031 0x6f, 0x6b, 0x69, 0x65,
3948 0x07, 0x66, 0x6f, 0x6f, 4032 0x07, 0x66, 0x6f, 0x6f,
3949 0x3d, 0x62, 0x61, 0x72, 4033 0x3d, 0x62, 0x61, 0x72,
3950 4034
3951 0x00, 0x14, 0x09, 0x00, // CONTINUATION 4035 0x00, 0x00, 0x14, 0x09, 0x00, // CONTINUATION
3952 0x00, 0x00, 0x00, 0x02, // Stream 2 4036 0x00, 0x00, 0x00, 0x02, // Stream 2
3953 0x00, 0x06, 0x63, 0x6f, 4037 0x00, 0x06, 0x63, 0x6f,
3954 0x6f, 0x6b, 0x69, 0x65, 4038 0x6f, 0x6b, 0x69, 0x65,
3955 0x08, 0x62, 0x61, 0x7a, 4039 0x08, 0x62, 0x61, 0x7a,
3956 0x3d, 0x62, 0x69, 0x6e, 4040 0x3d, 0x62, 0x69, 0x6e,
3957 0x67, 0x00, 0x06, 0x63, 4041 0x67, 0x00, 0x06, 0x63,
3958 }; 4042 };
3959 4043
3960 SpdyFramer framer(spdy_version_); 4044 SpdyFramer framer(spdy_version_);
3961 TestSpdyVisitor visitor(spdy_version_); 4045 TestSpdyVisitor visitor(spdy_version_);
3962 framer.set_visitor(&visitor); 4046 framer.set_visitor(&visitor);
3963 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4047 visitor.SimulateInFramer(kInput, sizeof(kInput));
3964 4048
3965 EXPECT_EQ(1, visitor.error_count_); 4049 EXPECT_EQ(1, visitor.error_count_);
3966 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 4050 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
3967 visitor.framer_.error_code()) 4051 visitor.framer_.error_code())
3968 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4052 << SpdyFramer::ErrorCodeToString(framer.error_code());
3969 EXPECT_EQ(1, visitor.headers_frame_count_); 4053 EXPECT_EQ(1, visitor.headers_frame_count_);
3970 EXPECT_EQ(0, visitor.continuation_count_); 4054 EXPECT_EQ(0, visitor.continuation_count_);
3971 EXPECT_EQ(0u, visitor.header_buffer_length_); 4055 EXPECT_EQ(0u, visitor.header_buffer_length_);
3972 } 4056 }
3973 4057
3974 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) { 4058 TEST_P(SpdyFramerTest, ReadContinuationOutOfOrder) {
3975 if (spdy_version_ <= SPDY3) { 4059 if (spdy_version_ <= SPDY3) {
3976 return; 4060 return;
3977 } 4061 }
3978 4062
3979 const unsigned char kInput[] = { 4063 const unsigned char kInput[] = {
3980 0x00, 0x10, 0x09, 0x00, // CONTINUATION 4064 0x00, 0x00, 0x18, 0x09, 0x00, // CONTINUATION
3981 0x00, 0x00, 0x00, 0x01, // Stream 1 4065 0x00, 0x00, 0x00, 0x01, // Stream 1
3982 0x00, 0x06, 0x63, 0x6f, 4066 0x00, 0x06, 0x63, 0x6f,
3983 0x6f, 0x6b, 0x69, 0x65, 4067 0x6f, 0x6b, 0x69, 0x65,
3984 0x07, 0x66, 0x6f, 0x6f, 4068 0x07, 0x66, 0x6f, 0x6f,
3985 0x3d, 0x62, 0x61, 0x72, 4069 0x3d, 0x62, 0x61, 0x72,
3986 }; 4070 };
3987 4071
3988 SpdyFramer framer(spdy_version_); 4072 SpdyFramer framer(spdy_version_);
3989 TestSpdyVisitor visitor(spdy_version_); 4073 TestSpdyVisitor visitor(spdy_version_);
3990 framer.set_visitor(&visitor); 4074 framer.set_visitor(&visitor);
3991 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4075 visitor.SimulateInFramer(kInput, sizeof(kInput));
3992 4076
3993 EXPECT_EQ(1, visitor.error_count_); 4077 EXPECT_EQ(1, visitor.error_count_);
3994 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, 4078 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME,
3995 visitor.framer_.error_code()) 4079 visitor.framer_.error_code())
3996 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4080 << SpdyFramer::ErrorCodeToString(framer.error_code());
3997 EXPECT_EQ(0, visitor.continuation_count_); 4081 EXPECT_EQ(0, visitor.continuation_count_);
3998 EXPECT_EQ(0u, visitor.header_buffer_length_); 4082 EXPECT_EQ(0u, visitor.header_buffer_length_);
3999 } 4083 }
4000 4084
4001 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) { 4085 TEST_P(SpdyFramerTest, ExpectContinuationReceiveData) {
4002 if (spdy_version_ <= SPDY3) { 4086 if (spdy_version_ <= SPDY3) {
4003 return; 4087 return;
4004 } 4088 }
4005 4089
4006 const unsigned char kInput[] = { 4090 const unsigned char kInput[] = {
4007 0x00, 0x10, 0x01, 0x00, // HEADERS 4091 0x00, 0x00, 0x10, 0x01, 0x00, // HEADERS
4008 0x00, 0x00, 0x00, 0x01, // Stream 1 4092 0x00, 0x00, 0x00, 0x01, // Stream 1
4009 0x00, 0x06, 0x63, 0x6f, 4093 0x00, 0x06, 0x63, 0x6f,
4010 0x6f, 0x6b, 0x69, 0x65, 4094 0x6f, 0x6b, 0x69, 0x65,
4011 0x07, 0x66, 0x6f, 0x6f, 4095 0x07, 0x66, 0x6f, 0x6f,
4012 0x3d, 0x62, 0x61, 0x72, 4096 0x3d, 0x62, 0x61, 0x72,
4013 4097
4014 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1 4098 0x00, 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1
4015 0x00, 0x00, 0x00, 0x04, 4099 0x00, 0x00, 0x00, 0x04,
4016 0xde, 0xad, 0xbe, 0xef, 4100 0xde, 0xad, 0xbe, 0xef,
4017 }; 4101 };
4018 4102
4019 SpdyFramer framer(spdy_version_); 4103 SpdyFramer framer(spdy_version_);
4020 TestSpdyVisitor visitor(spdy_version_); 4104 TestSpdyVisitor visitor(spdy_version_);
4021 framer.set_visitor(&visitor); 4105 framer.set_visitor(&visitor);
4022 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4106 visitor.SimulateInFramer(kInput, sizeof(kInput));
4023 4107
4024 EXPECT_EQ(1, visitor.error_count_); 4108 EXPECT_EQ(1, visitor.error_count_);
4025 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, 4109 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME,
4026 visitor.framer_.error_code()) 4110 visitor.framer_.error_code())
4027 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4111 << SpdyFramer::ErrorCodeToString(framer.error_code());
4028 EXPECT_EQ(1, visitor.headers_frame_count_); 4112 EXPECT_EQ(1, visitor.headers_frame_count_);
4029 EXPECT_EQ(0, visitor.continuation_count_); 4113 EXPECT_EQ(0, visitor.continuation_count_);
4030 EXPECT_EQ(0u, visitor.header_buffer_length_); 4114 EXPECT_EQ(0u, visitor.header_buffer_length_);
4031 EXPECT_EQ(0, visitor.data_frame_count_); 4115 EXPECT_EQ(0, visitor.data_frame_count_);
4032 } 4116 }
4033 4117
4034 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) { 4118 TEST_P(SpdyFramerTest, ExpectContinuationReceiveControlFrame) {
4035 if (spdy_version_ <= SPDY3) { 4119 if (spdy_version_ <= SPDY3) {
4036 return; 4120 return;
4037 } 4121 }
4038 4122
4039 const unsigned char kInput[] = { 4123 const unsigned char kInput[] = {
4040 0x00, 0x10, 0x01, 0x00, // HEADERS 4124 0x00, 0x00, 0x18, 0x01, 0x00, // HEADERS
4041 0x00, 0x00, 0x00, 0x01, // Stream 1 4125 0x00, 0x00, 0x00, 0x01, // Stream 1
4042 0x00, 0x06, 0x63, 0x6f, 4126 0x00, 0x06, 0x63, 0x6f,
4043 0x6f, 0x6b, 0x69, 0x65, 4127 0x6f, 0x6b, 0x69, 0x65,
4044 0x07, 0x66, 0x6f, 0x6f, 4128 0x07, 0x66, 0x6f, 0x6f,
4045 0x3d, 0x62, 0x61, 0x72, 4129 0x3d, 0x62, 0x61, 0x72,
4046 4130
4047 0x00, 0x14, 0x08, 0x00, // HEADERS 4131 0x00, 0x00, 0x1c, 0x08, 0x00, // HEADERS
4048 0x00, 0x00, 0x00, 0x01, // Stream 1 4132 0x00, 0x00, 0x00, 0x01, // Stream 1
4049 0x00, 0x06, 0x63, 0x6f, // (Note this is a valid continued encoding). 4133 0x00, 0x06, 0x63, 0x6f, // (Note this is a valid continued encoding).
4050 0x6f, 0x6b, 0x69, 0x65, 4134 0x6f, 0x6b, 0x69, 0x65,
4051 0x08, 0x62, 0x61, 0x7a, 4135 0x08, 0x62, 0x61, 0x7a,
4052 0x3d, 0x62, 0x69, 0x6e, 4136 0x3d, 0x62, 0x69, 0x6e,
4053 0x67, 0x00, 0x06, 0x63, 4137 0x67, 0x00, 0x06, 0x63,
4054 }; 4138 };
4055 4139
4056 SpdyFramer framer(spdy_version_); 4140 SpdyFramer framer(spdy_version_);
4057 TestSpdyVisitor visitor(spdy_version_); 4141 TestSpdyVisitor visitor(spdy_version_);
4058 framer.set_visitor(&visitor); 4142 framer.set_visitor(&visitor);
4059 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4143 visitor.SimulateInFramer(kInput, sizeof(kInput));
4060 4144
4061 EXPECT_EQ(1, visitor.error_count_); 4145 EXPECT_EQ(1, visitor.error_count_);
4062 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, 4146 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME,
4063 visitor.framer_.error_code()) 4147 visitor.framer_.error_code())
4064 << SpdyFramer::ErrorCodeToString(framer.error_code()); 4148 << SpdyFramer::ErrorCodeToString(framer.error_code());
4065 EXPECT_EQ(1, visitor.headers_frame_count_); 4149 EXPECT_EQ(1, visitor.headers_frame_count_);
4066 EXPECT_EQ(0, visitor.continuation_count_); 4150 EXPECT_EQ(0, visitor.continuation_count_);
4067 EXPECT_EQ(0u, visitor.header_buffer_length_); 4151 EXPECT_EQ(0u, visitor.header_buffer_length_);
4068 EXPECT_EQ(0, visitor.data_frame_count_); 4152 EXPECT_EQ(0, visitor.data_frame_count_);
4069 } 4153 }
4070 4154
4071 TEST_P(SpdyFramerTest, EndSegmentOnDataFrame) { 4155 TEST_P(SpdyFramerTest, EndSegmentOnDataFrame) {
4072 if (spdy_version_ <= SPDY3) { 4156 if (spdy_version_ <= SPDY3) {
4073 return; 4157 return;
4074 } 4158 }
4075 const unsigned char kInput[] = { 4159 const unsigned char kInput[] = {
4076 0x00, 0x0c, 0x00, 0x02, // DATA: END_SEGMENT 4160 0x00, 0x00, 0x0c, 0x00, 0x02, // DATA: END_SEGMENT
4077 0x00, 0x00, 0x00, 0x01, // Stream 1 4161 0x00, 0x00, 0x00, 0x01, // Stream 1
4078 0xde, 0xad, 0xbe, 0xef, 4162 0xde, 0xad, 0xbe, 0xef,
4079 0xde, 0xad, 0xbe, 0xef, 4163 0xde, 0xad, 0xbe, 0xef,
4080 0xde, 0xad, 0xbe, 0xef, 4164 0xde, 0xad, 0xbe, 0xef,
4081 }; 4165 };
4082 4166
4083 TestSpdyVisitor visitor(spdy_version_); 4167 TestSpdyVisitor visitor(spdy_version_);
4084 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4168 visitor.SimulateInFramer(kInput, sizeof(kInput));
4085 4169
4086 // TODO(jgraettinger): Verify END_SEGMENT when support is added. 4170 // TODO(jgraettinger): Verify END_SEGMENT when support is added.
4087 EXPECT_EQ(0, visitor.error_count_); 4171 EXPECT_EQ(0, visitor.error_count_);
4088 EXPECT_EQ(12, visitor.data_bytes_); 4172 EXPECT_EQ(12, visitor.data_bytes_);
4089 EXPECT_EQ(0, visitor.fin_frame_count_); 4173 EXPECT_EQ(0, visitor.fin_frame_count_);
4090 EXPECT_EQ(0, visitor.fin_flag_count_); 4174 EXPECT_EQ(0, visitor.fin_flag_count_);
4091 } 4175 }
4092 4176
4093 TEST_P(SpdyFramerTest, EndSegmentOnHeadersFrame) { 4177 TEST_P(SpdyFramerTest, EndSegmentOnHeadersFrame) {
4094 if (spdy_version_ <= SPDY3) { 4178 if (spdy_version_ <= SPDY3) {
4095 return; 4179 return;
4096 } 4180 }
4097 const unsigned char kInput[] = { 4181 const unsigned char kInput[] = {
4098 0x00, 0x10, 0x01, 0x06, // HEADERS: END_SEGMENT | END_HEADERS 4182 0x00, 0x00, 0x10, 0x01, 0x06, // HEADERS: END_SEGMENT | END_HEADERS
4099 0x00, 0x00, 0x00, 0x01, // Stream 1 4183 0x00, 0x00, 0x00, 0x01, // Stream 1
4100 0x00, 0x06, 0x63, 0x6f, 4184 0x00, 0x06, 0x63, 0x6f,
4101 0x6f, 0x6b, 0x69, 0x65, 4185 0x6f, 0x6b, 0x69, 0x65,
4102 0x07, 0x66, 0x6f, 0x6f, 4186 0x07, 0x66, 0x6f, 0x6f,
4103 0x3d, 0x62, 0x61, 0x72, 4187 0x3d, 0x62, 0x61, 0x72,
4104 }; 4188 };
4105 4189
4106 TestSpdyVisitor visitor(spdy_version_); 4190 TestSpdyVisitor visitor(spdy_version_);
4107 visitor.SimulateInFramer(kInput, sizeof(kInput)); 4191 visitor.SimulateInFramer(kInput, sizeof(kInput));
4108 4192
4109 // TODO(jgraettinger): Verify END_SEGMENT when support is added. 4193 // TODO(jgraettinger): Verify END_SEGMENT when support is added.
4110 EXPECT_EQ(0, visitor.error_count_); 4194 EXPECT_EQ(0, visitor.error_count_);
4111 EXPECT_EQ(1, visitor.headers_frame_count_); 4195 EXPECT_EQ(1, visitor.headers_frame_count_);
4112 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); 4196 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_);
4113 4197
4114 EXPECT_THAT(visitor.headers_, ElementsAre( 4198 EXPECT_THAT(visitor.headers_, ElementsAre(
4115 Pair("cookie", "foo=bar"))); 4199 Pair("cookie", "foo=bar")));
4116 } 4200 }
4117 4201
4118 TEST_P(SpdyFramerTest, ReadGarbage) { 4202 TEST_P(SpdyFramerTest, ReadGarbage) {
4119 SpdyFramer framer(spdy_version_); 4203 SpdyFramer framer(spdy_version_);
4120 unsigned char garbage_frame[256]; 4204 unsigned char garbage_frame[256];
4121 memset(garbage_frame, ~0, sizeof(garbage_frame)); 4205 memset(garbage_frame, ~0, sizeof(garbage_frame));
4122 TestSpdyVisitor visitor(spdy_version_); 4206 TestSpdyVisitor visitor(spdy_version_);
4123 visitor.use_compression_ = false; 4207 visitor.use_compression_ = false;
4124 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); 4208 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame));
4125 EXPECT_EQ(1, visitor.error_count_); 4209 EXPECT_EQ(1, visitor.error_count_);
4126 } 4210 }
4127 4211
4212 TEST_P(SpdyFramerTest, ReadUnknownExtensionFrame) {
4213 if (spdy_version_ <= SPDY3) {
4214 return;
4215 }
4216 SpdyFramer framer(spdy_version_);
4217
4218 // The unrecognized frame type should still have a valid length.
4219 const unsigned char unknown_frame[] = {
4220 0x00, 0x00, 0x08, 0xff, 0xff,
4221 0xff, 0xff, 0xff, 0xff,
4222 0xff, 0xff, 0xff, 0xff,
4223 0xff, 0xff, 0xff, 0xff,
4224 };
4225 TestSpdyVisitor visitor(spdy_version_);
4226
4227 // Simulate the case where the stream id validation checks out.
4228 visitor.on_unknown_frame_result_ = true;
4229 visitor.use_compression_ = false;
4230 visitor.SimulateInFramer(unknown_frame, arraysize(unknown_frame));
4231 EXPECT_EQ(0, visitor.error_count_);
4232
4233 // Follow it up with a valid control frame to make sure we handle
4234 // subsequent frames correctly.
4235 SpdySettingsIR settings_ir;
4236 settings_ir.AddSetting(SpdyConstants::ParseSettingId(spdy_version_, 1),
4237 false, // persist
4238 false, // persisted
4239 10);
4240 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSettings(settings_ir));
4241 visitor.SimulateInFramer(
4242 reinterpret_cast<unsigned char*>(control_frame->data()),
4243 control_frame->size());
4244 EXPECT_EQ(0, visitor.error_count_);
4245 EXPECT_EQ(1u, static_cast<unsigned>(visitor.setting_count_));
4246 EXPECT_EQ(1u, static_cast<unsigned>(visitor.settings_ack_sent_));
4247 }
4248
4128 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) { 4249 TEST_P(SpdyFramerTest, ReadGarbageWithValidLength) {
4129 if (!IsSpdy4()) { 4250 if (!IsSpdy4()) {
4130 return; 4251 return;
4131 } 4252 }
4132 SpdyFramer framer(spdy_version_); 4253 SpdyFramer framer(spdy_version_);
4133 const unsigned char kFrameData[] = { 4254 const unsigned char kFrameData[] = {
4134 0x00, 0x10, 0xff, 0xff, 4255 0x00, 0x00, 0x08, 0xff, 0xff,
4135 0xff, 0xff, 0xff, 0xff, 4256 0xff, 0xff, 0xff, 0xff,
4136 0xff, 0xff, 0xff, 0xff, 4257 0xff, 0xff, 0xff, 0xff,
4137 0xff, 0xff, 0xff, 0xff, 4258 0xff, 0xff, 0xff, 0xff,
4138 }; 4259 };
4139 TestSpdyVisitor visitor(spdy_version_); 4260 TestSpdyVisitor visitor(spdy_version_);
4140 visitor.use_compression_ = false; 4261 visitor.use_compression_ = false;
4141 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); 4262 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData));
4142 EXPECT_EQ(1, visitor.error_count_); 4263 EXPECT_EQ(1, visitor.error_count_);
4143 } 4264 }
4144 4265
(...skipping 27 matching lines...) Expand all
4172 0xff, 0xff, 4293 0xff, 0xff,
4173 }; 4294 };
4174 4295
4175 TestSpdyVisitor visitor(spdy_version_); 4296 TestSpdyVisitor visitor(spdy_version_);
4176 visitor.SimulateInFramer(kInput, arraysize(kInput)); 4297 visitor.SimulateInFramer(kInput, arraysize(kInput));
4177 EXPECT_EQ(1, visitor.error_count_); 4298 EXPECT_EQ(1, visitor.error_count_);
4178 } 4299 }
4179 4300
4180 TEST_P(SpdyFramerTest, SizesTest) { 4301 TEST_P(SpdyFramerTest, SizesTest) {
4181 SpdyFramer framer(spdy_version_); 4302 SpdyFramer framer(spdy_version_);
4182 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize());
4183 if (IsSpdy4() || IsSpdy5()) { 4303 if (IsSpdy4() || IsSpdy5()) {
4184 EXPECT_EQ(8u, framer.GetSynReplyMinimumSize()); 4304 EXPECT_EQ(9u, framer.GetDataFrameMinimumSize());
4185 EXPECT_EQ(12u, framer.GetRstStreamMinimumSize()); 4305 EXPECT_EQ(9u, framer.GetControlFrameHeaderSize());
4186 EXPECT_EQ(8u, framer.GetSettingsMinimumSize()); 4306 EXPECT_EQ(14u, framer.GetSynStreamMinimumSize());
4187 EXPECT_EQ(16u, framer.GetPingSize()); 4307 EXPECT_EQ(9u, framer.GetSynReplyMinimumSize());
4188 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); 4308 EXPECT_EQ(13u, framer.GetRstStreamMinimumSize());
4189 EXPECT_EQ(8u, framer.GetHeadersMinimumSize()); 4309 EXPECT_EQ(9u, framer.GetSettingsMinimumSize());
4190 EXPECT_EQ(12u, framer.GetWindowUpdateSize()); 4310 EXPECT_EQ(17u, framer.GetPingSize());
4191 EXPECT_EQ(8u, framer.GetBlockedSize()); 4311 EXPECT_EQ(17u, framer.GetGoAwayMinimumSize());
4192 EXPECT_EQ(12u, framer.GetPushPromiseMinimumSize()); 4312 EXPECT_EQ(9u, framer.GetHeadersMinimumSize());
4193 EXPECT_EQ(17u, framer.GetAltSvcMinimumSize()); 4313 EXPECT_EQ(13u, framer.GetWindowUpdateSize());
4194 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); 4314 EXPECT_EQ(9u, framer.GetBlockedSize());
4195 EXPECT_EQ(16383u, framer.GetFrameMaximumSize()); 4315 EXPECT_EQ(13u, framer.GetPushPromiseMinimumSize());
4196 EXPECT_EQ(16375u, framer.GetDataFrameMaximumPayload()); 4316 EXPECT_EQ(18u, framer.GetAltSvcMinimumSize());
4317 EXPECT_EQ(9u, framer.GetFrameMinimumSize());
4318 EXPECT_EQ(16393u, framer.GetFrameMaximumSize());
4319 EXPECT_EQ(16384u, framer.GetDataFrameMaximumPayload());
4197 } else { 4320 } else {
4321 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize());
4198 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); 4322 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize());
4199 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); 4323 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize());
4200 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); 4324 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize());
4201 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); 4325 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize());
4202 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); 4326 EXPECT_EQ(12u, framer.GetSettingsMinimumSize());
4203 EXPECT_EQ(12u, framer.GetPingSize()); 4327 EXPECT_EQ(12u, framer.GetPingSize());
4204 EXPECT_EQ(IsSpdy2() ? 12u : 16u, framer.GetGoAwayMinimumSize()); 4328 EXPECT_EQ(IsSpdy2() ? 12u : 16u, framer.GetGoAwayMinimumSize());
4205 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetHeadersMinimumSize()); 4329 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetHeadersMinimumSize());
4206 EXPECT_EQ(16u, framer.GetWindowUpdateSize()); 4330 EXPECT_EQ(16u, framer.GetWindowUpdateSize());
4207 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); 4331 EXPECT_EQ(8u, framer.GetFrameMinimumSize());
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
4993 TEST_P(SpdyFramerTest, RstStreamStatusBounds) { 5117 TEST_P(SpdyFramerTest, RstStreamStatusBounds) {
4994 const unsigned char kRstStreamStatusTooLow = 0x00; 5118 const unsigned char kRstStreamStatusTooLow = 0x00;
4995 const unsigned char kRstStreamStatusTooHigh = 0xff; 5119 const unsigned char kRstStreamStatusTooHigh = 0xff;
4996 const unsigned char kV3RstStreamInvalid[] = { 5120 const unsigned char kV3RstStreamInvalid[] = {
4997 0x80, spdy_version_ch_, 0x00, 0x03, 5121 0x80, spdy_version_ch_, 0x00, 0x03,
4998 0x00, 0x00, 0x00, 0x08, 5122 0x00, 0x00, 0x00, 0x08,
4999 0x00, 0x00, 0x00, 0x01, 5123 0x00, 0x00, 0x00, 0x01,
5000 0x00, 0x00, 0x00, kRstStreamStatusTooLow 5124 0x00, 0x00, 0x00, kRstStreamStatusTooLow
5001 }; 5125 };
5002 const unsigned char kV4RstStreamInvalid[] = { 5126 const unsigned char kV4RstStreamInvalid[] = {
5003 0x00, 0x04, 0x03, 0x00, 5127 0x00, 0x00, 0x04, 0x03,
5004 0x00, 0x00, 0x00, 0x01, 5128 0x00, 0x00, 0x00, 0x00,
5005 0x00, 0x00, 0x00, kRstStreamStatusTooLow 5129 0x01, 0x00, 0x00, 0x00,
5130 kRstStreamStatusTooLow
5006 }; 5131 };
5007 5132
5008 const unsigned char kV3RstStreamNumStatusCodes[] = { 5133 const unsigned char kV3RstStreamNumStatusCodes[] = {
5009 0x80, spdy_version_ch_, 0x00, 0x03, 5134 0x80, spdy_version_ch_, 0x00, 0x03,
5010 0x00, 0x00, 0x00, 0x08, 5135 0x00, 0x00, 0x00, 0x08,
5011 0x00, 0x00, 0x00, 0x01, 5136 0x00, 0x00, 0x00, 0x01,
5012 0x00, 0x00, 0x00, kRstStreamStatusTooHigh 5137 0x00, 0x00, 0x00, kRstStreamStatusTooHigh
5013 }; 5138 };
5014 const unsigned char kV4RstStreamNumStatusCodes[] = { 5139 const unsigned char kV4RstStreamNumStatusCodes[] = {
5015 0x00, 0x04, 0x03, 0x00, 5140 0x00, 0x00, 0x04, 0x03,
5016 0x00, 0x00, 0x00, 0x01, 5141 0x00, 0x00, 0x00, 0x00,
5017 0x00, 0x00, 0x00, kRstStreamStatusTooHigh 5142 0x01, 0x00, 0x00, 0x00,
5143 kRstStreamStatusTooHigh
5018 }; 5144 };
5019 5145
5020 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5146 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5021 SpdyFramer framer(spdy_version_); 5147 SpdyFramer framer(spdy_version_);
5022 framer.set_visitor(&visitor); 5148 framer.set_visitor(&visitor);
5023 5149
5024 if (IsSpdy4()) { 5150 if (IsSpdy4()) {
5025 EXPECT_CALL(visitor, OnError(_)); 5151 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR));
5026 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid), 5152 framer.ProcessInput(reinterpret_cast<const char*>(kV4RstStreamInvalid),
5027 arraysize(kV4RstStreamInvalid)); 5153 arraysize(kV4RstStreamInvalid));
5028 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state());
5029 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code())
5030 << SpdyFramer::ErrorCodeToString(framer.error_code());
5031 } else { 5154 } else {
5032 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); 5155 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID));
5033 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid), 5156 framer.ProcessInput(reinterpret_cast<const char*>(kV3RstStreamInvalid),
5034 arraysize(kV3RstStreamInvalid)); 5157 arraysize(kV3RstStreamInvalid));
5035 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 5158 }
5036 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5159 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
5160 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5037 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5161 << SpdyFramer::ErrorCodeToString(framer.error_code());
5038 }
5039 5162
5040 5163
5041 framer.Reset(); 5164 framer.Reset();
5042 5165
5043 if (IsSpdy4()) { 5166 if (IsSpdy4()) {
5044 EXPECT_CALL(visitor, OnError(_)); 5167 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INTERNAL_ERROR));
5045 framer.ProcessInput( 5168 framer.ProcessInput(
5046 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes), 5169 reinterpret_cast<const char*>(kV4RstStreamNumStatusCodes),
5047 arraysize(kV4RstStreamNumStatusCodes)); 5170 arraysize(kV4RstStreamNumStatusCodes));
5048 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state());
5049 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, framer.error_code())
5050 << SpdyFramer::ErrorCodeToString(framer.error_code());
5051 } else { 5171 } else {
5052 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID)); 5172 EXPECT_CALL(visitor, OnRstStream(1, RST_STREAM_INVALID));
5053 framer.ProcessInput( 5173 framer.ProcessInput(
5054 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes), 5174 reinterpret_cast<const char*>(kV3RstStreamNumStatusCodes),
5055 arraysize(kV3RstStreamNumStatusCodes)); 5175 arraysize(kV3RstStreamNumStatusCodes));
5056 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 5176 }
5057 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5177 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
5178 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5058 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5179 << SpdyFramer::ErrorCodeToString(framer.error_code());
5180 }
5181
5182 // Test handling of GOAWAY frames with out-of-bounds status code.
5183 TEST_P(SpdyFramerTest, GoAwayStatusBounds) {
5184 if (spdy_version_ <= SPDY2) {
5185 return;
5059 } 5186 }
5187 SpdyFramer framer(spdy_version_);
5188
5189 const unsigned char kV3FrameData[] = {
5190 0x80, spdy_version_ch_, 0x00, 0x07,
5191 0x00, 0x00, 0x00, 0x08,
5192 0x00, 0x00, 0x00, 0x01, // Stream Id
5193 0xff, 0xff, 0xff, 0xff, // Status
5194 };
5195 const unsigned char kV4FrameData[] = {
5196 0x00, 0x00, 0x0a, 0x07,
5197 0x00, 0x00, 0x00, 0x00,
5198 0x00, 0x00, 0x00, 0x00, // Stream id
5199 0x01, 0xff, 0xff, 0xff, // Status
5200 0xff, 0x47, 0x41, // Opaque Description
5201 };
5202 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5203 framer.set_visitor(&visitor);
5204
5205 if (IsSpdy3()) {
5206 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_OK));
5207 framer.ProcessInput(reinterpret_cast<const char*>(kV3FrameData),
5208 arraysize(kV3FrameData));
5209 } else {
5210 EXPECT_CALL(visitor, OnGoAway(1, GOAWAY_INTERNAL_ERROR));
5211 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData),
5212 arraysize(kV4FrameData));
5213 }
5214 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
5215 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5216 << SpdyFramer::ErrorCodeToString(framer.error_code());
5060 } 5217 }
5061 5218
5062 // Tests handling of a GOAWAY frame with out-of-bounds stream ID. 5219 // Tests handling of a GOAWAY frame with out-of-bounds stream ID.
5063 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) { 5220 TEST_P(SpdyFramerTest, GoAwayStreamIdBounds) {
5064 const unsigned char kV2FrameData[] = { 5221 const unsigned char kV2FrameData[] = {
5065 0x80, spdy_version_ch_, 0x00, 0x07, 5222 0x80, spdy_version_ch_, 0x00, 0x07,
5066 0x00, 0x00, 0x00, 0x04, 5223 0x00, 0x00, 0x00, 0x04,
5067 0xff, 0xff, 0xff, 0xff, 5224 0xff, 0xff, 0xff, 0xff,
5068 }; 5225 };
5069 const unsigned char kV3FrameData[] = { 5226 const unsigned char kV3FrameData[] = {
5070 0x80, spdy_version_ch_, 0x00, 0x07, 5227 0x80, spdy_version_ch_, 0x00, 0x07,
5071 0x00, 0x00, 0x00, 0x08, 5228 0x00, 0x00, 0x00, 0x08,
5072 0xff, 0xff, 0xff, 0xff, 5229 0xff, 0xff, 0xff, 0xff,
5073 0x00, 0x00, 0x00, 0x00, 5230 0x00, 0x00, 0x00, 0x00,
5074 }; 5231 };
5075 const unsigned char kV4FrameData[] = { 5232 const unsigned char kV4FrameData[] = {
5076 0x00, 0x08, 0x07, 0x00, 5233 0x00, 0x00, 0x08, 0x07,
5077 0x00, 0x00, 0x00, 0x00, 5234 0x00, 0x00, 0x00, 0x00,
5078 0xff, 0xff, 0xff, 0xff, 5235 0x00, 0xff, 0xff, 0xff,
5079 0x00, 0x00, 0x00, 0x00, 5236 0xff, 0x00, 0x00, 0x00,
5237 0x00,
5080 }; 5238 };
5081 5239
5082 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; 5240 testing::StrictMock<test::MockSpdyFramerVisitor> visitor;
5083 SpdyFramer framer(spdy_version_); 5241 SpdyFramer framer(spdy_version_);
5084 framer.set_visitor(&visitor); 5242 framer.set_visitor(&visitor);
5085 5243
5086 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK)); 5244 EXPECT_CALL(visitor, OnGoAway(0x7fffffff, GOAWAY_OK));
5087 if (IsSpdy2()) { 5245 if (IsSpdy2()) {
5088 framer.ProcessInput(reinterpret_cast<const char*>(kV2FrameData), 5246 framer.ProcessInput(reinterpret_cast<const char*>(kV2FrameData),
5089 arraysize(kV2FrameData)); 5247 arraysize(kV2FrameData));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5195 } 5353 }
5196 5354
5197 const unsigned char kType = static_cast<unsigned char>( 5355 const unsigned char kType = static_cast<unsigned char>(
5198 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); 5356 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC));
5199 { 5357 {
5200 TestSpdyVisitor visitor(spdy_version_); 5358 TestSpdyVisitor visitor(spdy_version_);
5201 SpdyFramer framer(spdy_version_); 5359 SpdyFramer framer(spdy_version_);
5202 framer.set_visitor(&visitor); 5360 framer.set_visitor(&visitor);
5203 5361
5204 const unsigned char kFrameDataLargePIDLen[] = { 5362 const unsigned char kFrameDataLargePIDLen[] = {
5205 0x00, 0x17, kType, 0x00, 5363 0x00, 0x00, 0x17, kType, 0x00,
5206 0x00, 0x00, 0x00, 0x03, 5364 0x00, 0x00, 0x00, 0x03,
5207 0x00, 0x00, 0x00, 0x05, 5365 0x00, 0x00, 0x00, 0x05,
5208 0x01, 0xbb, 0x00, 0x05, // Port = 443 5366 0x01, 0xbb, 0x00, 0x05, // Port = 443
5209 'p', 'i', 'd', '1', // Protocol-ID 5367 'p', 'i', 'd', '1', // Protocol-ID
5210 0x04, 'h', 'o', 's', 5368 0x04, 'h', 'o', 's',
5211 't', 'o', 'r', 'i', 5369 't', 'o', 'r', 'i',
5212 'g', 'i', 'n', 5370 'g', 'i', 'n',
5213 }; 5371 };
5214 5372
5215 visitor.SimulateInFramer(kFrameDataLargePIDLen, 5373 visitor.SimulateInFramer(kFrameDataLargePIDLen,
5216 sizeof(kFrameDataLargePIDLen)); 5374 sizeof(kFrameDataLargePIDLen));
5217 EXPECT_EQ(1, visitor.error_count_); 5375 EXPECT_EQ(1, visitor.error_count_);
5218 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 5376 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5219 visitor.framer_.error_code()); 5377 visitor.framer_.error_code());
5220 } 5378 }
5221 5379
5222 { 5380 {
5223 TestSpdyVisitor visitor(spdy_version_); 5381 TestSpdyVisitor visitor(spdy_version_);
5224 SpdyFramer framer(spdy_version_); 5382 SpdyFramer framer(spdy_version_);
5225 framer.set_visitor(&visitor); 5383 framer.set_visitor(&visitor);
5226 const unsigned char kFrameDataPIDLenLargerThanFrame[] = { 5384 const unsigned char kFrameDataPIDLenLargerThanFrame[] = {
5227 0x00, 0x17, kType, 0x00, 5385 0x00, 0x00, 0x17, kType, 0x00,
5228 0x00, 0x00, 0x00, 0x03, 5386 0x00, 0x00, 0x00, 0x03,
5229 0x00, 0x00, 0x00, 0x05, 5387 0x00, 0x00, 0x00, 0x05,
5230 0x01, 0xbb, 0x00, 0x99, // Port = 443 5388 0x01, 0xbb, 0x00, 0x99, // Port = 443
5231 'p', 'i', 'd', '1', // Protocol-ID 5389 'p', 'i', 'd', '1', // Protocol-ID
5232 0x04, 'h', 'o', 's', 5390 0x04, 'h', 'o', 's',
5233 't', 'o', 'r', 'i', 5391 't', 'o', 'r', 'i',
5234 'g', 'i', 'n', 5392 'g', 'i', 'n',
5235 }; 5393 };
5236 5394
5237 visitor.SimulateInFramer(kFrameDataPIDLenLargerThanFrame, 5395 visitor.SimulateInFramer(kFrameDataPIDLenLargerThanFrame,
5238 sizeof(kFrameDataPIDLenLargerThanFrame)); 5396 sizeof(kFrameDataPIDLenLargerThanFrame));
5239 EXPECT_EQ(1, visitor.error_count_); 5397 EXPECT_EQ(1, visitor.error_count_);
5240 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 5398 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5241 visitor.framer_.error_code()); 5399 visitor.framer_.error_code());
5242 } 5400 }
5243 5401
5244 { 5402 {
5245 TestSpdyVisitor visitor(spdy_version_); 5403 TestSpdyVisitor visitor(spdy_version_);
5246 SpdyFramer framer(spdy_version_); 5404 SpdyFramer framer(spdy_version_);
5247 framer.set_visitor(&visitor); 5405 framer.set_visitor(&visitor);
5248 5406
5249 const unsigned char kFrameDataLargeHostLen[] = { 5407 const unsigned char kFrameDataLargeHostLen[] = {
5250 0x00, 0x17, kType, 0x00, 5408 0x00, 0x00, 0x17, kType, 0x00,
5251 0x00, 0x00, 0x00, 0x03, 5409 0x00, 0x00, 0x00, 0x03,
5252 0x00, 0x00, 0x00, 0x05, 5410 0x00, 0x00, 0x00, 0x05,
5253 0x01, 0xbb, 0x00, 0x04, // Port = 443 5411 0x01, 0xbb, 0x00, 0x04, // Port = 443
5254 'p', 'i', 'd', '1', // Protocol-ID 5412 'p', 'i', 'd', '1', // Protocol-ID
5255 0x0f, 'h', 'o', 's', 5413 0x0f, 'h', 'o', 's',
5256 't', 'o', 'r', 'i', 5414 't', 'o', 'r', 'i',
5257 'g', 'i', 'n', 5415 'g', 'i', 'n',
5258 }; 5416 };
5259 5417
5260 visitor.SimulateInFramer(kFrameDataLargeHostLen, 5418 visitor.SimulateInFramer(kFrameDataLargeHostLen,
5261 sizeof(kFrameDataLargeHostLen)); 5419 sizeof(kFrameDataLargeHostLen));
5262 EXPECT_EQ(1, visitor.error_count_); 5420 EXPECT_EQ(1, visitor.error_count_);
5263 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, 5421 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5264 visitor.framer_.error_code()); 5422 visitor.framer_.error_code());
5265 } 5423 }
5266 5424
5267 { 5425 {
5268 TestSpdyVisitor visitor(spdy_version_); 5426 TestSpdyVisitor visitor(spdy_version_);
5269 SpdyFramer framer(spdy_version_); 5427 SpdyFramer framer(spdy_version_);
5270 framer.set_visitor(&visitor); 5428 framer.set_visitor(&visitor);
5271 const unsigned char kFrameDataSmallPIDLen[] = { 5429 const unsigned char kFrameDataSmallPIDLen[] = {
5272 0x00, 0x17, kType, 0x00, 5430 0x00, 0x00, 0x17, kType, 0x00,
5273 0x00, 0x00, 0x00, 0x03, 5431 0x00, 0x00, 0x00, 0x03,
5274 0x00, 0x00, 0x00, 0x05, 5432 0x00, 0x00, 0x00, 0x05,
5275 0x01, 0xbb, 0x00, 0x01, // Port = 443 5433 0x01, 0xbb, 0x00, 0x01, // Port = 443
5276 'p', 'i', 'd', '1', // Protocol-ID 5434 'p', 'i', 'd', '1', // Protocol-ID
5277 0x04, 'h', 'o', 's', 5435 0x04, 'h', 'o', 's',
5278 't', 'o', 'r', 'i', 5436 't', 'o', 'r', 'i',
5279 'g', 'i', 'n', 5437 'g', 'i', 'n',
5280 }; 5438 };
5281 5439
5282 visitor.SimulateInFramer(kFrameDataSmallPIDLen, 5440 visitor.SimulateInFramer(kFrameDataSmallPIDLen,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 EXPECT_CALL(visitor, OnPriority(3, 1, 255, false)); 5494 EXPECT_CALL(visitor, OnPriority(3, 1, 255, false));
5337 framer.ProcessInput(frame->data(), frame->size()); 5495 framer.ProcessInput(frame->data(), frame->size());
5338 5496
5339 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); 5497 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state());
5340 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) 5498 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code())
5341 << SpdyFramer::ErrorCodeToString(framer.error_code()); 5499 << SpdyFramer::ErrorCodeToString(framer.error_code());
5342 // TODO(mlavan): once we actually maintain a priority tree, 5500 // TODO(mlavan): once we actually maintain a priority tree,
5343 // check that state is adjusted correctly. 5501 // check that state is adjusted correctly.
5344 } 5502 }
5345 5503
5346 // Tests handling of PRIORITY frame with incorrect size.
5347 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) {
5348 if (spdy_version_ <= SPDY3) {
5349 return;
5350 }
5351
5352 // PRIORITY frame of size 4, which isn't correct.
5353 const unsigned char kFrameData[] = {
5354 0x00, 0x04, 0x02, 0x00,
5355 0x00, 0x00, 0x00, 0x03,
5356 0x00, 0x00, 0x00, 0x01,
5357 };
5358
5359 TestSpdyVisitor visitor(spdy_version_);
5360 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData));
5361
5362 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state());
5363 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5364 visitor.framer_.error_code())
5365 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code());
5366 }
5367
5368 TEST_P(SpdyFramerTest, PriorityWeightMapping) { 5504 TEST_P(SpdyFramerTest, PriorityWeightMapping) {
5369 if (spdy_version_ <= SPDY3) { 5505 if (spdy_version_ <= SPDY3) {
5370 return; 5506 return;
5371 } 5507 }
5372 SpdyFramer framer(spdy_version_); 5508 SpdyFramer framer(spdy_version_);
5373 5509
5374 EXPECT_EQ(255u, framer.MapPriorityToWeight(0)); 5510 EXPECT_EQ(255u, framer.MapPriorityToWeight(0));
5375 EXPECT_EQ(219u, framer.MapPriorityToWeight(1)); 5511 EXPECT_EQ(219u, framer.MapPriorityToWeight(1));
5376 EXPECT_EQ(182u, framer.MapPriorityToWeight(2)); 5512 EXPECT_EQ(182u, framer.MapPriorityToWeight(2));
5377 EXPECT_EQ(146u, framer.MapPriorityToWeight(3)); 5513 EXPECT_EQ(146u, framer.MapPriorityToWeight(3));
(...skipping 12 matching lines...) Expand all
5390 EXPECT_EQ(3u, framer.MapWeightToPriority(110)); 5526 EXPECT_EQ(3u, framer.MapWeightToPriority(110));
5391 EXPECT_EQ(4u, framer.MapWeightToPriority(109)); 5527 EXPECT_EQ(4u, framer.MapWeightToPriority(109));
5392 EXPECT_EQ(4u, framer.MapWeightToPriority(74)); 5528 EXPECT_EQ(4u, framer.MapWeightToPriority(74));
5393 EXPECT_EQ(5u, framer.MapWeightToPriority(73)); 5529 EXPECT_EQ(5u, framer.MapWeightToPriority(73));
5394 EXPECT_EQ(5u, framer.MapWeightToPriority(37)); 5530 EXPECT_EQ(5u, framer.MapWeightToPriority(37));
5395 EXPECT_EQ(6u, framer.MapWeightToPriority(36)); 5531 EXPECT_EQ(6u, framer.MapWeightToPriority(36));
5396 EXPECT_EQ(6u, framer.MapWeightToPriority(1)); 5532 EXPECT_EQ(6u, framer.MapWeightToPriority(1));
5397 EXPECT_EQ(7u, framer.MapWeightToPriority(0)); 5533 EXPECT_EQ(7u, framer.MapWeightToPriority(0));
5398 } 5534 }
5399 5535
5536 // Tests handling of PRIORITY frame with incorrect size.
5537 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) {
5538 if (spdy_version_ <= SPDY3) {
5539 return;
5540 }
5541
5542 // PRIORITY frame of size 4, which isn't correct.
5543 const unsigned char kFrameData[] = {
5544 0x00, 0x00, 0x04, 0x02, 0x00,
5545 0x00, 0x00, 0x00, 0x03,
5546 0x00, 0x00, 0x00, 0x01,
5547 };
5548
5549 TestSpdyVisitor visitor(spdy_version_);
5550 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData));
5551
5552 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state());
5553 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME,
5554 visitor.framer_.error_code())
5555 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code());
5556 }
5557
5400 } // namespace net 5558 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_framer.cc ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698