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