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

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

Issue 2870483002: Fix QuicChromiumClientStreamTest.HeadersBeforeDelegate to actually set (Closed)
Patch Set: Rebase Created 3 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 | « no previous file | no next file » | 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/chromium/quic_chromium_client_stream.h" 5 #include "net/quic/chromium/quic_chromium_client_stream.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 263
264 QuicStreamId GetNthClientInitiatedStreamId(int n) { 264 QuicStreamId GetNthClientInitiatedStreamId(int n) {
265 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n); 265 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n);
266 } 266 }
267 267
268 QuicStreamId GetNthServerInitiatedStreamId(int n) { 268 QuicStreamId GetNthServerInitiatedStreamId(int n) {
269 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n); 269 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n);
270 } 270 }
271 271
272 QuicCryptoClientConfig crypto_config_; 272 QuicCryptoClientConfig crypto_config_;
273 testing::StrictMock<MockDelegate> delegate2_;
273 testing::StrictMock<MockDelegate> delegate_; 274 testing::StrictMock<MockDelegate> delegate_;
274 MockQuicConnectionHelper helper_; 275 MockQuicConnectionHelper helper_;
275 MockAlarmFactory alarm_factory_; 276 MockAlarmFactory alarm_factory_;
276 MockQuicClientSessionBase session_; 277 MockQuicClientSessionBase session_;
277 QuicChromiumClientStream* stream_; 278 QuicChromiumClientStream* stream_;
278 SpdyHeaderBlock headers_; 279 SpdyHeaderBlock headers_;
279 QuicClientPushPromiseIndex push_promise_index_; 280 QuicClientPushPromiseIndex push_promise_index_;
280 }; 281 };
281 282
282 INSTANTIATE_TEST_CASE_P(Version, 283 INSTANTIATE_TEST_CASE_P(Version,
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 609 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
609 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); 610 .WillOnce(Return(QuicConsumedData(buf2->size(), true)));
610 stream_->OnCanWrite(); 611 stream_->OnCanWrite();
611 ASSERT_TRUE(callback.have_result()); 612 ASSERT_TRUE(callback.have_result());
612 EXPECT_THAT(callback.WaitForResult(), IsOk()); 613 EXPECT_THAT(callback.WaitForResult(), IsOk());
613 } 614 }
614 615
615 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { 616 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) {
616 // We don't use stream_ because we want an incoming server push 617 // We don't use stream_ because we want an incoming server push
617 // stream. 618 // stream.
618 QuicChromiumClientStream* stream = new QuicChromiumClientStream( 619 QuicStreamId stream_id = GetNthServerInitiatedStreamId(0);
619 GetNthServerInitiatedStreamId(0), &session_, NetLogWithSource()); 620 QuicChromiumClientStream* stream2 =
620 session_.ActivateStream(base::WrapUnique(stream)); 621 new QuicChromiumClientStream(stream_id, &session_, NetLogWithSource());
622 session_.ActivateStream(base::WrapUnique(stream2));
621 623
622 InitializeHeaders(); 624 InitializeHeaders();
623 stream->SetDelegate(&delegate_);
624 ProcessHeadersFull(headers_);
625 625
626 // Times(2) because OnClose will be called for stream and stream_. 626 // Receive the headers before the delegate is set.
627 EXPECT_CALL(delegate_, OnClose()).Times(2); 627 QuicHeaderList header_list = AsHeaderList(headers_);
628 stream2->OnStreamHeaderList(true, header_list.uncompressed_header_bytes(),
629 header_list);
630 EXPECT_TRUE(delegate2_.headers_.empty());
631
632 // Now set the delegate and verify that the headers are delivered.
633 EXPECT_CALL(delegate2_, OnHeadersAvailableMock(
634 _, header_list.uncompressed_header_bytes()));
635 stream2->SetDelegate(&delegate2_);
636 base::RunLoop().RunUntilIdle();
637 EXPECT_EQ(headers_, delegate2_.headers_);
638
639 // Both delegates should be notified that theirs streams are closed.
640 EXPECT_CALL(delegate2_, OnClose());
641 EXPECT_CALL(delegate_, OnClose());
642 }
643
644 TEST_P(QuicChromiumClientStreamTest, HeadersAndDataBeforeDelegate) {
645 // We don't use stream_ because we want an incoming server push
646 // stream.
647 QuicStreamId stream_id = GetNthServerInitiatedStreamId(0);
648 QuicChromiumClientStream* stream2 =
649 new QuicChromiumClientStream(stream_id, &session_, NetLogWithSource());
650 session_.ActivateStream(base::WrapUnique(stream2));
651
652 InitializeHeaders();
653
654 // Receive the headers and data before the delegate is set.
655 QuicHeaderList header_list = AsHeaderList(headers_);
656 stream2->OnStreamHeaderList(false, header_list.uncompressed_header_bytes(),
657 header_list);
658 EXPECT_TRUE(delegate2_.headers_.empty());
659 const char data[] = "hello world!";
660 stream2->OnStreamFrame(QuicStreamFrame(stream_id, /*fin=*/false,
661 /*offset=*/0, data));
662
663 // Now set the delegate and verify that the headers are delivered, but
664 // not the data, which needs to be read explicitly.
665 EXPECT_CALL(delegate2_, OnHeadersAvailableMock(
666 _, header_list.uncompressed_header_bytes()));
667 stream2->SetDelegate(&delegate2_);
668 base::RunLoop().RunUntilIdle();
669 EXPECT_EQ(headers_, delegate2_.headers_);
670 base::RunLoop().RunUntilIdle();
671
672 // Now explicitly read the data.
673 int data_len = arraysize(data) - 1;
674 scoped_refptr<IOBuffer> buffer(new IOBuffer(data_len + 1));
675 ASSERT_EQ(data_len, stream2->Read(buffer.get(), data_len + 1));
676 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len));
677
678 // Both delegates should be notified that theirs streams are closed.
679 EXPECT_CALL(delegate2_, OnClose());
680 EXPECT_CALL(delegate_, OnClose());
628 } 681 }
629 682
630 } // namespace 683 } // namespace
631 } // namespace test 684 } // namespace test
632 } // namespace net 685 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698