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

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

Issue 1983183002: Landing Recent QUIC changes until 5/14/2016 02:25:25 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: "first try to fix link error for win_clang build" 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_session_test.cc ('k') | net/quic/quic_connection.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/io_buffer.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 QuicCryptoStream* GetCryptoStream() override { return crypto_stream_.get(); } 59 QuicCryptoStream* GetCryptoStream() override { return crypto_stream_.get(); }
60 60
61 // From QuicSession. 61 // From QuicSession.
62 MOCK_METHOD3(OnConnectionClosed, 62 MOCK_METHOD3(OnConnectionClosed,
63 void(QuicErrorCode error, 63 void(QuicErrorCode error,
64 const std::string& error_details, 64 const std::string& error_details,
65 ConnectionCloseSource source)); 65 ConnectionCloseSource source));
66 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); 66 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id));
67 MOCK_METHOD1(CreateOutgoingDynamicStream, 67 MOCK_METHOD1(CreateOutgoingDynamicStream,
68 QuicChromiumClientStream*(SpdyPriority priority)); 68 QuicChromiumClientStream*(SpdyPriority priority));
69 MOCK_METHOD5(WritevData, 69 MOCK_METHOD6(WritevData,
70 QuicConsumedData(QuicStreamId id, 70 QuicConsumedData(ReliableQuicStream* stream,
71 QuicStreamId id,
71 QuicIOVector data, 72 QuicIOVector data,
72 QuicStreamOffset offset, 73 QuicStreamOffset offset,
73 bool fin, 74 bool fin,
74 QuicAckListenerInterface*)); 75 QuicAckListenerInterface*));
75 MOCK_METHOD3(SendRstStream, 76 MOCK_METHOD3(SendRstStream,
76 void(QuicStreamId stream_id, 77 void(QuicStreamId stream_id,
77 QuicRstStreamErrorCode error, 78 QuicRstStreamErrorCode error,
78 QuicStreamOffset bytes_written)); 79 QuicStreamOffset bytes_written));
79 80
80 MOCK_METHOD2(OnStreamHeaders, 81 MOCK_METHOD2(OnStreamHeaders,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 }; 127 };
127 128
128 MockQuicClientSessionBase::MockQuicClientSessionBase( 129 MockQuicClientSessionBase::MockQuicClientSessionBase(
129 QuicConnection* connection, 130 QuicConnection* connection,
130 QuicClientPushPromiseIndex* push_promise_index) 131 QuicClientPushPromiseIndex* push_promise_index)
131 : QuicClientSessionBase(connection, 132 : QuicClientSessionBase(connection,
132 push_promise_index, 133 push_promise_index,
133 DefaultQuicConfig()) { 134 DefaultQuicConfig()) {
134 crypto_stream_.reset(new QuicCryptoStream(this)); 135 crypto_stream_.reset(new QuicCryptoStream(this));
135 Initialize(); 136 Initialize();
136 ON_CALL(*this, WritevData(_, _, _, _, _)) 137 ON_CALL(*this, WritevData(_, _, _, _, _, _))
137 .WillByDefault(testing::Return(QuicConsumedData(0, false))); 138 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
138 } 139 }
139 140
140 MockQuicClientSessionBase::~MockQuicClientSessionBase() {} 141 MockQuicClientSessionBase::~MockQuicClientSessionBase() {}
141 142
142 class QuicChromiumClientStreamTest 143 class QuicChromiumClientStreamTest
143 : public ::testing::TestWithParam<QuicVersion> { 144 : public ::testing::TestWithParam<QuicVersion> {
144 public: 145 public:
145 QuicChromiumClientStreamTest() 146 QuicChromiumClientStreamTest()
146 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), 147 : crypto_config_(CryptoTestUtils::ProofVerifierForTesting()),
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 428 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
428 } 429 }
429 430
430 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { 431 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) {
431 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 432 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
432 433
433 const char kData1[] = "hello world"; 434 const char kData1[] = "hello world";
434 const size_t kDataLen = arraysize(kData1); 435 const size_t kDataLen = arraysize(kData1);
435 436
436 // All data written. 437 // All data written.
437 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 438 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
438 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 439 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
439 TestCompletionCallback callback; 440 TestCompletionCallback callback;
440 EXPECT_EQ(OK, stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), 441 EXPECT_EQ(OK, stream_->WriteStreamData(base::StringPiece(kData1, kDataLen),
441 true, callback.callback())); 442 true, callback.callback()));
442 } 443 }
443 444
444 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { 445 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) {
445 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); 446 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
446 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 447 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
447 448
448 const char kData1[] = "hello world"; 449 const char kData1[] = "hello world";
449 const size_t kDataLen = arraysize(kData1); 450 const size_t kDataLen = arraysize(kData1);
450 451
451 // No data written. 452 // No data written.
452 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 453 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
453 .WillOnce(Return(QuicConsumedData(0, false))); 454 .WillOnce(Return(QuicConsumedData(0, false)));
454 TestCompletionCallback callback; 455 TestCompletionCallback callback;
455 EXPECT_EQ(ERR_IO_PENDING, 456 EXPECT_EQ(ERR_IO_PENDING,
456 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true, 457 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true,
457 callback.callback())); 458 callback.callback()));
458 ASSERT_FALSE(callback.have_result()); 459 ASSERT_FALSE(callback.have_result());
459 460
460 // All data written. 461 // All data written.
461 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 462 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
462 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 463 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
463 stream_->OnCanWrite(); 464 stream_->OnCanWrite();
464 ASSERT_TRUE(callback.have_result()); 465 ASSERT_TRUE(callback.have_result());
465 EXPECT_EQ(OK, callback.WaitForResult()); 466 EXPECT_EQ(OK, callback.WaitForResult());
466 } 467 }
467 468
468 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) { 469 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) {
469 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 470 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
470 471
471 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); 472 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!"));
472 scoped_refptr<StringIOBuffer> buf2( 473 scoped_refptr<StringIOBuffer> buf2(
473 new StringIOBuffer("Just a small payload")); 474 new StringIOBuffer("Just a small payload"));
474 475
475 // All data written. 476 // All data written.
476 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 477 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
477 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) 478 .WillOnce(Return(QuicConsumedData(buf1->size(), false)))
478 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); 479 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
479 TestCompletionCallback callback; 480 TestCompletionCallback callback;
480 EXPECT_EQ( 481 EXPECT_EQ(
481 OK, stream_->WritevStreamData({buf1, buf2}, {buf1->size(), buf2->size()}, 482 OK, stream_->WritevStreamData({buf1, buf2}, {buf1->size(), buf2->size()},
482 true, callback.callback())); 483 true, callback.callback()));
483 } 484 }
484 485
485 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) { 486 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) {
486 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); 487 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
487 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 488 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
488 489
489 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); 490 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!"));
490 scoped_refptr<StringIOBuffer> buf2( 491 scoped_refptr<StringIOBuffer> buf2(
491 new StringIOBuffer("Just a small payload")); 492 new StringIOBuffer("Just a small payload"));
492 493
493 // Only a part of the data is written. 494 // Only a part of the data is written.
494 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 495 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
495 // First piece of data is written. 496 // First piece of data is written.
496 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) 497 .WillOnce(Return(QuicConsumedData(buf1->size(), false)))
497 // Second piece of data is queued. 498 // Second piece of data is queued.
498 .WillOnce(Return(QuicConsumedData(0, false))); 499 .WillOnce(Return(QuicConsumedData(0, false)));
499 TestCompletionCallback callback; 500 TestCompletionCallback callback;
500 EXPECT_EQ(ERR_IO_PENDING, 501 EXPECT_EQ(ERR_IO_PENDING,
501 stream_->WritevStreamData({buf1.get(), buf2.get()}, 502 stream_->WritevStreamData({buf1.get(), buf2.get()},
502 {buf1->size(), buf2->size()}, true, 503 {buf1->size(), buf2->size()}, true,
503 callback.callback())); 504 callback.callback()));
504 ASSERT_FALSE(callback.have_result()); 505 ASSERT_FALSE(callback.have_result());
505 506
506 // The second piece of data is written. 507 // The second piece of data is written.
507 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _)) 508 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
508 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); 509 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
509 stream_->OnCanWrite(); 510 stream_->OnCanWrite();
510 ASSERT_TRUE(callback.have_result()); 511 ASSERT_TRUE(callback.have_result());
511 EXPECT_EQ(OK, callback.WaitForResult()); 512 EXPECT_EQ(OK, callback.WaitForResult());
512 } 513 }
513 514
514 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { 515 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) {
515 // We don't use stream_ because we want an incoming server push 516 // We don't use stream_ because we want an incoming server push
516 // stream. 517 // stream.
517 QuicChromiumClientStream* stream = new QuicChromiumClientStream( 518 QuicChromiumClientStream* stream = new QuicChromiumClientStream(
(...skipping 12 matching lines...) Expand all
530 stream->SetDelegate(&delegate_); 531 stream->SetDelegate(&delegate_);
531 base::MessageLoop::current()->RunUntilIdle(); 532 base::MessageLoop::current()->RunUntilIdle();
532 533
533 // Times(2) because OnClose will be called for stream and stream_. 534 // Times(2) because OnClose will be called for stream and stream_.
534 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2); 535 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2);
535 } 536 }
536 537
537 } // namespace 538 } // namespace
538 } // namespace test 539 } // namespace test
539 } // namespace net 540 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_chromium_client_session_test.cc ('k') | net/quic/quic_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698