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
3 // found in the LICENSE file.
5 #include "net/tools/quic/quic_spdy_client_stream.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "net/quic/quic_utils.h"
9 #include "net/quic/test_tools/quic_test_utils.h"
10 #include "net/tools/epoll_server/epoll_server.h"
11 #include "net/tools/quic/quic_client_session.h"
12 #include "net/tools/quic/quic_spdy_client_stream.h"
13 #include "net/tools/quic/spdy_utils.h"
14 #include "net/tools/quic/test_tools/quic_test_utils.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using net::test::DefaultQuicConfig;
19 using net::test::SupportedVersions;
20 using testing::TestWithParam;
21 using testing::StrictMock;
28 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> {
30 QuicSpdyClientStreamTest()
31 : connection_(new StrictMock<MockConnection>(
32 false, SupportedVersions(GetParam()))),
33 session_(QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED),
37 body_("hello world") {
38 crypto_config_.SetDefaults();
40 headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
41 headers_.ReplaceOrAppendHeader("content-length", "11");
43 headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_);
45 // New streams rely on having the peer's flow control receive window
46 // negotiated in the config.
47 session_.config()->SetInitialFlowControlWindowToSend(
48 kInitialFlowControlWindowForTest);
49 stream_.reset(new QuicSpdyClientStream(3, &session_));
52 StrictMock<MockConnection>* connection_;
53 QuicClientSession session_;
54 scoped_ptr<QuicSpdyClientStream> stream_;
55 BalsaHeaders headers_;
56 string headers_string_;
58 QuicCryptoClientConfig crypto_config_;
61 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest,
62 ::testing::ValuesIn(QuicSupportedVersions()));
64 TEST_P(QuicSpdyClientStreamTest, TestFraming) {
65 EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
66 headers_string_.c_str(), headers_string_.size()));
67 EXPECT_EQ(body_.size(),
68 stream_->ProcessData(body_.c_str(), body_.size()));
69 EXPECT_EQ(200u, stream_->headers().parsed_response_code());
70 EXPECT_EQ(body_, stream_->data());
73 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) {
74 string message = headers_string_ + body_;
76 EXPECT_EQ(message.size(), stream_->ProcessData(
77 message.c_str(), message.size()));
78 EXPECT_EQ(200u, stream_->headers().parsed_response_code());
79 EXPECT_EQ(body_, stream_->data());
82 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
83 string large_body = "hello world!!!!!!";
85 EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
86 headers_string_.c_str(), headers_string_.size()));
87 // The headers should parse successfully.
88 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
89 EXPECT_EQ(200u, stream_->headers().parsed_response_code());
91 EXPECT_CALL(*connection_,
92 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0));
93 stream_->ProcessData(large_body.c_str(), large_body.size());
95 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error());
98 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) {
99 QuicStreamFrame frame(3, false, 3, MakeIOVector("asd"));
101 EXPECT_FALSE(stream_->write_side_closed());
102 EXPECT_TRUE(stream_->OnStreamFrame(frame));
103 EXPECT_TRUE(stream_->write_side_closed());