| OLD | NEW |
| 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" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 saved_header_data_.append(data, len); | 150 saved_header_data_.append(data, len); |
| 151 return true; | 151 return true; |
| 152 } | 152 } |
| 153 | 153 |
| 154 void SaveHeaderDataStringPiece(StringPiece data) { | 154 void SaveHeaderDataStringPiece(StringPiece data) { |
| 155 saved_header_data_.append(data.data(), data.length()); | 155 saved_header_data_.append(data.data(), data.length()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void WriteHeadersAndExpectSynStream(QuicStreamId stream_id, | 158 void WriteHeadersAndExpectSynStream(QuicStreamId stream_id, |
| 159 bool fin, | 159 bool fin, |
| 160 QuicPriority priority) { | 160 SpdyPriority priority) { |
| 161 WriteHeadersAndCheckData(stream_id, fin, priority, SYN_STREAM); | 161 WriteHeadersAndCheckData(stream_id, fin, priority, SYN_STREAM); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void WriteHeadersAndExpectSynReply(QuicStreamId stream_id, | 164 void WriteHeadersAndExpectSynReply(QuicStreamId stream_id, |
| 165 bool fin) { | 165 bool fin) { |
| 166 WriteHeadersAndCheckData(stream_id, fin, 0, SYN_REPLY); | 166 WriteHeadersAndCheckData(stream_id, fin, 0, SYN_REPLY); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void WriteHeadersAndCheckData(QuicStreamId stream_id, | 169 void WriteHeadersAndCheckData(QuicStreamId stream_id, |
| 170 bool fin, | 170 bool fin, |
| 171 QuicPriority priority, | 171 SpdyPriority priority, |
| 172 SpdyFrameType type) { | 172 SpdyFrameType type) { |
| 173 // Write the headers and capture the outgoing data | 173 // Write the headers and capture the outgoing data |
| 174 EXPECT_CALL(session_, WritevData(kHeadersStreamId, _, _, false, _, nullptr)) | 174 EXPECT_CALL(session_, WritevData(kHeadersStreamId, _, _, false, _, nullptr)) |
| 175 .WillOnce(WithArgs<1>(Invoke(this, &QuicHeadersStreamTest::SaveIov))); | 175 .WillOnce(WithArgs<1>(Invoke(this, &QuicHeadersStreamTest::SaveIov))); |
| 176 headers_stream_->WriteHeaders(stream_id, headers_, fin, priority, nullptr); | 176 headers_stream_->WriteHeaders(stream_id, headers_, fin, priority, nullptr); |
| 177 | 177 |
| 178 // Parse the outgoing data and check that it matches was was written. | 178 // Parse the outgoing data and check that it matches was was written. |
| 179 if (type == SYN_STREAM) { | 179 if (type == SYN_STREAM) { |
| 180 EXPECT_CALL(visitor_, OnHeaders(stream_id, kHasPriority, priority, | 180 EXPECT_CALL(visitor_, OnHeaders(stream_id, kHasPriority, priority, |
| 181 /*parent_stream_id=*/0, | 181 /*parent_stream_id=*/0, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 EXPECT_EQ(0u, headers_stream_->Priority()); | 252 EXPECT_EQ(0u, headers_stream_->Priority()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 TEST_P(QuicHeadersStreamTest, WriteHeaders) { | 255 TEST_P(QuicHeadersStreamTest, WriteHeaders) { |
| 256 for (QuicStreamId stream_id = kClientDataStreamId1; | 256 for (QuicStreamId stream_id = kClientDataStreamId1; |
| 257 stream_id < kClientDataStreamId3; stream_id += 2) { | 257 stream_id < kClientDataStreamId3; stream_id += 2) { |
| 258 for (bool fin : kFins) { | 258 for (bool fin : kFins) { |
| 259 if (perspective() == Perspective::IS_SERVER) { | 259 if (perspective() == Perspective::IS_SERVER) { |
| 260 WriteHeadersAndExpectSynReply(stream_id, fin); | 260 WriteHeadersAndExpectSynReply(stream_id, fin); |
| 261 } else { | 261 } else { |
| 262 for (QuicPriority priority = 0; priority < 7; ++priority) { | 262 for (SpdyPriority priority = 0; priority < 7; ++priority) { |
| 263 // TODO(rch): implement priorities correctly. | 263 // TODO(rch): implement priorities correctly. |
| 264 WriteHeadersAndExpectSynStream(stream_id, fin, 0); | 264 WriteHeadersAndExpectSynStream(stream_id, fin, 0); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 TEST_P(QuicHeadersStreamTest, ProcessRawData) { | 271 TEST_P(QuicHeadersStreamTest, ProcessRawData) { |
| 272 for (QuicStreamId stream_id = kClientDataStreamId1; | 272 for (QuicStreamId stream_id = kClientDataStreamId1; |
| 273 stream_id < kClientDataStreamId3; stream_id += 2) { | 273 stream_id < kClientDataStreamId3; stream_id += 2) { |
| 274 for (bool fin : kFins) { | 274 for (bool fin : {false, true}) { |
| 275 for (QuicPriority priority = 0; priority < 7; ++priority) { | 275 for (SpdyPriority priority = 0; priority < 7; ++priority) { |
| 276 // Replace with "WriteHeadersAndSaveData" | 276 // Replace with "WriteHeadersAndSaveData" |
| 277 scoped_ptr<SpdySerializedFrame> frame; | 277 scoped_ptr<SpdySerializedFrame> frame; |
| 278 if (perspective() == Perspective::IS_SERVER) { | 278 if (perspective() == Perspective::IS_SERVER) { |
| 279 SpdyHeadersIR headers_frame(stream_id); | 279 SpdyHeadersIR headers_frame(stream_id); |
| 280 headers_frame.set_header_block(headers_); | 280 headers_frame.set_header_block(headers_); |
| 281 headers_frame.set_fin(fin); | 281 headers_frame.set_fin(fin); |
| 282 headers_frame.set_has_priority(true); | 282 headers_frame.set_has_priority(true); |
| 283 frame.reset(framer_.SerializeFrame(headers_frame)); | 283 frame.reset(framer_.SerializeFrame(headers_frame)); |
| 284 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0)); | 284 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0)); |
| 285 } else { | 285 } else { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 382 |
| 383 TEST_P(QuicHeadersStreamTest, ProcessLargeRawData) { | 383 TEST_P(QuicHeadersStreamTest, ProcessLargeRawData) { |
| 384 // We want to create a frame that is more than the SPDY Framer's max control | 384 // 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 | 385 // frame size, which is 16K, but less than the HPACK decoders max decode |
| 386 // buffer size, which is 32K. | 386 // buffer size, which is 32K. |
| 387 headers_["key0"] = string(1 << 13, '.'); | 387 headers_["key0"] = string(1 << 13, '.'); |
| 388 headers_["key1"] = string(1 << 13, '.'); | 388 headers_["key1"] = string(1 << 13, '.'); |
| 389 headers_["key2"] = string(1 << 13, '.'); | 389 headers_["key2"] = string(1 << 13, '.'); |
| 390 for (QuicStreamId stream_id = kClientDataStreamId1; | 390 for (QuicStreamId stream_id = kClientDataStreamId1; |
| 391 stream_id < kClientDataStreamId3; stream_id += 2) { | 391 stream_id < kClientDataStreamId3; stream_id += 2) { |
| 392 for (bool fin : kFins) { | 392 for (bool fin : {false, true}) { |
| 393 for (QuicPriority priority = 0; priority < 7; ++priority) { | 393 for (SpdyPriority priority = 0; priority < 7; ++priority) { |
| 394 // Replace with "WriteHeadersAndSaveData" | 394 // Replace with "WriteHeadersAndSaveData" |
| 395 scoped_ptr<SpdySerializedFrame> frame; | 395 scoped_ptr<SpdySerializedFrame> frame; |
| 396 if (perspective() == Perspective::IS_SERVER) { | 396 if (perspective() == Perspective::IS_SERVER) { |
| 397 SpdyHeadersIR headers_frame(stream_id); | 397 SpdyHeadersIR headers_frame(stream_id); |
| 398 headers_frame.set_header_block(headers_); | 398 headers_frame.set_header_block(headers_); |
| 399 headers_frame.set_fin(fin); | 399 headers_frame.set_fin(fin); |
| 400 headers_frame.set_has_priority(true); | 400 headers_frame.set_has_priority(true); |
| 401 frame.reset(framer_.SerializeFrame(headers_frame)); | 401 frame.reset(framer_.SerializeFrame(headers_frame)); |
| 402 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0)); | 402 EXPECT_CALL(session_, OnStreamHeadersPriority(stream_id, 0)); |
| 403 } else { | 403 } else { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 506 } |
| 507 | 507 |
| 508 TEST_P(QuicHeadersStreamTest, NoConnectionLevelFlowControl) { | 508 TEST_P(QuicHeadersStreamTest, NoConnectionLevelFlowControl) { |
| 509 EXPECT_FALSE(ReliableQuicStreamPeer::StreamContributesToConnectionFlowControl( | 509 EXPECT_FALSE(ReliableQuicStreamPeer::StreamContributesToConnectionFlowControl( |
| 510 headers_stream_)); | 510 headers_stream_)); |
| 511 } | 511 } |
| 512 | 512 |
| 513 } // namespace | 513 } // namespace |
| 514 } // namespace test | 514 } // namespace test |
| 515 } // namespace net | 515 } // namespace net |
| OLD | NEW |