OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/reliable_quic_stream.h" | 5 #include "net/quic/reliable_quic_stream.h" |
6 | 6 |
7 #include "net/quic/quic_connection.h" | 7 #include "net/quic/quic_connection.h" |
8 #include "net/quic/quic_spdy_compressor.h" | 8 #include "net/quic/quic_spdy_compressor.h" |
9 #include "net/quic/quic_spdy_decompressor.h" | 9 #include "net/quic/quic_spdy_decompressor.h" |
10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 class TestStream : public ReliableQuicStream { | 36 class TestStream : public ReliableQuicStream { |
37 public: | 37 public: |
38 TestStream(QuicStreamId id, | 38 TestStream(QuicStreamId id, |
39 QuicSession* session, | 39 QuicSession* session, |
40 bool should_process_data) | 40 bool should_process_data) |
41 : ReliableQuicStream(id, session), | 41 : ReliableQuicStream(id, session), |
42 should_process_data_(should_process_data) { | 42 should_process_data_(should_process_data) { |
43 } | 43 } |
44 | 44 |
45 virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE { | 45 virtual uint32 ProcessData(const char* data, uint32 data_len) OVERRIDE { |
46 LOG(INFO) << "data_len: " << data_len; | 46 DVLOG(1) << "ProcessData data_len: " << data_len; |
47 data_ += string(data, data_len); | 47 data_ += string(data, data_len); |
48 return should_process_data_ ? data_len : 0; | 48 return should_process_data_ ? data_len : 0; |
49 } | 49 } |
50 | 50 |
51 using ReliableQuicStream::WriteData; | 51 using ReliableQuicStream::WriteData; |
52 using ReliableQuicStream::CloseReadSide; | 52 using ReliableQuicStream::CloseReadSide; |
53 using ReliableQuicStream::CloseWriteSide; | 53 using ReliableQuicStream::CloseWriteSide; |
54 | 54 |
55 const string& data() const { return data_; } | 55 const string& data() const { return data_; } |
56 | 56 |
57 private: | 57 private: |
58 bool should_process_data_; | 58 bool should_process_data_; |
59 string data_; | 59 string data_; |
60 }; | 60 }; |
61 | 61 |
62 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { | 62 class ReliableQuicStreamTest : public ::testing::TestWithParam<bool> { |
63 public: | 63 public: |
64 ReliableQuicStreamTest() { | 64 ReliableQuicStreamTest() { |
65 headers_[":host"] = "www.google.com"; | 65 headers_[":host"] = "www.google.com"; |
66 headers_[":path"] = "/index.hml"; | 66 headers_[":path"] = "/index.hml"; |
67 headers_[":scheme"] = "https"; | 67 headers_[":scheme"] = "https"; |
68 } | 68 } |
69 | 69 |
70 void Initialize(bool stream_should_process_data) { | 70 void Initialize(bool stream_should_process_data) { |
71 connection_ = new MockConnection(kGuid, IPEndPoint(), kIsServer); | 71 connection_ = new testing::StrictMock<MockConnection>( |
72 session_.reset(new MockSession(connection_, kIsServer)); | 72 kGuid, IPEndPoint(), kIsServer); |
| 73 session_.reset(new testing::StrictMock<MockSession>( |
| 74 connection_, kIsServer)); |
73 stream_.reset(new TestStream(kStreamId, session_.get(), | 75 stream_.reset(new TestStream(kStreamId, session_.get(), |
74 stream_should_process_data)); | 76 stream_should_process_data)); |
75 stream2_.reset(new TestStream(kStreamId + 2, session_.get(), | 77 stream2_.reset(new TestStream(kStreamId + 2, session_.get(), |
76 stream_should_process_data)); | 78 stream_should_process_data)); |
77 compressor_.reset(new QuicSpdyCompressor()); | 79 compressor_.reset(new QuicSpdyCompressor()); |
78 decompressor_.reset(new QuicSpdyDecompressor); | 80 decompressor_.reset(new QuicSpdyDecompressor); |
79 } | 81 } |
80 | 82 |
81 protected: | 83 protected: |
82 MockConnection* connection_; | 84 MockConnection* connection_; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 stream2_->OnStreamFrame(frame2); | 302 stream2_->OnStreamFrame(frame2); |
301 EXPECT_EQ("", stream_->data()); | 303 EXPECT_EQ("", stream_->data()); |
302 | 304 |
303 stream_->OnStreamFrame(frame1); | 305 stream_->OnStreamFrame(frame1); |
304 EXPECT_EQ(decompressed_headers1, stream_->data()); | 306 EXPECT_EQ(decompressed_headers1, stream_->data()); |
305 | 307 |
306 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); | 308 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
307 stream2_->OnDecompressorAvailable(); | 309 stream2_->OnDecompressorAvailable(); |
308 EXPECT_EQ(decompressed_headers2, stream2_->data()); | 310 EXPECT_EQ(decompressed_headers2, stream2_->data()); |
309 } | 311 } |
| 312 TEST_F(ReliableQuicStreamTest, ProcessHeadersDelay) { |
| 313 Initialize(!kShouldProcessData); |
| 314 |
| 315 string compressed_headers = compressor_->CompressHeaders(headers_); |
| 316 QuicStreamFrame frame1(stream_->id(), false, 0, compressed_headers); |
| 317 string decompressed_headers = |
| 318 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 319 |
| 320 // Send the headers to the stream and verify they were decompressed. |
| 321 stream_->OnStreamFrame(frame1); |
| 322 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
| 323 |
| 324 // Verify that we are now able to handle the body data, |
| 325 // even though the stream has not processed the headers. |
| 326 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) |
| 327 .Times(0); |
| 328 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), |
| 329 "body data"); |
| 330 stream_->OnStreamFrame(frame2); |
| 331 } |
310 | 332 |
311 } // namespace | 333 } // namespace |
312 } // namespace test | 334 } // namespace test |
313 } // namespace net | 335 } // namespace net |
OLD | NEW |