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 |
11 #include "net/quic/core/quic_utils.h" | 11 #include "net/quic/core/quic_utils.h" |
12 #include "net/quic/core/spdy_utils.h" | 12 #include "net/quic/core/spdy_utils.h" |
13 #include "net/quic/platform/api/quic_ptr_util.h" | 13 #include "net/quic/platform/api/quic_ptr_util.h" |
14 #include "net/quic/platform/api/quic_socket_address.h" | 14 #include "net/quic/platform/api/quic_socket_address.h" |
15 #include "net/quic/platform/api/quic_test.h" | 15 #include "net/quic/platform/api/quic_test.h" |
16 #include "net/quic/test_tools/crypto_test_utils.h" | 16 #include "net/quic/test_tools/crypto_test_utils.h" |
| 17 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
17 #include "net/quic/test_tools/quic_stream_peer.h" | 18 #include "net/quic/test_tools/quic_stream_peer.h" |
18 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
19 #include "net/test/gtest_util.h" | 20 #include "net/test/gtest_util.h" |
20 #include "net/tools/quic/quic_http_response_cache.h" | 21 #include "net/tools/quic/quic_http_response_cache.h" |
21 #include "net/tools/quic/quic_simple_server_session.h" | 22 #include "net/tools/quic/quic_simple_server_session.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 using std::string; | 26 using std::string; |
26 using testing::_; | 27 using testing::_; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 header_list_.OnHeader(":version", "HTTP/1.1"); | 194 header_list_.OnHeader(":version", "HTTP/1.1"); |
194 header_list_.OnHeader("content-length", "11"); | 195 header_list_.OnHeader("content-length", "11"); |
195 header_list_.OnHeaderBlockEnd(128); | 196 header_list_.OnHeaderBlockEnd(128); |
196 | 197 |
197 // New streams rely on having the peer's flow control receive window | 198 // New streams rely on having the peer's flow control receive window |
198 // negotiated in the config. | 199 // negotiated in the config. |
199 session_.config()->SetInitialStreamFlowControlWindowToSend( | 200 session_.config()->SetInitialStreamFlowControlWindowToSend( |
200 kInitialStreamFlowControlWindowForTest); | 201 kInitialStreamFlowControlWindowForTest); |
201 session_.config()->SetInitialSessionFlowControlWindowToSend( | 202 session_.config()->SetInitialSessionFlowControlWindowToSend( |
202 kInitialSessionFlowControlWindowForTest); | 203 kInitialSessionFlowControlWindowForTest); |
203 stream_ = new QuicSimpleServerStreamPeer(kClientDataStreamId1, &session_, | 204 stream_ = new QuicSimpleServerStreamPeer( |
204 &response_cache_); | 205 QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, 0), |
| 206 &session_, &response_cache_); |
205 // Register stream_ in dynamic_stream_map_ and pass ownership to session_. | 207 // Register stream_ in dynamic_stream_map_ and pass ownership to session_. |
206 session_.ActivateStream(QuicWrapUnique(stream_)); | 208 session_.ActivateStream(QuicWrapUnique(stream_)); |
207 } | 209 } |
208 | 210 |
209 const string& StreamBody() { | 211 const string& StreamBody() { |
210 return QuicSimpleServerStreamPeer::body(stream_); | 212 return QuicSimpleServerStreamPeer::body(stream_); |
211 } | 213 } |
212 | 214 |
213 string StreamHeadersValue(const string& key) { | 215 string StreamHeadersValue(const string& key) { |
214 return (*stream_->mutable_headers())[key].as_string(); | 216 return (*stream_->mutable_headers())[key].as_string(); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 host, request_path, 200, body, push_resources); | 439 host, request_path, 200, body, push_resources); |
438 | 440 |
439 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); | 441 SpdyHeaderBlock* request_headers = stream_->mutable_headers(); |
440 (*request_headers)[":path"] = request_path; | 442 (*request_headers)[":path"] = request_path; |
441 (*request_headers)[":authority"] = host; | 443 (*request_headers)[":authority"] = host; |
442 (*request_headers)[":version"] = "HTTP/1.1"; | 444 (*request_headers)[":version"] = "HTTP/1.1"; |
443 (*request_headers)[":method"] = "GET"; | 445 (*request_headers)[":method"] = "GET"; |
444 | 446 |
445 stream_->set_fin_received(true); | 447 stream_->set_fin_received(true); |
446 InSequence s; | 448 InSequence s; |
447 EXPECT_CALL(session_, PromisePushResourcesMock(host + request_path, _, | 449 EXPECT_CALL( |
448 kClientDataStreamId1, _)); | 450 session_, |
| 451 PromisePushResourcesMock( |
| 452 host + request_path, _, |
| 453 QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, 0), _)); |
449 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); | 454 EXPECT_CALL(session_, WriteHeadersMock(stream_->id(), _, false, _, _)); |
450 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 455 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
451 .Times(1) | 456 .Times(1) |
452 .WillOnce(Return(QuicConsumedData(body.length(), true))); | 457 .WillOnce(Return(QuicConsumedData(body.length(), true))); |
453 QuicSimpleServerStreamPeer::SendResponse(stream_); | 458 QuicSimpleServerStreamPeer::SendResponse(stream_); |
454 EXPECT_EQ(*request_headers, session_.original_request_headers_); | 459 EXPECT_EQ(*request_headers, session_.original_request_headers_); |
455 } | 460 } |
456 | 461 |
457 TEST_P(QuicSimpleServerStreamTest, PushResponseOnClientInitiatedStream) { | 462 TEST_P(QuicSimpleServerStreamTest, PushResponseOnClientInitiatedStream) { |
458 // Calling PushResponse() on a client initialted stream is never supposed to | 463 // Calling PushResponse() on a client initialted stream is never supposed to |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 496 |
492 // Call PushResponse() should trigger stream to fetch response from cache | 497 // Call PushResponse() should trigger stream to fetch response from cache |
493 // and send it back. | 498 // and send it back. |
494 EXPECT_CALL(session_, | 499 EXPECT_CALL(session_, |
495 WriteHeadersMock(kServerInitiatedStreamId, _, false, | 500 WriteHeadersMock(kServerInitiatedStreamId, _, false, |
496 server_initiated_stream->priority(), _)); | 501 server_initiated_stream->priority(), _)); |
497 EXPECT_CALL(session_, WritevData(_, kServerInitiatedStreamId, _, _, _, _)) | 502 EXPECT_CALL(session_, WritevData(_, kServerInitiatedStreamId, _, _, _, _)) |
498 .Times(1) | 503 .Times(1) |
499 .WillOnce(Return(QuicConsumedData(kBody.size(), true))); | 504 .WillOnce(Return(QuicConsumedData(kBody.size(), true))); |
500 server_initiated_stream->PushResponse(std::move(headers)); | 505 server_initiated_stream->PushResponse(std::move(headers)); |
501 EXPECT_EQ( | 506 EXPECT_EQ(kPath, QuicSimpleServerStreamPeer::headers( |
502 kPath, | 507 server_initiated_stream)[":path"] |
503 QuicSimpleServerStreamPeer::headers(server_initiated_stream)[":path"] | 508 .as_string()); |
504 .as_string()); | 509 EXPECT_EQ("GET", QuicSimpleServerStreamPeer::headers( |
505 EXPECT_EQ( | 510 server_initiated_stream)[":method"] |
506 "GET", | 511 .as_string()); |
507 QuicSimpleServerStreamPeer::headers(server_initiated_stream)[":method"] | |
508 .as_string()); | |
509 } | 512 } |
510 | 513 |
511 TEST_P(QuicSimpleServerStreamTest, TestSendErrorResponse) { | 514 TEST_P(QuicSimpleServerStreamTest, TestSendErrorResponse) { |
512 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); | 515 EXPECT_CALL(session_, SendRstStream(_, QUIC_STREAM_NO_ERROR, _)).Times(0); |
513 | 516 |
514 stream_->set_fin_received(true); | 517 stream_->set_fin_received(true); |
515 | 518 |
516 InSequence s; | 519 InSequence s; |
517 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); | 520 EXPECT_CALL(session_, WriteHeadersMock(_, _, _, _, _)); |
518 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) | 521 EXPECT_CALL(session_, WritevData(_, _, _, _, _, _)) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 }; | 641 }; |
639 QuicStringPiece data(arr, arraysize(arr)); | 642 QuicStringPiece data(arr, arraysize(arr)); |
640 QuicStreamFrame frame(stream_->id(), true, 0, data); | 643 QuicStreamFrame frame(stream_->id(), true, 0, data); |
641 // Verify that we don't crash when we get a invalid headers in stream frame. | 644 // Verify that we don't crash when we get a invalid headers in stream frame. |
642 stream_->OnStreamFrame(frame); | 645 stream_->OnStreamFrame(frame); |
643 } | 646 } |
644 | 647 |
645 } // namespace | 648 } // namespace |
646 } // namespace test | 649 } // namespace test |
647 } // namespace net | 650 } // namespace net |
OLD | NEW |