| 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/quic_data_stream.h" | 5 #include "net/quic/quic_data_stream.h" |
| 6 | 6 |
| 7 #include "net/quic/quic_ack_notifier.h" | 7 #include "net/quic/quic_ack_notifier.h" |
| 8 #include "net/quic/quic_connection.h" | 8 #include "net/quic/quic_connection.h" |
| 9 #include "net/quic/quic_spdy_compressor.h" | 9 #include "net/quic/quic_spdy_compressor.h" |
| 10 #include "net/quic/quic_spdy_decompressor.h" | 10 #include "net/quic/quic_spdy_decompressor.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 scoped_ptr<QuicSpdyCompressor> compressor_; | 110 scoped_ptr<QuicSpdyCompressor> compressor_; |
| 111 scoped_ptr<QuicSpdyDecompressor> decompressor_; | 111 scoped_ptr<QuicSpdyDecompressor> decompressor_; |
| 112 SpdyHeaderBlock headers_; | 112 SpdyHeaderBlock headers_; |
| 113 WriteBlockedList<QuicStreamId>* write_blocked_list_; | 113 WriteBlockedList<QuicStreamId>* write_blocked_list_; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 TEST_F(QuicDataStreamTest, ProcessHeaders) { | 116 TEST_F(QuicDataStreamTest, ProcessHeaders) { |
| 117 Initialize(kShouldProcessData); | 117 Initialize(kShouldProcessData); |
| 118 | 118 |
| 119 string compressed_headers = compressor_->CompressHeadersWithPriority( | 119 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 120 kHighestPriority, headers_); | 120 QuicUtils::HighestPriority(), headers_); |
| 121 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(compressed_headers)); | 121 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(compressed_headers)); |
| 122 | 122 |
| 123 stream_->OnStreamFrame(frame); | 123 stream_->OnStreamFrame(frame); |
| 124 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers_), stream_->data()); | 124 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers_), stream_->data()); |
| 125 EXPECT_EQ(static_cast<QuicPriority>(kHighestPriority), | 125 EXPECT_EQ(QuicUtils::HighestPriority(), stream_->EffectivePriority()); |
| 126 stream_->EffectivePriority()); | |
| 127 } | 126 } |
| 128 | 127 |
| 129 TEST_F(QuicDataStreamTest, ProcessHeadersWithInvalidHeaderId) { | 128 TEST_F(QuicDataStreamTest, ProcessHeadersWithInvalidHeaderId) { |
| 130 Initialize(kShouldProcessData); | 129 Initialize(kShouldProcessData); |
| 131 | 130 |
| 132 string compressed_headers = compressor_->CompressHeadersWithPriority( | 131 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 133 kHighestPriority, headers_); | 132 QuicUtils::HighestPriority(), headers_); |
| 134 compressed_headers[4] = '\xFF'; // Illegal header id. | 133 compressed_headers[4] = '\xFF'; // Illegal header id. |
| 135 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(compressed_headers)); | 134 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(compressed_headers)); |
| 136 | 135 |
| 137 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)); | 136 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)); |
| 138 stream_->OnStreamFrame(frame); | 137 stream_->OnStreamFrame(frame); |
| 139 } | 138 } |
| 140 | 139 |
| 141 TEST_F(QuicDataStreamTest, ProcessHeadersWithInvalidPriority) { | 140 TEST_F(QuicDataStreamTest, ProcessHeadersWithInvalidPriority) { |
| 142 Initialize(kShouldProcessData); | 141 Initialize(kShouldProcessData); |
| 143 | 142 |
| 144 string compressed_headers = compressor_->CompressHeadersWithPriority( | 143 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 145 kHighestPriority, headers_); | 144 QuicUtils::HighestPriority(), headers_); |
| 146 compressed_headers[0] = '\xFF'; // Illegal priority. | 145 compressed_headers[0] = '\xFF'; // Illegal priority. |
| 147 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(compressed_headers)); | 146 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(compressed_headers)); |
| 148 | 147 |
| 149 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_PRIORITY)); | 148 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_PRIORITY)); |
| 150 stream_->OnStreamFrame(frame); | 149 stream_->OnStreamFrame(frame); |
| 151 } | 150 } |
| 152 | 151 |
| 153 TEST_F(QuicDataStreamTest, ProcessHeadersAndBody) { | 152 TEST_F(QuicDataStreamTest, ProcessHeadersAndBody) { |
| 154 Initialize(kShouldProcessData); | 153 Initialize(kShouldProcessData); |
| 155 | 154 |
| 156 string compressed_headers = compressor_->CompressHeadersWithPriority( | 155 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 157 kHighestPriority, headers_); | 156 QuicUtils::HighestPriority(), headers_); |
| 158 string body = "this is the body"; | 157 string body = "this is the body"; |
| 159 string data = compressed_headers + body; | 158 string data = compressed_headers + body; |
| 160 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); | 159 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); |
| 161 | 160 |
| 162 stream_->OnStreamFrame(frame); | 161 stream_->OnStreamFrame(frame); |
| 163 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers_) + body, | 162 EXPECT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers_) + body, |
| 164 stream_->data()); | 163 stream_->data()); |
| 165 } | 164 } |
| 166 | 165 |
| 167 TEST_F(QuicDataStreamTest, ProcessHeadersAndBodyFragments) { | 166 TEST_F(QuicDataStreamTest, ProcessHeadersAndBodyFragments) { |
| 168 Initialize(kShouldProcessData); | 167 Initialize(kShouldProcessData); |
| 169 | 168 |
| 170 string compressed_headers = compressor_->CompressHeadersWithPriority( | 169 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 171 kLowestPriority, headers_); | 170 QuicUtils::LowestPriority(), headers_); |
| 172 string body = "this is the body"; | 171 string body = "this is the body"; |
| 173 string data = compressed_headers + body; | 172 string data = compressed_headers + body; |
| 174 | 173 |
| 175 for (size_t fragment_size = 1; fragment_size < data.size(); ++fragment_size) { | 174 for (size_t fragment_size = 1; fragment_size < data.size(); ++fragment_size) { |
| 176 Initialize(kShouldProcessData); | 175 Initialize(kShouldProcessData); |
| 177 for (size_t offset = 0; offset < data.size(); offset += fragment_size) { | 176 for (size_t offset = 0; offset < data.size(); offset += fragment_size) { |
| 178 size_t remaining_data = data.length() - offset; | 177 size_t remaining_data = data.length() - offset; |
| 179 StringPiece fragment(data.data() + offset, | 178 StringPiece fragment(data.data() + offset, |
| 180 min(fragment_size, remaining_data)); | 179 min(fragment_size, remaining_data)); |
| 181 QuicStreamFrame frame(kStreamId, false, offset, MakeIOVector(fragment)); | 180 QuicStreamFrame frame(kStreamId, false, offset, MakeIOVector(fragment)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 194 stream_->OnStreamFrame(frame1); | 193 stream_->OnStreamFrame(frame1); |
| 195 | 194 |
| 196 StringPiece fragment2(data.data() + split_point, data.size() - split_point); | 195 StringPiece fragment2(data.data() + split_point, data.size() - split_point); |
| 197 QuicStreamFrame frame2( | 196 QuicStreamFrame frame2( |
| 198 kStreamId, false, split_point, MakeIOVector(fragment2)); | 197 kStreamId, false, split_point, MakeIOVector(fragment2)); |
| 199 stream_->OnStreamFrame(frame2); | 198 stream_->OnStreamFrame(frame2); |
| 200 | 199 |
| 201 ASSERT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers_) + body, | 200 ASSERT_EQ(SpdyUtils::SerializeUncompressedHeaders(headers_) + body, |
| 202 stream_->data()) << "split_point: " << split_point; | 201 stream_->data()) << "split_point: " << split_point; |
| 203 } | 202 } |
| 204 EXPECT_EQ(static_cast<QuicPriority>(kLowestPriority), | 203 EXPECT_EQ(QuicUtils::LowestPriority(), stream_->EffectivePriority()); |
| 205 stream_->EffectivePriority()); | |
| 206 } | 204 } |
| 207 | 205 |
| 208 TEST_F(QuicDataStreamTest, ProcessHeadersAndBodyReadv) { | 206 TEST_F(QuicDataStreamTest, ProcessHeadersAndBodyReadv) { |
| 209 Initialize(!kShouldProcessData); | 207 Initialize(!kShouldProcessData); |
| 210 | 208 |
| 211 string compressed_headers = compressor_->CompressHeadersWithPriority( | 209 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 212 kHighestPriority, headers_); | 210 QuicUtils::HighestPriority(), headers_); |
| 213 string body = "this is the body"; | 211 string body = "this is the body"; |
| 214 string data = compressed_headers + body; | 212 string data = compressed_headers + body; |
| 215 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); | 213 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); |
| 216 string uncompressed_headers = | 214 string uncompressed_headers = |
| 217 SpdyUtils::SerializeUncompressedHeaders(headers_); | 215 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 218 string uncompressed_data = uncompressed_headers + body; | 216 string uncompressed_data = uncompressed_headers + body; |
| 219 | 217 |
| 220 stream_->OnStreamFrame(frame); | 218 stream_->OnStreamFrame(frame); |
| 221 EXPECT_EQ(uncompressed_headers, stream_->data()); | 219 EXPECT_EQ(uncompressed_headers, stream_->data()); |
| 222 | 220 |
| 223 char buffer[2048]; | 221 char buffer[2048]; |
| 224 ASSERT_LT(data.length(), arraysize(buffer)); | 222 ASSERT_LT(data.length(), arraysize(buffer)); |
| 225 struct iovec vec; | 223 struct iovec vec; |
| 226 vec.iov_base = buffer; | 224 vec.iov_base = buffer; |
| 227 vec.iov_len = arraysize(buffer); | 225 vec.iov_len = arraysize(buffer); |
| 228 | 226 |
| 229 size_t bytes_read = stream_->Readv(&vec, 1); | 227 size_t bytes_read = stream_->Readv(&vec, 1); |
| 230 EXPECT_EQ(uncompressed_headers.length(), bytes_read); | 228 EXPECT_EQ(uncompressed_headers.length(), bytes_read); |
| 231 EXPECT_EQ(uncompressed_headers, string(buffer, bytes_read)); | 229 EXPECT_EQ(uncompressed_headers, string(buffer, bytes_read)); |
| 232 | 230 |
| 233 bytes_read = stream_->Readv(&vec, 1); | 231 bytes_read = stream_->Readv(&vec, 1); |
| 234 EXPECT_EQ(body.length(), bytes_read); | 232 EXPECT_EQ(body.length(), bytes_read); |
| 235 EXPECT_EQ(body, string(buffer, bytes_read)); | 233 EXPECT_EQ(body, string(buffer, bytes_read)); |
| 236 } | 234 } |
| 237 | 235 |
| 238 TEST_F(QuicDataStreamTest, ProcessHeadersAndBodyIncrementalReadv) { | 236 TEST_F(QuicDataStreamTest, ProcessHeadersAndBodyIncrementalReadv) { |
| 239 Initialize(!kShouldProcessData); | 237 Initialize(!kShouldProcessData); |
| 240 | 238 |
| 241 string compressed_headers = compressor_->CompressHeadersWithPriority( | 239 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 242 kHighestPriority, headers_); | 240 QuicUtils::HighestPriority(), headers_); |
| 243 string body = "this is the body"; | 241 string body = "this is the body"; |
| 244 string data = compressed_headers + body; | 242 string data = compressed_headers + body; |
| 245 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); | 243 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); |
| 246 string uncompressed_headers = | 244 string uncompressed_headers = |
| 247 SpdyUtils::SerializeUncompressedHeaders(headers_); | 245 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 248 string uncompressed_data = uncompressed_headers + body; | 246 string uncompressed_data = uncompressed_headers + body; |
| 249 | 247 |
| 250 stream_->OnStreamFrame(frame); | 248 stream_->OnStreamFrame(frame); |
| 251 EXPECT_EQ(uncompressed_headers, stream_->data()); | 249 EXPECT_EQ(uncompressed_headers, stream_->data()); |
| 252 | 250 |
| 253 char buffer[1]; | 251 char buffer[1]; |
| 254 struct iovec vec; | 252 struct iovec vec; |
| 255 vec.iov_base = buffer; | 253 vec.iov_base = buffer; |
| 256 vec.iov_len = arraysize(buffer); | 254 vec.iov_len = arraysize(buffer); |
| 257 for (size_t i = 0; i < uncompressed_data.length(); ++i) { | 255 for (size_t i = 0; i < uncompressed_data.length(); ++i) { |
| 258 size_t bytes_read = stream_->Readv(&vec, 1); | 256 size_t bytes_read = stream_->Readv(&vec, 1); |
| 259 ASSERT_EQ(1u, bytes_read); | 257 ASSERT_EQ(1u, bytes_read); |
| 260 EXPECT_EQ(uncompressed_data.data()[i], buffer[0]); | 258 EXPECT_EQ(uncompressed_data.data()[i], buffer[0]); |
| 261 } | 259 } |
| 262 } | 260 } |
| 263 | 261 |
| 264 TEST_F(QuicDataStreamTest, ProcessHeadersUsingReadvWithMultipleIovecs) { | 262 TEST_F(QuicDataStreamTest, ProcessHeadersUsingReadvWithMultipleIovecs) { |
| 265 Initialize(!kShouldProcessData); | 263 Initialize(!kShouldProcessData); |
| 266 | 264 |
| 267 string compressed_headers = compressor_->CompressHeadersWithPriority( | 265 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 268 kHighestPriority, headers_); | 266 QuicUtils::HighestPriority(), headers_); |
| 269 string body = "this is the body"; | 267 string body = "this is the body"; |
| 270 string data = compressed_headers + body; | 268 string data = compressed_headers + body; |
| 271 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); | 269 QuicStreamFrame frame(kStreamId, false, 0, MakeIOVector(data)); |
| 272 string uncompressed_headers = | 270 string uncompressed_headers = |
| 273 SpdyUtils::SerializeUncompressedHeaders(headers_); | 271 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 274 string uncompressed_data = uncompressed_headers + body; | 272 string uncompressed_data = uncompressed_headers + body; |
| 275 | 273 |
| 276 stream_->OnStreamFrame(frame); | 274 stream_->OnStreamFrame(frame); |
| 277 EXPECT_EQ(uncompressed_headers, stream_->data()); | 275 EXPECT_EQ(uncompressed_headers, stream_->data()); |
| 278 | 276 |
| 279 char buffer1[1]; | 277 char buffer1[1]; |
| 280 char buffer2[1]; | 278 char buffer2[1]; |
| 281 struct iovec vec[2]; | 279 struct iovec vec[2]; |
| 282 vec[0].iov_base = buffer1; | 280 vec[0].iov_base = buffer1; |
| 283 vec[0].iov_len = arraysize(buffer1); | 281 vec[0].iov_len = arraysize(buffer1); |
| 284 vec[1].iov_base = buffer2; | 282 vec[1].iov_base = buffer2; |
| 285 vec[1].iov_len = arraysize(buffer2); | 283 vec[1].iov_len = arraysize(buffer2); |
| 286 for (size_t i = 0; i < uncompressed_data.length(); i += 2) { | 284 for (size_t i = 0; i < uncompressed_data.length(); i += 2) { |
| 287 size_t bytes_read = stream_->Readv(vec, 2); | 285 size_t bytes_read = stream_->Readv(vec, 2); |
| 288 ASSERT_EQ(2u, bytes_read) << i; | 286 ASSERT_EQ(2u, bytes_read) << i; |
| 289 ASSERT_EQ(uncompressed_data.data()[i], buffer1[0]) << i; | 287 ASSERT_EQ(uncompressed_data.data()[i], buffer1[0]) << i; |
| 290 ASSERT_EQ(uncompressed_data.data()[i + 1], buffer2[0]) << i; | 288 ASSERT_EQ(uncompressed_data.data()[i + 1], buffer2[0]) << i; |
| 291 } | 289 } |
| 292 } | 290 } |
| 293 | 291 |
| 294 TEST_F(QuicDataStreamTest, ProcessCorruptHeadersEarly) { | 292 TEST_F(QuicDataStreamTest, ProcessCorruptHeadersEarly) { |
| 295 Initialize(kShouldProcessData); | 293 Initialize(kShouldProcessData); |
| 296 | 294 |
| 297 string compressed_headers1 = compressor_->CompressHeadersWithPriority( | 295 string compressed_headers1 = compressor_->CompressHeadersWithPriority( |
| 298 kHighestPriority, headers_); | 296 QuicUtils::HighestPriority(), headers_); |
| 299 QuicStreamFrame frame1( | 297 QuicStreamFrame frame1( |
| 300 stream_->id(), false, 0, MakeIOVector(compressed_headers1)); | 298 stream_->id(), false, 0, MakeIOVector(compressed_headers1)); |
| 301 string decompressed_headers1 = | 299 string decompressed_headers1 = |
| 302 SpdyUtils::SerializeUncompressedHeaders(headers_); | 300 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 303 | 301 |
| 304 headers_["content-type"] = "text/plain"; | 302 headers_["content-type"] = "text/plain"; |
| 305 string compressed_headers2 = compressor_->CompressHeadersWithPriority( | 303 string compressed_headers2 = compressor_->CompressHeadersWithPriority( |
| 306 kHighestPriority, headers_); | 304 QuicUtils::HighestPriority(), headers_); |
| 307 // Corrupt the compressed data. | 305 // Corrupt the compressed data. |
| 308 compressed_headers2[compressed_headers2.length() - 1] ^= 0xA1; | 306 compressed_headers2[compressed_headers2.length() - 1] ^= 0xA1; |
| 309 QuicStreamFrame frame2( | 307 QuicStreamFrame frame2( |
| 310 stream2_->id(), false, 0, MakeIOVector(compressed_headers2)); | 308 stream2_->id(), false, 0, MakeIOVector(compressed_headers2)); |
| 311 string decompressed_headers2 = | 309 string decompressed_headers2 = |
| 312 SpdyUtils::SerializeUncompressedHeaders(headers_); | 310 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 313 | 311 |
| 314 // Deliver frame2 to stream2 out of order. The decompressor is not | 312 // Deliver frame2 to stream2 out of order. The decompressor is not |
| 315 // available yet, so no data will be processed. The compressed data | 313 // available yet, so no data will be processed. The compressed data |
| 316 // will be buffered until OnDecompressorAvailable() is called | 314 // will be buffered until OnDecompressorAvailable() is called |
| (...skipping 13 matching lines...) Expand all Loading... |
| 330 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); | 328 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
| 331 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); | 329 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_DECOMPRESSION_FAILURE)); |
| 332 stream2_->OnDecompressorAvailable(); | 330 stream2_->OnDecompressorAvailable(); |
| 333 EXPECT_EQ("", stream2_->data()); | 331 EXPECT_EQ("", stream2_->data()); |
| 334 } | 332 } |
| 335 | 333 |
| 336 TEST_F(QuicDataStreamTest, ProcessPartialHeadersEarly) { | 334 TEST_F(QuicDataStreamTest, ProcessPartialHeadersEarly) { |
| 337 Initialize(kShouldProcessData); | 335 Initialize(kShouldProcessData); |
| 338 | 336 |
| 339 string compressed_headers1 = compressor_->CompressHeadersWithPriority( | 337 string compressed_headers1 = compressor_->CompressHeadersWithPriority( |
| 340 kHighestPriority, headers_); | 338 QuicUtils::HighestPriority(), headers_); |
| 341 QuicStreamFrame frame1( | 339 QuicStreamFrame frame1( |
| 342 stream_->id(), false, 0, MakeIOVector(compressed_headers1)); | 340 stream_->id(), false, 0, MakeIOVector(compressed_headers1)); |
| 343 string decompressed_headers1 = | 341 string decompressed_headers1 = |
| 344 SpdyUtils::SerializeUncompressedHeaders(headers_); | 342 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 345 | 343 |
| 346 headers_["content-type"] = "text/plain"; | 344 headers_["content-type"] = "text/plain"; |
| 347 string compressed_headers2 = compressor_->CompressHeadersWithPriority( | 345 string compressed_headers2 = compressor_->CompressHeadersWithPriority( |
| 348 kHighestPriority, headers_); | 346 QuicUtils::HighestPriority(), headers_); |
| 349 string partial_compressed_headers = | 347 string partial_compressed_headers = |
| 350 compressed_headers2.substr(0, compressed_headers2.length() / 2); | 348 compressed_headers2.substr(0, compressed_headers2.length() / 2); |
| 351 QuicStreamFrame frame2( | 349 QuicStreamFrame frame2( |
| 352 stream2_->id(), false, 0, MakeIOVector(partial_compressed_headers)); | 350 stream2_->id(), false, 0, MakeIOVector(partial_compressed_headers)); |
| 353 string decompressed_headers2 = | 351 string decompressed_headers2 = |
| 354 SpdyUtils::SerializeUncompressedHeaders(headers_); | 352 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 355 | 353 |
| 356 // Deliver frame2 to stream2 out of order. The decompressor is not | 354 // Deliver frame2 to stream2 out of order. The decompressor is not |
| 357 // available yet, so no data will be processed. The compressed data | 355 // available yet, so no data will be processed. The compressed data |
| 358 // will be buffered until OnDecompressorAvailable() is called | 356 // will be buffered until OnDecompressorAvailable() is called |
| (...skipping 24 matching lines...) Expand all Loading... |
| 383 partial_compressed_headers.length(), | 381 partial_compressed_headers.length(), |
| 384 MakeIOVector(remaining_compressed_headers)); | 382 MakeIOVector(remaining_compressed_headers)); |
| 385 stream2_->OnStreamFrame(frame3); | 383 stream2_->OnStreamFrame(frame3); |
| 386 EXPECT_EQ(decompressed_headers2, stream2_->data()); | 384 EXPECT_EQ(decompressed_headers2, stream2_->data()); |
| 387 } | 385 } |
| 388 | 386 |
| 389 TEST_F(QuicDataStreamTest, ProcessHeadersEarly) { | 387 TEST_F(QuicDataStreamTest, ProcessHeadersEarly) { |
| 390 Initialize(kShouldProcessData); | 388 Initialize(kShouldProcessData); |
| 391 | 389 |
| 392 string compressed_headers1 = compressor_->CompressHeadersWithPriority( | 390 string compressed_headers1 = compressor_->CompressHeadersWithPriority( |
| 393 kHighestPriority, headers_); | 391 QuicUtils::HighestPriority(), headers_); |
| 394 QuicStreamFrame frame1( | 392 QuicStreamFrame frame1( |
| 395 stream_->id(), false, 0, MakeIOVector(compressed_headers1)); | 393 stream_->id(), false, 0, MakeIOVector(compressed_headers1)); |
| 396 string decompressed_headers1 = | 394 string decompressed_headers1 = |
| 397 SpdyUtils::SerializeUncompressedHeaders(headers_); | 395 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 398 | 396 |
| 399 headers_["content-type"] = "text/plain"; | 397 headers_["content-type"] = "text/plain"; |
| 400 string compressed_headers2 = compressor_->CompressHeadersWithPriority( | 398 string compressed_headers2 = compressor_->CompressHeadersWithPriority( |
| 401 kHighestPriority, headers_); | 399 QuicUtils::HighestPriority(), headers_); |
| 402 QuicStreamFrame frame2( | 400 QuicStreamFrame frame2( |
| 403 stream2_->id(), false, 0, MakeIOVector(compressed_headers2)); | 401 stream2_->id(), false, 0, MakeIOVector(compressed_headers2)); |
| 404 string decompressed_headers2 = | 402 string decompressed_headers2 = |
| 405 SpdyUtils::SerializeUncompressedHeaders(headers_); | 403 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 406 | 404 |
| 407 // Deliver frame2 to stream2 out of order. The decompressor is not | 405 // Deliver frame2 to stream2 out of order. The decompressor is not |
| 408 // available yet, so no data will be processed. The compressed data | 406 // available yet, so no data will be processed. The compressed data |
| 409 // will be buffered until OnDecompressorAvailable() is called | 407 // will be buffered until OnDecompressorAvailable() is called |
| 410 // to process it. | 408 // to process it. |
| 411 stream2_->OnStreamFrame(frame2); | 409 stream2_->OnStreamFrame(frame2); |
| 412 EXPECT_EQ("", stream2_->data()); | 410 EXPECT_EQ("", stream2_->data()); |
| 413 | 411 |
| 414 // Now deliver frame1 to stream1. The decompressor is available so | 412 // Now deliver frame1 to stream1. The decompressor is available so |
| 415 // the data will be processed, and the decompressor will become | 413 // the data will be processed, and the decompressor will become |
| 416 // available for stream2. | 414 // available for stream2. |
| 417 stream_->OnStreamFrame(frame1); | 415 stream_->OnStreamFrame(frame1); |
| 418 EXPECT_EQ(decompressed_headers1, stream_->data()); | 416 EXPECT_EQ(decompressed_headers1, stream_->data()); |
| 419 | 417 |
| 420 // Verify that the decompressor is available, and inform stream2 | 418 // Verify that the decompressor is available, and inform stream2 |
| 421 // that it can now decompress the buffered compressed data. | 419 // that it can now decompress the buffered compressed data. |
| 422 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); | 420 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
| 423 stream2_->OnDecompressorAvailable(); | 421 stream2_->OnDecompressorAvailable(); |
| 424 EXPECT_EQ(decompressed_headers2, stream2_->data()); | 422 EXPECT_EQ(decompressed_headers2, stream2_->data()); |
| 425 } | 423 } |
| 426 | 424 |
| 427 TEST_F(QuicDataStreamTest, ProcessHeadersDelay) { | 425 TEST_F(QuicDataStreamTest, ProcessHeadersDelay) { |
| 428 Initialize(!kShouldProcessData); | 426 Initialize(!kShouldProcessData); |
| 429 | 427 |
| 430 string compressed_headers = compressor_->CompressHeadersWithPriority( | 428 string compressed_headers = compressor_->CompressHeadersWithPriority( |
| 431 kHighestPriority, headers_); | 429 QuicUtils::HighestPriority(), headers_); |
| 432 QuicStreamFrame frame1( | 430 QuicStreamFrame frame1( |
| 433 stream_->id(), false, 0, MakeIOVector(compressed_headers)); | 431 stream_->id(), false, 0, MakeIOVector(compressed_headers)); |
| 434 string decompressed_headers = | 432 string decompressed_headers = |
| 435 SpdyUtils::SerializeUncompressedHeaders(headers_); | 433 SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 436 | 434 |
| 437 // Send the headers to the stream and verify they were decompressed. | 435 // Send the headers to the stream and verify they were decompressed. |
| 438 stream_->OnStreamFrame(frame1); | 436 stream_->OnStreamFrame(frame1); |
| 439 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); | 437 EXPECT_EQ(2u, session_->decompressor()->current_header_id()); |
| 440 | 438 |
| 441 // Verify that we are now able to handle the body data, | 439 // Verify that we are now able to handle the body data, |
| 442 // even though the stream has not processed the headers. | 440 // even though the stream has not processed the headers. |
| 443 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) | 441 EXPECT_CALL(*connection_, SendConnectionClose(QUIC_INVALID_HEADER_ID)) |
| 444 .Times(0); | 442 .Times(0); |
| 445 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), | 443 QuicStreamFrame frame2(stream_->id(), false, compressed_headers.length(), |
| 446 MakeIOVector("body data")); | 444 MakeIOVector("body data")); |
| 447 stream_->OnStreamFrame(frame2); | 445 stream_->OnStreamFrame(frame2); |
| 448 } | 446 } |
| 449 | 447 |
| 450 } // namespace | 448 } // namespace |
| 451 } // namespace test | 449 } // namespace test |
| 452 } // namespace net | 450 } // namespace net |
| OLD | NEW |