Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / net / tools / quic / quic_spdy_client_stream_test.cc
blob09795da10cdf3ad1cd6ff867f9836573a7f14807
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::SupportedVersions;
19 using std::string;
20 using testing::StrictMock;
21 using testing::TestWithParam;
23 namespace net {
24 namespace tools {
25 namespace test {
26 namespace {
28 class QuicSpdyClientStreamTest : public TestWithParam<QuicVersion> {
29 public:
30 QuicSpdyClientStreamTest()
31 : connection_(new StrictMock<MockConnection>(
32 false, SupportedVersions(GetParam()))),
33 session_(DefaultQuicConfig(), connection_),
34 body_("hello world") {
35 session_.InitializeSession(
36 QuicServerId("example.com", 80, false, PRIVACY_MODE_DISABLED),
37 &crypto_config_);
39 headers_.SetResponseFirstlineFromStringPieces("HTTP/1.1", "200", "Ok");
40 headers_.ReplaceOrAppendHeader("content-length", "11");
42 headers_string_ = SpdyUtils::SerializeResponseHeaders(headers_);
44 // New streams rely on having the peer's flow control receive window
45 // negotiated in the config.
46 session_.config()->SetInitialStreamFlowControlWindowToSend(
47 kInitialStreamFlowControlWindowForTest);
48 session_.config()->SetInitialSessionFlowControlWindowToSend(
49 kInitialSessionFlowControlWindowForTest);
50 stream_.reset(new QuicSpdyClientStream(3, &session_));
53 StrictMock<MockConnection>* connection_;
54 QuicClientSession session_;
55 scoped_ptr<QuicSpdyClientStream> stream_;
56 BalsaHeaders headers_;
57 string headers_string_;
58 string body_;
59 QuicCryptoClientConfig crypto_config_;
62 INSTANTIATE_TEST_CASE_P(Tests, QuicSpdyClientStreamTest,
63 ::testing::ValuesIn(QuicSupportedVersions()));
65 TEST_P(QuicSpdyClientStreamTest, TestFraming) {
66 EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
67 headers_string_.c_str(), headers_string_.size()));
68 EXPECT_EQ(body_.size(),
69 stream_->ProcessData(body_.c_str(), body_.size()));
70 EXPECT_EQ(200u, stream_->headers().parsed_response_code());
71 EXPECT_EQ(body_, stream_->data());
74 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) {
75 string message = headers_string_ + body_;
77 EXPECT_EQ(message.size(), stream_->ProcessData(
78 message.c_str(), message.size()));
79 EXPECT_EQ(200u, stream_->headers().parsed_response_code());
80 EXPECT_EQ(body_, stream_->data());
83 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
84 string large_body = "hello world!!!!!!";
86 EXPECT_EQ(headers_string_.size(), stream_->ProcessData(
87 headers_string_.c_str(), headers_string_.size()));
88 // The headers should parse successfully.
89 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
90 EXPECT_EQ(200u, stream_->headers().parsed_response_code());
92 EXPECT_CALL(*connection_,
93 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0));
94 stream_->ProcessData(large_body.c_str(), large_body.size());
96 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error());
99 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) {
100 QuicStreamFrame frame(3, false, 3, MakeIOVector("asd"));
102 EXPECT_FALSE(stream_->write_side_closed());
103 stream_->OnStreamFrame(frame);
104 EXPECT_TRUE(stream_->write_side_closed());
107 } // namespace
108 } // namespace test
109 } // namespace tools
110 } // namespace net