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

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

Issue 2868633002: Create a QuicChromiumClientStream::Handle class for allowing a stream (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 | « net/quic/chromium/quic_chromium_client_stream.cc ('k') | net/quic/chromium/quic_http_stream.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/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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 QuicChromiumClientStreamTest() 199 QuicChromiumClientStreamTest()
200 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()), 200 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()),
201 session_(new MockQuicConnection(&helper_, 201 session_(new MockQuicConnection(&helper_,
202 &alarm_factory_, 202 &alarm_factory_,
203 Perspective::IS_CLIENT, 203 Perspective::IS_CLIENT,
204 SupportedVersions(GetParam())), 204 SupportedVersions(GetParam())),
205 &push_promise_index_) { 205 &push_promise_index_) {
206 stream_ = new QuicChromiumClientStream(kTestStreamId, &session_, 206 stream_ = new QuicChromiumClientStream(kTestStreamId, &session_,
207 NetLogWithSource()); 207 NetLogWithSource());
208 session_.ActivateStream(base::WrapUnique(stream_)); 208 session_.ActivateStream(base::WrapUnique(stream_));
209 stream_->SetDelegate(&delegate_); 209 handle_ = stream_->CreateHandle(&delegate_);
210 } 210 }
211 211
212 void InitializeHeaders() { 212 void InitializeHeaders() {
213 headers_[":host"] = "www.google.com"; 213 headers_[":host"] = "www.google.com";
214 headers_[":path"] = "/index.hml"; 214 headers_[":path"] = "/index.hml";
215 headers_[":scheme"] = "https"; 215 headers_[":scheme"] = "https";
216 headers_["cookie"] = 216 headers_["cookie"] =
217 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " 217 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
218 "__utmc=160408618; " 218 "__utmc=160408618; "
219 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" 219 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 271
272 QuicStreamId GetNthClientInitiatedStreamId(int n) { 272 QuicStreamId GetNthClientInitiatedStreamId(int n) {
273 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n); 273 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n);
274 } 274 }
275 275
276 QuicStreamId GetNthServerInitiatedStreamId(int n) { 276 QuicStreamId GetNthServerInitiatedStreamId(int n) {
277 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n); 277 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n);
278 } 278 }
279 279
280 QuicCryptoClientConfig crypto_config_; 280 QuicCryptoClientConfig crypto_config_;
281 std::unique_ptr<QuicChromiumClientStream::Handle> handle_;
282 testing::StrictMock<MockDelegate> delegate_;
283 std::unique_ptr<QuicChromiumClientStream::Handle> handle2_;
281 testing::StrictMock<MockDelegate> delegate2_; 284 testing::StrictMock<MockDelegate> delegate2_;
282 testing::StrictMock<MockDelegate> delegate_;
283 MockQuicConnectionHelper helper_; 285 MockQuicConnectionHelper helper_;
284 MockAlarmFactory alarm_factory_; 286 MockAlarmFactory alarm_factory_;
285 MockQuicClientSessionBase session_; 287 MockQuicClientSessionBase session_;
286 QuicChromiumClientStream* stream_; 288 QuicChromiumClientStream* stream_;
287 SpdyHeaderBlock headers_; 289 SpdyHeaderBlock headers_;
288 QuicClientPushPromiseIndex push_promise_index_; 290 QuicClientPushPromiseIndex push_promise_index_;
289 }; 291 };
290 292
291 INSTANTIATE_TEST_CASE_P(Version, 293 INSTANTIATE_TEST_CASE_P(Version,
292 QuicChromiumClientStreamTest, 294 QuicChromiumClientStreamTest,
293 ::testing::ValuesIn(AllSupportedVersions())); 295 ::testing::ValuesIn(AllSupportedVersions()));
294 296
297 TEST_P(QuicChromiumClientStreamTest, Handle) {
298 EXPECT_TRUE(handle_->IsOpen());
299 EXPECT_EQ(kTestStreamId, handle_->id());
300 EXPECT_EQ(QUIC_NO_ERROR, handle_->connection_error());
301 EXPECT_EQ(QUIC_STREAM_NO_ERROR, handle_->stream_error());
302 EXPECT_TRUE(handle_->IsFirstStream());
303 EXPECT_FALSE(handle_->IsDoneReading());
304 EXPECT_FALSE(handle_->fin_sent());
305 EXPECT_FALSE(handle_->fin_received());
306 EXPECT_EQ(0u, handle_->stream_bytes_read());
307 EXPECT_EQ(0u, handle_->stream_bytes_written());
308 EXPECT_EQ(0u, handle_->NumBytesConsumed());
309
310 InitializeHeaders();
311 QuicStreamOffset offset = 0;
312 ProcessHeadersFull(headers_);
313 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece());
314 EXPECT_CALL(delegate_, OnClose());
315 stream_->OnStreamFrame(frame2);
316 EXPECT_TRUE(handle_->fin_received());
317 handle_->OnFinRead();
318
319 const char kData1[] = "hello world";
320 const size_t kDataLen = arraysize(kData1);
321
322 // All data written.
323 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
324 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
325 TestCompletionCallback callback;
326 EXPECT_EQ(OK, handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen),
327 true, callback.callback()));
328
329 EXPECT_FALSE(handle_->IsOpen());
330 EXPECT_EQ(kTestStreamId, handle_->id());
331 EXPECT_EQ(QUIC_NO_ERROR, handle_->connection_error());
332 EXPECT_EQ(QUIC_STREAM_NO_ERROR, handle_->stream_error());
333 EXPECT_TRUE(handle_->IsFirstStream());
334 EXPECT_TRUE(handle_->IsDoneReading());
335 EXPECT_TRUE(handle_->fin_sent());
336 EXPECT_TRUE(handle_->fin_received());
337 EXPECT_EQ(0u, handle_->stream_bytes_read());
338 EXPECT_EQ(kDataLen, handle_->stream_bytes_written());
339 EXPECT_EQ(0u, handle_->NumBytesConsumed());
340
341 EXPECT_EQ(ERR_CONNECTION_CLOSED,
342 handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen), true,
343 callback.callback()));
344
345 std::vector<scoped_refptr<IOBuffer>> buffers = {
346 scoped_refptr<IOBuffer>(new IOBuffer(10))};
347 std::vector<int> lengths = {10};
348 EXPECT_EQ(
349 ERR_CONNECTION_CLOSED,
350 handle_->WritevStreamData(buffers, lengths, true, callback.callback()));
351
352 SpdyHeaderBlock headers;
353 EXPECT_EQ(0u, handle_->WriteHeaders(std::move(headers), true, nullptr));
354 }
355
356 TEST_P(QuicChromiumClientStreamTest, HandleAfterConnectionClose) {
357 // Verify that the delegate's OnClose is called after closing the connection.
358 EXPECT_CALL(delegate_, OnClose());
359 EXPECT_CALL(session_,
360 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0));
361 stream_->OnConnectionClosed(QUIC_INVALID_FRAME_DATA,
362 ConnectionCloseSource::FROM_PEER);
363
364 EXPECT_FALSE(handle_->IsOpen());
365 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, handle_->connection_error());
366 }
367
368 TEST_P(QuicChromiumClientStreamTest, HandleAfterStreamReset) {
369 // Verify that the delegate's OnClose is called after the stream is reset,
370 // but that the Handle still behaves correctly.
371 EXPECT_CALL(delegate_, OnClose());
372 QuicRstStreamFrame rst(kTestStreamId, QUIC_STREAM_CANCELLED, 0);
373 EXPECT_CALL(session_,
374 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0));
375 stream_->OnStreamReset(rst);
376
377 EXPECT_FALSE(handle_->IsOpen());
378 EXPECT_EQ(QUIC_STREAM_CANCELLED, handle_->stream_error());
379 }
380
381 TEST_P(QuicChromiumClientStreamTest, HandleAfterClearDelegate) {
382 EXPECT_TRUE(handle_->IsOpen());
383 handle_->ClearDelegate();
384
385 // Verify that the delegate's OnClose is not called after ClearDelegate.
386 EXPECT_CALL(delegate_, OnClose()).Times(0);
387 QuicRstStreamFrame rst(kTestStreamId, QUIC_STREAM_CANCELLED, 0);
388 EXPECT_CALL(session_,
389 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0));
390 stream_->OnStreamReset(rst);
391
392 EXPECT_FALSE(handle_->IsOpen());
393 EXPECT_EQ(QUIC_STREAM_CANCELLED, handle_->stream_error());
394 }
395
295 TEST_P(QuicChromiumClientStreamTest, OnFinRead) { 396 TEST_P(QuicChromiumClientStreamTest, OnFinRead) {
296 InitializeHeaders(); 397 InitializeHeaders();
297 QuicStreamOffset offset = 0; 398 QuicStreamOffset offset = 0;
298 ProcessHeadersFull(headers_); 399 ProcessHeadersFull(headers_);
299 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece()); 400 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece());
300 EXPECT_CALL(delegate_, OnClose()); 401 EXPECT_CALL(delegate_, OnClose());
301 stream_->OnStreamFrame(frame2); 402 stream_->OnStreamFrame(frame2);
302 } 403 }
303 404
304 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableBeforeHeaders) { 405 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableBeforeHeaders) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 EXPECT_CALL(delegate_, OnDataAvailable()) 453 EXPECT_CALL(delegate_, OnDataAvailable())
353 .WillOnce(testing::Invoke(CreateFunctor( 454 .WillOnce(testing::Invoke(CreateFunctor(
354 &QuicChromiumClientStream::Reset, 455 &QuicChromiumClientStream::Reset,
355 base::Unretained(stream_), QUIC_STREAM_CANCELLED))); 456 base::Unretained(stream_), QUIC_STREAM_CANCELLED)));
356 base::RunLoop().RunUntilIdle(); 457 base::RunLoop().RunUntilIdle();
357 458
358 EXPECT_CALL(delegate_, OnClose()); 459 EXPECT_CALL(delegate_, OnClose());
359 } 460 }
360 461
361 TEST_P(QuicChromiumClientStreamTest, OnError) { 462 TEST_P(QuicChromiumClientStreamTest, OnError) {
362 EXPECT_CALL(delegate_, OnError(ERR_INTERNET_DISCONNECTED)); 463 EXPECT_CALL(delegate_, OnError(ERR_INTERNET_DISCONNECTED)).Times(1);
363 464
364 stream_->OnError(ERR_INTERNET_DISCONNECTED); 465 stream_->OnError(ERR_INTERNET_DISCONNECTED);
365 EXPECT_FALSE(stream_->GetDelegate()); 466 stream_->OnError(ERR_INTERNET_DISCONNECTED);
366 } 467 }
367 468
368 TEST_P(QuicChromiumClientStreamTest, OnTrailers) { 469 TEST_P(QuicChromiumClientStreamTest, OnTrailers) {
369 InitializeHeaders(); 470 InitializeHeaders();
370 ProcessHeadersFull(headers_); 471 ProcessHeadersFull(headers_);
371 472
372 const char data[] = "hello world!"; 473 const char data[] = "hello world!";
373 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, 474 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
374 /*offset=*/0, data)); 475 /*offset=*/0, data));
375 476
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 734
634 // Receive the headers before the delegate is set. 735 // Receive the headers before the delegate is set.
635 QuicHeaderList header_list = AsHeaderList(headers_); 736 QuicHeaderList header_list = AsHeaderList(headers_);
636 stream2->OnStreamHeaderList(true, header_list.uncompressed_header_bytes(), 737 stream2->OnStreamHeaderList(true, header_list.uncompressed_header_bytes(),
637 header_list); 738 header_list);
638 EXPECT_TRUE(delegate2_.headers_.empty()); 739 EXPECT_TRUE(delegate2_.headers_.empty());
639 740
640 // Now set the delegate and verify that the headers are delivered. 741 // Now set the delegate and verify that the headers are delivered.
641 EXPECT_CALL(delegate2_, OnInitialHeadersAvailableMock( 742 EXPECT_CALL(delegate2_, OnInitialHeadersAvailableMock(
642 _, header_list.uncompressed_header_bytes())); 743 _, header_list.uncompressed_header_bytes()));
643 stream2->SetDelegate(&delegate2_); 744 handle2_ = stream2->CreateHandle(&delegate2_);
644 base::RunLoop().RunUntilIdle(); 745 base::RunLoop().RunUntilIdle();
645 EXPECT_EQ(headers_, delegate2_.headers_); 746 EXPECT_EQ(headers_, delegate2_.headers_);
646 747
647 // Both delegates should be notified that theirs streams are closed. 748 // Both delegates should be notified that theirs streams are closed.
648 EXPECT_CALL(delegate2_, OnClose()); 749 EXPECT_CALL(delegate2_, OnClose());
649 EXPECT_CALL(delegate_, OnClose()); 750 EXPECT_CALL(delegate_, OnClose());
650 } 751 }
651 752
652 TEST_P(QuicChromiumClientStreamTest, HeadersAndDataBeforeDelegate) { 753 TEST_P(QuicChromiumClientStreamTest, HeadersAndDataBeforeDelegate) {
653 // We don't use stream_ because we want an incoming server push 754 // We don't use stream_ because we want an incoming server push
(...skipping 11 matching lines...) Expand all
665 header_list); 766 header_list);
666 EXPECT_TRUE(delegate2_.headers_.empty()); 767 EXPECT_TRUE(delegate2_.headers_.empty());
667 const char data[] = "hello world!"; 768 const char data[] = "hello world!";
668 stream2->OnStreamFrame(QuicStreamFrame(stream_id, /*fin=*/false, 769 stream2->OnStreamFrame(QuicStreamFrame(stream_id, /*fin=*/false,
669 /*offset=*/0, data)); 770 /*offset=*/0, data));
670 771
671 // Now set the delegate and verify that the headers are delivered, but 772 // Now set the delegate and verify that the headers are delivered, but
672 // not the data, which needs to be read explicitly. 773 // not the data, which needs to be read explicitly.
673 EXPECT_CALL(delegate2_, OnInitialHeadersAvailableMock( 774 EXPECT_CALL(delegate2_, OnInitialHeadersAvailableMock(
674 _, header_list.uncompressed_header_bytes())); 775 _, header_list.uncompressed_header_bytes()));
675 stream2->SetDelegate(&delegate2_); 776 handle2_ = stream2->CreateHandle(&delegate2_);
676 base::RunLoop().RunUntilIdle(); 777 base::RunLoop().RunUntilIdle();
677 EXPECT_EQ(headers_, delegate2_.headers_); 778 EXPECT_EQ(headers_, delegate2_.headers_);
678 base::RunLoop().RunUntilIdle(); 779 base::RunLoop().RunUntilIdle();
679 780
680 // Now explicitly read the data. 781 // Now explicitly read the data.
681 int data_len = arraysize(data) - 1; 782 int data_len = arraysize(data) - 1;
682 scoped_refptr<IOBuffer> buffer(new IOBuffer(data_len + 1)); 783 scoped_refptr<IOBuffer> buffer(new IOBuffer(data_len + 1));
683 ASSERT_EQ(data_len, stream2->Read(buffer.get(), data_len + 1)); 784 ASSERT_EQ(data_len, stream2->Read(buffer.get(), data_len + 1));
684 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); 785 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len));
685 786
686 // Both delegates should be notified that theirs streams are closed. 787 // Both delegates should be notified that theirs streams are closed.
687 EXPECT_CALL(delegate2_, OnClose()); 788 EXPECT_CALL(delegate2_, OnClose());
688 EXPECT_CALL(delegate_, OnClose()); 789 EXPECT_CALL(delegate_, OnClose());
689 } 790 }
690 791
691 } // namespace 792 } // namespace
692 } // namespace test 793 } // namespace test
693 } // namespace net 794 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_stream.cc ('k') | net/quic/chromium/quic_http_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698