We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / quic / quic_reliable_client_stream_test.cc
blob977542adbb30ee0098e055f147c42830e2347964
1 // Copyright (c) 2012 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/quic/quic_reliable_client_stream.h"
7 #include "net/base/net_errors.h"
8 #include "net/base/test_completion_callback.h"
9 #include "net/quic/quic_client_session.h"
10 #include "net/quic/quic_utils.h"
11 #include "net/quic/spdy_utils.h"
12 #include "net/quic/test_tools/quic_test_utils.h"
13 #include "testing/gmock/include/gmock/gmock.h"
15 using testing::AnyNumber;
16 using testing::Return;
17 using testing::StrEq;
18 using testing::_;
20 namespace net {
21 namespace test {
22 namespace {
24 const QuicConnectionId kStreamId = 3;
26 class MockDelegate : public QuicReliableClientStream::Delegate {
27 public:
28 MockDelegate() {}
30 MOCK_METHOD0(OnSendData, int());
31 MOCK_METHOD2(OnSendDataComplete, int(int, bool*));
32 MOCK_METHOD2(OnDataReceived, int(const char*, int));
33 MOCK_METHOD1(OnClose, void(QuicErrorCode));
34 MOCK_METHOD1(OnError, void(int));
35 MOCK_METHOD0(HasSendHeadersComplete, bool());
37 private:
38 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
41 class QuicReliableClientStreamTest
42 : public ::testing::TestWithParam<QuicVersion> {
43 public:
44 QuicReliableClientStreamTest()
45 : session_(new MockConnection(Perspective::IS_CLIENT,
46 SupportedVersions(GetParam()))) {
47 stream_ = new QuicReliableClientStream(kStreamId, &session_, BoundNetLog());
48 session_.ActivateStream(stream_);
49 stream_->SetDelegate(&delegate_);
52 void InitializeHeaders() {
53 headers_[":host"] = "www.google.com";
54 headers_[":path"] = "/index.hml";
55 headers_[":scheme"] = "https";
56 headers_["cookie"] =
57 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; "
58 "__utmc=160408618; "
59 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d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75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
77 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
78 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
79 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
82 testing::StrictMock<MockDelegate> delegate_;
83 MockSession session_;
84 QuicReliableClientStream* stream_;
85 QuicCryptoClientConfig crypto_config_;
86 SpdyHeaderBlock headers_;
89 INSTANTIATE_TEST_CASE_P(Version, QuicReliableClientStreamTest,
90 ::testing::ValuesIn(QuicSupportedVersions()));
92 TEST_P(QuicReliableClientStreamTest, OnFinRead) {
93 InitializeHeaders();
94 std::string uncompressed_headers =
95 SpdyUtils::SerializeUncompressedHeaders(headers_);
96 EXPECT_CALL(delegate_, OnDataReceived(StrEq(uncompressed_headers.data()),
97 uncompressed_headers.size()));
98 QuicStreamOffset offset = 0;
99 stream_->OnStreamHeaders(uncompressed_headers);
100 stream_->OnStreamHeadersComplete(false, uncompressed_headers.length());
102 IOVector iov;
103 QuicStreamFrame frame2(kStreamId, true, offset, iov);
104 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
105 stream_->OnStreamFrame(frame2);
108 TEST_P(QuicReliableClientStreamTest, ProcessData) {
109 const char data[] = "hello world!";
110 EXPECT_CALL(delegate_, OnDataReceived(StrEq(data), arraysize(data)));
111 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
113 EXPECT_EQ(arraysize(data), stream_->ProcessData(data, arraysize(data)));
116 TEST_P(QuicReliableClientStreamTest, ProcessDataWithError) {
117 const char data[] = "hello world!";
118 EXPECT_CALL(delegate_,
119 OnDataReceived(StrEq(data),
120 arraysize(data))).WillOnce(Return(ERR_UNEXPECTED));
121 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
124 EXPECT_EQ(0u, stream_->ProcessData(data, arraysize(data)));
127 TEST_P(QuicReliableClientStreamTest, OnError) {
128 EXPECT_CALL(delegate_, OnError(ERR_INTERNET_DISCONNECTED));
130 stream_->OnError(ERR_INTERNET_DISCONNECTED);
131 EXPECT_FALSE(stream_->GetDelegate());
134 TEST_P(QuicReliableClientStreamTest, WriteStreamData) {
135 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
137 const char kData1[] = "hello world";
138 const size_t kDataLen = arraysize(kData1);
140 // All data written.
141 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _, _)).WillOnce(
142 Return(QuicConsumedData(kDataLen, true)));
143 TestCompletionCallback callback;
144 EXPECT_EQ(OK, stream_->WriteStreamData(base::StringPiece(kData1, kDataLen),
145 true, callback.callback()));
148 TEST_P(QuicReliableClientStreamTest, WriteStreamDataAsync) {
149 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
150 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
152 const char kData1[] = "hello world";
153 const size_t kDataLen = arraysize(kData1);
155 // No data written.
156 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _, _)).WillOnce(
157 Return(QuicConsumedData(0, false)));
158 TestCompletionCallback callback;
159 EXPECT_EQ(ERR_IO_PENDING,
160 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen),
161 true, callback.callback()));
162 ASSERT_FALSE(callback.have_result());
164 // All data written.
165 EXPECT_CALL(session_, WritevData(stream_->id(), _, _, _, _, _)).WillOnce(
166 Return(QuicConsumedData(kDataLen, true)));
167 stream_->OnCanWrite();
168 ASSERT_TRUE(callback.have_result());
169 EXPECT_EQ(OK, callback.WaitForResult());
172 } // namespace
173 } // namespace test
174 } // namespace net