If there are no local credentials for a locked profile, show sign in button
[chromium-blink-merge.git] / net / tools / quic / quic_spdy_client_stream_test.cc
blob03f8cc29e6032dbdf1939385539ef8059c0b4dd9
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 stream_->OnStreamFrame(
76 QuicStreamFrame(stream_->id(), /*fin=*/false, /*offset=*/0, body_));
77 if (GetParam() > QUIC_VERSION_24) {
78 EXPECT_EQ("200", stream_->headers().find(":status")->second);
79 } else {
80 EXPECT_EQ("200 Ok", stream_->headers().find(":status")->second);
82 EXPECT_EQ(200, stream_->response_code());
83 EXPECT_EQ(body_, stream_->data());
86 TEST_P(QuicSpdyClientStreamTest, TestFramingOnePacket) {
87 stream_->OnStreamHeaders(headers_string_);
88 stream_->OnStreamHeadersComplete(false, headers_string_.size());
89 stream_->OnStreamFrame(
90 QuicStreamFrame(stream_->id(), /*fin=*/false, /*offset=*/0, body_));
91 if (GetParam() > QUIC_VERSION_24) {
92 EXPECT_EQ("200", stream_->headers().find(":status")->second);
93 } else {
94 EXPECT_EQ("200 Ok", stream_->headers().find(":status")->second);
96 EXPECT_EQ(200, stream_->response_code());
97 EXPECT_EQ(body_, stream_->data());
100 TEST_P(QuicSpdyClientStreamTest, DISABLED_TestFramingExtraData) {
101 string large_body = "hello world!!!!!!";
103 stream_->OnStreamHeaders(headers_string_);
104 stream_->OnStreamHeadersComplete(false, headers_string_.size());
105 // The headers should parse successfully.
106 EXPECT_EQ(QUIC_STREAM_NO_ERROR, stream_->stream_error());
107 if (GetParam() > QUIC_VERSION_24) {
108 EXPECT_EQ("200", stream_->headers().find(":status")->second);
109 } else {
110 EXPECT_EQ("200 Ok", stream_->headers().find(":status")->second);
112 EXPECT_EQ(200, stream_->response_code());
114 EXPECT_CALL(*connection_,
115 SendRstStream(stream_->id(), QUIC_BAD_APPLICATION_PAYLOAD, 0));
116 stream_->OnStreamFrame(
117 QuicStreamFrame(stream_->id(), /*fin=*/false, /*offset=*/0, large_body));
119 EXPECT_NE(QUIC_STREAM_NO_ERROR, stream_->stream_error());
122 TEST_P(QuicSpdyClientStreamTest, TestNoBidirectionalStreaming) {
123 QuicStreamFrame frame(kClientDataStreamId1, false, 3, StringPiece("asd"));
125 EXPECT_FALSE(stream_->write_side_closed());
126 stream_->OnStreamFrame(frame);
127 EXPECT_TRUE(stream_->write_side_closed());
130 } // namespace
131 } // namespace test
132 } // namespace tools
133 } // namespace net