Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / net / tools / quic / quic_spdy_client_stream_test.cc
blob4396305879e063fa94065bda8944f3effa1ef522
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 "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 using net::test::DefaultQuicConfig;
17 using net::test::MockConnection;
18 using net::test::SupportedVersions;
19 using net::test::kClientDataStreamId1;
20 using net::test::kInitialSessionFlowControlWindowForTest;
21 using net::test::kInitialStreamFlowControlWindowForTest;
23 using std::string;
24 using testing::StrictMock;
25 using testing::TestWithParam;
27 namespace net {
28 namespace tools {
29 namespace test {
30 namespace {
32 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> {
33 public:
34 QuicSpdyClientStreamTest()
35 : connection_(
36 new StrictMock<MockConnection>(Perspective::IS_CLIENT,
37 SupportedVersions(GetParam()))),
38 session_(DefaultQuicConfig(),
39 connection_,
40 QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED),
41 &crypto_config_),
42 body_("hello world") {
43 session_.Initialize();
45 headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
46 headers_.ReplaceOrAppendHeader("content-length", "11");
48 headers_string_ = net::tools::SpdyBalsaUtils::SerializeResponseHeaders(
49 headers_, GetParam());
51 // New streams rely on having the peer's flow control receive window
52 // negotiated in the config.
53 session_.config()->SetInitialStreamFlowControlWindowToSend(
54 kInitialStreamFlowControlWindowForTest);
55 session_.config()->SetInitialSessionFlowControlWindowToSend(
56 kInitialSessionFlowControlWindowForTest);
57 stream_.reset(new QuicSpdyClientStream(kClientDataStreamId1, &session_));
60 StrictMock<MockConnection>* connection_;
61 QuicCryptoClientConfig crypto_config_;
62 QuicClientSession session_;
63 scoped_ptr<QuicSpdyClientStream> stream_;
64 BalsaHeaders headers_;
65 string headers_string_;
66 string body_;
69 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest,
70 ::testing::ValuesIn(QuicSupportedVersions()));
72 TEST_P(QuicSpdyClientStreamTest, TestFraming) {
73 stream_->OnStreamHeaders(headers_string_);
74 stream_->OnStreamHeadersComplete(false, headers_string_.size());
75 EXPECT_EQ(body_.size(), stream_->ProcessData(body_.c_str(), body_.size()));
76 if (GetParam() > QUIC_VERSION_24) {
77 EXPECT_EQ("200", stream_->headers().find(":status")->second);
78 } else {
79 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, TestFramingOnePacket) {
86 stream_->OnStreamHeaders(headers_string_);
87 stream_->OnStreamHeadersComplete(false, headers_string_.size());
88 EXPECT_EQ(body_.size(), stream_->ProcessData(body_.c_str(), body_.size()));
89 if (GetParam() > QUIC_VERSION_24) {
90 EXPECT_EQ("200", stream_->headers().find(":status")->second);
91 } else {
92 EXPECT_EQ("200 Ok", stream_->headers().find(":status")->second);
94 EXPECT_EQ(200, stream_->response_code());
95 EXPECT_EQ(body_, stream_->data());
98 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
99 string large_body = "hello world!!!!!!";
101 stream_->OnStreamHeaders(headers_string_);
102 stream_->OnStreamHeadersComplete(false, headers_string_.size());
103 // The headers should parse successfully.
104 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
105 if (GetParam() > QUIC_VERSION_24) {
106 EXPECT_EQ("200", stream_->headers().find(":status")->second);
107 } else {
108 EXPECT_EQ("200 Ok", stream_->headers().find(":status")->second);
110 EXPECT_EQ(200, stream_->response_code());
112 EXPECT_CALL(*connection_,
113 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0));
114 stream_->ProcessData(large_body.c_str(), large_body.size());
116 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error());
119 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) {
120 QuicStreamFrame frame(kClientDataStreamId1, false, 3, StringPiece("asd"));
122 EXPECT_FALSE(stream_->write_side_closed());
123 stream_->OnStreamFrame(frame);
124 EXPECT_TRUE(stream_->write_side_closed());
127 } // namespace
128 } // namespace test
129 } // namespace tools
130 } // namespace net