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