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

Side by Side Diff: net/tools/quic/quic_simple_server_session_test.cc

Issue 2825083003: Landing Recent QUIC changes until Mon Apr 17 2017 (Closed)
Patch Set: Format Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/tools/quic/quic_simple_server_session.h" 5 #include "net/tools/quic/quic_simple_server_session.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "net/quic/core/crypto/quic_crypto_server_config.h" 11 #include "net/quic/core/crypto/quic_crypto_server_config.h"
12 #include "net/quic/core/crypto/quic_random.h" 12 #include "net/quic/core/crypto/quic_random.h"
13 #include "net/quic/core/proto/cached_network_parameters.pb.h" 13 #include "net/quic/core/proto/cached_network_parameters.pb.h"
14 #include "net/quic/core/quic_connection.h" 14 #include "net/quic/core/quic_connection.h"
15 #include "net/quic/core/quic_crypto_server_stream.h" 15 #include "net/quic/core/quic_crypto_server_stream.h"
16 #include "net/quic/core/quic_utils.h" 16 #include "net/quic/core/quic_utils.h"
17 #include "net/quic/platform/api/quic_flags.h"
17 #include "net/quic/platform/api/quic_socket_address.h" 18 #include "net/quic/platform/api/quic_socket_address.h"
18 #include "net/quic/platform/api/quic_string_piece.h" 19 #include "net/quic/platform/api/quic_string_piece.h"
19 #include "net/quic/platform/api/quic_text_utils.h" 20 #include "net/quic/platform/api/quic_text_utils.h"
20 #include "net/quic/test_tools/crypto_test_utils.h" 21 #include "net/quic/test_tools/crypto_test_utils.h"
21 #include "net/quic/test_tools/quic_config_peer.h" 22 #include "net/quic/test_tools/quic_config_peer.h"
22 #include "net/quic/test_tools/quic_connection_peer.h" 23 #include "net/quic/test_tools/quic_connection_peer.h"
23 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 24 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
24 #include "net/quic/test_tools/quic_session_peer.h" 25 #include "net/quic/test_tools/quic_session_peer.h"
25 #include "net/quic/test_tools/quic_spdy_session_peer.h" 26 #include "net/quic/test_tools/quic_spdy_session_peer.h"
26 #include "net/quic/test_tools/quic_spdy_stream_peer.h" 27 #include "net/quic/test_tools/quic_spdy_stream_peer.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 alarm_factory, 117 alarm_factory,
117 perspective, 118 perspective,
118 supported_versions) {} 119 supported_versions) {}
119 120
120 MOCK_METHOD5( 121 MOCK_METHOD5(
121 SendStreamData, 122 SendStreamData,
122 QuicConsumedData( 123 QuicConsumedData(
123 QuicStreamId id, 124 QuicStreamId id,
124 QuicIOVector iov, 125 QuicIOVector iov,
125 QuicStreamOffset offset, 126 QuicStreamOffset offset,
126 bool fin, 127 StreamSendingState state,
127 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener)); 128 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener));
128 }; 129 };
129 130
130 class MockQuicSimpleServerSession : public QuicSimpleServerSession { 131 class MockQuicSimpleServerSession : public QuicSimpleServerSession {
131 public: 132 public:
132 MockQuicSimpleServerSession(const QuicConfig& config, 133 MockQuicSimpleServerSession(const QuicConfig& config,
133 QuicConnection* connection, 134 QuicConnection* connection,
134 QuicSession::Visitor* visitor, 135 QuicSession::Visitor* visitor,
135 QuicCryptoServerStream::Helper* helper, 136 QuicCryptoServerStream::Helper* helper,
136 const QuicCryptoServerConfig* crypto_config, 137 const QuicCryptoServerConfig* crypto_config,
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 // PUSH_PROMISED are sent for all the resources. 484 // PUSH_PROMISED are sent for all the resources.
484 EXPECT_CALL(*session_, 485 EXPECT_CALL(*session_,
485 WritePushPromiseMock(kClientDataStreamId1, stream_id, _)); 486 WritePushPromiseMock(kClientDataStreamId1, stream_id, _));
486 if (i <= kMaxStreamsForTest) { 487 if (i <= kMaxStreamsForTest) {
487 // |kMaxStreamsForTest| promised responses should be sent. 488 // |kMaxStreamsForTest| promised responses should be sent.
488 EXPECT_CALL(*session_, 489 EXPECT_CALL(*session_,
489 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _)); 490 WriteHeadersMock(stream_id, _, false, kDefaultPriority, _));
490 // Since flow control window is smaller than response body, not the 491 // Since flow control window is smaller than response body, not the
491 // whole body will be sent. 492 // whole body will be sent.
492 if (!session_->force_hol_blocking()) { 493 if (!session_->force_hol_blocking()) {
493 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, false, _)) 494 EXPECT_CALL(*connection_, SendStreamData(stream_id, _, 0, NO_FIN, _))
494 .WillOnce(Return( 495 .WillOnce(Return(
495 QuicConsumedData(kStreamFlowControlWindowSize, false))); 496 QuicConsumedData(kStreamFlowControlWindowSize, false)));
496 EXPECT_CALL(*connection_, SendBlocked(stream_id)); 497 EXPECT_CALL(*connection_, SendBlocked(stream_id));
497 } else { 498 } else {
498 // The forced HOL blocking encapsulates the stream data into 499 // The forced HOL blocking encapsulates the stream data into
499 // HTTP/2 DATA frames within the headers stream. HTTP/2 500 // HTTP/2 DATA frames within the headers stream. HTTP/2
500 // DATA frames are limited to a max size of 16KB, so the 501 // DATA frames are limited to a max size of 16KB, so the
501 // 64KB body will be fragemented into four DATA frames. 502 // 64KB body will be fragemented into four DATA frames.
502 EXPECT_CALL(*connection_, SendStreamData(_, _, _, false, _)) 503 EXPECT_CALL(*connection_, SendStreamData(_, _, _, NO_FIN, _))
503 .Times(body_size / 16384) 504 .Times(body_size / 16384)
504 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) 505 .WillOnce(Return(QuicConsumedData(9 + 16394, false)))
505 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) 506 .WillOnce(Return(QuicConsumedData(9 + 16394, false)))
506 .WillOnce(Return(QuicConsumedData(9 + 16394, false))) 507 .WillOnce(Return(QuicConsumedData(9 + 16394, false)))
507 .WillOnce(Return(QuicConsumedData(9 + 16394, false))); 508 .WillOnce(Return(QuicConsumedData(9 + 16394, false)));
508 EXPECT_CALL(*connection_, SendBlocked(_)); 509 EXPECT_CALL(*connection_, SendBlocked(_));
509 } 510 }
510 } 511 }
511 } 512 }
512 session_->PromisePushResources(request_url, push_resources, 513 session_->PromisePushResources(request_url, push_resources,
(...skipping 28 matching lines...) Expand all
541 // draining, a queued promised stream will become open and send push response. 542 // draining, a queued promised stream will become open and send push response.
542 size_t num_resources = kMaxStreamsForTest + 1; 543 size_t num_resources = kMaxStreamsForTest + 1;
543 PromisePushResources(num_resources); 544 PromisePushResources(num_resources);
544 QuicStreamId next_out_going_stream_id = num_resources * 2; 545 QuicStreamId next_out_going_stream_id = num_resources * 2;
545 546
546 // After an open stream is marked draining, a new stream is expected to be 547 // After an open stream is marked draining, a new stream is expected to be
547 // created and a response sent on the stream. 548 // created and a response sent on the stream.
548 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false, 549 EXPECT_CALL(*session_, WriteHeadersMock(next_out_going_stream_id, _, false,
549 kDefaultPriority, _)); 550 kDefaultPriority, _));
550 EXPECT_CALL(*connection_, 551 EXPECT_CALL(*connection_,
551 SendStreamData(next_out_going_stream_id, _, 0, false, _)) 552 SendStreamData(next_out_going_stream_id, _, 0, NO_FIN, _))
552 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 553 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
553 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id)); 554 EXPECT_CALL(*connection_, SendBlocked(next_out_going_stream_id));
554 session_->StreamDraining(2); 555 session_->StreamDraining(2);
555 // Number of open outgoing streams should still be the same, because a new 556 // Number of open outgoing streams should still be the same, because a new
556 // stream is opened. And the queue should be empty. 557 // stream is opened. And the queue should be empty.
557 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams()); 558 EXPECT_EQ(kMaxStreamsForTest, session_->GetNumOpenOutgoingStreams());
558 } 559 }
559 560
560 TEST_P(QuicSimpleServerSessionServerPushTest, 561 TEST_P(QuicSimpleServerSessionServerPushTest,
561 ResetPromisedStreamToCancelServerPush) { 562 ResetPromisedStreamToCancelServerPush) {
(...skipping 16 matching lines...) Expand all
578 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0)); 579 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, 0));
579 visitor_->OnRstStream(rst); 580 visitor_->OnRstStream(rst);
580 581
581 // When the first 2 streams becomes draining, the two queued up stream could 582 // When the first 2 streams becomes draining, the two queued up stream could
582 // be created. But since one of them was marked cancelled due to RST frame, 583 // be created. But since one of them was marked cancelled due to RST frame,
583 // only one queued resource will be sent out. 584 // only one queued resource will be sent out.
584 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2; 585 QuicStreamId stream_not_reset = (kMaxStreamsForTest + 1) * 2;
585 InSequence s; 586 InSequence s;
586 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false, 587 EXPECT_CALL(*session_, WriteHeadersMock(stream_not_reset, _, false,
587 kDefaultPriority, _)); 588 kDefaultPriority, _));
588 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, false, _)) 589 EXPECT_CALL(*connection_, SendStreamData(stream_not_reset, _, 0, NO_FIN, _))
589 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 590 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
590 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset)); 591 EXPECT_CALL(*connection_, SendBlocked(stream_not_reset));
591 EXPECT_CALL(*session_, 592 EXPECT_CALL(*session_,
592 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _)) 593 WriteHeadersMock(stream_got_reset, _, false, kDefaultPriority, _))
593 .Times(0); 594 .Times(0);
594 595
595 session_->StreamDraining(2); 596 session_->StreamDraining(2);
596 session_->StreamDraining(4); 597 session_->StreamDraining(4);
597 } 598 }
598 599
599 TEST_P(QuicSimpleServerSessionServerPushTest, 600 TEST_P(QuicSimpleServerSessionServerPushTest,
600 CloseStreamToHandleMorePromisedStream) { 601 CloseStreamToHandleMorePromisedStream) {
601 if (session_->force_hol_blocking()) { 602 if (session_->force_hol_blocking()) {
602 return; 603 return;
603 } 604 }
604 // Tests that closing a open outgoing stream can trigger a promised resource 605 // Tests that closing a open outgoing stream can trigger a promised resource
605 // in the queue to be send out. 606 // in the queue to be send out.
606 size_t num_resources = kMaxStreamsForTest + 1; 607 size_t num_resources = kMaxStreamsForTest + 1;
607 PromisePushResources(num_resources); 608 PromisePushResources(num_resources);
608 QuicStreamId stream_to_open = num_resources * 2; 609 QuicStreamId stream_to_open = num_resources * 2;
609 610
610 // Resetting 1st open stream will close the stream and give space for extra 611 // Resetting 1st open stream will close the stream and give space for extra
611 // stream to be opened. 612 // stream to be opened.
612 QuicStreamId stream_got_reset = 2; 613 QuicStreamId stream_got_reset = 2;
613 EXPECT_CALL(*connection_, 614 EXPECT_CALL(*connection_,
614 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _)); 615 SendRstStream(stream_got_reset, QUIC_RST_ACKNOWLEDGEMENT, _));
615 EXPECT_CALL(*session_, 616 EXPECT_CALL(*session_,
616 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _)); 617 WriteHeadersMock(stream_to_open, _, false, kDefaultPriority, _));
617 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, false, _)) 618 EXPECT_CALL(*connection_, SendStreamData(stream_to_open, _, 0, NO_FIN, _))
618 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false))); 619 .WillOnce(Return(QuicConsumedData(kStreamFlowControlWindowSize, false)));
619 620
620 EXPECT_CALL(*connection_, SendBlocked(stream_to_open)); 621 EXPECT_CALL(*connection_, SendBlocked(stream_to_open));
621 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1); 622 EXPECT_CALL(owner_, OnRstStreamReceived(_)).Times(1);
622 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0); 623 QuicRstStreamFrame rst(stream_got_reset, QUIC_STREAM_CANCELLED, 0);
623 visitor_->OnRstStream(rst); 624 visitor_->OnRstStream(rst);
624 } 625 }
625 626
626 } // namespace 627 } // namespace
627 } // namespace test 628 } // namespace test
628 } // namespace net 629 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_server_session.cc ('k') | net/tools/quic/quic_simple_server_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698