Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: net/quic/quic_headers_stream_test.cc

Issue 1470713003: Landing Recent QUIC changes until and including Mon Nov 16 14:15:48 2015 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding NET_EXPORT_PRIVATE to DelegateInterface. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_headers_stream.h" 5 #include "net/quic/quic_headers_stream.h"
6 6
7 #include "net/quic/quic_utils.h" 7 #include "net/quic/quic_utils.h"
8 #include "net/quic/spdy_utils.h" 8 #include "net/quic/spdy_utils.h"
9 #include "net/quic/test_tools/quic_connection_peer.h" 9 #include "net/quic/test_tools/quic_connection_peer.h"
10 #include "net/quic/test_tools/quic_spdy_session_peer.h" 10 #include "net/quic/test_tools/quic_spdy_session_peer.h"
11 #include "net/quic/test_tools/quic_test_utils.h" 11 #include "net/quic/test_tools/quic_test_utils.h"
12 #include "net/quic/test_tools/reliable_quic_stream_peer.h" 12 #include "net/quic/test_tools/reliable_quic_stream_peer.h"
13 #include "net/spdy/spdy_alt_svc_wire_format.h" 13 #include "net/spdy/spdy_alt_svc_wire_format.h"
14 #include "net/spdy/spdy_protocol.h" 14 #include "net/spdy/spdy_protocol.h"
15 #include "net/spdy/spdy_test_utils.h" 15 #include "net/spdy/spdy_test_utils.h"
16 #include "net/test/gtest_util.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 using base::StringPiece; 19 using base::StringPiece;
19 using std::ostream; 20 using std::ostream;
20 using std::string; 21 using std::string;
21 using std::vector; 22 using std::vector;
22 using testing::ElementsAre; 23 using testing::ElementsAre;
23 using testing::InSequence; 24 using testing::InSequence;
24 using testing::Invoke; 25 using testing::Invoke;
25 using testing::StrictMock; 26 using testing::StrictMock;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 class QuicHeadersStreamTest : public ::testing::TestWithParam<TestParams> { 120 class QuicHeadersStreamTest : public ::testing::TestWithParam<TestParams> {
120 public: 121 public:
121 QuicHeadersStreamTest() 122 QuicHeadersStreamTest()
122 : connection_(new StrictMock<MockConnection>(&helper_, 123 : connection_(new StrictMock<MockConnection>(&helper_,
123 perspective(), 124 perspective(),
124 GetVersion())), 125 GetVersion())),
125 session_(connection_), 126 session_(connection_),
126 headers_stream_(QuicSpdySessionPeer::GetHeadersStream(&session_)), 127 headers_stream_(QuicSpdySessionPeer::GetHeadersStream(&session_)),
127 body_("hello world"), 128 body_("hello world"),
128 framer_(HTTP2), 129 framer_(HTTP2),
129 stream_frame_(kHeadersStreamId, /*fin=*/false, /*offset=*/0, "") { 130 stream_frame_(kHeadersStreamId, /*fin=*/false, /*offset=*/0, ""),
131 next_promised_stream_id_(2) {
130 headers_[":version"] = "HTTP/1.1"; 132 headers_[":version"] = "HTTP/1.1";
131 headers_[":status"] = "200 Ok"; 133 headers_[":status"] = "200 Ok";
132 headers_["content-length"] = "11"; 134 headers_["content-length"] = "11";
133 framer_.set_visitor(&visitor_); 135 framer_.set_visitor(&visitor_);
134 EXPECT_EQ(version(), session_.connection()->version()); 136 EXPECT_EQ(version(), session_.connection()->version());
135 EXPECT_TRUE(headers_stream_ != nullptr); 137 EXPECT_TRUE(headers_stream_ != nullptr);
136 VLOG(1) << GetParam(); 138 VLOG(1) << GetParam();
137 connection_->AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 139 connection_->AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
138 } 140 }
139 141
(...skipping 10 matching lines...) Expand all
150 saved_header_data_.append(data, len); 152 saved_header_data_.append(data, len);
151 return true; 153 return true;
152 } 154 }
153 155
154 void SaveHeaderDataStringPiece(StringPiece data) { 156 void SaveHeaderDataStringPiece(StringPiece data) {
155 saved_header_data_.append(data.data(), data.length()); 157 saved_header_data_.append(data.data(), data.length());
156 } 158 }
157 159
158 void WriteHeadersAndExpectSynStream(QuicStreamId stream_id, 160 void WriteHeadersAndExpectSynStream(QuicStreamId stream_id,
159 bool fin, 161 bool fin,
160 QuicPriority priority) { 162 SpdyPriority priority) {
161 WriteHeadersAndCheckData(stream_id, fin, priority, SYN_STREAM); 163 WriteHeadersAndCheckData(stream_id, fin, priority, SYN_STREAM);
162 } 164 }
163 165
164 void WriteHeadersAndExpectSynReply(QuicStreamId stream_id, 166 void WriteHeadersAndExpectSynReply(QuicStreamId stream_id,
165 bool fin) { 167 bool fin) {
166 WriteHeadersAndCheckData(stream_id, fin, 0, SYN_REPLY); 168 WriteHeadersAndCheckData(stream_id, fin, 0, SYN_REPLY);
167 } 169 }
168 170
169 void WriteHeadersAndCheckData(QuicStreamId stream_id, 171 void WriteHeadersAndCheckData(QuicStreamId stream_id,
170 bool fin, 172 bool fin,
171 QuicPriority priority, 173 SpdyPriority priority,
172 SpdyFrameType type) { 174 SpdyFrameType type) {
173 // Write the headers and capture the outgoing data 175 // Write the headers and capture the outgoing data
174 EXPECT_CALL(session_, WritevData(kHeadersStreamId, _, _, false, _, nullptr)) 176 EXPECT_CALL(session_, WritevData(kHeadersStreamId, _, _, false, _, nullptr))
175 .WillOnce(WithArgs<1>(Invoke(this, &QuicHeadersStreamTest::SaveIov))); 177 .WillOnce(WithArgs<1>(Invoke(this, &QuicHeadersStreamTest::SaveIov)));
176 headers_stream_->WriteHeaders(stream_id, headers_, fin, priority, nullptr); 178 headers_stream_->WriteHeaders(stream_id, headers_, fin, priority, nullptr);
177 179
178 // Parse the outgoing data and check that it matches was was written. 180 // Parse the outgoing data and check that it matches was was written.
179 if (type == SYN_STREAM) { 181 if (type == SYN_STREAM) {
180 EXPECT_CALL(visitor_, OnHeaders(stream_id, kHasPriority, priority, 182 EXPECT_CALL(visitor_, OnHeaders(stream_id, kHasPriority, priority,
181 /*parent_stream_id=*/0, 183 /*parent_stream_id=*/0,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 QuicVersionVector GetVersion() { 219 QuicVersionVector GetVersion() {
218 QuicVersionVector versions; 220 QuicVersionVector versions;
219 versions.push_back(version()); 221 versions.push_back(version());
220 return versions; 222 return versions;
221 } 223 }
222 224
223 void CloseConnection() { 225 void CloseConnection() {
224 QuicConnectionPeer::CloseConnection(connection_); 226 QuicConnectionPeer::CloseConnection(connection_);
225 } 227 }
226 228
229 QuicStreamId NextPromisedStreamId() { return next_promised_stream_id_++; }
230
227 static const bool kFrameComplete = true; 231 static const bool kFrameComplete = true;
228 static const bool kHasPriority = true; 232 static const bool kHasPriority = true;
229 233
230 MockConnectionHelper helper_; 234 MockConnectionHelper helper_;
231 StrictMock<MockConnection>* connection_; 235 StrictMock<MockConnection>* connection_;
232 StrictMock<MockQuicSpdySession> session_; 236 StrictMock<MockQuicSpdySession> session_;
233 QuicHeadersStream* headers_stream_; 237 QuicHeadersStream* headers_stream_;
234 SpdyHeaderBlock headers_; 238 SpdyHeaderBlock headers_;
235 string body_; 239 string body_;
236 string saved_data_; 240 string saved_data_;
237 string saved_header_data_; 241 string saved_header_data_;
238 SpdyFramer framer_; 242 SpdyFramer framer_;
239 StrictMock<MockVisitor> visitor_; 243 StrictMock<MockVisitor> visitor_;
240 QuicStreamFrame stream_frame_; 244 QuicStreamFrame stream_frame_;
245 QuicStreamId next_promised_stream_id_;
241 }; 246 };
242 247
243 INSTANTIATE_TEST_CASE_P(Tests, 248 INSTANTIATE_TEST_CASE_P(Tests,
244 QuicHeadersStreamTest, 249 QuicHeadersStreamTest,
245 ::testing::ValuesIn(GetTestParams())); 250 ::testing::ValuesIn(GetTestParams()));
246 251
247 TEST_P(QuicHeadersStreamTest, StreamId) { 252 TEST_P(QuicHeadersStreamTest, StreamId) {
248 EXPECT_EQ(3u, headers_stream_->id()); 253 EXPECT_EQ(3u, headers_stream_->id());
249 } 254 }
250 255
251 TEST_P(QuicHeadersStreamTest, EffectivePriority) { 256 TEST_P(QuicHeadersStreamTest, Priority) {
252 EXPECT_EQ(0u, headers_stream_->EffectivePriority()); 257 EXPECT_EQ(0u, headers_stream_->Priority());
253 } 258 }
254 259
255 TEST_P(QuicHeadersStreamTest, WriteHeaders) { 260 TEST_P(QuicHeadersStreamTest, WriteHeaders) {
256 for (QuicStreamId stream_id = kClientDataStreamId1; 261 for (QuicStreamId stream_id = kClientDataStreamId1;
257 stream_id < kClientDataStreamId3; stream_id += 2) { 262 stream_id < kClientDataStreamId3; stream_id += 2) {
258 for (bool fin : kFins) { 263 for (bool fin : kFins) {
259 if (perspective() == Perspective::IS_SERVER) { 264 if (perspective() == Perspective::IS_SERVER) {
260 WriteHeadersAndExpectSynReply(stream_id, fin); 265 WriteHeadersAndExpectSynReply(stream_id, fin);
261 } else { 266 } else {
262 for (QuicPriority priority = 0; priority < 7; ++priority) { 267 for (SpdyPriority priority = 0; priority < 7; ++priority) {
263 // TODO(rch): implement priorities correctly. 268 // TODO(rch): implement priorities correctly.
264 WriteHeadersAndExpectSynStream(stream_id, fin, 0); 269 WriteHeadersAndExpectSynStream(stream_id, fin, 0);
265 } 270 }
266 } 271 }
267 } 272 }
268 } 273 }
269 } 274 }
270 275
276 TEST_P(QuicHeadersStreamTest, WritePushPromises) {
277 for (QuicStreamId stream_id = kClientDataStreamId1;
278 stream_id < kClientDataStreamId3; stream_id += 2) {
279 QuicStreamId promised_stream_id = NextPromisedStreamId();
280 if (perspective() == Perspective::IS_SERVER) {
281 // Write the headers and capture the outgoing data
282 EXPECT_CALL(session_,
283 WritevData(kHeadersStreamId, _, _, false, _, nullptr))
284 .WillOnce(WithArgs<1>(Invoke(this, &QuicHeadersStreamTest::SaveIov)));
285 headers_stream_->WritePushPromise(stream_id, promised_stream_id, headers_,
286 nullptr);
287
288 // Parse the outgoing data and check that it matches was was written.
289 EXPECT_CALL(visitor_,
290 OnPushPromise(stream_id, promised_stream_id, kFrameComplete));
291 EXPECT_CALL(visitor_, OnControlFrameHeaderData(stream_id, _, _))
292 .WillRepeatedly(WithArgs<1, 2>(
293 Invoke(this, &QuicHeadersStreamTest::SaveHeaderData)));
294 framer_.ProcessInput(saved_data_.data(), saved_data_.length());
295 EXPECT_FALSE(framer_.HasError())
296 << SpdyFramer::ErrorCodeToString(framer_.error_code());
297 CheckHeaders();
298 saved_data_.clear();
299 } else {
300 EXPECT_DFATAL(headers_stream_->WritePushPromise(
301 stream_id, promised_stream_id, headers_, nullptr),
302 "Client shouldn't send PUSH_PROMISE");
303 }
304 }
305 }
306
271 TEST_P(QuicHeadersStreamTest, ProcessRawData) { 307 TEST_P(QuicHeadersStreamTest, ProcessRawData) {
272 for (QuicStreamId stream_id = kClientDataStreamId1; 308 for (QuicStreamId stream_id = kClientDataStreamId1;
273 stream_id < kClientDataStreamId3; stream_id += 2) { 309 stream_id < kClientDataStreamId3; stream_id += 2) {
274 for (bool fin : kFins) { 310 for (bool fin : {false, true}) {
275 for (QuicPriority priority = 0; priority < 7; ++priority) { 311 for (SpdyPriority priority = 0; priority < 7; ++priority) {
276 // Replace with "WriteHeadersAndSaveData" 312 // Replace with "WriteHeadersAndSaveData"
277 scoped_ptr<SpdySerializedFrame> frame; 313 scoped_ptr<SpdySerializedFrame> frame;
278 if (perspective() == Perspective::IS_SERVER) { 314 if (perspective() == Perspective::IS_SERVER) {
279 SpdyHeadersIR headers_frame(stream_id); 315 SpdyHeadersIR headers_frame(stream_id);
280 headers_frame.set_header_block(headers_); 316 headers_frame.set_header_block(headers_);
281 headers_frame.set_fin(fin); 317 headers_frame.set_fin(fin);
282 headers_frame.set_has_priority(true); 318 headers_frame.set_has_priority(true);
283 frame.reset(framer_.SerializeFrame(headers_frame)); 319 frame.reset(framer_.SerializeFrame(headers_frame));
284 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0)); 320 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0));
285 } else { 321 } else {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 418
383 TEST_P(QuicHeadersStreamTest, ProcessLargeRawData) { 419 TEST_P(QuicHeadersStreamTest, ProcessLargeRawData) {
384 // We want to create a frame that is more than the SPDY Framer's max control 420 // We want to create a frame that is more than the SPDY Framer's max control
385 // frame size, which is 16K, but less than the HPACK decoders max decode 421 // frame size, which is 16K, but less than the HPACK decoders max decode
386 // buffer size, which is 32K. 422 // buffer size, which is 32K.
387 headers_["key0"] = string(1 << 13, '.'); 423 headers_["key0"] = string(1 << 13, '.');
388 headers_["key1"] = string(1 << 13, '.'); 424 headers_["key1"] = string(1 << 13, '.');
389 headers_["key2"] = string(1 << 13, '.'); 425 headers_["key2"] = string(1 << 13, '.');
390 for (QuicStreamId stream_id = kClientDataStreamId1; 426 for (QuicStreamId stream_id = kClientDataStreamId1;
391 stream_id < kClientDataStreamId3; stream_id += 2) { 427 stream_id < kClientDataStreamId3; stream_id += 2) {
392 for (bool fin : kFins) { 428 for (bool fin : {false, true}) {
393 for (QuicPriority priority = 0; priority < 7; ++priority) { 429 for (SpdyPriority priority = 0; priority < 7; ++priority) {
394 // Replace with "WriteHeadersAndSaveData" 430 // Replace with "WriteHeadersAndSaveData"
395 scoped_ptr<SpdySerializedFrame> frame; 431 scoped_ptr<SpdySerializedFrame> frame;
396 if (perspective() == Perspective::IS_SERVER) { 432 if (perspective() == Perspective::IS_SERVER) {
397 SpdyHeadersIR headers_frame(stream_id); 433 SpdyHeadersIR headers_frame(stream_id);
398 headers_frame.set_header_block(headers_); 434 headers_frame.set_header_block(headers_);
399 headers_frame.set_fin(fin); 435 headers_frame.set_fin(fin);
400 headers_frame.set_has_priority(true); 436 headers_frame.set_has_priority(true);
401 frame.reset(framer_.SerializeFrame(headers_frame)); 437 frame.reset(framer_.SerializeFrame(headers_frame));
402 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0)); 438 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0));
403 } else { 439 } else {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 542 }
507 543
508 TEST_P(QuicHeadersStreamTest, NoConnectionLevelFlowControl) { 544 TEST_P(QuicHeadersStreamTest, NoConnectionLevelFlowControl) {
509 EXPECT_FALSE(ReliableQuicStreamPeer::StreamContributesToConnectionFlowControl( 545 EXPECT_FALSE(ReliableQuicStreamPeer::StreamContributesToConnectionFlowControl(
510 headers_stream_)); 546 headers_stream_));
511 } 547 }
512 548
513 } // namespace 549 } // namespace
514 } // namespace test 550 } // namespace test
515 } // namespace net 551 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698