OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_stream.h" | 5 #include "net/tools/quic/quic_simple_server_stream.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 static int content_length(QuicSimpleServerStream* stream) { | 73 static int content_length(QuicSimpleServerStream* stream) { |
74 return stream->content_length_; | 74 return stream->content_length_; |
75 } | 75 } |
76 | 76 |
77 static SpdyHeaderBlock& headers(QuicSimpleServerStream* stream) { | 77 static SpdyHeaderBlock& headers(QuicSimpleServerStream* stream) { |
78 return stream->request_headers_; | 78 return stream->request_headers_; |
79 } | 79 } |
80 }; | 80 }; |
81 | 81 |
| 82 namespace { |
| 83 |
82 class MockQuicSimpleServerSession : public QuicSimpleServerSession { | 84 class MockQuicSimpleServerSession : public QuicSimpleServerSession { |
83 public: | 85 public: |
84 const size_t kMaxStreamsForTest = 100; | 86 const size_t kMaxStreamsForTest = 100; |
85 | 87 |
86 explicit MockQuicSimpleServerSession( | 88 explicit MockQuicSimpleServerSession( |
87 QuicConnection* connection, | 89 QuicConnection* connection, |
88 MockQuicSessionVisitor* owner, | 90 MockQuicSessionVisitor* owner, |
89 MockQuicCryptoServerStreamHelper* helper, | 91 MockQuicCryptoServerStreamHelper* helper, |
90 QuicCryptoServerConfig* crypto_config, | 92 QuicCryptoServerConfig* crypto_config, |
91 QuicCompressedCertsCache* compressed_certs_cache, | 93 QuicCompressedCertsCache* compressed_certs_cache, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 const SpdyHeaderBlock&)); | 167 const SpdyHeaderBlock&)); |
166 | 168 |
167 using QuicSession::ActivateStream; | 169 using QuicSession::ActivateStream; |
168 | 170 |
169 SpdyHeaderBlock original_request_headers_; | 171 SpdyHeaderBlock original_request_headers_; |
170 | 172 |
171 private: | 173 private: |
172 DISALLOW_COPY_AND_ASSIGN(MockQuicSimpleServerSession); | 174 DISALLOW_COPY_AND_ASSIGN(MockQuicSimpleServerSession); |
173 }; | 175 }; |
174 | 176 |
175 namespace { | |
176 | |
177 class QuicSimpleServerStreamTest | 177 class QuicSimpleServerStreamTest |
178 : public ::testing::TestWithParam<QuicVersion> { | 178 : public ::testing::TestWithParam<QuicVersion> { |
179 public: | 179 public: |
180 QuicSimpleServerStreamTest() | 180 QuicSimpleServerStreamTest() |
181 : connection_( | 181 : connection_( |
182 new StrictMock<MockQuicConnection>(&helper_, | 182 new StrictMock<MockQuicConnection>(&helper_, |
183 &alarm_factory_, | 183 &alarm_factory_, |
184 Perspective::IS_SERVER, | 184 Perspective::IS_SERVER, |
185 SupportedVersions(GetParam()))), | 185 SupportedVersions(GetParam()))), |
186 crypto_config_(new QuicCryptoServerConfig( | 186 crypto_config_(new QuicCryptoServerConfig( |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 // Call PushResponse() should trigger stream to fetch response from cache | 498 // Call PushResponse() should trigger stream to fetch response from cache |
499 // and send it back. | 499 // and send it back. |
500 EXPECT_CALL(session_, | 500 EXPECT_CALL(session_, |
501 WriteHeadersMock(kServerInitiatedStreamId, _, false, | 501 WriteHeadersMock(kServerInitiatedStreamId, _, false, |
502 server_initiated_stream->priority(), _)); | 502 server_initiated_stream->priority(), _)); |
503 EXPECT_CALL(session_, WritevData(_, kServerInitiatedStreamId, _, _, _, _)) | 503 EXPECT_CALL(session_, WritevData(_, kServerInitiatedStreamId, _, _, _, _)) |
504 .Times(1) | 504 .Times(1) |
505 .WillOnce(Return(QuicConsumedData(kBody.size(), true))); | 505 .WillOnce(Return(QuicConsumedData(kBody.size(), true))); |
506 server_initiated_stream->PushResponse(std::move(headers)); | 506 server_initiated_stream->PushResponse(std::move(headers)); |
507 EXPECT_EQ(kPath, QuicSimpleServerStreamPeer::headers( | 507 EXPECT_EQ( |
508 server_initiated_stream)[":path"] | 508 kPath, |
509 .as_string()); | 509 QuicSimpleServerStreamPeer::headers(server_initiated_stream)[":path"] |
510 EXPECT_EQ("GET", QuicSimpleServerStreamPeer::headers( | 510 .as_string()); |
511 server_initiated_stream)[":method"] | 511 EXPECT_EQ( |
512 .as_string()); | 512 "GET", |
| 513 QuicSimpleServerStreamPeer::headers(server_initiated_stream)[":method"] |
| 514 .as_string()); |
513 } | 515 } |
514 | 516 |
515 TEST_P(QuicSimpleServerStreamTest, TestSendErrorResponse) { | 517 TEST_P(QuicSimpleServerStreamTest, TestSendErrorResponse) { |
516 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); | 518 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); |
517 | 519 |
518 stream_->set_fin_received(true); | 520 stream_->set_fin_received(true); |
519 | 521 |
520 InSequence s; | 522 InSequence s; |
521 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); | 523 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); |
522 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 524 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 }; | 639 }; |
638 StringPiece data(arr, arraysize(arr)); | 640 StringPiece data(arr, arraysize(arr)); |
639 QuicStreamFrame frame(stream_->id(), true, 0, data); | 641 QuicStreamFrame frame(stream_->id(), true, 0, data); |
640 // Verify that we don't crash when we get a invalid headers in stream frame. | 642 // Verify that we don't crash when we get a invalid headers in stream frame. |
641 stream_->OnStreamFrame(frame); | 643 stream_->OnStreamFrame(frame); |
642 } | 644 } |
643 | 645 |
644 } // namespace | 646 } // namespace |
645 } // namespace test | 647 } // namespace test |
646 } // namespace net | 648 } // namespace net |
OLD | NEW |