| 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 "net/quic/quic_chromium_client_stream.h" | 5 #include "net/quic/quic_chromium_client_stream.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "net/quic/quic_chromium_client_session.h" | 14 #include "net/quic/quic_chromium_client_session.h" |
| 15 #include "net/quic/quic_client_session_base.h" | 15 #include "net/quic/quic_client_session_base.h" |
| 16 #include "net/quic/quic_utils.h" | 16 #include "net/quic/quic_utils.h" |
| 17 #include "net/quic/spdy_utils.h" | 17 #include "net/quic/spdy_utils.h" |
| 18 #include "net/quic/test_tools/crypto_test_utils.h" | 18 #include "net/quic/test_tools/crypto_test_utils.h" |
| 19 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
| 20 #include "net/test/gtest_util.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gmock_mutant.h" | 22 #include "testing/gmock_mutant.h" |
| 22 | 23 |
| 24 using net::test::IsError; |
| 25 using net::test::IsOk; |
| 26 |
| 23 using testing::AnyNumber; | 27 using testing::AnyNumber; |
| 24 using testing::CreateFunctor; | 28 using testing::CreateFunctor; |
| 25 using testing::Invoke; | 29 using testing::Invoke; |
| 26 using testing::Return; | 30 using testing::Return; |
| 27 using testing::StrEq; | 31 using testing::StrEq; |
| 28 using testing::_; | 32 using testing::_; |
| 29 | 33 |
| 30 namespace net { | 34 namespace net { |
| 31 namespace test { | 35 namespace test { |
| 32 namespace { | 36 namespace { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 testing::Invoke(CreateFunctor( | 398 testing::Invoke(CreateFunctor( |
| 395 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this), | 399 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this), |
| 396 StringPiece(data, arraysize(data) - 1))), | 400 StringPiece(data, arraysize(data) - 1))), |
| 397 testing::Invoke([&run_loop]() { run_loop.Quit(); }))); | 401 testing::Invoke([&run_loop]() { run_loop.Quit(); }))); |
| 398 | 402 |
| 399 // Wait for the read to complete. | 403 // Wait for the read to complete. |
| 400 run_loop.Run(); | 404 run_loop.Run(); |
| 401 | 405 |
| 402 // Read again, and it will be pending. | 406 // Read again, and it will be pending. |
| 403 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); | 407 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); |
| 404 EXPECT_EQ(ERR_IO_PENDING, stream_->Read(buffer.get(), 1)); | 408 EXPECT_THAT(stream_->Read(buffer.get(), 1), IsError(ERR_IO_PENDING)); |
| 405 | 409 |
| 406 SpdyHeaderBlock trailers; | 410 SpdyHeaderBlock trailers; |
| 407 trailers["bar"] = "foo"; | 411 trailers["bar"] = "foo"; |
| 408 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); | 412 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); |
| 409 std::string uncompressed_trailers = | 413 std::string uncompressed_trailers = |
| 410 SpdyUtils::SerializeUncompressedHeaders(trailers); | 414 SpdyUtils::SerializeUncompressedHeaders(trailers); |
| 411 | 415 |
| 412 stream_->OnStreamHeaders(uncompressed_trailers); | 416 stream_->OnStreamHeaders(uncompressed_trailers); |
| 413 stream_->OnStreamHeadersComplete(true, uncompressed_trailers.length()); | 417 stream_->OnStreamHeadersComplete(true, uncompressed_trailers.length()); |
| 414 EXPECT_FALSE(stream_->IsDoneReading()); | 418 EXPECT_FALSE(stream_->IsDoneReading()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 EXPECT_EQ(ERR_IO_PENDING, | 478 EXPECT_EQ(ERR_IO_PENDING, |
| 475 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true, | 479 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true, |
| 476 callback.callback())); | 480 callback.callback())); |
| 477 ASSERT_FALSE(callback.have_result()); | 481 ASSERT_FALSE(callback.have_result()); |
| 478 | 482 |
| 479 // All data written. | 483 // All data written. |
| 480 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 484 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
| 481 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 485 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
| 482 stream_->OnCanWrite(); | 486 stream_->OnCanWrite(); |
| 483 ASSERT_TRUE(callback.have_result()); | 487 ASSERT_TRUE(callback.have_result()); |
| 484 EXPECT_EQ(OK, callback.WaitForResult()); | 488 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 485 } | 489 } |
| 486 | 490 |
| 487 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) { | 491 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) { |
| 488 EXPECT_CALL(delegate_, OnClose()); | 492 EXPECT_CALL(delegate_, OnClose()); |
| 489 | 493 |
| 490 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); | 494 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); |
| 491 scoped_refptr<StringIOBuffer> buf2( | 495 scoped_refptr<StringIOBuffer> buf2( |
| 492 new StringIOBuffer("Just a small payload")); | 496 new StringIOBuffer("Just a small payload")); |
| 493 | 497 |
| 494 // All data written. | 498 // All data written. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 520 stream_->WritevStreamData({buf1.get(), buf2.get()}, | 524 stream_->WritevStreamData({buf1.get(), buf2.get()}, |
| 521 {buf1->size(), buf2->size()}, true, | 525 {buf1->size(), buf2->size()}, true, |
| 522 callback.callback())); | 526 callback.callback())); |
| 523 ASSERT_FALSE(callback.have_result()); | 527 ASSERT_FALSE(callback.have_result()); |
| 524 | 528 |
| 525 // The second piece of data is written. | 529 // The second piece of data is written. |
| 526 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 530 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
| 527 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); | 531 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); |
| 528 stream_->OnCanWrite(); | 532 stream_->OnCanWrite(); |
| 529 ASSERT_TRUE(callback.have_result()); | 533 ASSERT_TRUE(callback.have_result()); |
| 530 EXPECT_EQ(OK, callback.WaitForResult()); | 534 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 531 } | 535 } |
| 532 | 536 |
| 533 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { | 537 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { |
| 534 // We don't use stream_ because we want an incoming server push | 538 // We don't use stream_ because we want an incoming server push |
| 535 // stream. | 539 // stream. |
| 536 QuicChromiumClientStream* stream = new QuicChromiumClientStream( | 540 QuicChromiumClientStream* stream = new QuicChromiumClientStream( |
| 537 kServerDataStreamId1, &session_, BoundNetLog()); | 541 kServerDataStreamId1, &session_, BoundNetLog()); |
| 538 session_.ActivateStream(stream); | 542 session_.ActivateStream(stream); |
| 539 | 543 |
| 540 InitializeHeaders(); | 544 InitializeHeaders(); |
| 541 std::string uncompressed_headers = | 545 std::string uncompressed_headers = |
| 542 SpdyUtils::SerializeUncompressedHeaders(headers_); | 546 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 543 stream->OnStreamHeaders(uncompressed_headers); | 547 stream->OnStreamHeaders(uncompressed_headers); |
| 544 stream->OnStreamHeadersComplete(false, uncompressed_headers.length()); | 548 stream->OnStreamHeadersComplete(false, uncompressed_headers.length()); |
| 545 EXPECT_TRUE(stream->decompressed_headers().empty()); | 549 EXPECT_TRUE(stream->decompressed_headers().empty()); |
| 546 | 550 |
| 547 EXPECT_CALL(delegate_, | 551 EXPECT_CALL(delegate_, |
| 548 OnHeadersAvailableMock(_, uncompressed_headers.length())); | 552 OnHeadersAvailableMock(_, uncompressed_headers.length())); |
| 549 stream->SetDelegate(&delegate_); | 553 stream->SetDelegate(&delegate_); |
| 550 base::RunLoop().RunUntilIdle(); | 554 base::RunLoop().RunUntilIdle(); |
| 551 EXPECT_EQ(headers_, delegate_.headers_); | 555 EXPECT_EQ(headers_, delegate_.headers_); |
| 552 | 556 |
| 553 // Times(2) because OnClose will be called for stream and stream_. | 557 // Times(2) because OnClose will be called for stream and stream_. |
| 554 EXPECT_CALL(delegate_, OnClose()).Times(2); | 558 EXPECT_CALL(delegate_, OnClose()).Times(2); |
| 555 } | 559 } |
| 556 | 560 |
| 557 } // namespace | 561 } // namespace |
| 558 } // namespace test | 562 } // namespace test |
| 559 } // namespace net | 563 } // namespace net |
| OLD | NEW |