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_balsa_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
;
20 using net::test::kClientDataStreamId1
;
22 using testing::StrictMock
;
23 using testing::TestWithParam
;
30 class QuicSpdyClientStreamTest
: public TestWithParam
<QuicVersion
> {
32 QuicSpdyClientStreamTest()
34 new StrictMock
<MockConnection
>(Perspective::IS_CLIENT
,
35 SupportedVersions(GetParam()))),
36 session_(DefaultQuicConfig(),
38 QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED
),
40 body_("hello world") {
41 session_
.Initialize();
43 headers_
.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
44 headers_
.ReplaceOrAppendHeader("content-length", "11");
46 headers_string_
= net::tools::SpdyBalsaUtils::SerializeResponseHeaders(
47 headers_
, GetParam());
49 // New streams rely on having the peer's flow control receive window
50 // negotiated in the config.
51 session_
.config()->SetInitialStreamFlowControlWindowToSend(
52 kInitialStreamFlowControlWindowForTest
);
53 session_
.config()->SetInitialSessionFlowControlWindowToSend(
54 kInitialSessionFlowControlWindowForTest
);
55 stream_
.reset(new QuicSpdyClientStream(kClientDataStreamId1
, &session_
));
58 StrictMock
<MockConnection
>* connection_
;
59 QuicCryptoClientConfig crypto_config_
;
60 QuicClientSession session_
;
61 scoped_ptr
<QuicSpdyClientStream
> stream_
;
62 BalsaHeaders headers_
;
63 string headers_string_
;
67 INSTANTIATE_TEST_CASE_P(Tests
, QuicSpdyClientStreamTest
,
68 ::testing::ValuesIn(QuicSupportedVersions()));
70 TEST_P(QuicSpdyClientStreamTest
, TestFraming
) {
71 stream_
->OnStreamHeaders(headers_string_
);
72 stream_
->OnStreamHeadersComplete(false, headers_string_
.size());
73 EXPECT_EQ(body_
.size(), stream_
->ProcessData(body_
.c_str(), body_
.size()));
74 if (GetParam() > QUIC_VERSION_24
) {
75 EXPECT_EQ("200", stream_
->headers().find(":status")->second
);
77 EXPECT_EQ("200 Ok", stream_
->headers().find(":status")->second
);
79 EXPECT_EQ(200, stream_
->response_code());
80 EXPECT_EQ(body_
, stream_
->data());
83 TEST_P(QuicSpdyClientStreamTest
, TestFramingOnePacket
) {
84 stream_
->OnStreamHeaders(headers_string_
);
85 stream_
->OnStreamHeadersComplete(false, headers_string_
.size());
86 EXPECT_EQ(body_
.size(), stream_
->ProcessData(body_
.c_str(), body_
.size()));
87 if (GetParam() > QUIC_VERSION_24
) {
88 EXPECT_EQ("200", stream_
->headers().find(":status")->second
);
90 EXPECT_EQ("200 Ok", stream_
->headers().find(":status")->second
);
92 EXPECT_EQ(200, stream_
->response_code());
93 EXPECT_EQ(body_
, stream_
->data());
96 TEST_P(QuicSpdyClientStreamTest
, DISABLED_TestFramingExtraData
) {
97 string large_body
= "hello world!!!!!!";
99 stream_
->OnStreamHeaders(headers_string_
);
100 stream_
->OnStreamHeadersComplete(false, headers_string_
.size());
101 // The headers should parse successfully.
102 EXPECT_EQ(QUIC_STREAM_NO_ERROR
, stream_
->stream_error());
103 if (GetParam() > QUIC_VERSION_24
) {
104 EXPECT_EQ("200", stream_
->headers().find(":status")->second
);
106 EXPECT_EQ("200 Ok", stream_
->headers().find(":status")->second
);
108 EXPECT_EQ(200, stream_
->response_code());
110 EXPECT_CALL(*connection_
,
111 SendRstStream(stream_
->id(), QUIC_BAD_APPLICATION_PAYLOAD
, 0));
112 stream_
->ProcessData(large_body
.c_str(), large_body
.size());
114 EXPECT_NE(QUIC_STREAM_NO_ERROR
, stream_
->stream_error());
117 TEST_P(QuicSpdyClientStreamTest
, TestNoBidirectionalStreaming
) {
118 QuicStreamFrame
frame(kClientDataStreamId1
, false, 3, StringPiece("asd"));
120 EXPECT_FALSE(stream_
->write_side_closed());
121 stream_
->OnStreamFrame(frame
);
122 EXPECT_TRUE(stream_
->write_side_closed());