Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / net / tools / quic / quic_spdy_client_stream_test.cc
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.
4
5 #include "net/tools/quic/quic_spdy_client_stream.h"
6
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"
17
18 using net::test::DefaultQuicConfig;
19 using net::test::SupportedVersions;
20 using testing::TestWithParam;
21 using testing::StrictMock;
22
23 namespace net {
24 namespace tools {
25 namespace test {
26 namespace {
27
28 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> {
29  public:
30   QuicSpdyClientStreamTest()
31       : connection_(new StrictMock<MockConnection>(
32             false, SupportedVersions(GetParam()))),
33         session_(QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED),
34                  DefaultQuicConfig(),
35                  connection_,
36                  &crypto_config_),
37         body_("hello world") {
38     crypto_config_.SetDefaults();
39
40     headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
41     headers_.ReplaceOrAppendHeader("content-length", "11");
42
43     headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_);
44
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_));
50   }
51
52   StrictMock<MockConnection>* connection_;
53   QuicClientSession session_;
54   scoped_ptr<QuicSpdyClientStream> stream_;
55   BalsaHeaders headers_;
56   string headers_string_;
57   string body_;
58   QuicCryptoClientConfig crypto_config_;
59 };
60
61 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest,
62                         ::testing::ValuesIn(QuicSupportedVersions()));
63
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());
71 }
72
73 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) {
74   string message = headers_string_ + body_;
75
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());
80 }
81
82 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
83   string large_body = "hello world!!!!!!";
84
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());
90
91   EXPECT_CALL(*connection_,
92               SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0));
93   stream_->ProcessData(large_body.c_str(), large_body.size());
94
95   EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error());
96 }
97
98 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) {
99   QuicStreamFrame frame(3, false, 3, MakeIOVector("asd"));
100
101   EXPECT_FALSE(stream_->write_side_closed());
102   EXPECT_TRUE(stream_->OnStreamFrame(frame));
103   EXPECT_TRUE(stream_->write_side_closed());
104 }
105
106 }  // namespace
107 }  // namespace test
108 }  // namespace tools
109 }  // namespace net