OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <algorithm> | 5 #include <algorithm> |
6 #include <iostream> | 6 #include <iostream> |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 error_count_(0), | 232 error_count_(0), |
233 syn_frame_count_(0), | 233 syn_frame_count_(0), |
234 syn_reply_frame_count_(0), | 234 syn_reply_frame_count_(0), |
235 headers_frame_count_(0), | 235 headers_frame_count_(0), |
236 push_promise_frame_count_(0), | 236 push_promise_frame_count_(0), |
237 goaway_count_(0), | 237 goaway_count_(0), |
238 setting_count_(0), | 238 setting_count_(0), |
239 settings_ack_sent_(0), | 239 settings_ack_sent_(0), |
240 settings_ack_received_(0), | 240 settings_ack_received_(0), |
241 continuation_count_(0), | 241 continuation_count_(0), |
| 242 altsvc_count_(0), |
| 243 test_altsvc_ir_(0), |
242 last_window_update_stream_(0), | 244 last_window_update_stream_(0), |
243 last_window_update_delta_(0), | 245 last_window_update_delta_(0), |
244 last_push_promise_stream_(0), | 246 last_push_promise_stream_(0), |
245 last_push_promise_promised_stream_(0), | 247 last_push_promise_promised_stream_(0), |
246 data_bytes_(0), | 248 data_bytes_(0), |
247 fin_frame_count_(0), | 249 fin_frame_count_(0), |
248 fin_opaque_data_(), | 250 fin_opaque_data_(), |
249 fin_flag_count_(0), | 251 fin_flag_count_(0), |
250 zero_length_data_frame_count_(0), | 252 zero_length_data_frame_count_(0), |
251 control_frame_header_data_count_(0), | 253 control_frame_header_data_count_(0), |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 ++push_promise_frame_count_; | 399 ++push_promise_frame_count_; |
398 InitHeaderStreaming(PUSH_PROMISE, stream_id); | 400 InitHeaderStreaming(PUSH_PROMISE, stream_id); |
399 last_push_promise_stream_ = stream_id; | 401 last_push_promise_stream_ = stream_id; |
400 last_push_promise_promised_stream_ = promised_stream_id; | 402 last_push_promise_promised_stream_ = promised_stream_id; |
401 } | 403 } |
402 | 404 |
403 virtual void OnContinuation(SpdyStreamId stream_id, bool end) OVERRIDE { | 405 virtual void OnContinuation(SpdyStreamId stream_id, bool end) OVERRIDE { |
404 ++continuation_count_; | 406 ++continuation_count_; |
405 } | 407 } |
406 | 408 |
| 409 virtual void OnAltSvc(SpdyStreamId stream_id, |
| 410 uint32 max_age, |
| 411 uint16 port, |
| 412 StringPiece protocol_id, |
| 413 StringPiece host, |
| 414 StringPiece origin) OVERRIDE { |
| 415 test_altsvc_ir_.set_stream_id(stream_id); |
| 416 test_altsvc_ir_.set_max_age(max_age); |
| 417 test_altsvc_ir_.set_port(port); |
| 418 test_altsvc_ir_.set_protocol_id(protocol_id.as_string()); |
| 419 test_altsvc_ir_.set_host(host.as_string()); |
| 420 if (origin.length() > 0) { |
| 421 test_altsvc_ir_.set_origin(origin.as_string()); |
| 422 } |
| 423 ++altsvc_count_; |
| 424 } |
| 425 |
407 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, | 426 virtual void OnSendCompressedFrame(SpdyStreamId stream_id, |
408 SpdyFrameType type, | 427 SpdyFrameType type, |
409 size_t payload_len, | 428 size_t payload_len, |
410 size_t frame_len) OVERRIDE { | 429 size_t frame_len) OVERRIDE { |
411 last_payload_len_ = payload_len; | 430 last_payload_len_ = payload_len; |
412 last_frame_len_ = frame_len; | 431 last_frame_len_ = frame_len; |
413 } | 432 } |
414 | 433 |
415 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, | 434 virtual void OnReceiveCompressedFrame(SpdyStreamId stream_id, |
416 SpdyFrameType type, | 435 SpdyFrameType type, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 int error_count_; | 486 int error_count_; |
468 int syn_frame_count_; | 487 int syn_frame_count_; |
469 int syn_reply_frame_count_; | 488 int syn_reply_frame_count_; |
470 int headers_frame_count_; | 489 int headers_frame_count_; |
471 int push_promise_frame_count_; | 490 int push_promise_frame_count_; |
472 int goaway_count_; | 491 int goaway_count_; |
473 int setting_count_; | 492 int setting_count_; |
474 int settings_ack_sent_; | 493 int settings_ack_sent_; |
475 int settings_ack_received_; | 494 int settings_ack_received_; |
476 int continuation_count_; | 495 int continuation_count_; |
| 496 int altsvc_count_; |
| 497 SpdyAltSvcIR test_altsvc_ir_; |
477 SpdyStreamId last_window_update_stream_; | 498 SpdyStreamId last_window_update_stream_; |
478 uint32 last_window_update_delta_; | 499 uint32 last_window_update_delta_; |
479 SpdyStreamId last_push_promise_stream_; | 500 SpdyStreamId last_push_promise_stream_; |
480 SpdyStreamId last_push_promise_promised_stream_; | 501 SpdyStreamId last_push_promise_promised_stream_; |
481 int data_bytes_; | 502 int data_bytes_; |
482 int fin_frame_count_; // The count of RST_STREAM type frames received. | 503 int fin_frame_count_; // The count of RST_STREAM type frames received. |
483 std::string fin_opaque_data_; | 504 std::string fin_opaque_data_; |
484 int fin_flag_count_; // The count of frames with the FIN flag set. | 505 int fin_flag_count_; // The count of frames with the FIN flag set. |
485 int zero_length_data_frame_count_; // The count of zero-length data frames. | 506 int zero_length_data_frame_count_; // The count of zero-length data frames. |
486 int control_frame_header_data_count_; // The count of chunks received. | 507 int control_frame_header_data_count_; // The count of chunks received. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 << "'."; | 621 << "'."; |
601 return false; | 622 return false; |
602 } | 623 } |
603 } | 624 } |
604 return true; | 625 return true; |
605 } | 626 } |
606 | 627 |
607 bool IsSpdy2() { return spdy_version_ == SPDY2; } | 628 bool IsSpdy2() { return spdy_version_ == SPDY2; } |
608 bool IsSpdy3() { return spdy_version_ == SPDY3; } | 629 bool IsSpdy3() { return spdy_version_ == SPDY3; } |
609 bool IsSpdy4() { return spdy_version_ == SPDY4; } | 630 bool IsSpdy4() { return spdy_version_ == SPDY4; } |
| 631 bool IsSpdy5() { return spdy_version_ == SPDY5; } |
610 | 632 |
611 // Version of SPDY protocol to be used. | 633 // Version of SPDY protocol to be used. |
612 SpdyMajorVersion spdy_version_; | 634 SpdyMajorVersion spdy_version_; |
613 unsigned char spdy_version_ch_; | 635 unsigned char spdy_version_ch_; |
614 }; | 636 }; |
615 | 637 |
616 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. | 638 // All tests are run with 3 different SPDY versions: SPDY/2, SPDY/3, SPDY/4. |
617 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, | 639 INSTANTIATE_TEST_CASE_P(SpdyFramerTests, |
618 SpdyFramerTest, | 640 SpdyFramerTest, |
619 ::testing::Values(SPDY2, SPDY3, SPDY4)); | 641 ::testing::Values(SPDY2, SPDY3, SPDY4)); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 | 1088 |
1067 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 | 1089 0x80, spdy_version_ch_, 0x00, 0x03, // RST_STREAM on Stream #3 |
1068 0x00, 0x00, 0x00, 0x08, | 1090 0x00, 0x00, 0x00, 0x08, |
1069 0x00, 0x00, 0x00, 0x03, | 1091 0x00, 0x00, 0x00, 0x03, |
1070 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL | 1092 0x00, 0x00, 0x00, 0x05, // RST_STREAM_CANCEL |
1071 }; | 1093 }; |
1072 | 1094 |
1073 // SYN_STREAM doesn't exist in SPDY4, so instead we send | 1095 // SYN_STREAM doesn't exist in SPDY4, so instead we send |
1074 // HEADERS frames with PRIORITY and END_HEADERS set. | 1096 // HEADERS frames with PRIORITY and END_HEADERS set. |
1075 const unsigned char kV4Input[] = { | 1097 const unsigned char kV4Input[] = { |
1076 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1098 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS |
1077 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1099 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1078 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1100 0x00, 0x00, 0x00, 0x00, // Priority 0 |
1079 0x82, // :method: GET | 1101 0x82, // :method: GET |
1080 | 1102 |
1081 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS | 1103 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS |
1082 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1104 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1083 0x8c, // :status: 200 | 1105 0x8c, // :status: 200 |
1084 | 1106 |
1085 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 | 1107 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 |
1086 0x00, 0x00, 0x00, 0x01, | 1108 0x00, 0x00, 0x00, 0x01, |
1087 0xde, 0xad, 0xbe, 0xef, | 1109 0xde, 0xad, 0xbe, 0xef, |
1088 0xde, 0xad, 0xbe, 0xef, | 1110 0xde, 0xad, 0xbe, 0xef, |
1089 0xde, 0xad, 0xbe, 0xef, | 1111 0xde, 0xad, 0xbe, 0xef, |
1090 | 1112 |
1091 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1113 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS |
1092 0x00, 0x00, 0x00, 0x03, // Stream 3 | 1114 0x00, 0x00, 0x00, 0x03, // Stream 3 |
1093 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1115 0x00, 0x00, 0x00, 0x00, // Priority 0 |
1094 0x82, // :method: GET | 1116 0x82, // :method: GET |
1095 | 1117 |
1096 0x00, 0x08, 0x00, 0x00, // DATA on Stream #3 | 1118 0x00, 0x08, 0x00, 0x00, // DATA on Stream #3 |
1097 0x00, 0x00, 0x00, 0x03, | 1119 0x00, 0x00, 0x00, 0x03, |
1098 0xde, 0xad, 0xbe, 0xef, | 1120 0xde, 0xad, 0xbe, 0xef, |
1099 0xde, 0xad, 0xbe, 0xef, | 1121 0xde, 0xad, 0xbe, 0xef, |
1100 | 1122 |
1101 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 | 1123 0x00, 0x04, 0x00, 0x00, // DATA on Stream #1 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 0xde, 0xad, 0xbe, 0xef, | 1223 0xde, 0xad, 0xbe, 0xef, |
1202 | 1224 |
1203 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF | 1225 0x00, 0x00, 0x00, 0x01, // DATA on Stream #1, with EOF |
1204 0x01, 0x00, 0x00, 0x04, | 1226 0x01, 0x00, 0x00, 0x04, |
1205 0xde, 0xad, 0xbe, 0xef, | 1227 0xde, 0xad, 0xbe, 0xef, |
1206 }; | 1228 }; |
1207 | 1229 |
1208 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send | 1230 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send |
1209 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. | 1231 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. |
1210 const unsigned char kV4Input[] = { | 1232 const unsigned char kV4Input[] = { |
1211 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1233 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS |
1212 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1234 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1213 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1235 0x00, 0x00, 0x00, 0x00, // Priority 0 |
1214 0x82, // :method: GET | 1236 0x82, // :method: GET |
1215 | 1237 |
1216 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS | 1238 0x00, 0x01, 0x01, 0x04, // HEADERS: END_HEADERS |
1217 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1239 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1218 0x8c, // :status: 200 | 1240 0x8c, // :status: 200 |
1219 | 1241 |
1220 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 | 1242 0x00, 0x0c, 0x00, 0x00, // DATA on Stream #1 |
1221 0x00, 0x00, 0x00, 0x01, | 1243 0x00, 0x00, 0x00, 0x01, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 0x00, 0x00, 0x00, 0x01, | 1309 0x00, 0x00, 0x00, 0x01, |
1288 0x00, 0x00, 0x00, 0x01, | 1310 0x00, 0x00, 0x00, 0x01, |
1289 0x00, 0x00, 0x00, 0x02, | 1311 0x00, 0x00, 0x00, 0x02, |
1290 'a', 'a', 0x00, 0x00, | 1312 'a', 'a', 0x00, 0x00, |
1291 0x00, 0x02, 'b', 'b', | 1313 0x00, 0x02, 'b', 'b', |
1292 }; | 1314 }; |
1293 | 1315 |
1294 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send | 1316 // SYN_STREAM and SYN_REPLY don't exist in SPDY4, so instead we send |
1295 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. | 1317 // HEADERS frames with PRIORITY(SYN_STREAM only) and END_HEADERS set. |
1296 const unsigned char kV4Input[] = { | 1318 const unsigned char kV4Input[] = { |
1297 0x00, 0x05, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1319 0x00, 0x05, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS |
1298 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1320 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1299 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1321 0x00, 0x00, 0x00, 0x00, // Priority 0 |
1300 0x82, // :method: GET | 1322 0x82, // :method: GET |
1301 | 1323 |
1302 0x00, 0x01, 0x01, 0x05, // HEADERS: FIN | END_HEADERS | 1324 0x00, 0x01, 0x01, 0x05, // HEADERS: FIN | END_HEADERS |
1303 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1325 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1304 0x8c, // :status: 200 | 1326 0x8c, // :status: 200 |
1305 }; | 1327 }; |
1306 | 1328 |
1307 TestSpdyVisitor visitor(spdy_version_); | 1329 TestSpdyVisitor visitor(spdy_version_); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 { | 1580 { |
1559 const char kDescription[] = "'hello' data frame with more padding, no FIN"; | 1581 const char kDescription[] = "'hello' data frame with more padding, no FIN"; |
1560 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1582 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1561 0x00, 0x00, 0x00, 0x01, | 1583 0x00, 0x00, 0x00, 0x01, |
1562 0x00, 0x00, 0x00, 0x05, | 1584 0x00, 0x00, 0x00, 0x05, |
1563 'h', 'e', 'l', 'l', | 1585 'h', 'e', 'l', 'l', |
1564 'o' | 1586 'o' |
1565 }; | 1587 }; |
1566 | 1588 |
1567 const unsigned char kV4FrameData[] = { | 1589 const unsigned char kV4FrameData[] = { |
1568 0x01, 0x0b, 0x00, 0x30, // Length = 267. PAD_HIGH and PAD_LOW set. | 1590 0x01, 0x0b, 0x00, 0x18, // Length = 267. PAD_HIGH and PAD_LOW set. |
1569 0x00, 0x00, 0x00, 0x01, | 1591 0x00, 0x00, 0x00, 0x01, |
1570 0x01, 0x04, // Pad Low and Pad High fields. | 1592 0x01, 0x04, // Pad Low and Pad High fields. |
1571 'h', 'e', 'l', 'l', // Data | 1593 'h', 'e', 'l', 'l', // Data |
1572 'o', | 1594 'o', |
1573 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). | 1595 // Padding of 260 zeros (so both PAD_HIGH and PAD_LOW fields are used). |
1574 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1596 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1575 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1597 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1576 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1598 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1577 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1599 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
1578 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', | 1600 '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1619 { | 1641 { |
1620 const char kDescription[] = "'hello' data frame with few padding, no FIN"; | 1642 const char kDescription[] = "'hello' data frame with few padding, no FIN"; |
1621 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1643 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1622 0x00, 0x00, 0x00, 0x01, | 1644 0x00, 0x00, 0x00, 0x01, |
1623 0x00, 0x00, 0x00, 0x05, | 1645 0x00, 0x00, 0x00, 0x05, |
1624 'h', 'e', 'l', 'l', | 1646 'h', 'e', 'l', 'l', |
1625 'o' | 1647 'o' |
1626 }; | 1648 }; |
1627 | 1649 |
1628 const unsigned char kV4FrameData[] = { | 1650 const unsigned char kV4FrameData[] = { |
1629 0x00, 0x0d, 0x00, 0x10, // Length = 13. PAD_LOW set. | 1651 0x00, 0x0d, 0x00, 0x08, // Length = 13. PAD_LOW set. |
1630 0x00, 0x00, 0x00, 0x01, | 1652 0x00, 0x00, 0x00, 0x01, |
1631 0x07, // Pad Low field. | 1653 0x07, // Pad Low field. |
1632 'h', 'e', 'l', 'l', // Data | 1654 'h', 'e', 'l', 'l', // Data |
1633 'o', | 1655 'o', |
1634 '0', '0', '0', '0', // Padding | 1656 '0', '0', '0', '0', // Padding |
1635 '0', '0', '0' | 1657 '0', '0', '0' |
1636 }; | 1658 }; |
1637 const char bytes[] = "hello"; | 1659 const char bytes[] = "hello"; |
1638 | 1660 |
1639 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1661 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
(...skipping 13 matching lines...) Expand all Loading... |
1653 const char kDescription[] = | 1675 const char kDescription[] = |
1654 "'hello' data frame with 1 byte padding, no FIN"; | 1676 "'hello' data frame with 1 byte padding, no FIN"; |
1655 const unsigned char kV3FrameData[] = { // Also applies for V2. | 1677 const unsigned char kV3FrameData[] = { // Also applies for V2. |
1656 0x00, 0x00, 0x00, 0x01, | 1678 0x00, 0x00, 0x00, 0x01, |
1657 0x00, 0x00, 0x00, 0x05, | 1679 0x00, 0x00, 0x00, 0x05, |
1658 'h', 'e', 'l', 'l', | 1680 'h', 'e', 'l', 'l', |
1659 'o' | 1681 'o' |
1660 }; | 1682 }; |
1661 | 1683 |
1662 const unsigned char kV4FrameData[] = { | 1684 const unsigned char kV4FrameData[] = { |
1663 0x00, 0x06, 0x00, 0x10, // Length = 6. PAD_LOW set. | 1685 0x00, 0x06, 0x00, 0x08, // Length = 6. PAD_LOW set. |
1664 0x00, 0x00, 0x00, 0x01, | 1686 0x00, 0x00, 0x00, 0x01, |
1665 0x00, // Pad Low field. | 1687 0x00, // Pad Low field. |
1666 'h', 'e', 'l', 'l', // Data | 1688 'h', 'e', 'l', 'l', // Data |
1667 'o', | 1689 'o', |
1668 }; | 1690 }; |
1669 const char bytes[] = "hello"; | 1691 const char bytes[] = "hello"; |
1670 | 1692 |
1671 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); | 1693 SpdyDataIR data_ir(1, StringPiece(bytes, strlen(bytes))); |
1672 // The pad low field itself is used for the 1-byte padding and no padding | 1694 // The pad low field itself is used for the 1-byte padding and no padding |
1673 // payload is needed. | 1695 // payload is needed. |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1847 0x00, 0x02, 0x00, 0x00, | 1869 0x00, 0x02, 0x00, 0x00, |
1848 0x00, 0x03, 'b', 'a', | 1870 0x00, 0x03, 'b', 'a', |
1849 'r', 0x00, 0x00, 0x00, | 1871 'r', 0x00, 0x00, 0x00, |
1850 0x03, 'f', 'o', 'o', | 1872 0x03, 'f', 'o', 'o', |
1851 0x00, 0x00, 0x00, 0x03, | 1873 0x00, 0x00, 0x00, 0x03, |
1852 'f', 'o', 'o', 0x00, | 1874 'f', 'o', 'o', 0x00, |
1853 0x00, 0x00, 0x03, 'b', | 1875 0x00, 0x00, 0x03, 'b', |
1854 'a', 'r' | 1876 'a', 'r' |
1855 }; | 1877 }; |
1856 const unsigned char kV4FrameData[] = { | 1878 const unsigned char kV4FrameData[] = { |
1857 0x00, 0x16, 0x01, 0x0c, // HEADERS: PRIORITY | END_HEADERS | 1879 0x00, 0x16, 0x01, 0x24, // HEADERS: PRIORITY | END_HEADERS |
1858 0x00, 0x00, 0x00, 0x01, // Stream 1 | 1880 0x00, 0x00, 0x00, 0x01, // Stream 1 |
1859 0x00, 0x00, 0x00, 0x07, // Priority 7 | 1881 0x00, 0x00, 0x00, 0x07, // Priority 7 |
1860 0x00, 0x03, 0x62, 0x61, // @.ba | 1882 0x00, 0x03, 0x62, 0x61, // @.ba |
1861 0x72, 0x03, 0x66, 0x6f, // r.fo | 1883 0x72, 0x03, 0x66, 0x6f, // r.fo |
1862 0x6f, 0x00, 0x03, 0x66, // o@.f | 1884 0x6f, 0x00, 0x03, 0x66, // o@.f |
1863 0x6f, 0x6f, 0x03, 0x62, // oo.b | 1885 0x6f, 0x6f, 0x03, 0x62, // oo.b |
1864 0x61, 0x72, // ar | 1886 0x61, 0x72, // ar |
1865 }; | 1887 }; |
1866 SpdySynStreamIR syn_stream(1); | 1888 SpdySynStreamIR syn_stream(1); |
1867 syn_stream.set_priority(framer.GetLowestPriority()); | 1889 syn_stream.set_priority(framer.GetLowestPriority()); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 0x00, 0x00, 0x00, 0x00, | 1924 0x00, 0x00, 0x00, 0x00, |
1903 0x00, 0x02, 0x00, 0x00, | 1925 0x00, 0x02, 0x00, 0x00, |
1904 0x00, 0x00, 0x00, 0x00, | 1926 0x00, 0x00, 0x00, 0x00, |
1905 0x00, 0x03, 'f', 'o', | 1927 0x00, 0x03, 'f', 'o', |
1906 'o', 0x00, 0x00, 0x00, | 1928 'o', 0x00, 0x00, 0x00, |
1907 0x03, 'f', 'o', 'o', | 1929 0x03, 'f', 'o', 'o', |
1908 0x00, 0x00, 0x00, 0x03, | 1930 0x00, 0x00, 0x00, 0x03, |
1909 'b', 'a', 'r' | 1931 'b', 'a', 'r' |
1910 }; | 1932 }; |
1911 const unsigned char kV4FrameData[] = { | 1933 const unsigned char kV4FrameData[] = { |
1912 0x00, 0x13, 0x01, 0x0d, // HEADERS: PRIORITY | FIN | END_HEADERS | 1934 0x00, 0x13, 0x01, 0x25, // HEADERS: PRIORITY | FIN | END_HEADERS |
1913 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 1935 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
1914 0x00, 0x00, 0x00, 0x00, // Priority 0 | 1936 0x00, 0x00, 0x00, 0x00, // Priority 0 |
1915 0x00, 0x00, 0x03, 0x66, // @..f | 1937 0x00, 0x00, 0x03, 0x66, // @..f |
1916 0x6f, 0x6f, 0x00, 0x03, // oo@. | 1938 0x6f, 0x6f, 0x00, 0x03, // oo@. |
1917 0x66, 0x6f, 0x6f, 0x03, // foo. | 1939 0x66, 0x6f, 0x6f, 0x03, // foo. |
1918 0x62, 0x61, 0x72, // bar | 1940 0x62, 0x61, 0x72, // bar |
1919 }; | 1941 }; |
1920 SpdySynStreamIR syn_stream(0x7fffffff); | 1942 SpdySynStreamIR syn_stream(0x7fffffff); |
1921 syn_stream.set_associated_to_stream_id(0x7fffffff); | 1943 syn_stream.set_associated_to_stream_id(0x7fffffff); |
1922 syn_stream.set_priority(framer.GetHighestPriority()); | 1944 syn_stream.set_priority(framer.GetHighestPriority()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1959 kPri, 0x00, 0x00, 0x00, | 1981 kPri, 0x00, 0x00, 0x00, |
1960 0x00, 0x02, 0x00, 0x00, | 1982 0x00, 0x02, 0x00, 0x00, |
1961 0x00, 0x03, 'b', 'a', | 1983 0x00, 0x03, 'b', 'a', |
1962 'r', 0x00, 0x00, 0x00, | 1984 'r', 0x00, 0x00, 0x00, |
1963 0x03, 'f', 'o', 'o', | 1985 0x03, 'f', 'o', 'o', |
1964 0x00, 0x00, 0x00, 0x03, | 1986 0x00, 0x00, 0x00, 0x03, |
1965 'f', 'o', 'o', 0x00, | 1987 'f', 'o', 'o', 0x00, |
1966 0x00, 0x00, 0x00 | 1988 0x00, 0x00, 0x00 |
1967 }; | 1989 }; |
1968 const unsigned char kV4FrameData[] = { | 1990 const unsigned char kV4FrameData[] = { |
1969 0x00, 0x13, 0x01, 0x0d, // HEADERS: PRIORITY | FIN | END_HEADERS | 1991 0x00, 0x13, 0x01, 0x25, // HEADERS: PRIORITY | FIN | END_HEADERS |
1970 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff | 1992 0x7f, 0xff, 0xff, 0xff, // Stream 0x7fffffff |
1971 0x00, 0x00, 0x00, 0x01, // Priority 1 | 1993 0x00, 0x00, 0x00, 0x01, // Priority 1 |
1972 0x00, 0x03, 0x62, 0x61, // @.ba | 1994 0x00, 0x03, 0x62, 0x61, // @.ba |
1973 0x72, 0x03, 0x66, 0x6f, // r.fo | 1995 0x72, 0x03, 0x66, 0x6f, // r.fo |
1974 0x6f, 0x00, 0x03, 0x66, // o@.f | 1996 0x6f, 0x00, 0x03, 0x66, // o@.f |
1975 0x6f, 0x6f, 0x00, // oo. | 1997 0x6f, 0x6f, 0x00, // oo. |
1976 }; | 1998 }; |
1977 SpdySynStreamIR syn_stream(0x7fffffff); | 1999 SpdySynStreamIR syn_stream(0x7fffffff); |
1978 syn_stream.set_associated_to_stream_id(0x7fffffff); | 2000 syn_stream.set_associated_to_stream_id(0x7fffffff); |
1979 syn_stream.set_priority(1); | 2001 syn_stream.set_priority(1); |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2876 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); | 2898 SpdyWindowUpdateIR(1, 0x7FFFFFFF))); |
2877 if (IsSpdy4()) { | 2899 if (IsSpdy4()) { |
2878 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); | 2900 CompareFrame(kDescription, *frame, kV4FrameData, arraysize(kV4FrameData)); |
2879 } else { | 2901 } else { |
2880 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); | 2902 CompareFrame(kDescription, *frame, kV3FrameData, arraysize(kV3FrameData)); |
2881 } | 2903 } |
2882 } | 2904 } |
2883 } | 2905 } |
2884 | 2906 |
2885 TEST_P(SpdyFramerTest, SerializeBlocked) { | 2907 TEST_P(SpdyFramerTest, SerializeBlocked) { |
2886 if (spdy_version_ < SPDY4) { | 2908 if (spdy_version_ <= SPDY3) { |
2887 return; | 2909 return; |
2888 } | 2910 } |
2889 | 2911 |
2890 SpdyFramer framer(spdy_version_); | 2912 SpdyFramer framer(spdy_version_); |
2891 | 2913 |
2892 const char kDescription[] = "BLOCKED frame"; | 2914 const char kDescription[] = "BLOCKED frame"; |
| 2915 const char kType = static_cast<unsigned char>( |
| 2916 SpdyConstants::SerializeFrameType(spdy_version_, BLOCKED)); |
2893 const unsigned char kFrameData[] = { | 2917 const unsigned char kFrameData[] = { |
2894 0x00, 0x00, 0x0a, 0x00, | 2918 0x00, 0x00, kType, 0x00, |
2895 0x00, 0x00, 0x00, 0x00, | 2919 0x00, 0x00, 0x00, 0x00, |
2896 }; | 2920 }; |
2897 SpdyBlockedIR blocked_ir(0); | 2921 SpdyBlockedIR blocked_ir(0); |
2898 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 2922 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
2899 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2923 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
2900 } | 2924 } |
2901 | 2925 |
2902 TEST_P(SpdyFramerTest, CreateBlocked) { | 2926 TEST_P(SpdyFramerTest, CreateBlocked) { |
2903 if (spdy_version_ < SPDY4) { | 2927 if (spdy_version_ <= SPDY3) { |
2904 return; | 2928 return; |
2905 } | 2929 } |
2906 | 2930 |
2907 SpdyFramer framer(spdy_version_); | 2931 SpdyFramer framer(spdy_version_); |
2908 | 2932 |
2909 const char kDescription[] = "BLOCKED frame"; | 2933 const char kDescription[] = "BLOCKED frame"; |
2910 const SpdyStreamId kStreamId = 3; | 2934 const SpdyStreamId kStreamId = 3; |
2911 | 2935 |
2912 scoped_ptr<SpdySerializedFrame> frame_serialized( | 2936 scoped_ptr<SpdySerializedFrame> frame_serialized( |
2913 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); | 2937 framer.SerializeBlocked(SpdyBlockedIR(kStreamId))); |
2914 SpdyBlockedIR blocked_ir(kStreamId); | 2938 SpdyBlockedIR blocked_ir(kStreamId); |
2915 scoped_ptr<SpdySerializedFrame> frame_created( | 2939 scoped_ptr<SpdySerializedFrame> frame_created( |
2916 framer.SerializeFrame(blocked_ir)); | 2940 framer.SerializeFrame(blocked_ir)); |
2917 | 2941 |
2918 CompareFrames(kDescription, *frame_serialized, *frame_created); | 2942 CompareFrames(kDescription, *frame_serialized, *frame_created); |
2919 } | 2943 } |
2920 | 2944 |
2921 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { | 2945 TEST_P(SpdyFramerTest, CreatePushPromiseUncompressed) { |
2922 if (spdy_version_ < SPDY4) { | 2946 if (spdy_version_ <= SPDY3) { |
2923 return; | 2947 return; |
2924 } | 2948 } |
2925 | 2949 |
2926 SpdyFramer framer(spdy_version_); | 2950 SpdyFramer framer(spdy_version_); |
2927 framer.set_enable_compression(false); | 2951 framer.set_enable_compression(false); |
2928 const char kDescription[] = "PUSH_PROMISE frame"; | 2952 const char kDescription[] = "PUSH_PROMISE frame"; |
2929 | 2953 |
2930 const unsigned char kFrameData[] = { | 2954 const unsigned char kFrameData[] = { |
2931 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS | 2955 0x00, 0x16, 0x05, 0x04, // PUSH_PROMISE: END_HEADERS |
2932 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 2956 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
2933 0x00, 0x00, 0x00, 0x39, // Promised stream 57 | 2957 0x00, 0x00, 0x00, 0x39, // Promised stream 57 |
2934 0x00, 0x03, 0x62, 0x61, // @.ba | 2958 0x00, 0x03, 0x62, 0x61, // @.ba |
2935 0x72, 0x03, 0x66, 0x6f, // r.fo | 2959 0x72, 0x03, 0x66, 0x6f, // r.fo |
2936 0x6f, 0x00, 0x03, 0x66, // o@.f | 2960 0x6f, 0x00, 0x03, 0x66, // o@.f |
2937 0x6f, 0x6f, 0x03, 0x62, // oo.b | 2961 0x6f, 0x6f, 0x03, 0x62, // oo.b |
2938 0x61, 0x72, // ar | 2962 0x61, 0x72, // ar |
2939 }; | 2963 }; |
2940 | 2964 |
2941 SpdyPushPromiseIR push_promise(42, 57); | 2965 SpdyPushPromiseIR push_promise(42, 57); |
2942 push_promise.SetHeader("bar", "foo"); | 2966 push_promise.SetHeader("bar", "foo"); |
2943 push_promise.SetHeader("foo", "bar"); | 2967 push_promise.SetHeader("foo", "bar"); |
2944 scoped_ptr<SpdySerializedFrame> frame( | 2968 scoped_ptr<SpdySerializedFrame> frame( |
2945 framer.SerializePushPromise(push_promise)); | 2969 framer.SerializePushPromise(push_promise)); |
2946 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); | 2970 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
2947 } | 2971 } |
2948 | 2972 |
| 2973 TEST_P(SpdyFramerTest, CreateAltSvc) { |
| 2974 if (spdy_version_ <= SPDY3) { |
| 2975 return; |
| 2976 } |
| 2977 |
| 2978 SpdyFramer framer(spdy_version_); |
| 2979 |
| 2980 const char kDescription[] = "ALTSVC frame"; |
| 2981 const char kType = static_cast<unsigned char>( |
| 2982 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
| 2983 const unsigned char kFrameData[] = { |
| 2984 0x00, 0x17, kType, 0x00, |
| 2985 0x00, 0x00, 0x00, 0x03, |
| 2986 0x00, 0x00, 0x00, 0x05, |
| 2987 0x01, 0xbb, 0x00, 0x04, // Port = 443 |
| 2988 'p', 'i', 'd', '1', // Protocol-ID |
| 2989 0x04, 'h', 'o', 's', |
| 2990 't', 'o', 'r', 'i', |
| 2991 'g', 'i', 'n', |
| 2992 }; |
| 2993 SpdyAltSvcIR altsvc_ir(3); |
| 2994 altsvc_ir.set_max_age(5); |
| 2995 altsvc_ir.set_port(443); |
| 2996 altsvc_ir.set_protocol_id("pid1"); |
| 2997 altsvc_ir.set_host("host"); |
| 2998 altsvc_ir.set_origin("origin"); |
| 2999 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
| 3000 CompareFrame(kDescription, *frame, kFrameData, arraysize(kFrameData)); |
| 3001 } |
| 3002 |
2949 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { | 3003 TEST_P(SpdyFramerTest, ReadCompressedSynStreamHeaderBlock) { |
2950 SpdyFramer framer(spdy_version_); | 3004 SpdyFramer framer(spdy_version_); |
2951 SpdySynStreamIR syn_stream(1); | 3005 SpdySynStreamIR syn_stream(1); |
2952 syn_stream.set_priority(1); | 3006 syn_stream.set_priority(1); |
2953 syn_stream.SetHeader("aa", "vv"); | 3007 syn_stream.SetHeader("aa", "vv"); |
2954 syn_stream.SetHeader("bb", "ww"); | 3008 syn_stream.SetHeader("bb", "ww"); |
2955 SpdyHeaderBlock headers = syn_stream.name_value_block(); | 3009 SpdyHeaderBlock headers = syn_stream.name_value_block(); |
2956 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3010 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
2957 EXPECT_TRUE(control_frame.get() != NULL); | 3011 EXPECT_TRUE(control_frame.get() != NULL); |
2958 TestSpdyVisitor visitor(spdy_version_); | 3012 TestSpdyVisitor visitor(spdy_version_); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3047 framer.set_enable_compression(false); | 3101 framer.set_enable_compression(false); |
3048 SpdySynStreamIR syn_stream(1); | 3102 SpdySynStreamIR syn_stream(1); |
3049 syn_stream.set_priority(1); | 3103 syn_stream.set_priority(1); |
3050 syn_stream.SetHeader("aa", ""); | 3104 syn_stream.SetHeader("aa", ""); |
3051 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3105 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
3052 const size_t kBigValueSize = | 3106 const size_t kBigValueSize = |
3053 framer.GetControlFrameBufferMaxSize() - control_frame->size(); | 3107 framer.GetControlFrameBufferMaxSize() - control_frame->size(); |
3054 | 3108 |
3055 // Create a frame at exactly that size. | 3109 // Create a frame at exactly that size. |
3056 string big_value(kBigValueSize, 'x'); | 3110 string big_value(kBigValueSize, 'x'); |
3057 syn_stream.SetHeader("aa", big_value.c_str()); | 3111 syn_stream.SetHeader("aa", big_value); |
3058 control_frame.reset(framer.SerializeSynStream(syn_stream)); | 3112 control_frame.reset(framer.SerializeSynStream(syn_stream)); |
3059 EXPECT_TRUE(control_frame.get() != NULL); | 3113 EXPECT_TRUE(control_frame.get() != NULL); |
3060 EXPECT_EQ(framer.GetControlFrameBufferMaxSize(), control_frame->size()); | 3114 EXPECT_EQ(framer.GetControlFrameBufferMaxSize(), control_frame->size()); |
3061 | 3115 |
3062 TestSpdyVisitor visitor(spdy_version_); | 3116 TestSpdyVisitor visitor(spdy_version_); |
3063 visitor.SimulateInFramer( | 3117 visitor.SimulateInFramer( |
3064 reinterpret_cast<unsigned char*>(control_frame->data()), | 3118 reinterpret_cast<unsigned char*>(control_frame->data()), |
3065 control_frame->size()); | 3119 control_frame->size()); |
3066 EXPECT_TRUE(visitor.header_buffer_valid_); | 3120 EXPECT_TRUE(visitor.header_buffer_valid_); |
3067 EXPECT_EQ(0, visitor.error_count_); | 3121 EXPECT_EQ(0, visitor.error_count_); |
(...skipping 14 matching lines...) Expand all Loading... |
3082 framer.set_enable_compression(false); | 3136 framer.set_enable_compression(false); |
3083 SpdySynStreamIR syn_stream(1); | 3137 SpdySynStreamIR syn_stream(1); |
3084 syn_stream.SetHeader("aa", ""); | 3138 syn_stream.SetHeader("aa", ""); |
3085 syn_stream.set_priority(1); | 3139 syn_stream.set_priority(1); |
3086 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3140 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
3087 const size_t kBigValueSize = | 3141 const size_t kBigValueSize = |
3088 framer.GetControlFrameBufferMaxSize() - control_frame->size() + 1; | 3142 framer.GetControlFrameBufferMaxSize() - control_frame->size() + 1; |
3089 | 3143 |
3090 // Create a frame at exatly that size. | 3144 // Create a frame at exatly that size. |
3091 string big_value(kBigValueSize, 'x'); | 3145 string big_value(kBigValueSize, 'x'); |
3092 syn_stream.SetHeader("aa", big_value.c_str()); | 3146 syn_stream.SetHeader("aa", big_value); |
3093 // Upstream branches here and wraps SPDY4 with EXPECT_DEBUG_DFATAL. We | 3147 // Upstream branches here and wraps SPDY4 with EXPECT_DEBUG_DFATAL. We |
3094 // neither support that in Chromium, nor do we use the same DFATAL (see | 3148 // neither support that in Chromium, nor do we use the same DFATAL (see |
3095 // SpdyFrameBuilder::WriteFramePrefix()). | 3149 // SpdyFrameBuilder::WriteFramePrefix()). |
3096 control_frame.reset(framer.SerializeSynStream(syn_stream)); | 3150 control_frame.reset(framer.SerializeSynStream(syn_stream)); |
3097 | 3151 |
3098 EXPECT_TRUE(control_frame.get() != NULL); | 3152 EXPECT_TRUE(control_frame.get() != NULL); |
3099 EXPECT_EQ(framer.GetControlFrameBufferMaxSize() + 1, | 3153 EXPECT_EQ(framer.GetControlFrameBufferMaxSize() + 1, |
3100 control_frame->size()); | 3154 control_frame->size()); |
3101 | 3155 |
3102 TestSpdyVisitor visitor(spdy_version_); | 3156 TestSpdyVisitor visitor(spdy_version_); |
3103 visitor.SimulateInFramer( | 3157 visitor.SimulateInFramer( |
3104 reinterpret_cast<unsigned char*>(control_frame->data()), | 3158 reinterpret_cast<unsigned char*>(control_frame->data()), |
3105 control_frame->size()); | 3159 control_frame->size()); |
3106 EXPECT_FALSE(visitor.header_buffer_valid_); | 3160 EXPECT_FALSE(visitor.header_buffer_valid_); |
3107 EXPECT_EQ(1, visitor.error_count_); | 3161 EXPECT_EQ(1, visitor.error_count_); |
3108 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, | 3162 EXPECT_EQ(SpdyFramer::SPDY_CONTROL_PAYLOAD_TOO_LARGE, |
3109 visitor.framer_.error_code()) | 3163 visitor.framer_.error_code()) |
3110 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 3164 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
3111 EXPECT_EQ(0, visitor.syn_frame_count_); | 3165 EXPECT_EQ(0, visitor.syn_frame_count_); |
3112 EXPECT_EQ(0u, visitor.header_buffer_length_); | 3166 EXPECT_EQ(0u, visitor.header_buffer_length_); |
3113 } | 3167 } |
3114 | 3168 |
3115 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { | 3169 TEST_P(SpdyFramerTest, TooLargeHeadersFrameUsesContinuation) { |
3116 if (spdy_version_ < SPDY4) { | 3170 if (spdy_version_ <= SPDY3) { |
3117 return; | 3171 return; |
3118 } | 3172 } |
3119 SpdyFramer framer(spdy_version_); | 3173 SpdyFramer framer(spdy_version_); |
3120 framer.set_enable_compression(false); | 3174 framer.set_enable_compression(false); |
3121 SpdyHeadersIR headers(1); | 3175 SpdyHeadersIR headers(1); |
3122 | 3176 |
3123 // Exact payload length will change with HPACK, but this should be long | 3177 // Exact payload length will change with HPACK, but this should be long |
3124 // enough to cause an overflow. | 3178 // enough to cause an overflow. |
3125 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); | 3179 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); |
3126 string big_value(kBigValueSize, 'x'); | 3180 string big_value(kBigValueSize, 'x'); |
3127 headers.SetHeader("aa", big_value.c_str()); | 3181 headers.SetHeader("aa", big_value); |
3128 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); | 3182 scoped_ptr<SpdyFrame> control_frame(framer.SerializeHeaders(headers)); |
3129 EXPECT_TRUE(control_frame.get() != NULL); | 3183 EXPECT_TRUE(control_frame.get() != NULL); |
3130 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); | 3184 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); |
3131 | 3185 |
3132 TestSpdyVisitor visitor(spdy_version_); | 3186 TestSpdyVisitor visitor(spdy_version_); |
3133 visitor.SimulateInFramer( | 3187 visitor.SimulateInFramer( |
3134 reinterpret_cast<unsigned char*>(control_frame->data()), | 3188 reinterpret_cast<unsigned char*>(control_frame->data()), |
3135 control_frame->size()); | 3189 control_frame->size()); |
3136 EXPECT_TRUE(visitor.header_buffer_valid_); | 3190 EXPECT_TRUE(visitor.header_buffer_valid_); |
3137 EXPECT_EQ(0, visitor.error_count_); | 3191 EXPECT_EQ(0, visitor.error_count_); |
3138 EXPECT_EQ(1, visitor.headers_frame_count_); | 3192 EXPECT_EQ(1, visitor.headers_frame_count_); |
3139 EXPECT_EQ(1, visitor.continuation_count_); | 3193 EXPECT_EQ(1, visitor.continuation_count_); |
3140 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3194 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3141 } | 3195 } |
3142 | 3196 |
3143 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { | 3197 TEST_P(SpdyFramerTest, TooLargePushPromiseFrameUsesContinuation) { |
3144 if (spdy_version_ < SPDY4) { | 3198 if (spdy_version_ <= SPDY3) { |
3145 return; | 3199 return; |
3146 } | 3200 } |
3147 SpdyFramer framer(spdy_version_); | 3201 SpdyFramer framer(spdy_version_); |
3148 framer.set_enable_compression(false); | 3202 framer.set_enable_compression(false); |
3149 SpdyPushPromiseIR push_promise(1, 2); | 3203 SpdyPushPromiseIR push_promise(1, 2); |
3150 | 3204 |
3151 // Exact payload length will change with HPACK, but this should be long | 3205 // Exact payload length will change with HPACK, but this should be long |
3152 // enough to cause an overflow. | 3206 // enough to cause an overflow. |
3153 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); | 3207 const size_t kBigValueSize = framer.GetControlFrameBufferMaxSize(); |
3154 string big_value(kBigValueSize, 'x'); | 3208 string big_value(kBigValueSize, 'x'); |
3155 push_promise.SetHeader("aa", big_value.c_str()); | 3209 push_promise.SetHeader("aa", big_value); |
3156 scoped_ptr<SpdyFrame> control_frame( | 3210 scoped_ptr<SpdyFrame> control_frame( |
3157 framer.SerializePushPromise(push_promise)); | 3211 framer.SerializePushPromise(push_promise)); |
3158 EXPECT_TRUE(control_frame.get() != NULL); | 3212 EXPECT_TRUE(control_frame.get() != NULL); |
3159 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); | 3213 EXPECT_GT(control_frame->size(), framer.GetControlFrameBufferMaxSize()); |
3160 | 3214 |
3161 TestSpdyVisitor visitor(spdy_version_); | 3215 TestSpdyVisitor visitor(spdy_version_); |
3162 visitor.SimulateInFramer( | 3216 visitor.SimulateInFramer( |
3163 reinterpret_cast<unsigned char*>(control_frame->data()), | 3217 reinterpret_cast<unsigned char*>(control_frame->data()), |
3164 control_frame->size()); | 3218 control_frame->size()); |
3165 EXPECT_TRUE(visitor.header_buffer_valid_); | 3219 EXPECT_TRUE(visitor.header_buffer_valid_); |
3166 EXPECT_EQ(0, visitor.error_count_); | 3220 EXPECT_EQ(0, visitor.error_count_); |
3167 EXPECT_EQ(1, visitor.push_promise_frame_count_); | 3221 EXPECT_EQ(1, visitor.push_promise_frame_count_); |
3168 EXPECT_EQ(1, visitor.continuation_count_); | 3222 EXPECT_EQ(1, visitor.continuation_count_); |
3169 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3223 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3170 } | 3224 } |
3171 | 3225 |
3172 // Check that the framer stops delivering header data chunks once the visitor | 3226 // Check that the framer stops delivering header data chunks once the visitor |
3173 // declares it doesn't want any more. This is important to guard against | 3227 // declares it doesn't want any more. This is important to guard against |
3174 // "zip bomb" types of attacks. | 3228 // "zip bomb" types of attacks. |
3175 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { | 3229 TEST_P(SpdyFramerTest, ControlFrameMuchTooLarge) { |
3176 const size_t kHeaderBufferChunks = 4; | 3230 const size_t kHeaderBufferChunks = 4; |
3177 const size_t kHeaderBufferSize = | 3231 const size_t kHeaderBufferSize = |
3178 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; | 3232 TestSpdyVisitor::header_data_chunk_max_size() * kHeaderBufferChunks; |
3179 const size_t kBigValueSize = kHeaderBufferSize * 2; | 3233 const size_t kBigValueSize = kHeaderBufferSize * 2; |
3180 string big_value(kBigValueSize, 'x'); | 3234 string big_value(kBigValueSize, 'x'); |
3181 SpdyFramer framer(spdy_version_); | 3235 SpdyFramer framer(spdy_version_); |
3182 SpdySynStreamIR syn_stream(1); | 3236 SpdySynStreamIR syn_stream(1); |
3183 syn_stream.set_priority(1); | 3237 syn_stream.set_priority(1); |
3184 syn_stream.set_fin(true); | 3238 syn_stream.set_fin(true); |
3185 syn_stream.SetHeader("aa", big_value.c_str()); | 3239 syn_stream.SetHeader("aa", big_value); |
3186 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); | 3240 scoped_ptr<SpdyFrame> control_frame(framer.SerializeSynStream(syn_stream)); |
3187 EXPECT_TRUE(control_frame.get() != NULL); | 3241 EXPECT_TRUE(control_frame.get() != NULL); |
3188 TestSpdyVisitor visitor(spdy_version_); | 3242 TestSpdyVisitor visitor(spdy_version_); |
3189 visitor.set_header_buffer_size(kHeaderBufferSize); | 3243 visitor.set_header_buffer_size(kHeaderBufferSize); |
3190 visitor.use_compression_ = true; | 3244 visitor.use_compression_ = true; |
3191 visitor.SimulateInFramer( | 3245 visitor.SimulateInFramer( |
3192 reinterpret_cast<unsigned char*>(control_frame->data()), | 3246 reinterpret_cast<unsigned char*>(control_frame->data()), |
3193 control_frame->size()); | 3247 control_frame->size()); |
3194 EXPECT_FALSE(visitor.header_buffer_valid_); | 3248 EXPECT_FALSE(visitor.header_buffer_valid_); |
3195 EXPECT_EQ(1, visitor.error_count_); | 3249 EXPECT_EQ(1, visitor.error_count_); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3429 EXPECT_EQ(1, visitor.error_count_); | 3483 EXPECT_EQ(1, visitor.error_count_); |
3430 } else { | 3484 } else { |
3431 // In SPDY 4+, duplicate settings are allowed; | 3485 // In SPDY 4+, duplicate settings are allowed; |
3432 // each setting replaces the previous value for that setting. | 3486 // each setting replaces the previous value for that setting. |
3433 EXPECT_EQ(3, visitor.setting_count_); | 3487 EXPECT_EQ(3, visitor.setting_count_); |
3434 EXPECT_EQ(0, visitor.error_count_); | 3488 EXPECT_EQ(0, visitor.error_count_); |
3435 EXPECT_EQ(1, visitor.settings_ack_sent_); | 3489 EXPECT_EQ(1, visitor.settings_ack_sent_); |
3436 } | 3490 } |
3437 } | 3491 } |
3438 | 3492 |
| 3493 // Tests handling of SETTINGS_COMPRESS_DATA. |
| 3494 TEST_P(SpdyFramerTest, AcceptSettingsCompressData) { |
| 3495 if (!IsSpdy4()) { return; } |
| 3496 SpdyFramer framer(spdy_version_); |
| 3497 |
| 3498 const unsigned char kFrameData[] = { |
| 3499 0x00, 0x05, 0x04, 0x00, |
| 3500 0x00, 0x00, 0x00, 0x00, |
| 3501 0x05, 0x00, 0x00, 0x00, |
| 3502 0x01, |
| 3503 }; |
| 3504 |
| 3505 TestSpdyVisitor visitor(spdy_version_); |
| 3506 visitor.use_compression_ = false; |
| 3507 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 3508 EXPECT_EQ(1, visitor.setting_count_); |
| 3509 EXPECT_EQ(0, visitor.error_count_); |
| 3510 } |
| 3511 |
3439 // Tests handling of SETTINGS frame with entries out of order. | 3512 // Tests handling of SETTINGS frame with entries out of order. |
3440 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { | 3513 TEST_P(SpdyFramerTest, ReadOutOfOrderSettings) { |
3441 SpdyFramer framer(spdy_version_); | 3514 SpdyFramer framer(spdy_version_); |
3442 | 3515 |
3443 const unsigned char kV2FrameData[] = { | 3516 const unsigned char kV2FrameData[] = { |
3444 0x80, spdy_version_ch_, 0x00, 0x04, | 3517 0x80, spdy_version_ch_, 0x00, 0x04, |
3445 0x00, 0x00, 0x00, 0x1C, | 3518 0x00, 0x00, 0x00, 0x1C, |
3446 0x00, 0x00, 0x00, 0x03, | 3519 0x00, 0x00, 0x00, 0x03, |
3447 0x02, 0x00, 0x00, 0x00, // 1st Setting | 3520 0x02, 0x00, 0x00, 0x00, // 1st Setting |
3448 0x00, 0x00, 0x00, 0x02, | 3521 0x00, 0x00, 0x00, 0x02, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3655 control_frame->size())); | 3728 control_frame->size())); |
3656 visitor.SimulateInFramer( | 3729 visitor.SimulateInFramer( |
3657 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), | 3730 reinterpret_cast<unsigned const char*>(multiple_frame_data.data()), |
3658 multiple_frame_data.length()); | 3731 multiple_frame_data.length()); |
3659 EXPECT_EQ(0, visitor.error_count_); | 3732 EXPECT_EQ(0, visitor.error_count_); |
3660 EXPECT_EQ(1u, visitor.last_window_update_stream_); | 3733 EXPECT_EQ(1u, visitor.last_window_update_stream_); |
3661 EXPECT_EQ(2u, visitor.last_window_update_delta_); | 3734 EXPECT_EQ(2u, visitor.last_window_update_delta_); |
3662 } | 3735 } |
3663 | 3736 |
3664 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { | 3737 TEST_P(SpdyFramerTest, CreateContinuationUncompressed) { |
3665 if (spdy_version_ < SPDY4) { | 3738 if (spdy_version_ <= SPDY3) { |
3666 return; | 3739 return; |
3667 } | 3740 } |
3668 | 3741 |
3669 SpdyFramer framer(spdy_version_); | 3742 SpdyFramer framer(spdy_version_); |
3670 framer.set_enable_compression(false); | 3743 framer.set_enable_compression(false); |
3671 const char kDescription[] = "CONTINUATION frame"; | 3744 const char kDescription[] = "CONTINUATION frame"; |
3672 | 3745 |
3673 const unsigned char kFrameData[] = { | 3746 const unsigned char kFrameData[] = { |
3674 0x00, 0x12, 0x09, 0x00, // CONTINUATION | 3747 0x00, 0x12, 0x09, 0x00, // CONTINUATION |
3675 0x00, 0x00, 0x00, 0x2a, // Stream 42 | 3748 0x00, 0x00, 0x00, 0x2a, // Stream 42 |
(...skipping 28 matching lines...) Expand all Loading... |
3704 TestSpdyVisitor visitor(spdy_version_); | 3777 TestSpdyVisitor visitor(spdy_version_); |
3705 visitor.use_compression_ = true; | 3778 visitor.use_compression_ = true; |
3706 visitor.SimulateInFramer( | 3779 visitor.SimulateInFramer( |
3707 reinterpret_cast<unsigned char*>(frame->data()), | 3780 reinterpret_cast<unsigned char*>(frame->data()), |
3708 frame->size()); | 3781 frame->size()); |
3709 EXPECT_EQ(42u, visitor.last_push_promise_stream_); | 3782 EXPECT_EQ(42u, visitor.last_push_promise_stream_); |
3710 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); | 3783 EXPECT_EQ(57u, visitor.last_push_promise_promised_stream_); |
3711 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); | 3784 EXPECT_TRUE(CompareHeaderBlocks(&headers, &visitor.headers_)); |
3712 } | 3785 } |
3713 | 3786 |
3714 TEST_P(SpdyFramerTest, ReadHeadersWithContinuation) { | 3787 TEST_P(SpdyFramerTest, ReadHeadersWithContinuationAndPadding) { |
3715 if (spdy_version_ <= SPDY3) { | 3788 if (spdy_version_ <= SPDY3) { |
3716 return; | 3789 return; |
3717 } | 3790 } |
3718 | 3791 |
3719 const unsigned char kInput[] = { | 3792 const unsigned char kInput[] = { |
3720 0x00, 0x10, 0x01, 0x00, // HEADERS | 3793 0x00, 0x14, 0x01, 0x08, // HEADERS: PAD_LOW |
3721 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3794 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3795 0x03, // Padding of 3. |
3722 0x00, 0x06, 0x63, 0x6f, | 3796 0x00, 0x06, 0x63, 0x6f, |
3723 0x6f, 0x6b, 0x69, 0x65, | 3797 0x6f, 0x6b, 0x69, 0x65, |
3724 0x07, 0x66, 0x6f, 0x6f, | 3798 0x07, 0x66, 0x6f, 0x6f, |
3725 0x3d, 0x62, 0x61, 0x72, | 3799 0x3d, 0x62, 0x61, 0x72, |
| 3800 0x00, 0x00, 0x00, |
3726 | 3801 |
3727 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3802 0x00, 0x1a, 0x09, 0x18, // CONTINUATION: PAD_LOW & PAD_HIGH |
3728 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3803 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3804 0x00, 0x04, // Padding of 4. |
3729 0x00, 0x06, 0x63, 0x6f, | 3805 0x00, 0x06, 0x63, 0x6f, |
3730 0x6f, 0x6b, 0x69, 0x65, | 3806 0x6f, 0x6b, 0x69, 0x65, |
3731 0x08, 0x62, 0x61, 0x7a, | 3807 0x08, 0x62, 0x61, 0x7a, |
3732 0x3d, 0x62, 0x69, 0x6e, | 3808 0x3d, 0x62, 0x69, 0x6e, |
3733 0x67, 0x00, 0x06, 0x63, | 3809 0x67, 0x00, 0x06, 0x63, |
| 3810 0x00, 0x00, 0x00, 0x00, |
3734 | 3811 |
3735 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | 3812 0x00, 0x13, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS |
3736 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3813 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3814 0x00, // Padding of 0. |
3737 0x6f, 0x6f, 0x6b, 0x69, | 3815 0x6f, 0x6f, 0x6b, 0x69, |
3738 0x65, 0x00, 0x00, 0x04, | 3816 0x65, 0x00, 0x00, 0x04, |
3739 0x6e, 0x61, 0x6d, 0x65, | 3817 0x6e, 0x61, 0x6d, 0x65, |
3740 0x05, 0x76, 0x61, 0x6c, | 3818 0x05, 0x76, 0x61, 0x6c, |
3741 0x75, 0x65, | 3819 0x75, 0x65, |
3742 }; | 3820 }; |
3743 | 3821 |
3744 SpdyFramer framer(spdy_version_); | |
3745 TestSpdyVisitor visitor(spdy_version_); | 3822 TestSpdyVisitor visitor(spdy_version_); |
3746 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3823 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
3747 | 3824 |
3748 EXPECT_EQ(0, visitor.error_count_); | 3825 EXPECT_EQ(0, visitor.error_count_); |
3749 EXPECT_EQ(1, visitor.headers_frame_count_); | 3826 EXPECT_EQ(1, visitor.headers_frame_count_); |
3750 EXPECT_EQ(2, visitor.continuation_count_); | 3827 EXPECT_EQ(2, visitor.continuation_count_); |
3751 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3828 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3752 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); | 3829 EXPECT_EQ(0, visitor.zero_length_data_frame_count_); |
3753 | 3830 |
3754 EXPECT_THAT(visitor.headers_, ElementsAre( | 3831 EXPECT_THAT(visitor.headers_, ElementsAre( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3795 EXPECT_EQ(2, visitor.continuation_count_); | 3872 EXPECT_EQ(2, visitor.continuation_count_); |
3796 EXPECT_EQ(1, visitor.fin_flag_count_); | 3873 EXPECT_EQ(1, visitor.fin_flag_count_); |
3797 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); | 3874 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
3798 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); | 3875 EXPECT_EQ(1, visitor.zero_length_data_frame_count_); |
3799 | 3876 |
3800 EXPECT_THAT(visitor.headers_, ElementsAre( | 3877 EXPECT_THAT(visitor.headers_, ElementsAre( |
3801 Pair("cookie", "foo=bar; baz=bing; "), | 3878 Pair("cookie", "foo=bar; baz=bing; "), |
3802 Pair("name", "value"))); | 3879 Pair("name", "value"))); |
3803 } | 3880 } |
3804 | 3881 |
3805 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuation) { | 3882 TEST_P(SpdyFramerTest, ReadPushPromiseWithContinuationAndPadding) { |
3806 if (spdy_version_ <= SPDY3) { | 3883 if (spdy_version_ <= SPDY3) { |
3807 return; | 3884 return; |
3808 } | 3885 } |
3809 | 3886 |
3810 const unsigned char kInput[] = { | 3887 const unsigned char kInput[] = { |
3811 0x00, 0x14, 0x05, 0x00, // PUSH_PROMISE | 3888 0x00, 0x18, 0x05, 0x18, // PUSH_PROMISE: PAD_LOW & PAD_HIGH |
3812 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3889 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3813 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 | 3890 0x00, 0x00, 0x00, 0x2A, // Promised stream 42 |
| 3891 0x00, 0x02, // Padding of 2. |
3814 0x00, 0x06, 0x63, 0x6f, | 3892 0x00, 0x06, 0x63, 0x6f, |
3815 0x6f, 0x6b, 0x69, 0x65, | 3893 0x6f, 0x6b, 0x69, 0x65, |
3816 0x07, 0x66, 0x6f, 0x6f, | 3894 0x07, 0x66, 0x6f, 0x6f, |
3817 0x3d, 0x62, 0x61, 0x72, | 3895 0x3d, 0x62, 0x61, 0x72, |
| 3896 0x00, 0x00, |
3818 | 3897 |
3819 0x00, 0x14, 0x09, 0x00, // CONTINUATION | 3898 0x00, 0x14, 0x09, 0x00, // CONTINUATION: |
3820 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3899 0x00, 0x00, 0x00, 0x01, // Stream 1 |
3821 0x00, 0x06, 0x63, 0x6f, | 3900 0x00, 0x06, 0x63, 0x6f, |
3822 0x6f, 0x6b, 0x69, 0x65, | 3901 0x6f, 0x6b, 0x69, 0x65, |
3823 0x08, 0x62, 0x61, 0x7a, | 3902 0x08, 0x62, 0x61, 0x7a, |
3824 0x3d, 0x62, 0x69, 0x6e, | 3903 0x3d, 0x62, 0x69, 0x6e, |
3825 0x67, 0x00, 0x06, 0x63, | 3904 0x67, 0x00, 0x06, 0x63, |
3826 | 3905 |
3827 0x00, 0x12, 0x09, 0x04, // CONTINUATION: END_HEADERS | 3906 0x00, 0x17, 0x09, 0x0c, // CONTINUATION: PAD_LOW & END_HEADERS |
3828 0x00, 0x00, 0x00, 0x01, // Stream 1 | 3907 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 3908 0x04, // Padding of 4. |
3829 0x6f, 0x6f, 0x6b, 0x69, | 3909 0x6f, 0x6f, 0x6b, 0x69, |
3830 0x65, 0x00, 0x00, 0x04, | 3910 0x65, 0x00, 0x00, 0x04, |
3831 0x6e, 0x61, 0x6d, 0x65, | 3911 0x6e, 0x61, 0x6d, 0x65, |
3832 0x05, 0x76, 0x61, 0x6c, | 3912 0x05, 0x76, 0x61, 0x6c, |
3833 0x75, 0x65, | 3913 0x75, 0x65, 0x00, 0x00, |
| 3914 0x00, 0x00, |
3834 }; | 3915 }; |
3835 | 3916 |
3836 SpdyFramer framer(spdy_version_); | 3917 SpdyFramer framer(spdy_version_); |
3837 TestSpdyVisitor visitor(spdy_version_); | 3918 TestSpdyVisitor visitor(spdy_version_); |
3838 visitor.SimulateInFramer(kInput, sizeof(kInput)); | 3919 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
3839 | 3920 |
3840 EXPECT_EQ(0, visitor.error_count_); | 3921 EXPECT_EQ(0, visitor.error_count_); |
3841 EXPECT_EQ(1u, visitor.last_push_promise_stream_); | 3922 EXPECT_EQ(1u, visitor.last_push_promise_stream_); |
3842 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); | 3923 EXPECT_EQ(42u, visitor.last_push_promise_promised_stream_); |
3843 EXPECT_EQ(2, visitor.continuation_count_); | 3924 EXPECT_EQ(2, visitor.continuation_count_); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3975 EXPECT_EQ(1, visitor.error_count_); | 4056 EXPECT_EQ(1, visitor.error_count_); |
3976 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, | 4057 EXPECT_EQ(SpdyFramer::SPDY_UNEXPECTED_FRAME, |
3977 visitor.framer_.error_code()) | 4058 visitor.framer_.error_code()) |
3978 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4059 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
3979 EXPECT_EQ(1, visitor.headers_frame_count_); | 4060 EXPECT_EQ(1, visitor.headers_frame_count_); |
3980 EXPECT_EQ(0, visitor.continuation_count_); | 4061 EXPECT_EQ(0, visitor.continuation_count_); |
3981 EXPECT_EQ(0u, visitor.header_buffer_length_); | 4062 EXPECT_EQ(0u, visitor.header_buffer_length_); |
3982 EXPECT_EQ(0, visitor.data_frame_count_); | 4063 EXPECT_EQ(0, visitor.data_frame_count_); |
3983 } | 4064 } |
3984 | 4065 |
| 4066 TEST_P(SpdyFramerTest, EndSegmentOnDataFrame) { |
| 4067 if (spdy_version_ <= SPDY3) { |
| 4068 return; |
| 4069 } |
| 4070 const unsigned char kInput[] = { |
| 4071 0x00, 0x0c, 0x00, 0x02, // DATA: END_SEGMENT |
| 4072 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4073 0xde, 0xad, 0xbe, 0xef, |
| 4074 0xde, 0xad, 0xbe, 0xef, |
| 4075 0xde, 0xad, 0xbe, 0xef, |
| 4076 }; |
| 4077 |
| 4078 TestSpdyVisitor visitor(spdy_version_); |
| 4079 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4080 |
| 4081 // TODO(jgraettinger): Verify END_SEGMENT when support is added. |
| 4082 EXPECT_EQ(0, visitor.error_count_); |
| 4083 EXPECT_EQ(12, visitor.data_bytes_); |
| 4084 EXPECT_EQ(0, visitor.fin_frame_count_); |
| 4085 EXPECT_EQ(0, visitor.fin_flag_count_); |
| 4086 } |
| 4087 |
| 4088 TEST_P(SpdyFramerTest, EndSegmentOnHeadersFrame) { |
| 4089 if (spdy_version_ <= SPDY3) { |
| 4090 return; |
| 4091 } |
| 4092 const unsigned char kInput[] = { |
| 4093 0x00, 0x10, 0x01, 0x06, // HEADERS: END_SEGMENT | END_HEADERS |
| 4094 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4095 0x00, 0x06, 0x63, 0x6f, |
| 4096 0x6f, 0x6b, 0x69, 0x65, |
| 4097 0x07, 0x66, 0x6f, 0x6f, |
| 4098 0x3d, 0x62, 0x61, 0x72, |
| 4099 }; |
| 4100 |
| 4101 TestSpdyVisitor visitor(spdy_version_); |
| 4102 visitor.SimulateInFramer(kInput, sizeof(kInput)); |
| 4103 |
| 4104 // TODO(jgraettinger): Verify END_SEGMENT when support is added. |
| 4105 EXPECT_EQ(0, visitor.error_count_); |
| 4106 EXPECT_EQ(1, visitor.headers_frame_count_); |
| 4107 EXPECT_EQ(1, visitor.zero_length_control_frame_header_data_count_); |
| 4108 |
| 4109 EXPECT_THAT(visitor.headers_, ElementsAre( |
| 4110 Pair("cookie", "foo=bar"))); |
| 4111 } |
| 4112 |
3985 TEST_P(SpdyFramerTest, ReadGarbage) { | 4113 TEST_P(SpdyFramerTest, ReadGarbage) { |
3986 SpdyFramer framer(spdy_version_); | 4114 SpdyFramer framer(spdy_version_); |
3987 unsigned char garbage_frame[256]; | 4115 unsigned char garbage_frame[256]; |
3988 memset(garbage_frame, ~0, sizeof(garbage_frame)); | 4116 memset(garbage_frame, ~0, sizeof(garbage_frame)); |
3989 TestSpdyVisitor visitor(spdy_version_); | 4117 TestSpdyVisitor visitor(spdy_version_); |
3990 visitor.use_compression_ = false; | 4118 visitor.use_compression_ = false; |
3991 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); | 4119 visitor.SimulateInFramer(garbage_frame, sizeof(garbage_frame)); |
3992 EXPECT_EQ(1, visitor.error_count_); | 4120 EXPECT_EQ(1, visitor.error_count_); |
3993 } | 4121 } |
3994 | 4122 |
(...skipping 23 matching lines...) Expand all Loading... |
4018 const unsigned char kFrameData[] = { | 4146 const unsigned char kFrameData[] = { |
4019 0x80, spdy_version_ch_, 0xff, 0xff, | 4147 0x80, spdy_version_ch_, 0xff, 0xff, |
4020 0xff, 0xff, 0xff, 0xff, | 4148 0xff, 0xff, 0xff, 0xff, |
4021 }; | 4149 }; |
4022 TestSpdyVisitor visitor(spdy_version_); | 4150 TestSpdyVisitor visitor(spdy_version_); |
4023 visitor.use_compression_ = false; | 4151 visitor.use_compression_ = false; |
4024 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); | 4152 visitor.SimulateInFramer(kFrameData, arraysize(kFrameData)); |
4025 EXPECT_EQ(1, visitor.error_count_); | 4153 EXPECT_EQ(1, visitor.error_count_); |
4026 } | 4154 } |
4027 | 4155 |
| 4156 TEST_P(SpdyFramerTest, ReadGarbageHPACKEncoding) { |
| 4157 if (spdy_version_ <= SPDY3) { |
| 4158 return; |
| 4159 } |
| 4160 const unsigned char kInput[] = { |
| 4161 0x00, 0x12, 0x01, 0x04, // HEADER: END_HEADERS |
| 4162 0x00, 0x00, 0x00, 0x01, // Stream 1 |
| 4163 0xef, 0xef, 0xff, 0xff, |
| 4164 0xff, 0xff, 0xff, 0xff, |
| 4165 0xff, 0xff, 0xff, 0xff, |
| 4166 0xff, 0xff, 0xff, 0xff, |
| 4167 0xff, 0xff, |
| 4168 }; |
| 4169 |
| 4170 TestSpdyVisitor visitor(spdy_version_); |
| 4171 visitor.SimulateInFramer(kInput, arraysize(kInput)); |
| 4172 EXPECT_EQ(1, visitor.error_count_); |
| 4173 } |
| 4174 |
4028 TEST_P(SpdyFramerTest, SizesTest) { | 4175 TEST_P(SpdyFramerTest, SizesTest) { |
4029 SpdyFramer framer(spdy_version_); | 4176 SpdyFramer framer(spdy_version_); |
4030 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); | 4177 EXPECT_EQ(8u, framer.GetDataFrameMinimumSize()); |
4031 if (IsSpdy4()) { | 4178 if (IsSpdy4() || IsSpdy5()) { |
4032 EXPECT_EQ(8u, framer.GetSynReplyMinimumSize()); | 4179 EXPECT_EQ(8u, framer.GetSynReplyMinimumSize()); |
4033 EXPECT_EQ(12u, framer.GetRstStreamMinimumSize()); | 4180 EXPECT_EQ(12u, framer.GetRstStreamMinimumSize()); |
4034 EXPECT_EQ(8u, framer.GetSettingsMinimumSize()); | 4181 EXPECT_EQ(8u, framer.GetSettingsMinimumSize()); |
4035 EXPECT_EQ(16u, framer.GetPingSize()); | 4182 EXPECT_EQ(16u, framer.GetPingSize()); |
4036 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); | 4183 EXPECT_EQ(16u, framer.GetGoAwayMinimumSize()); |
4037 EXPECT_EQ(8u, framer.GetHeadersMinimumSize()); | 4184 EXPECT_EQ(8u, framer.GetHeadersMinimumSize()); |
4038 EXPECT_EQ(12u, framer.GetWindowUpdateSize()); | 4185 EXPECT_EQ(12u, framer.GetWindowUpdateSize()); |
4039 EXPECT_EQ(8u, framer.GetBlockedSize()); | 4186 EXPECT_EQ(8u, framer.GetBlockedSize()); |
4040 EXPECT_EQ(12u, framer.GetPushPromiseMinimumSize()); | 4187 EXPECT_EQ(12u, framer.GetPushPromiseMinimumSize()); |
| 4188 EXPECT_EQ(17u, framer.GetAltSvcMinimumSize()); |
4041 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); | 4189 EXPECT_EQ(8u, framer.GetFrameMinimumSize()); |
4042 EXPECT_EQ(16383u, framer.GetFrameMaximumSize()); | 4190 EXPECT_EQ(16383u, framer.GetFrameMaximumSize()); |
4043 EXPECT_EQ(16375u, framer.GetDataFrameMaximumPayload()); | 4191 EXPECT_EQ(16375u, framer.GetDataFrameMaximumPayload()); |
4044 } else { | 4192 } else { |
4045 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); | 4193 EXPECT_EQ(8u, framer.GetControlFrameHeaderSize()); |
4046 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); | 4194 EXPECT_EQ(18u, framer.GetSynStreamMinimumSize()); |
4047 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); | 4195 EXPECT_EQ(IsSpdy2() ? 14u : 12u, framer.GetSynReplyMinimumSize()); |
4048 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); | 4196 EXPECT_EQ(16u, framer.GetRstStreamMinimumSize()); |
4049 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); | 4197 EXPECT_EQ(12u, framer.GetSettingsMinimumSize()); |
4050 EXPECT_EQ(12u, framer.GetPingSize()); | 4198 EXPECT_EQ(12u, framer.GetPingSize()); |
(...skipping 27 matching lines...) Expand all Loading... |
4078 SpdyFramer::SPDY_FORWARD_STREAM_FRAME)); | 4226 SpdyFramer::SPDY_FORWARD_STREAM_FRAME)); |
4079 EXPECT_STREQ("SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK", | 4227 EXPECT_STREQ("SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK", |
4080 SpdyFramer::StateToString( | 4228 SpdyFramer::StateToString( |
4081 SpdyFramer::SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK)); | 4229 SpdyFramer::SPDY_CONTROL_FRAME_BEFORE_HEADER_BLOCK)); |
4082 EXPECT_STREQ("SPDY_CONTROL_FRAME_HEADER_BLOCK", | 4230 EXPECT_STREQ("SPDY_CONTROL_FRAME_HEADER_BLOCK", |
4083 SpdyFramer::StateToString( | 4231 SpdyFramer::StateToString( |
4084 SpdyFramer::SPDY_CONTROL_FRAME_HEADER_BLOCK)); | 4232 SpdyFramer::SPDY_CONTROL_FRAME_HEADER_BLOCK)); |
4085 EXPECT_STREQ("SPDY_SETTINGS_FRAME_PAYLOAD", | 4233 EXPECT_STREQ("SPDY_SETTINGS_FRAME_PAYLOAD", |
4086 SpdyFramer::StateToString( | 4234 SpdyFramer::StateToString( |
4087 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); | 4235 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD)); |
| 4236 EXPECT_STREQ("SPDY_ALTSVC_FRAME_PAYLOAD", |
| 4237 SpdyFramer::StateToString( |
| 4238 SpdyFramer::SPDY_ALTSVC_FRAME_PAYLOAD)); |
4088 EXPECT_STREQ("UNKNOWN_STATE", | 4239 EXPECT_STREQ("UNKNOWN_STATE", |
4089 SpdyFramer::StateToString( | 4240 SpdyFramer::StateToString( |
4090 SpdyFramer::SPDY_SETTINGS_FRAME_PAYLOAD + 1)); | 4241 SpdyFramer::SPDY_ALTSVC_FRAME_PAYLOAD + 1)); |
4091 } | 4242 } |
4092 | 4243 |
4093 TEST_P(SpdyFramerTest, ErrorCodeToStringTest) { | 4244 TEST_P(SpdyFramerTest, ErrorCodeToStringTest) { |
4094 EXPECT_STREQ("NO_ERROR", | 4245 EXPECT_STREQ("NO_ERROR", |
4095 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); | 4246 SpdyFramer::ErrorCodeToString(SpdyFramer::SPDY_NO_ERROR)); |
4096 EXPECT_STREQ("INVALID_CONTROL_FRAME", | 4247 EXPECT_STREQ("INVALID_CONTROL_FRAME", |
4097 SpdyFramer::ErrorCodeToString( | 4248 SpdyFramer::ErrorCodeToString( |
4098 SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); | 4249 SpdyFramer::SPDY_INVALID_CONTROL_FRAME)); |
4099 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", | 4250 EXPECT_STREQ("CONTROL_PAYLOAD_TOO_LARGE", |
4100 SpdyFramer::ErrorCodeToString( | 4251 SpdyFramer::ErrorCodeToString( |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4305 | 4456 |
4306 SpdySynStreamIR syn_stream(8); | 4457 SpdySynStreamIR syn_stream(8); |
4307 syn_stream.set_associated_to_stream_id(3); | 4458 syn_stream.set_associated_to_stream_id(3); |
4308 syn_stream.set_priority(1); | 4459 syn_stream.set_priority(1); |
4309 syn_stream.SetHeader("foo", "bar"); | 4460 syn_stream.SetHeader("foo", "bar"); |
4310 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); | 4461 scoped_ptr<SpdyFrame> frame(framer.SerializeSynStream(syn_stream)); |
4311 int set_flags = flags; | 4462 int set_flags = flags; |
4312 if (IsSpdy4()) { | 4463 if (IsSpdy4()) { |
4313 // PRIORITY required for SYN_STREAM simulation. | 4464 // PRIORITY required for SYN_STREAM simulation. |
4314 set_flags |= HEADERS_FLAG_PRIORITY; | 4465 set_flags |= HEADERS_FLAG_PRIORITY; |
| 4466 |
| 4467 // TODO(jgraettinger): Add padding to SynStreamIR, and implement framing. |
| 4468 set_flags &= ~HEADERS_FLAG_PAD_LOW; |
| 4469 set_flags &= ~HEADERS_FLAG_PAD_HIGH; |
4315 } | 4470 } |
4316 SetFrameFlags(frame.get(), set_flags, spdy_version_); | 4471 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4317 | 4472 |
4318 if (!IsSpdy4() && | 4473 if (!IsSpdy4() && |
4319 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 4474 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
4320 EXPECT_CALL(visitor, OnError(_)); | 4475 EXPECT_CALL(visitor, OnError(_)); |
4321 } else if (IsSpdy4() && | 4476 } else if (IsSpdy4() && |
4322 flags & ~(CONTROL_FLAG_FIN | | 4477 flags & ~(CONTROL_FLAG_FIN | |
4323 HEADERS_FLAG_PRIORITY | | 4478 HEADERS_FLAG_PRIORITY | |
4324 HEADERS_FLAG_END_HEADERS)) { | 4479 HEADERS_FLAG_END_HEADERS | |
| 4480 HEADERS_FLAG_END_SEGMENT | |
| 4481 HEADERS_FLAG_PAD_LOW | |
| 4482 HEADERS_FLAG_PAD_HIGH)) { |
4325 EXPECT_CALL(visitor, OnError(_)); | 4483 EXPECT_CALL(visitor, OnError(_)); |
4326 } else { | 4484 } else { |
4327 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); | 4485 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(8, SYN_STREAM, _)); |
4328 if (IsSpdy4()) { | 4486 if (IsSpdy4()) { |
4329 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, | 4487 EXPECT_CALL(visitor, OnSynStream(8, 0, 1, flags & CONTROL_FLAG_FIN, |
4330 false)); | 4488 false)); |
4331 } else { | 4489 } else { |
4332 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, | 4490 EXPECT_CALL(visitor, OnSynStream(8, 3, 1, flags & CONTROL_FLAG_FIN, |
4333 flags & CONTROL_FLAG_UNIDIRECTIONAL)); | 4491 flags & CONTROL_FLAG_UNIDIRECTIONAL)); |
4334 } | 4492 } |
(...skipping 11 matching lines...) Expand all Loading... |
4346 framer.ProcessInput(frame->data(), frame->size()); | 4504 framer.ProcessInput(frame->data(), frame->size()); |
4347 if (!IsSpdy4() && | 4505 if (!IsSpdy4() && |
4348 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { | 4506 flags & ~(CONTROL_FLAG_FIN | CONTROL_FLAG_UNIDIRECTIONAL)) { |
4349 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4507 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4350 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4508 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4351 framer.error_code()) | 4509 framer.error_code()) |
4352 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4510 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4353 } else if (IsSpdy4() && | 4511 } else if (IsSpdy4() && |
4354 flags & ~(CONTROL_FLAG_FIN | | 4512 flags & ~(CONTROL_FLAG_FIN | |
4355 HEADERS_FLAG_PRIORITY | | 4513 HEADERS_FLAG_PRIORITY | |
4356 HEADERS_FLAG_END_HEADERS)) { | 4514 HEADERS_FLAG_END_HEADERS | |
| 4515 HEADERS_FLAG_END_SEGMENT | |
| 4516 HEADERS_FLAG_PAD_LOW | |
| 4517 HEADERS_FLAG_PAD_HIGH)) { |
4357 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4518 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4358 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4519 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4359 framer.error_code()) | 4520 framer.error_code()) |
4360 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4521 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4361 } else { | 4522 } else { |
4362 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4523 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4363 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4524 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4364 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4525 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4365 } | 4526 } |
4366 } | 4527 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4563 } | 4724 } |
4564 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4725 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4565 | 4726 |
4566 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4727 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4567 SpdyFramer framer(spdy_version_); | 4728 SpdyFramer framer(spdy_version_); |
4568 framer.set_visitor(&visitor); | 4729 framer.set_visitor(&visitor); |
4569 | 4730 |
4570 SpdyHeadersIR headers_ir(57); | 4731 SpdyHeadersIR headers_ir(57); |
4571 headers_ir.SetHeader("foo", "bar"); | 4732 headers_ir.SetHeader("foo", "bar"); |
4572 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); | 4733 scoped_ptr<SpdyFrame> frame(framer.SerializeHeaders(headers_ir)); |
4573 SetFrameFlags(frame.get(), flags, spdy_version_); | 4734 int set_flags = flags; |
| 4735 if (IsSpdy4()) { |
| 4736 // TODO(jgraettinger): Add padding to SpdyHeadersIR, |
| 4737 // and implement framing. |
| 4738 set_flags &= ~HEADERS_FLAG_PAD_LOW; |
| 4739 set_flags &= ~HEADERS_FLAG_PAD_HIGH; |
| 4740 } |
| 4741 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4574 | 4742 |
4575 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4743 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4576 EXPECT_CALL(visitor, OnError(_)); | 4744 EXPECT_CALL(visitor, OnError(_)); |
4577 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | | 4745 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4578 HEADERS_FLAG_END_HEADERS)) { | 4746 HEADERS_FLAG_END_HEADERS | |
| 4747 HEADERS_FLAG_END_SEGMENT | |
| 4748 HEADERS_FLAG_PAD_LOW | |
| 4749 HEADERS_FLAG_PAD_HIGH)) { |
4579 EXPECT_CALL(visitor, OnError(_)); | 4750 EXPECT_CALL(visitor, OnError(_)); |
4580 } else { | 4751 } else { |
4581 EXPECT_CALL(visitor, OnHeaders(57, | 4752 EXPECT_CALL(visitor, OnHeaders(57, |
4582 flags & CONTROL_FLAG_FIN, | 4753 flags & CONTROL_FLAG_FIN, |
4583 (flags & HEADERS_FLAG_END_HEADERS) || | 4754 (flags & HEADERS_FLAG_END_HEADERS) || |
4584 !IsSpdy4())); | 4755 !IsSpdy4())); |
4585 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) | 4756 EXPECT_CALL(visitor, OnControlFrameHeaderData(57, _, _)) |
4586 .WillRepeatedly(testing::Return(true)); | 4757 .WillRepeatedly(testing::Return(true)); |
4587 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || | 4758 if (flags & DATA_FLAG_FIN && (!IsSpdy4() || |
4588 flags & HEADERS_FLAG_END_HEADERS)) { | 4759 flags & HEADERS_FLAG_END_HEADERS)) { |
4589 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); | 4760 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)); |
4590 } else { | 4761 } else { |
4591 // Do not close the stream if we are expecting a CONTINUATION frame. | 4762 // Do not close the stream if we are expecting a CONTINUATION frame. |
4592 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); | 4763 EXPECT_CALL(visitor, OnStreamFrameData(_, _, 0, true)).Times(0); |
4593 } | 4764 } |
4594 } | 4765 } |
4595 | 4766 |
4596 framer.ProcessInput(frame->data(), frame->size()); | 4767 framer.ProcessInput(frame->data(), frame->size()); |
4597 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { | 4768 if (!IsSpdy4() && flags & ~CONTROL_FLAG_FIN) { |
4598 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4769 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4599 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4770 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4600 framer.error_code()) | 4771 framer.error_code()) |
4601 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4772 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4602 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | HEADERS_FLAG_PRIORITY | | 4773 } else if (IsSpdy4() && flags & ~(CONTROL_FLAG_FIN | |
4603 HEADERS_FLAG_END_HEADERS)) { | 4774 HEADERS_FLAG_END_HEADERS | |
| 4775 HEADERS_FLAG_END_SEGMENT | |
| 4776 HEADERS_FLAG_PAD_LOW | |
| 4777 HEADERS_FLAG_PAD_HIGH)) { |
4604 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4778 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4605 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4779 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4606 framer.error_code()) | 4780 framer.error_code()) |
4607 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4781 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4608 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { | 4782 } else if (IsSpdy4() && ~(flags & HEADERS_FLAG_END_HEADERS)) { |
4609 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4783 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4610 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4784 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4611 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4785 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4612 } else { | 4786 } else { |
4613 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4787 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4678 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4852 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4679 } else { | 4853 } else { |
4680 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4854 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4681 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4855 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4682 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4856 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4683 } | 4857 } |
4684 } | 4858 } |
4685 } | 4859 } |
4686 | 4860 |
4687 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { | 4861 TEST_P(SpdyFramerTest, PushPromiseFrameFlags) { |
4688 if (spdy_version_ < SPDY4) { | 4862 if (spdy_version_ <= SPDY3) { |
4689 return; | 4863 return; |
4690 } | 4864 } |
4691 | 4865 |
4692 for (int flags = 0; flags < 256; ++flags) { | 4866 for (int flags = 0; flags < 256; ++flags) { |
4693 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4867 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4694 | 4868 |
4695 testing::StrictMock<net::test::MockSpdyFramerVisitor> visitor; | 4869 testing::StrictMock<net::test::MockSpdyFramerVisitor> visitor; |
4696 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 4870 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
4697 SpdyFramer framer(spdy_version_); | 4871 SpdyFramer framer(spdy_version_); |
4698 framer.set_visitor(&visitor); | 4872 framer.set_visitor(&visitor); |
4699 framer.set_debug_visitor(&debug_visitor); | 4873 framer.set_debug_visitor(&debug_visitor); |
4700 | 4874 |
4701 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); | 4875 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, PUSH_PROMISE, _, _)); |
4702 | 4876 |
4703 SpdyPushPromiseIR push_promise(42, 57); | 4877 SpdyPushPromiseIR push_promise(42, 57); |
4704 push_promise.SetHeader("foo", "bar"); | 4878 push_promise.SetHeader("foo", "bar"); |
4705 scoped_ptr<SpdySerializedFrame> frame( | 4879 scoped_ptr<SpdySerializedFrame> frame( |
4706 framer.SerializePushPromise(push_promise)); | 4880 framer.SerializePushPromise(push_promise)); |
4707 SetFrameFlags(frame.get(), flags, spdy_version_); | 4881 // TODO(jgraettinger): Add padding to SpdyPushPromiseIR, |
| 4882 // and implement framing. |
| 4883 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; |
| 4884 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4708 | 4885 |
4709 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { | 4886 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | |
| 4887 HEADERS_FLAG_PAD_LOW | |
| 4888 HEADERS_FLAG_PAD_HIGH)) { |
4710 EXPECT_CALL(visitor, OnError(_)); | 4889 EXPECT_CALL(visitor, OnError(_)); |
4711 } else { | 4890 } else { |
4712 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); | 4891 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, PUSH_PROMISE, _)); |
4713 EXPECT_CALL(visitor, OnPushPromise(42, 57, | 4892 EXPECT_CALL(visitor, OnPushPromise(42, 57, |
4714 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); | 4893 flags & PUSH_PROMISE_FLAG_END_PUSH_PROMISE)); |
4715 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4894 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4716 .WillRepeatedly(testing::Return(true)); | 4895 .WillRepeatedly(testing::Return(true)); |
4717 } | 4896 } |
4718 | 4897 |
4719 framer.ProcessInput(frame->data(), frame->size()); | 4898 framer.ProcessInput(frame->data(), frame->size()); |
4720 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE)) { | 4899 if (flags & ~(PUSH_PROMISE_FLAG_END_PUSH_PROMISE | |
| 4900 HEADERS_FLAG_PAD_LOW | |
| 4901 HEADERS_FLAG_PAD_HIGH)) { |
4721 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4902 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4722 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4903 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4723 framer.error_code()) | 4904 framer.error_code()) |
4724 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4905 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4725 } else { | 4906 } else { |
4726 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4907 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4727 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4908 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4728 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4909 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4729 } | 4910 } |
4730 } | 4911 } |
4731 } | 4912 } |
4732 | 4913 |
4733 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { | 4914 TEST_P(SpdyFramerTest, ContinuationFrameFlags) { |
4734 if (spdy_version_ < SPDY4) { | 4915 if (spdy_version_ <= SPDY3) { |
4735 return; | 4916 return; |
4736 } | 4917 } |
4737 | 4918 |
4738 for (int flags = 0; flags < 256; ++flags) { | 4919 for (int flags = 0; flags < 256; ++flags) { |
4739 SCOPED_TRACE(testing::Message() << "Flags " << flags); | 4920 SCOPED_TRACE(testing::Message() << "Flags " << flags); |
4740 | 4921 |
4741 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4922 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4742 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; | 4923 testing::StrictMock<net::test::MockDebugVisitor> debug_visitor; |
4743 SpdyFramer framer(spdy_version_); | 4924 SpdyFramer framer(spdy_version_); |
4744 framer.set_visitor(&visitor); | 4925 framer.set_visitor(&visitor); |
4745 framer.set_debug_visitor(&debug_visitor); | 4926 framer.set_debug_visitor(&debug_visitor); |
4746 | 4927 |
4747 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); | 4928 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, HEADERS, _, _)); |
4748 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); | 4929 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, HEADERS, _)); |
4749 EXPECT_CALL(visitor, OnHeaders(42, 0, false)); | 4930 EXPECT_CALL(visitor, OnHeaders(42, 0, false)); |
4750 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4931 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4751 .WillRepeatedly(testing::Return(true)); | 4932 .WillRepeatedly(testing::Return(true)); |
4752 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, CONTINUATION, _, _)); | 4933 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(42, CONTINUATION, _, _)); |
4753 | 4934 |
4754 SpdyHeadersIR headers_ir(42); | 4935 SpdyHeadersIR headers_ir(42); |
4755 headers_ir.SetHeader("foo", "bar"); | 4936 headers_ir.SetHeader("foo", "bar"); |
4756 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); | 4937 scoped_ptr<SpdyFrame> frame0(framer.SerializeHeaders(headers_ir)); |
4757 SetFrameFlags(frame0.get(), 0, spdy_version_); | 4938 SetFrameFlags(frame0.get(), 0, spdy_version_); |
4758 | 4939 |
4759 SpdyContinuationIR continuation(42); | 4940 SpdyContinuationIR continuation(42); |
4760 continuation.SetHeader("foo", "bar"); | 4941 continuation.SetHeader("foo", "bar"); |
4761 scoped_ptr<SpdySerializedFrame> frame( | 4942 scoped_ptr<SpdySerializedFrame> frame( |
4762 framer.SerializeContinuation(continuation)); | 4943 framer.SerializeContinuation(continuation)); |
4763 SetFrameFlags(frame.get(), flags, spdy_version_); | 4944 // TODO(jgraettinger): Add padding to the eventual continuation |
| 4945 // serialization implementation. |
| 4946 int set_flags = flags & ~HEADERS_FLAG_PAD_LOW & ~HEADERS_FLAG_PAD_HIGH; |
| 4947 SetFrameFlags(frame.get(), set_flags, spdy_version_); |
4764 | 4948 |
4765 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 4949 if (flags & ~(HEADERS_FLAG_END_HEADERS | |
| 4950 HEADERS_FLAG_PAD_LOW | |
| 4951 HEADERS_FLAG_PAD_HIGH)) { |
4766 EXPECT_CALL(visitor, OnError(_)); | 4952 EXPECT_CALL(visitor, OnError(_)); |
4767 } else { | 4953 } else { |
4768 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); | 4954 EXPECT_CALL(debug_visitor, OnReceiveCompressedFrame(42, CONTINUATION, _)); |
4769 EXPECT_CALL(visitor, OnContinuation(42, | 4955 EXPECT_CALL(visitor, OnContinuation(42, |
4770 flags & HEADERS_FLAG_END_HEADERS)); | 4956 flags & HEADERS_FLAG_END_HEADERS)); |
4771 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) | 4957 EXPECT_CALL(visitor, OnControlFrameHeaderData(42, _, _)) |
4772 .WillRepeatedly(testing::Return(true)); | 4958 .WillRepeatedly(testing::Return(true)); |
4773 } | 4959 } |
4774 | 4960 |
4775 framer.ProcessInput(frame0->data(), frame0->size()); | 4961 framer.ProcessInput(frame0->data(), frame0->size()); |
4776 framer.ProcessInput(frame->data(), frame->size()); | 4962 framer.ProcessInput(frame->data(), frame->size()); |
4777 if (flags & ~(HEADERS_FLAG_END_HEADERS)) { | 4963 if (flags & ~(HEADERS_FLAG_END_HEADERS | |
| 4964 HEADERS_FLAG_PAD_LOW | |
| 4965 HEADERS_FLAG_PAD_HIGH)) { |
4778 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); | 4966 EXPECT_EQ(SpdyFramer::SPDY_ERROR, framer.state()); |
4779 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, | 4967 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME_FLAGS, |
4780 framer.error_code()) | 4968 framer.error_code()) |
4781 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4969 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4782 } else { | 4970 } else { |
4783 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 4971 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4784 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 4972 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4785 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 4973 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4786 } | 4974 } |
4787 } | 4975 } |
4788 } | 4976 } |
4789 | 4977 |
| 4978 // TODO(mlavan): Add TEST_P(SpdyFramerTest, AltSvcFrameFlags) |
| 4979 |
| 4980 // TODO(hkhalil): Add TEST_P(SpdyFramerTest, BlockedFrameFlags) |
| 4981 |
4790 TEST_P(SpdyFramerTest, EmptySynStream) { | 4982 TEST_P(SpdyFramerTest, EmptySynStream) { |
4791 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 4983 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4792 testing::StrictMock<test::MockDebugVisitor> debug_visitor; | 4984 testing::StrictMock<test::MockDebugVisitor> debug_visitor; |
4793 SpdyFramer framer(spdy_version_); | 4985 SpdyFramer framer(spdy_version_); |
4794 framer.set_visitor(&visitor); | 4986 framer.set_visitor(&visitor); |
4795 framer.set_debug_visitor(&debug_visitor); | 4987 framer.set_debug_visitor(&debug_visitor); |
4796 | 4988 |
4797 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); | 4989 EXPECT_CALL(debug_visitor, OnSendCompressedFrame(1, SYN_STREAM, _, _)); |
4798 | 4990 |
4799 SpdySynStreamIR syn_stream(1); | 4991 SpdySynStreamIR syn_stream(1); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4931 } else { | 5123 } else { |
4932 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), | 5124 framer.ProcessInput(reinterpret_cast<const char*>(kV4FrameData), |
4933 arraysize(kV4FrameData)); | 5125 arraysize(kV4FrameData)); |
4934 } | 5126 } |
4935 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5127 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4936 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5128 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4937 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5129 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4938 } | 5130 } |
4939 | 5131 |
4940 TEST_P(SpdyFramerTest, OnBlocked) { | 5132 TEST_P(SpdyFramerTest, OnBlocked) { |
4941 if (spdy_version_ < SPDY4) { | 5133 if (spdy_version_ <= SPDY3) { |
4942 return; | 5134 return; |
4943 } | 5135 } |
4944 | 5136 |
4945 const SpdyStreamId kStreamId = 0; | 5137 const SpdyStreamId kStreamId = 0; |
4946 | 5138 |
4947 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; | 5139 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
4948 SpdyFramer framer(spdy_version_); | 5140 SpdyFramer framer(spdy_version_); |
4949 framer.set_visitor(&visitor); | 5141 framer.set_visitor(&visitor); |
4950 | 5142 |
4951 EXPECT_CALL(visitor, OnBlocked(kStreamId)); | 5143 EXPECT_CALL(visitor, OnBlocked(kStreamId)); |
4952 | 5144 |
4953 SpdyBlockedIR blocked_ir(0); | 5145 SpdyBlockedIR blocked_ir(0); |
4954 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); | 5146 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(blocked_ir)); |
4955 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); | 5147 framer.ProcessInput(frame->data(), framer.GetBlockedSize()); |
4956 | 5148 |
4957 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); | 5149 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
4958 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) | 5150 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
4959 << SpdyFramer::ErrorCodeToString(framer.error_code()); | 5151 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
4960 } | 5152 } |
4961 | 5153 |
| 5154 TEST_P(SpdyFramerTest, OnAltSvc) { |
| 5155 if (spdy_version_ <= SPDY3) { |
| 5156 return; |
| 5157 } |
| 5158 |
| 5159 const SpdyStreamId kStreamId = 1; |
| 5160 |
| 5161 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5162 SpdyFramer framer(spdy_version_); |
| 5163 framer.set_visitor(&visitor); |
| 5164 |
| 5165 EXPECT_CALL(visitor, OnAltSvc(kStreamId, |
| 5166 10, |
| 5167 443, |
| 5168 StringPiece("pid"), |
| 5169 StringPiece("h1"), |
| 5170 StringPiece("o1"))); |
| 5171 |
| 5172 SpdyAltSvcIR altsvc_ir(1); |
| 5173 altsvc_ir.set_max_age(10); |
| 5174 altsvc_ir.set_port(443); |
| 5175 altsvc_ir.set_protocol_id("pid"); |
| 5176 altsvc_ir.set_host("h1"); |
| 5177 altsvc_ir.set_origin("o1"); |
| 5178 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
| 5179 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + |
| 5180 altsvc_ir.protocol_id().length() + |
| 5181 altsvc_ir.host().length() + |
| 5182 altsvc_ir.origin().length()); |
| 5183 |
| 5184 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5185 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5186 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5187 } |
| 5188 |
| 5189 TEST_P(SpdyFramerTest, OnAltSvcNoOrigin) { |
| 5190 if (spdy_version_ <= SPDY3) { |
| 5191 return; |
| 5192 } |
| 5193 |
| 5194 const SpdyStreamId kStreamId = 1; |
| 5195 |
| 5196 testing::StrictMock<test::MockSpdyFramerVisitor> visitor; |
| 5197 SpdyFramer framer(spdy_version_); |
| 5198 framer.set_visitor(&visitor); |
| 5199 |
| 5200 EXPECT_CALL(visitor, OnAltSvc(kStreamId, |
| 5201 10, |
| 5202 443, |
| 5203 StringPiece("pid"), |
| 5204 StringPiece("h1"), |
| 5205 StringPiece(""))); |
| 5206 |
| 5207 SpdyAltSvcIR altsvc_ir(1); |
| 5208 altsvc_ir.set_max_age(10); |
| 5209 altsvc_ir.set_port(443); |
| 5210 altsvc_ir.set_protocol_id("pid"); |
| 5211 altsvc_ir.set_host("h1"); |
| 5212 scoped_ptr<SpdySerializedFrame> frame(framer.SerializeFrame(altsvc_ir)); |
| 5213 framer.ProcessInput(frame->data(), framer.GetAltSvcMinimumSize() + |
| 5214 altsvc_ir.protocol_id().length() + |
| 5215 altsvc_ir.host().length()); |
| 5216 |
| 5217 EXPECT_EQ(SpdyFramer::SPDY_RESET, framer.state()); |
| 5218 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, framer.error_code()) |
| 5219 << SpdyFramer::ErrorCodeToString(framer.error_code()); |
| 5220 } |
| 5221 |
| 5222 TEST_P(SpdyFramerTest, OnAltSvcBadLengths) { |
| 5223 if (spdy_version_ <= SPDY3) { |
| 5224 return; |
| 5225 } |
| 5226 |
| 5227 const char kType = static_cast<unsigned char>( |
| 5228 SpdyConstants::SerializeFrameType(spdy_version_, ALTSVC)); |
| 5229 { |
| 5230 TestSpdyVisitor visitor(spdy_version_); |
| 5231 SpdyFramer framer(spdy_version_); |
| 5232 framer.set_visitor(&visitor); |
| 5233 |
| 5234 const unsigned char kFrameDataLargePIDLen[] = { |
| 5235 0x00, 0x17, kType, 0x00, |
| 5236 0x00, 0x00, 0x00, 0x03, |
| 5237 0x00, 0x00, 0x00, 0x05, |
| 5238 0x01, 0xbb, 0x00, 0x05, // Port = 443 |
| 5239 'p', 'i', 'd', '1', // Protocol-ID |
| 5240 0x04, 'h', 'o', 's', |
| 5241 't', 'o', 'r', 'i', |
| 5242 'g', 'i', 'n', |
| 5243 }; |
| 5244 |
| 5245 visitor.SimulateInFramer(kFrameDataLargePIDLen, |
| 5246 sizeof(kFrameDataLargePIDLen)); |
| 5247 EXPECT_EQ(1, visitor.error_count_); |
| 5248 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5249 visitor.framer_.error_code()); |
| 5250 } |
| 5251 |
| 5252 { |
| 5253 TestSpdyVisitor visitor(spdy_version_); |
| 5254 SpdyFramer framer(spdy_version_); |
| 5255 framer.set_visitor(&visitor); |
| 5256 const unsigned char kFrameDataPIDLenLargerThanFrame[] = { |
| 5257 0x00, 0x17, kType, 0x00, |
| 5258 0x00, 0x00, 0x00, 0x03, |
| 5259 0x00, 0x00, 0x00, 0x05, |
| 5260 0x01, 0xbb, 0x00, 0x99, // Port = 443 |
| 5261 'p', 'i', 'd', '1', // Protocol-ID |
| 5262 0x04, 'h', 'o', 's', |
| 5263 't', 'o', 'r', 'i', |
| 5264 'g', 'i', 'n', |
| 5265 }; |
| 5266 |
| 5267 visitor.SimulateInFramer(kFrameDataPIDLenLargerThanFrame, |
| 5268 sizeof(kFrameDataPIDLenLargerThanFrame)); |
| 5269 EXPECT_EQ(1, visitor.error_count_); |
| 5270 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5271 visitor.framer_.error_code()); |
| 5272 } |
| 5273 |
| 5274 { |
| 5275 TestSpdyVisitor visitor(spdy_version_); |
| 5276 SpdyFramer framer(spdy_version_); |
| 5277 framer.set_visitor(&visitor); |
| 5278 |
| 5279 const unsigned char kFrameDataLargeHostLen[] = { |
| 5280 0x00, 0x17, kType, 0x00, |
| 5281 0x00, 0x00, 0x00, 0x03, |
| 5282 0x00, 0x00, 0x00, 0x05, |
| 5283 0x01, 0xbb, 0x00, 0x04, // Port = 443 |
| 5284 'p', 'i', 'd', '1', // Protocol-ID |
| 5285 0x0f, 'h', 'o', 's', |
| 5286 't', 'o', 'r', 'i', |
| 5287 'g', 'i', 'n', |
| 5288 }; |
| 5289 |
| 5290 visitor.SimulateInFramer(kFrameDataLargeHostLen, |
| 5291 sizeof(kFrameDataLargeHostLen)); |
| 5292 EXPECT_EQ(1, visitor.error_count_); |
| 5293 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5294 visitor.framer_.error_code()); |
| 5295 } |
| 5296 |
| 5297 { |
| 5298 TestSpdyVisitor visitor(spdy_version_); |
| 5299 SpdyFramer framer(spdy_version_); |
| 5300 framer.set_visitor(&visitor); |
| 5301 const unsigned char kFrameDataSmallPIDLen[] = { |
| 5302 0x00, 0x17, kType, 0x00, |
| 5303 0x00, 0x00, 0x00, 0x03, |
| 5304 0x00, 0x00, 0x00, 0x05, |
| 5305 0x01, 0xbb, 0x00, 0x01, // Port = 443 |
| 5306 'p', 'i', 'd', '1', // Protocol-ID |
| 5307 0x04, 'h', 'o', 's', |
| 5308 't', 'o', 'r', 'i', |
| 5309 'g', 'i', 'n', |
| 5310 }; |
| 5311 |
| 5312 visitor.SimulateInFramer(kFrameDataSmallPIDLen, |
| 5313 sizeof(kFrameDataSmallPIDLen)); |
| 5314 EXPECT_EQ(1, visitor.error_count_); |
| 5315 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5316 visitor.framer_.error_code()); |
| 5317 } |
| 5318 } |
| 5319 |
| 5320 // Tests handling of ALTSVC frames delivered in small chunks. |
| 5321 TEST_P(SpdyFramerTest, ReadChunkedAltSvcFrame) { |
| 5322 if (spdy_version_ <= SPDY3) { |
| 5323 return; |
| 5324 } |
| 5325 SpdyFramer framer(spdy_version_); |
| 5326 SpdyAltSvcIR altsvc_ir(1); |
| 5327 altsvc_ir.set_max_age(20); |
| 5328 altsvc_ir.set_port(443); |
| 5329 altsvc_ir.set_protocol_id("protocolid"); |
| 5330 altsvc_ir.set_host("hostname"); |
| 5331 |
| 5332 scoped_ptr<SpdyFrame> control_frame(framer.SerializeAltSvc(altsvc_ir)); |
| 5333 TestSpdyVisitor visitor(spdy_version_); |
| 5334 visitor.use_compression_ = false; |
| 5335 |
| 5336 // Read data in small chunks. |
| 5337 size_t framed_data = 0; |
| 5338 size_t unframed_data = control_frame->size(); |
| 5339 size_t kReadChunkSize = 5; // Read five bytes at a time. |
| 5340 while (unframed_data > 0) { |
| 5341 size_t to_read = min(kReadChunkSize, unframed_data); |
| 5342 visitor.SimulateInFramer( |
| 5343 reinterpret_cast<unsigned char*>(control_frame->data() + framed_data), |
| 5344 to_read); |
| 5345 unframed_data -= to_read; |
| 5346 framed_data += to_read; |
| 5347 } |
| 5348 EXPECT_EQ(0, visitor.error_count_); |
| 5349 EXPECT_EQ(1, visitor.altsvc_count_); |
| 5350 EXPECT_EQ(20u, visitor.test_altsvc_ir_.max_age()); |
| 5351 EXPECT_EQ(443u, visitor.test_altsvc_ir_.port()); |
| 5352 EXPECT_EQ("protocolid", visitor.test_altsvc_ir_.protocol_id()); |
| 5353 EXPECT_EQ("hostname", visitor.test_altsvc_ir_.host()); |
| 5354 } |
| 5355 |
| 5356 // Tests handling of PRIORITY frames. |
| 5357 TEST_P(SpdyFramerTest, ReadPriority) { |
| 5358 if (spdy_version_ <= SPDY3) { |
| 5359 return; |
| 5360 } |
| 5361 |
| 5362 const unsigned char kFrameData[] = { |
| 5363 0x00, 0x05, 0x02, 0x00, // PRIORITY frame |
| 5364 0x00, 0x00, 0x00, 0x03, // stream ID 3 |
| 5365 0x00, 0x00, 0x00, 0x01, // dependent on stream id 1 |
| 5366 0x00 // weight 0 |
| 5367 }; |
| 5368 |
| 5369 TestSpdyVisitor visitor(spdy_version_); |
| 5370 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 5371 |
| 5372 EXPECT_EQ(SpdyFramer::SPDY_RESET, visitor.framer_.state()); |
| 5373 EXPECT_EQ(SpdyFramer::SPDY_NO_ERROR, visitor.framer_.error_code()) |
| 5374 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 5375 } |
| 5376 |
| 5377 // Tests handling of PRIORITY frame with incorrect size. |
| 5378 TEST_P(SpdyFramerTest, ReadIncorrectlySizedPriority) { |
| 5379 if (spdy_version_ <= SPDY3) { |
| 5380 return; |
| 5381 } |
| 5382 |
| 5383 // PRIORITY frame of size 4, which isn't correct. |
| 5384 const unsigned char kFrameData[] = { |
| 5385 0x00, 0x04, 0x02, 0x00, |
| 5386 0x00, 0x00, 0x00, 0x03, |
| 5387 0x00, 0x00, 0x00, 0x01, |
| 5388 }; |
| 5389 |
| 5390 TestSpdyVisitor visitor(spdy_version_); |
| 5391 visitor.SimulateInFramer(kFrameData, sizeof(kFrameData)); |
| 5392 |
| 5393 EXPECT_EQ(SpdyFramer::SPDY_ERROR, visitor.framer_.state()); |
| 5394 EXPECT_EQ(SpdyFramer::SPDY_INVALID_CONTROL_FRAME, |
| 5395 visitor.framer_.error_code()) |
| 5396 << SpdyFramer::ErrorCodeToString(visitor.framer_.error_code()); |
| 5397 } |
| 5398 |
4962 } // namespace net | 5399 } // namespace net |
OLD | NEW |