| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/tools/flip_server/spdy_interface.h" | 5 #include "net/tools/flip_server/spdy_interface.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 class SpdySMServerTest : public SpdySMTestBase { | 201 class SpdySMServerTest : public SpdySMTestBase { |
| 202 public: | 202 public: |
| 203 SpdySMServerTest() : SpdySMTestBase(FLIP_HANDLER_SPDY_SERVER) {} | 203 SpdySMServerTest() : SpdySMTestBase(FLIP_HANDLER_SPDY_SERVER) {} |
| 204 virtual ~SpdySMServerTest() {} | 204 virtual ~SpdySMServerTest() {} |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 INSTANTIATE_TEST_CASE_P(SpdySMProxyTest, | 207 INSTANTIATE_TEST_CASE_P(SpdySMProxyTest, |
| 208 SpdySMProxyTest, | 208 SpdySMProxyTest, |
| 209 Values(SPDY2, SPDY3, SPDY4)); | 209 Values(SPDY3, SPDY4)); |
| 210 INSTANTIATE_TEST_CASE_P(SpdySMServerTest, SpdySMServerTest, Values(SPDY2)); | 210 INSTANTIATE_TEST_CASE_P(SpdySMServerTest, SpdySMServerTest, Values(SPDY4)); |
| 211 | 211 |
| 212 TEST_P(SpdySMProxyTest, InitSMConnection) { | 212 TEST_P(SpdySMProxyTest, InitSMConnection) { |
| 213 { | 213 { |
| 214 InSequence s; | 214 InSequence s; |
| 215 EXPECT_CALL(*connection_, InitSMConnection(_, _, _, _, _, _, _, _)); | 215 EXPECT_CALL(*connection_, InitSMConnection(_, _, _, _, _, _, _, _)); |
| 216 } | 216 } |
| 217 interface_->InitSMConnection( | 217 interface_->InitSMConnection( |
| 218 NULL, NULL, epoll_server_.get(), -1, "", "", "", false); | 218 NULL, NULL, epoll_server_.get(), -1, "", "", "", false); |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST_P(SpdySMProxyTest, OnSynStream_SPDY2) { | 221 TEST_P(SpdySMProxyTest, OnStreamFrameData) { |
| 222 if (GetParam() != SPDY2) { | |
| 223 // This test case is for SPDY2. | |
| 224 return; | |
| 225 } | |
| 226 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); | 222 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); |
| 227 scoped_ptr<MockSMInterface> mock_interface(new MockSMInterface); | 223 scoped_ptr<MockSMInterface> mock_interface(new MockSMInterface); |
| 228 uint32 stream_id = 92; | 224 uint32 stream_id = 92; |
| 229 uint32 associated_id = 43; | |
| 230 std::string expected = "GET /path HTTP/1.0\r\n" | |
| 231 "Host: 127.0.0.1\r\n" | |
| 232 "hoge: fuga\r\n\r\n"; | |
| 233 SpdyHeaderBlock block; | |
| 234 block["method"] = "GET"; | |
| 235 block["url"] = "/path"; | |
| 236 block["scheme"] = "http"; | |
| 237 block["version"] = "HTTP/1.0"; | |
| 238 block["hoge"] = "fuga"; | |
| 239 StringSaver saver; | |
| 240 { | |
| 241 InSequence s; | |
| 242 EXPECT_CALL(*interface_, FindOrMakeNewSMConnectionInterface(_, _)) | |
| 243 .WillOnce(Return(mock_interface.get())); | |
| 244 EXPECT_CALL(*mock_interface, SetStreamID(stream_id)); | |
| 245 EXPECT_CALL(*mock_interface, ProcessWriteInput(_, _)) | |
| 246 .WillOnce(DoAll(SaveArg<0>(&saver.data), | |
| 247 SaveArg<1>(&saver.size), | |
| 248 InvokeWithoutArgs(&saver, &StringSaver::Save), | |
| 249 Return(0))); | |
| 250 } | |
| 251 visitor->OnSynStream(stream_id, associated_id, 0, false, false, block); | |
| 252 ASSERT_EQ(expected, saver.string); | |
| 253 } | |
| 254 | |
| 255 TEST_P(SpdySMProxyTest, OnSynStream) { | |
| 256 if (GetParam() == SPDY2) { | |
| 257 // This test case is not for SPDY2. | |
| 258 return; | |
| 259 } | |
| 260 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); | |
| 261 scoped_ptr<MockSMInterface> mock_interface(new MockSMInterface); | |
| 262 uint32 stream_id = 92; | |
| 263 uint32 associated_id = 43; | |
| 264 std::string expected = "GET /path HTTP/1.1\r\n" | |
| 265 "Host: 127.0.0.1\r\n" | |
| 266 "foo: bar\r\n\r\n"; | |
| 267 SpdyHeaderBlock block; | |
| 268 block[":method"] = "GET"; | |
| 269 block[":host"] = "www.example.com"; | |
| 270 block[":path"] = "/path"; | |
| 271 block[":scheme"] = "http"; | |
| 272 block["foo"] = "bar"; | |
| 273 StringSaver saver; | |
| 274 { | |
| 275 InSequence s; | |
| 276 EXPECT_CALL(*interface_, | |
| 277 FindOrMakeNewSMConnectionInterface(_, _)) | |
| 278 .WillOnce(Return(mock_interface.get())); | |
| 279 EXPECT_CALL(*mock_interface, SetStreamID(stream_id)); | |
| 280 EXPECT_CALL(*mock_interface, ProcessWriteInput(_, _)) | |
| 281 .WillOnce(DoAll(SaveArg<0>(&saver.data), | |
| 282 SaveArg<1>(&saver.size), | |
| 283 InvokeWithoutArgs(&saver, &StringSaver::Save), | |
| 284 Return(0))); | |
| 285 } | |
| 286 visitor->OnSynStream(stream_id, associated_id, 0, false, false, block); | |
| 287 ASSERT_EQ(expected, saver.string); | |
| 288 } | |
| 289 | |
| 290 TEST_P(SpdySMProxyTest, OnStreamFrameData_SPDY2) { | |
| 291 if (GetParam() != SPDY2) { | |
| 292 // This test case is for SPDY2. | |
| 293 return; | |
| 294 } | |
| 295 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); | |
| 296 scoped_ptr<MockSMInterface> mock_interface(new MockSMInterface); | |
| 297 uint32 stream_id = 92; | |
| 298 uint32 associated_id = 43; | |
| 299 SpdyHeaderBlock block; | |
| 300 testing::MockFunction<void(int)> checkpoint; // NOLINT | |
| 301 | |
| 302 scoped_ptr<SpdyFrame> frame(spdy_framer_->CreatePingFrame(12, false)); | |
| 303 block["method"] = "GET"; | |
| 304 block["url"] = "http://www.example.com/path"; | |
| 305 block["scheme"] = "http"; | |
| 306 block["version"] = "HTTP/1.0"; | |
| 307 { | |
| 308 InSequence s; | |
| 309 EXPECT_CALL(*interface_, FindOrMakeNewSMConnectionInterface(_, _)) | |
| 310 .WillOnce(Return(mock_interface.get())); | |
| 311 EXPECT_CALL(*mock_interface, SetStreamID(stream_id)); | |
| 312 EXPECT_CALL(*mock_interface, ProcessWriteInput(_, _)).Times(1); | |
| 313 EXPECT_CALL(checkpoint, Call(0)); | |
| 314 EXPECT_CALL(*mock_interface, | |
| 315 ProcessWriteInput(frame->data(), frame->size())).Times(1); | |
| 316 } | |
| 317 | |
| 318 visitor->OnSynStream(stream_id, associated_id, 0, false, false, block); | |
| 319 checkpoint.Call(0); | |
| 320 visitor->OnStreamFrameData(stream_id, frame->data(), frame->size(), true); | |
| 321 } | |
| 322 | |
| 323 TEST_P(SpdySMProxyTest, OnStreamFrameData) { | |
| 324 if (GetParam() == SPDY2) { | |
| 325 // This test case is not for SPDY2. | |
| 326 return; | |
| 327 } | |
| 328 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); | |
| 329 scoped_ptr<MockSMInterface> mock_interface(new MockSMInterface); | |
| 330 uint32 stream_id = 92; | |
| 331 uint32 associated_id = 43; | 225 uint32 associated_id = 43; |
| 332 SpdyHeaderBlock block; | 226 SpdyHeaderBlock block; |
| 333 testing::MockFunction<void(int)> checkpoint; // NOLINT | 227 testing::MockFunction<void(int)> checkpoint; // NOLINT |
| 334 | 228 |
| 335 scoped_ptr<SpdyFrame> frame(spdy_framer_->CreatePingFrame(12, false)); | 229 scoped_ptr<SpdyFrame> frame(spdy_framer_->CreatePingFrame(12, false)); |
| 336 block[":method"] = "GET"; | 230 block[":method"] = "GET"; |
| 337 block[":host"] = "www.example.com"; | 231 block[":host"] = "www.example.com"; |
| 338 block[":path"] = "/path"; | 232 block[":path"] = "/path"; |
| 339 block[":scheme"] = "http"; | 233 block[":scheme"] = "http"; |
| 340 block["foo"] = "bar"; | 234 block["foo"] = "bar"; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 interface_->ProcessReadInput(input, sizeof(input)); | 294 interface_->ProcessReadInput(input, sizeof(input)); |
| 401 ASSERT_NE(SpdyFramer::SPDY_RESET, interface_->spdy_framer()->state()); | 295 ASSERT_NE(SpdyFramer::SPDY_RESET, interface_->spdy_framer()->state()); |
| 402 | 296 |
| 403 interface_->ResetForNewConnection(); | 297 interface_->ResetForNewConnection(); |
| 404 ASSERT_FALSE(HasStream(stream_id)); | 298 ASSERT_FALSE(HasStream(stream_id)); |
| 405 ASSERT_TRUE(interface_->spdy_framer() == NULL); | 299 ASSERT_TRUE(interface_->spdy_framer() == NULL); |
| 406 } | 300 } |
| 407 | 301 |
| 408 TEST_P(SpdySMProxyTest, CreateFramer) { | 302 TEST_P(SpdySMProxyTest, CreateFramer) { |
| 409 interface_->ResetForNewConnection(); | 303 interface_->ResetForNewConnection(); |
| 410 interface_->CreateFramer(SPDY2); | |
| 411 ASSERT_TRUE(interface_->spdy_framer() != NULL); | |
| 412 ASSERT_EQ(interface_->spdy_version(), SPDY2); | |
| 413 | |
| 414 interface_->ResetForNewConnection(); | |
| 415 interface_->CreateFramer(SPDY3); | 304 interface_->CreateFramer(SPDY3); |
| 416 ASSERT_TRUE(interface_->spdy_framer() != NULL); | 305 ASSERT_TRUE(interface_->spdy_framer() != NULL); |
| 417 ASSERT_EQ(interface_->spdy_version(), SPDY3); | 306 ASSERT_EQ(interface_->spdy_version(), SPDY3); |
| 307 |
| 308 interface_->ResetForNewConnection(); |
| 309 interface_->CreateFramer(SPDY4); |
| 310 ASSERT_TRUE(interface_->spdy_framer() != NULL); |
| 311 ASSERT_EQ(interface_->spdy_version(), SPDY4); |
| 418 } | 312 } |
| 419 | 313 |
| 420 TEST_P(SpdySMProxyTest, PostAcceptHook) { | 314 TEST_P(SpdySMProxyTest, PostAcceptHook) { |
| 421 interface_->PostAcceptHook(); | 315 interface_->PostAcceptHook(); |
| 422 | 316 |
| 423 ASSERT_EQ(1u, connection_->output_list()->size()); | 317 ASSERT_EQ(1u, connection_->output_list()->size()); |
| 424 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | 318 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); |
| 425 DataFrame* df = *i++; | 319 DataFrame* df = *i++; |
| 426 | 320 |
| 427 { | 321 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 448 BalsaHeaders headers; | 342 BalsaHeaders headers; |
| 449 std::string filename = "foobar"; | 343 std::string filename = "foobar"; |
| 450 memory_cache_->InsertFile(&headers, filename, ""); | 344 memory_cache_->InsertFile(&headers, filename, ""); |
| 451 mci.file_data = memory_cache_->GetFileData(filename); | 345 mci.file_data = memory_cache_->GetFileData(filename); |
| 452 } | 346 } |
| 453 | 347 |
| 454 interface_->AddToOutputOrder(mci); | 348 interface_->AddToOutputOrder(mci); |
| 455 ASSERT_TRUE(HasStream(stream_id)); | 349 ASSERT_TRUE(HasStream(stream_id)); |
| 456 } | 350 } |
| 457 | 351 |
| 458 TEST_P(SpdySMProxyTest, SendErrorNotFound_SPDY2) { | 352 TEST_P(SpdySMProxyTest, SendErrorNotFound) { |
| 459 if (GetParam() != SPDY2) { | |
| 460 // This test is for SPDY2. | |
| 461 return; | |
| 462 } | |
| 463 uint32 stream_id = 82; | 353 uint32 stream_id = 82; |
| 464 SpdyHeaderBlock actual_header_block; | 354 SpdyHeaderBlock actual_header_block; |
| 465 const char* actual_data; | 355 const char* actual_data; |
| 466 size_t actual_size; | |
| 467 testing::MockFunction<void(int)> checkpoint; // NOLINT | |
| 468 | |
| 469 interface_->SendErrorNotFound(stream_id); | |
| 470 | |
| 471 ASSERT_EQ(2u, connection_->output_list()->size()); | |
| 472 | |
| 473 { | |
| 474 InSequence s; | |
| 475 if (GetParam() < SPDY4) { | |
| 476 EXPECT_CALL(*spdy_framer_visitor_, OnSynReply(stream_id, false, _)) | |
| 477 .WillOnce(SaveArg<2>(&actual_header_block)); | |
| 478 } else { | |
| 479 EXPECT_CALL(*spdy_framer_visitor_, | |
| 480 OnHeaders(stream_id, false, 0, false, _)) | |
| 481 .WillOnce(SaveArg<4>(&actual_header_block)); | |
| 482 } | |
| 483 EXPECT_CALL(checkpoint, Call(0)); | |
| 484 EXPECT_CALL(*spdy_framer_visitor_, | |
| 485 OnDataFrameHeader(stream_id, _, true)); | |
| 486 EXPECT_CALL(*spdy_framer_visitor_, | |
| 487 OnStreamFrameData(stream_id, _, _, false)).Times(1) | |
| 488 .WillOnce(DoAll(SaveArg<1>(&actual_data), | |
| 489 SaveArg<2>(&actual_size))); | |
| 490 EXPECT_CALL(*spdy_framer_visitor_, | |
| 491 OnStreamFrameData(stream_id, NULL, 0, true)).Times(1); | |
| 492 } | |
| 493 | |
| 494 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | |
| 495 DataFrame* df = *i++; | |
| 496 spdy_framer_->ProcessInput(df->data, df->size); | |
| 497 checkpoint.Call(0); | |
| 498 df = *i++; | |
| 499 spdy_framer_->ProcessInput(df->data, df->size); | |
| 500 | |
| 501 ASSERT_EQ(2, spdy_framer_->frames_received()); | |
| 502 ASSERT_EQ(2u, actual_header_block.size()); | |
| 503 ASSERT_EQ("404 Not Found", actual_header_block["status"]); | |
| 504 ASSERT_EQ("HTTP/1.1", actual_header_block["version"]); | |
| 505 ASSERT_EQ("wtf?", StringPiece(actual_data, actual_size)); | |
| 506 } | |
| 507 | |
| 508 TEST_P(SpdySMProxyTest, SendErrorNotFound) { | |
| 509 if (GetParam() == SPDY2) { | |
| 510 // This test is not for SPDY2. | |
| 511 return; | |
| 512 } | |
| 513 uint32 stream_id = 82; | |
| 514 SpdyHeaderBlock actual_header_block; | |
| 515 const char* actual_data; | |
| 516 size_t actual_size; | 356 size_t actual_size; |
| 517 testing::MockFunction<void(int)> checkpoint; // NOLINT | 357 testing::MockFunction<void(int)> checkpoint; // NOLINT |
| 518 | 358 |
| 519 interface_->SendErrorNotFound(stream_id); | 359 interface_->SendErrorNotFound(stream_id); |
| 520 | 360 |
| 521 ASSERT_EQ(2u, connection_->output_list()->size()); | 361 ASSERT_EQ(2u, connection_->output_list()->size()); |
| 522 | 362 |
| 523 { | 363 { |
| 524 InSequence s; | 364 InSequence s; |
| 525 if (GetParam() < SPDY4) { | 365 if (GetParam() < SPDY4) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 549 df = *i++; | 389 df = *i++; |
| 550 spdy_framer_->ProcessInput(df->data, df->size); | 390 spdy_framer_->ProcessInput(df->data, df->size); |
| 551 | 391 |
| 552 ASSERT_EQ(2, spdy_framer_->frames_received()); | 392 ASSERT_EQ(2, spdy_framer_->frames_received()); |
| 553 ASSERT_EQ(2u, actual_header_block.size()); | 393 ASSERT_EQ(2u, actual_header_block.size()); |
| 554 ASSERT_EQ("404 Not Found", actual_header_block[":status"]); | 394 ASSERT_EQ("404 Not Found", actual_header_block[":status"]); |
| 555 ASSERT_EQ("HTTP/1.1", actual_header_block[":version"]); | 395 ASSERT_EQ("HTTP/1.1", actual_header_block[":version"]); |
| 556 ASSERT_EQ("wtf?", StringPiece(actual_data, actual_size)); | 396 ASSERT_EQ("wtf?", StringPiece(actual_data, actual_size)); |
| 557 } | 397 } |
| 558 | 398 |
| 559 TEST_P(SpdySMProxyTest, SendSynStream_SPDY2) { | 399 TEST_P(SpdySMProxyTest, SendSynStream) { |
| 560 if (GetParam() != SPDY2) { | |
| 561 // This test is for SPDY2. | |
| 562 return; | |
| 563 } | |
| 564 uint32 stream_id = 82; | 400 uint32 stream_id = 82; |
| 565 BalsaHeaders headers; | 401 BalsaHeaders headers; |
| 566 SpdyHeaderBlock actual_header_block; | 402 SpdyHeaderBlock actual_header_block; |
| 567 headers.AppendHeader("key1", "value1"); | |
| 568 headers.SetRequestFirstlineFromStringPieces("GET", "/path", "HTTP/1.0"); | |
| 569 | |
| 570 interface_->SendSynStream(stream_id, headers); | |
| 571 | |
| 572 ASSERT_EQ(1u, connection_->output_list()->size()); | |
| 573 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | |
| 574 DataFrame* df = *i++; | |
| 575 | |
| 576 { | |
| 577 InSequence s; | |
| 578 EXPECT_CALL(*spdy_framer_visitor_, | |
| 579 OnSynStream(stream_id, 0, _, false, false, _)) | |
| 580 .WillOnce(SaveArg<5>(&actual_header_block)); | |
| 581 } | |
| 582 | |
| 583 spdy_framer_->ProcessInput(df->data, df->size); | |
| 584 ASSERT_EQ(1, spdy_framer_->frames_received()); | |
| 585 ASSERT_EQ(4u, actual_header_block.size()); | |
| 586 ASSERT_EQ("GET", actual_header_block["method"]); | |
| 587 ASSERT_EQ("HTTP/1.0", actual_header_block["version"]); | |
| 588 ASSERT_EQ("/path", actual_header_block["url"]); | |
| 589 ASSERT_EQ("value1", actual_header_block["key1"]); | |
| 590 } | |
| 591 | |
| 592 TEST_P(SpdySMProxyTest, SendSynStream) { | |
| 593 if (GetParam() == SPDY2) { | |
| 594 // This test is not for SPDY2. | |
| 595 return; | |
| 596 } | |
| 597 uint32 stream_id = 82; | |
| 598 BalsaHeaders headers; | |
| 599 SpdyHeaderBlock actual_header_block; | |
| 600 headers.AppendHeader("key1", "value1"); | 403 headers.AppendHeader("key1", "value1"); |
| 601 headers.AppendHeader("Host", "www.example.com"); | 404 headers.AppendHeader("Host", "www.example.com"); |
| 602 headers.SetRequestFirstlineFromStringPieces("GET", "/path", "HTTP/1.1"); | 405 headers.SetRequestFirstlineFromStringPieces("GET", "/path", "HTTP/1.1"); |
| 603 | 406 |
| 604 interface_->SendSynStream(stream_id, headers); | 407 interface_->SendSynStream(stream_id, headers); |
| 605 | 408 |
| 606 ASSERT_EQ(1u, connection_->output_list()->size()); | 409 ASSERT_EQ(1u, connection_->output_list()->size()); |
| 607 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | 410 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); |
| 608 DataFrame* df = *i++; | 411 DataFrame* df = *i++; |
| 609 | 412 |
| 610 { | 413 { |
| 611 InSequence s; | 414 InSequence s; |
| 612 EXPECT_CALL(*spdy_framer_visitor_, | 415 EXPECT_CALL(*spdy_framer_visitor_, |
| 613 OnSynStream(stream_id, 0, _, false, false, _)) | 416 OnSynStream(stream_id, 0, _, false, false, _)) |
| 614 .WillOnce(SaveArg<5>(&actual_header_block)); | 417 .WillOnce(SaveArg<5>(&actual_header_block)); |
| 615 } | 418 } |
| 616 | 419 |
| 617 spdy_framer_->ProcessInput(df->data, df->size); | 420 spdy_framer_->ProcessInput(df->data, df->size); |
| 618 ASSERT_EQ(1, spdy_framer_->frames_received()); | 421 ASSERT_EQ(1, spdy_framer_->frames_received()); |
| 619 ASSERT_EQ(5u, actual_header_block.size()); | 422 ASSERT_EQ(5u, actual_header_block.size()); |
| 620 ASSERT_EQ("GET", actual_header_block[":method"]); | 423 ASSERT_EQ("GET", actual_header_block[":method"]); |
| 621 ASSERT_EQ("HTTP/1.1", actual_header_block[":version"]); | 424 ASSERT_EQ("HTTP/1.1", actual_header_block[":version"]); |
| 622 ASSERT_EQ("/path", actual_header_block[":path"]); | 425 ASSERT_EQ("/path", actual_header_block[":path"]); |
| 623 ASSERT_EQ("www.example.com", actual_header_block[":host"]); | 426 ASSERT_EQ("www.example.com", actual_header_block[":host"]); |
| 624 ASSERT_EQ("value1", actual_header_block["key1"]); | 427 ASSERT_EQ("value1", actual_header_block["key1"]); |
| 625 } | 428 } |
| 626 | 429 |
| 627 TEST_P(SpdySMProxyTest, SendSynReply_SPDY2) { | |
| 628 if (GetParam() != SPDY2) { | |
| 629 // This test is for SPDY2. | |
| 630 return; | |
| 631 } | |
| 632 uint32 stream_id = 82; | |
| 633 BalsaHeaders headers; | |
| 634 SpdyHeaderBlock actual_header_block; | |
| 635 headers.AppendHeader("key1", "value1"); | |
| 636 headers.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "OK"); | |
| 637 | |
| 638 interface_->SendSynReply(stream_id, headers); | |
| 639 | |
| 640 ASSERT_EQ(1u, connection_->output_list()->size()); | |
| 641 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | |
| 642 DataFrame* df = *i++; | |
| 643 | |
| 644 { | |
| 645 InSequence s; | |
| 646 if (GetParam() < SPDY4) { | |
| 647 EXPECT_CALL(*spdy_framer_visitor_, OnSynReply(stream_id, false, _)) | |
| 648 .WillOnce(SaveArg<2>(&actual_header_block)); | |
| 649 } else { | |
| 650 EXPECT_CALL(*spdy_framer_visitor_, | |
| 651 OnHeaders(stream_id, false, 0, false, _)) | |
| 652 .WillOnce(SaveArg<4>(&actual_header_block)); | |
| 653 } | |
| 654 } | |
| 655 | |
| 656 spdy_framer_->ProcessInput(df->data, df->size); | |
| 657 ASSERT_EQ(1, spdy_framer_->frames_received()); | |
| 658 ASSERT_EQ(3u, actual_header_block.size()); | |
| 659 ASSERT_EQ("200 OK", actual_header_block["status"]); | |
| 660 ASSERT_EQ("HTTP/1.1", actual_header_block["version"]); | |
| 661 ASSERT_EQ("value1", actual_header_block["key1"]); | |
| 662 } | |
| 663 | |
| 664 TEST_P(SpdySMProxyTest, SendSynReply) { | 430 TEST_P(SpdySMProxyTest, SendSynReply) { |
| 665 if (GetParam() == SPDY2) { | |
| 666 // This test is not for SPDY2. | |
| 667 return; | |
| 668 } | |
| 669 uint32 stream_id = 82; | 431 uint32 stream_id = 82; |
| 670 BalsaHeaders headers; | 432 BalsaHeaders headers; |
| 671 SpdyHeaderBlock actual_header_block; | 433 SpdyHeaderBlock actual_header_block; |
| 672 headers.AppendHeader("key1", "value1"); | 434 headers.AppendHeader("key1", "value1"); |
| 673 headers.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "OK"); | 435 headers.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "OK"); |
| 674 | 436 |
| 675 interface_->SendSynReply(stream_id, headers); | 437 interface_->SendSynReply(stream_id, headers); |
| 676 | 438 |
| 677 ASSERT_EQ(1u, connection_->output_list()->size()); | 439 ASSERT_EQ(1u, connection_->output_list()->size()); |
| 678 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | 440 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 df = *i++; | 518 df = *i++; |
| 757 spdy_framer_->ProcessInput(df->data, df->size); | 519 spdy_framer_->ProcessInput(df->data, df->size); |
| 758 ASSERT_EQ(std::string(kSpdySegmentSize, 'b'), | 520 ASSERT_EQ(std::string(kSpdySegmentSize, 'b'), |
| 759 StringPiece(actual_data, actual_size)); | 521 StringPiece(actual_data, actual_size)); |
| 760 | 522 |
| 761 df = *i++; | 523 df = *i++; |
| 762 spdy_framer_->ProcessInput(df->data, df->size); | 524 spdy_framer_->ProcessInput(df->data, df->size); |
| 763 ASSERT_EQ("c", StringPiece(actual_data, actual_size)); | 525 ASSERT_EQ("c", StringPiece(actual_data, actual_size)); |
| 764 } | 526 } |
| 765 | 527 |
| 766 TEST_P(SpdySMProxyTest, SendEOF_SPDY2) { | |
| 767 // This test is for SPDY2. | |
| 768 if (GetParam() != SPDY2) { | |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 uint32 stream_id = 82; | |
| 773 // SPDY2 data frame | |
| 774 char empty_data_frame[] = {'\0', '\0', '\0', '\x52', '\x1', '\0', '\0', '\0'}; | |
| 775 MemCacheIter mci; | |
| 776 mci.stream_id = stream_id; | |
| 777 | |
| 778 { | |
| 779 BalsaHeaders headers; | |
| 780 std::string filename = "foobar"; | |
| 781 memory_cache_->InsertFile(&headers, filename, ""); | |
| 782 mci.file_data = memory_cache_->GetFileData(filename); | |
| 783 } | |
| 784 | |
| 785 interface_->AddToOutputOrder(mci); | |
| 786 ASSERT_TRUE(HasStream(stream_id)); | |
| 787 interface_->SendEOF(stream_id); | |
| 788 ASSERT_FALSE(HasStream(stream_id)); | |
| 789 | |
| 790 ASSERT_EQ(1u, connection_->output_list()->size()); | |
| 791 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | |
| 792 DataFrame* df = *i++; | |
| 793 ASSERT_EQ(StringPiece(empty_data_frame, sizeof(empty_data_frame)), | |
| 794 StringPiece(df->data, df->size)); | |
| 795 } | |
| 796 | |
| 797 TEST_P(SpdySMProxyTest, SendEmptyDataFrame_SPDY2) { | |
| 798 // This test is for SPDY2. | |
| 799 if (GetParam() != SPDY2) { | |
| 800 return; | |
| 801 } | |
| 802 | |
| 803 uint32 stream_id = 133; | |
| 804 SpdyDataFlags flags = DATA_FLAG_NONE; | |
| 805 // SPDY2 data frame | |
| 806 char expected[] = {'\0', '\0', '\0', '\x85', '\0', '\0', '\0', '\0'}; | |
| 807 | |
| 808 interface_->SendDataFrame(stream_id, "hello", 0, flags, true); | |
| 809 | |
| 810 ASSERT_EQ(1u, connection_->output_list()->size()); | |
| 811 std::list<DataFrame*>::const_iterator i = connection_->output_list()->begin(); | |
| 812 DataFrame* df = *i++; | |
| 813 | |
| 814 ASSERT_EQ(StringPiece(expected, sizeof(expected)), | |
| 815 StringPiece(df->data, df->size)); | |
| 816 } | |
| 817 | |
| 818 TEST_P(SpdySMServerTest, OnSynStream) { | 528 TEST_P(SpdySMServerTest, OnSynStream) { |
| 819 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); | 529 BufferedSpdyFramerVisitorInterface* visitor = interface_.get(); |
| 820 uint32 stream_id = 82; | 530 uint32 stream_id = 82; |
| 821 SpdyHeaderBlock spdy_headers; | 531 SpdyHeaderBlock spdy_headers; |
| 822 spdy_headers["url"] = "http://www.example.com/path"; | 532 spdy_headers["url"] = "http://www.example.com/path"; |
| 823 spdy_headers["method"] = "GET"; | 533 spdy_headers["method"] = "GET"; |
| 824 spdy_headers["scheme"] = "http"; | 534 spdy_headers["scheme"] = "http"; |
| 825 spdy_headers["version"] = "HTTP/1.1"; | 535 spdy_headers["version"] = "HTTP/1.1"; |
| 826 | 536 |
| 827 { | 537 { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 ASSERT_EQ(2, spdy_framer_->frames_received()); | 597 ASSERT_EQ(2, spdy_framer_->frames_received()); |
| 888 ASSERT_EQ(2u, actual_header_block.size()); | 598 ASSERT_EQ(2u, actual_header_block.size()); |
| 889 ASSERT_EQ("404 Not Found", actual_header_block["status"]); | 599 ASSERT_EQ("404 Not Found", actual_header_block["status"]); |
| 890 ASSERT_EQ("HTTP/1.1", actual_header_block["version"]); | 600 ASSERT_EQ("HTTP/1.1", actual_header_block["version"]); |
| 891 ASSERT_EQ("wtf?", StringPiece(actual_data, actual_size)); | 601 ASSERT_EQ("wtf?", StringPiece(actual_data, actual_size)); |
| 892 } | 602 } |
| 893 | 603 |
| 894 } // namespace | 604 } // namespace |
| 895 | 605 |
| 896 } // namespace net | 606 } // namespace net |
| OLD | NEW |