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

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

Issue 1471583002: Add WritePushPromise() method in QuicHeadersStream for server push. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@107697347
Patch Set: Created 5 years, 1 month 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 77 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
(...skipping 10 matching lines...) Expand all
261 } else { 266 } else {
262 for (SpdyPriority 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,
286 headers_, nullptr);
287
288 // Parse the outgoing data and check that it matches was was written.
289 EXPECT_CALL(visitor_, OnPushPromise(stream_id,
290 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(
301 headers_stream_->WritePushPromise(
302 stream_id, promised_stream_id, headers_, nullptr),
303 "Client shouldn't send PUSH_PROMISE");
304 }
305 }
306 }
307
271 TEST_P(QuicHeadersStreamTest, ProcessRawData) { 308 TEST_P(QuicHeadersStreamTest, ProcessRawData) {
272 for (QuicStreamId stream_id = kClientDataStreamId1; 309 for (QuicStreamId stream_id = kClientDataStreamId1;
273 stream_id < kClientDataStreamId3; stream_id += 2) { 310 stream_id < kClientDataStreamId3; stream_id += 2) {
274 for (bool fin : {false, true}) { 311 for (bool fin : {false, true}) {
275 for (SpdyPriority priority = 0; priority < 7; ++priority) { 312 for (SpdyPriority priority = 0; priority < 7; ++priority) {
276 // Replace with "WriteHeadersAndSaveData" 313 // Replace with "WriteHeadersAndSaveData"
277 scoped_ptr<SpdySerializedFrame> frame; 314 scoped_ptr<SpdySerializedFrame> frame;
278 if (perspective() == Perspective::IS_SERVER) { 315 if (perspective() == Perspective::IS_SERVER) {
279 SpdyHeadersIR headers_frame(stream_id); 316 SpdyHeadersIR headers_frame(stream_id);
280 headers_frame.set_header_block(headers_); 317 headers_frame.set_header_block(headers_);
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 543 }
507 544
508 TEST_P(QuicHeadersStreamTest, NoConnectionLevelFlowControl) { 545 TEST_P(QuicHeadersStreamTest, NoConnectionLevelFlowControl) {
509 EXPECT_FALSE(ReliableQuicStreamPeer::StreamContributesToConnectionFlowControl( 546 EXPECT_FALSE(ReliableQuicStreamPeer::StreamContributesToConnectionFlowControl(
510 headers_stream_)); 547 headers_stream_));
511 } 548 }
512 549
513 } // namespace 550 } // namespace
514 } // namespace test 551 } // namespace test
515 } // namespace net 552 } // namespace net
OLDNEW
« net/quic/quic_connection_test.cc ('K') | « net/quic/quic_headers_stream.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698