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/quic/quic_client_session.h"
11 #include "net/tools/quic/quic_spdy_client_stream.h"
12 #include "net/tools/quic/spdy_utils.h"
13 #include "net/tools/quic/test_tools/quic_test_utils.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 using net::test::DefaultQuicConfig
;
18 using net::test::MockConnection
;
19 using net::test::SupportedVersions
;
21 using testing::StrictMock
;
22 using testing::TestWithParam
;
29 class QuicSpdyClientStreamTest
: public TestWithParam
<QuicVersion
> {
31 QuicSpdyClientStreamTest()
33 new StrictMock
<MockConnection
>(Perspective::IS_CLIENT
,
34 SupportedVersions(GetParam()))),
35 session_(DefaultQuicConfig(), connection_
),
36 body_("hello world") {
37 session_
.InitializeSession(
38 QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED
),
41 headers_
.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
42 headers_
.ReplaceOrAppendHeader("content-length", "11");
44 headers_string_
= SpdyUtils::SerializeResponseHeaders(headers_
);
46 // New streams rely on having the peer's flow control receive window
47 // negotiated in the config.
48 session_
.config()->SetInitialStreamFlowControlWindowToSend(
49 kInitialStreamFlowControlWindowForTest
);
50 session_
.config()->SetInitialSessionFlowControlWindowToSend(
51 kInitialSessionFlowControlWindowForTest
);
52 stream_
.reset(new QuicSpdyClientStream(3, &session_
));
55 StrictMock
<MockConnection
>* connection_
;
56 QuicClientSession session_
;
57 scoped_ptr
<QuicSpdyClientStream
> stream_
;
58 BalsaHeaders headers_
;
59 string headers_string_
;
61 QuicCryptoClientConfig crypto_config_
;
64 INSTANTIATE_TEST_CASE_P(Tests
, QuicSpdyClientStreamTest
,
65 ::testing::ValuesIn(QuicSupportedVersions()));
67 TEST_P(QuicSpdyClientStreamTest
, TestFraming
) {
68 stream_
->OnStreamHeaders(headers_string_
);
69 stream_
->OnStreamHeadersComplete(false, headers_string_
.size());
70 EXPECT_EQ(body_
.size(), stream_
->ProcessData(body_
.c_str(), body_
.size()));
71 EXPECT_EQ("200 Ok", stream_
->headers().find(":status")->second
);
72 EXPECT_EQ(200, stream_
->response_code());
73 EXPECT_EQ(body_
, stream_
->data());
76 TEST_P(QuicSpdyClientStreamTest
, TestFramingOnePacket
) {
77 stream_
->OnStreamHeaders(headers_string_
);
78 stream_
->OnStreamHeadersComplete(false, headers_string_
.size());
79 EXPECT_EQ(body_
.size(), stream_
->ProcessData(body_
.c_str(), body_
.size()));
80 EXPECT_EQ("200 Ok", stream_
->headers().find(":status")->second
);
81 EXPECT_EQ(200, stream_
->response_code());
82 EXPECT_EQ(body_
, stream_
->data());
85 TEST_P(QuicSpdyClientStreamTest
, DISABLED_TestFramingExtraData
) {
86 string large_body
= "hello world!!!!!!";
88 stream_
->OnStreamHeaders(headers_string_
);
89 stream_
->OnStreamHeadersComplete(false, headers_string_
.size());
90 // The headers should parse successfully.
91 EXPECT_EQ(QUIC_STREAM_NO_ERROR
, stream_
->stream_error());
92 EXPECT_EQ("200 Ok", stream_
->headers().find(":status")->second
);
93 EXPECT_EQ(200, stream_
->response_code());
95 EXPECT_CALL(*connection_
,
96 SendRstStream(stream_
->id(), QUIC_BAD_APPLICATION_PAYLOAD
, 0));
97 stream_
->ProcessData(large_body
.c_str(), large_body
.size());
99 EXPECT_NE(QUIC_STREAM_NO_ERROR
, stream_
->stream_error());
102 TEST_P(QuicSpdyClientStreamTest
, TestNoBidirectionalStreaming
) {
103 QuicStreamFrame
frame(3, false, 3, MakeIOVector("asd"));
105 EXPECT_FALSE(stream_
->write_side_closed());
106 stream_
->OnStreamFrame(frame
);
107 EXPECT_TRUE(stream_
->write_side_closed());