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

Side by Side Diff: net/quic/quic_chromium_client_stream_test.cc

Issue 1856073002: Coalesce small buffers in net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix javadoc Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_chromium_client_stream.cc ('k') | net/quic/test_tools/quic_test_packet_maker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_chromium_client_stream.h" 5 #include "net/quic/quic_chromium_client_stream.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
11 #include "net/base/test_completion_callback.h" 12 #include "net/base/test_completion_callback.h"
12 #include "net/quic/quic_chromium_client_session.h" 13 #include "net/quic/quic_chromium_client_session.h"
13 #include "net/quic/quic_client_session_base.h" 14 #include "net/quic/quic_client_session_base.h"
14 #include "net/quic/quic_utils.h" 15 #include "net/quic/quic_utils.h"
15 #include "net/quic/spdy_utils.h" 16 #include "net/quic/spdy_utils.h"
16 #include "net/quic/test_tools/crypto_test_utils.h" 17 #include "net/quic/test_tools/crypto_test_utils.h"
17 #include "net/quic/test_tools/quic_test_utils.h" 18 #include "net/quic/test_tools/quic_test_utils.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gmock_mutant.h" 20 #include "testing/gmock_mutant.h"
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 ASSERT_FALSE(callback.have_result()); 458 ASSERT_FALSE(callback.have_result());
458 459
459 // All data written. 460 // All data written.
460 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 461 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _))
461 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 462 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
462 stream_->OnCanWrite(); 463 stream_->OnCanWrite();
463 ASSERT_TRUE(callback.have_result()); 464 ASSERT_TRUE(callback.have_result());
464 EXPECT_EQ(OK, callback.WaitForResult()); 465 EXPECT_EQ(OK, callback.WaitForResult());
465 } 466 }
466 467
468 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) {
469 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
470
471 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!"));
472 scoped_refptr<StringIOBuffer> buf2(
473 new StringIOBuffer("Just a small payload"));
474
475 // All data written.
476 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _))
477 .WillOnce(Return(QuicConsumedData(buf1->size(), false)))
478 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
479 TestCompletionCallback callback;
480 EXPECT_EQ(OK, stream_->WritevStreamData({buf1.get(), buf2.get()},
481 {buf1->size(), buf2->size()}, true,
482 callback.callback()));
483 }
484
485 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) {
486 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
487 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
488
489 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!"));
490 scoped_refptr<StringIOBuffer> buf2(
491 new StringIOBuffer("Just a small payload"));
492
493 // Only a part of the data is written.
494 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _))
495 // First piece of data is written.
496 .WillOnce(Return(QuicConsumedData(buf1->size(), false)))
497 // Second piece of data is queued.
498 .WillOnce(Return(QuicConsumedData(0, false)));
499 TestCompletionCallback callback;
500 EXPECT_EQ(ERR_IO_PENDING,
501 stream_->WritevStreamData({buf1.get(), buf2.get()},
502 {buf1->size(), buf2->size()}, true,
503 callback.callback()));
504 ASSERT_FALSE(callback.have_result());
505
506 // The second piece of data is written.
507 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _))
508 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
509 stream_->OnCanWrite();
510 ASSERT_TRUE(callback.have_result());
511 EXPECT_EQ(OK, callback.WaitForResult());
512 }
513
467 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { 514 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) {
468 // We don't use stream_ because we want an incoming server push 515 // We don't use stream_ because we want an incoming server push
469 // stream. 516 // stream.
470 QuicChromiumClientStream* stream = new QuicChromiumClientStream( 517 QuicChromiumClientStream* stream = new QuicChromiumClientStream(
471 kServerDataStreamId1, &session_, BoundNetLog()); 518 kServerDataStreamId1, &session_, BoundNetLog());
472 session_.ActivateStream(stream); 519 session_.ActivateStream(stream);
473 520
474 InitializeHeaders(); 521 InitializeHeaders();
475 std::string uncompressed_headers = 522 std::string uncompressed_headers =
476 SpdyUtils::SerializeUncompressedHeaders(headers_); 523 SpdyUtils::SerializeUncompressedHeaders(headers_);
477 stream->OnStreamHeaders(uncompressed_headers); 524 stream->OnStreamHeaders(uncompressed_headers);
478 stream->OnStreamHeadersComplete(false, uncompressed_headers.length()); 525 stream->OnStreamHeadersComplete(false, uncompressed_headers.length());
479 EXPECT_TRUE(stream->decompressed_headers().empty()); 526 EXPECT_TRUE(stream->decompressed_headers().empty());
480 527
481 EXPECT_CALL(delegate_, 528 EXPECT_CALL(delegate_,
482 OnHeadersAvailable(headers_, uncompressed_headers.length())); 529 OnHeadersAvailable(headers_, uncompressed_headers.length()));
483 stream->SetDelegate(&delegate_); 530 stream->SetDelegate(&delegate_);
484 base::MessageLoop::current()->RunUntilIdle(); 531 base::MessageLoop::current()->RunUntilIdle();
485 532
486 // Times(2) because OnClose will be called for stream and stream_. 533 // Times(2) because OnClose will be called for stream and stream_.
487 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2); 534 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2);
488 } 535 }
489 536
490 } // namespace 537 } // namespace
491 } // namespace test 538 } // namespace test
492 } // namespace net 539 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_chromium_client_stream.cc ('k') | net/quic/test_tools/quic_test_packet_maker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698