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/chromium/quic_chromium_client_stream.h" | 5 #include "net/quic/chromium/quic_chromium_client_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 using testing::Return; | 31 using testing::Return; |
32 using testing::StrEq; | 32 using testing::StrEq; |
33 using testing::_; | 33 using testing::_; |
34 | 34 |
35 namespace net { | 35 namespace net { |
36 namespace test { | 36 namespace test { |
37 namespace { | 37 namespace { |
38 | 38 |
39 const QuicStreamId kTestStreamId = 5u; | 39 const QuicStreamId kTestStreamId = 5u; |
40 | 40 |
41 class MockDelegate : public QuicChromiumClientStream::Delegate { | |
42 public: | |
43 MockDelegate() {} | |
44 | |
45 MOCK_METHOD0(OnSendData, int()); | |
46 MOCK_METHOD2(OnSendDataComplete, int(int, bool*)); | |
47 MOCK_METHOD0(OnClose, void()); | |
48 MOCK_METHOD1(OnError, void(int)); | |
49 MOCK_METHOD0(HasSendHeadersComplete, bool()); | |
50 | |
51 SpdyHeaderBlock headers_; | |
52 SpdyHeaderBlock trailers_; | |
53 | |
54 private: | |
55 DISALLOW_COPY_AND_ASSIGN(MockDelegate); | |
56 }; | |
57 | |
58 class MockQuicClientSessionBase : public QuicClientSessionBase { | 41 class MockQuicClientSessionBase : public QuicClientSessionBase { |
59 public: | 42 public: |
60 explicit MockQuicClientSessionBase(QuicConnection* connection, | 43 explicit MockQuicClientSessionBase(QuicConnection* connection, |
61 QuicClientPushPromiseIndex* index); | 44 QuicClientPushPromiseIndex* index); |
62 ~MockQuicClientSessionBase() override; | 45 ~MockQuicClientSessionBase() override; |
63 | 46 |
64 const QuicCryptoStream* GetCryptoStream() const override { | 47 const QuicCryptoStream* GetCryptoStream() const override { |
65 return crypto_stream_.get(); | 48 return crypto_stream_.get(); |
66 } | 49 } |
67 | 50 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 QuicChromiumClientStreamTest() | 159 QuicChromiumClientStreamTest() |
177 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()), | 160 : crypto_config_(crypto_test_utils::ProofVerifierForTesting()), |
178 session_(new MockQuicConnection(&helper_, | 161 session_(new MockQuicConnection(&helper_, |
179 &alarm_factory_, | 162 &alarm_factory_, |
180 Perspective::IS_CLIENT, | 163 Perspective::IS_CLIENT, |
181 SupportedVersions(GetParam())), | 164 SupportedVersions(GetParam())), |
182 &push_promise_index_) { | 165 &push_promise_index_) { |
183 stream_ = new QuicChromiumClientStream(kTestStreamId, &session_, | 166 stream_ = new QuicChromiumClientStream(kTestStreamId, &session_, |
184 NetLogWithSource()); | 167 NetLogWithSource()); |
185 session_.ActivateStream(base::WrapUnique(stream_)); | 168 session_.ActivateStream(base::WrapUnique(stream_)); |
186 handle_ = stream_->CreateHandle(&delegate_); | 169 handle_ = stream_->CreateHandle(); |
187 } | 170 } |
188 | 171 |
189 void InitializeHeaders() { | 172 void InitializeHeaders() { |
190 headers_[":host"] = "www.google.com"; | 173 headers_[":host"] = "www.google.com"; |
191 headers_[":path"] = "/index.hml"; | 174 headers_[":path"] = "/index.hml"; |
192 headers_[":scheme"] = "https"; | 175 headers_[":scheme"] = "https"; |
193 headers_["cookie"] = | 176 headers_["cookie"] = |
194 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " | 177 "__utma=208381060.1228362404.1372200928.1372200928.1372200928.1; " |
195 "__utmc=160408618; " | 178 "__utmc=160408618; " |
196 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" | 179 "GX=DQAAAOEAAACWJYdewdE9rIrW6qw3PtVi2-d729qaa-74KqOsM1NVQblK4VhX" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 215 |
233 QuicHeaderList ProcessTrailers(const SpdyHeaderBlock& headers) { | 216 QuicHeaderList ProcessTrailers(const SpdyHeaderBlock& headers) { |
234 QuicHeaderList h = AsHeaderList(headers); | 217 QuicHeaderList h = AsHeaderList(headers); |
235 stream_->OnStreamHeaderList(true, h.uncompressed_header_bytes(), h); | 218 stream_->OnStreamHeaderList(true, h.uncompressed_header_bytes(), h); |
236 return h; | 219 return h; |
237 } | 220 } |
238 | 221 |
239 QuicHeaderList ProcessHeadersFull(const SpdyHeaderBlock& headers) { | 222 QuicHeaderList ProcessHeadersFull(const SpdyHeaderBlock& headers) { |
240 QuicHeaderList h = ProcessHeaders(headers); | 223 QuicHeaderList h = ProcessHeaders(headers); |
241 TestCompletionCallback callback; | 224 TestCompletionCallback callback; |
242 EXPECT_EQ( | 225 EXPECT_EQ(static_cast<int>(h.uncompressed_header_bytes()), |
243 static_cast<int>(h.uncompressed_header_bytes()), | 226 handle_->ReadInitialHeaders(&headers_, callback.callback())); |
244 handle_->ReadInitialHeaders(&delegate_.headers_, callback.callback())); | 227 EXPECT_EQ(headers, headers_); |
245 EXPECT_EQ(headers, delegate_.headers_); | |
246 EXPECT_TRUE(stream_->header_list().empty()); | 228 EXPECT_TRUE(stream_->header_list().empty()); |
247 return h; | 229 return h; |
248 } | 230 } |
249 | 231 |
250 QuicStreamId GetNthClientInitiatedStreamId(int n) { | 232 QuicStreamId GetNthClientInitiatedStreamId(int n) { |
251 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n); | 233 return QuicSpdySessionPeer::GetNthClientInitiatedStreamId(session_, n); |
252 } | 234 } |
253 | 235 |
254 QuicStreamId GetNthServerInitiatedStreamId(int n) { | 236 QuicStreamId GetNthServerInitiatedStreamId(int n) { |
255 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n); | 237 return QuicSpdySessionPeer::GetNthServerInitiatedStreamId(session_, n); |
256 } | 238 } |
257 | 239 |
258 void ResetStreamCallback(QuicChromiumClientStream* stream, int /*rv*/) { | 240 void ResetStreamCallback(QuicChromiumClientStream* stream, int /*rv*/) { |
259 stream->Reset(QUIC_STREAM_CANCELLED); | 241 stream->Reset(QUIC_STREAM_CANCELLED); |
260 } | 242 } |
261 | 243 |
262 QuicCryptoClientConfig crypto_config_; | 244 QuicCryptoClientConfig crypto_config_; |
263 std::unique_ptr<QuicChromiumClientStream::Handle> handle_; | 245 std::unique_ptr<QuicChromiumClientStream::Handle> handle_; |
264 testing::StrictMock<MockDelegate> delegate_; | |
265 std::unique_ptr<QuicChromiumClientStream::Handle> handle2_; | 246 std::unique_ptr<QuicChromiumClientStream::Handle> handle2_; |
266 testing::StrictMock<MockDelegate> delegate2_; | |
267 MockQuicConnectionHelper helper_; | 247 MockQuicConnectionHelper helper_; |
268 MockAlarmFactory alarm_factory_; | 248 MockAlarmFactory alarm_factory_; |
269 MockQuicClientSessionBase session_; | 249 MockQuicClientSessionBase session_; |
270 QuicChromiumClientStream* stream_; | 250 QuicChromiumClientStream* stream_; |
271 SpdyHeaderBlock headers_; | 251 SpdyHeaderBlock headers_; |
| 252 SpdyHeaderBlock trailers_; |
272 QuicClientPushPromiseIndex push_promise_index_; | 253 QuicClientPushPromiseIndex push_promise_index_; |
273 }; | 254 }; |
274 | 255 |
275 INSTANTIATE_TEST_CASE_P(Version, | 256 INSTANTIATE_TEST_CASE_P(Version, |
276 QuicChromiumClientStreamTest, | 257 QuicChromiumClientStreamTest, |
277 ::testing::ValuesIn(AllSupportedVersions())); | 258 ::testing::ValuesIn(AllSupportedVersions())); |
278 | 259 |
279 TEST_P(QuicChromiumClientStreamTest, Handle) { | 260 TEST_P(QuicChromiumClientStreamTest, Handle) { |
280 EXPECT_TRUE(handle_->IsOpen()); | 261 EXPECT_TRUE(handle_->IsOpen()); |
281 EXPECT_EQ(kTestStreamId, handle_->id()); | 262 EXPECT_EQ(kTestStreamId, handle_->id()); |
282 EXPECT_EQ(QUIC_NO_ERROR, handle_->connection_error()); | 263 EXPECT_EQ(QUIC_NO_ERROR, handle_->connection_error()); |
283 EXPECT_EQ(QUIC_STREAM_NO_ERROR, handle_->stream_error()); | 264 EXPECT_EQ(QUIC_STREAM_NO_ERROR, handle_->stream_error()); |
284 EXPECT_TRUE(handle_->IsFirstStream()); | 265 EXPECT_TRUE(handle_->IsFirstStream()); |
285 EXPECT_FALSE(handle_->IsDoneReading()); | 266 EXPECT_FALSE(handle_->IsDoneReading()); |
286 EXPECT_FALSE(handle_->fin_sent()); | 267 EXPECT_FALSE(handle_->fin_sent()); |
287 EXPECT_FALSE(handle_->fin_received()); | 268 EXPECT_FALSE(handle_->fin_received()); |
288 EXPECT_EQ(0u, handle_->stream_bytes_read()); | 269 EXPECT_EQ(0u, handle_->stream_bytes_read()); |
289 EXPECT_EQ(0u, handle_->stream_bytes_written()); | 270 EXPECT_EQ(0u, handle_->stream_bytes_written()); |
290 EXPECT_EQ(0u, handle_->NumBytesConsumed()); | 271 EXPECT_EQ(0u, handle_->NumBytesConsumed()); |
291 | 272 |
292 InitializeHeaders(); | 273 InitializeHeaders(); |
293 QuicStreamOffset offset = 0; | 274 QuicStreamOffset offset = 0; |
294 ProcessHeadersFull(headers_); | 275 ProcessHeadersFull(headers_); |
295 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece()); | 276 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece()); |
296 EXPECT_CALL(delegate_, OnClose()); | |
297 stream_->OnStreamFrame(frame2); | 277 stream_->OnStreamFrame(frame2); |
298 EXPECT_TRUE(handle_->fin_received()); | 278 EXPECT_TRUE(handle_->fin_received()); |
299 handle_->OnFinRead(); | 279 handle_->OnFinRead(); |
300 | 280 |
301 const char kData1[] = "hello world"; | 281 const char kData1[] = "hello world"; |
302 const size_t kDataLen = arraysize(kData1); | 282 const size_t kDataLen = arraysize(kData1); |
303 | 283 |
304 // All data written. | 284 // All data written. |
305 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 285 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
306 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 286 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
(...skipping 18 matching lines...) Expand all Loading... |
325 callback.callback())); | 305 callback.callback())); |
326 | 306 |
327 std::vector<scoped_refptr<IOBuffer>> buffers = { | 307 std::vector<scoped_refptr<IOBuffer>> buffers = { |
328 scoped_refptr<IOBuffer>(new IOBuffer(10))}; | 308 scoped_refptr<IOBuffer>(new IOBuffer(10))}; |
329 std::vector<int> lengths = {10}; | 309 std::vector<int> lengths = {10}; |
330 EXPECT_EQ( | 310 EXPECT_EQ( |
331 ERR_CONNECTION_CLOSED, | 311 ERR_CONNECTION_CLOSED, |
332 handle_->WritevStreamData(buffers, lengths, true, callback.callback())); | 312 handle_->WritevStreamData(buffers, lengths, true, callback.callback())); |
333 | 313 |
334 SpdyHeaderBlock headers; | 314 SpdyHeaderBlock headers; |
335 EXPECT_EQ(0u, handle_->WriteHeaders(std::move(headers), true, nullptr)); | 315 EXPECT_EQ(0, handle_->WriteHeaders(std::move(headers), true, nullptr)); |
336 } | 316 } |
337 | 317 |
338 TEST_P(QuicChromiumClientStreamTest, HandleAfterConnectionClose) { | 318 TEST_P(QuicChromiumClientStreamTest, HandleAfterConnectionClose) { |
339 // Verify that the delegate's OnClose is called after closing the connection. | |
340 EXPECT_CALL(delegate_, OnClose()); | |
341 EXPECT_CALL(session_, | 319 EXPECT_CALL(session_, |
342 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 320 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
343 stream_->OnConnectionClosed(QUIC_INVALID_FRAME_DATA, | 321 stream_->OnConnectionClosed(QUIC_INVALID_FRAME_DATA, |
344 ConnectionCloseSource::FROM_PEER); | 322 ConnectionCloseSource::FROM_PEER); |
345 | 323 |
346 EXPECT_FALSE(handle_->IsOpen()); | 324 EXPECT_FALSE(handle_->IsOpen()); |
347 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, handle_->connection_error()); | 325 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, handle_->connection_error()); |
348 } | 326 } |
349 | 327 |
350 TEST_P(QuicChromiumClientStreamTest, HandleAfterStreamReset) { | 328 TEST_P(QuicChromiumClientStreamTest, HandleAfterStreamReset) { |
351 // Verify that the delegate's OnClose is called after the stream is reset, | 329 // Verify that the Handle still behaves correctly after the stream is reset. |
352 // but that the Handle still behaves correctly. | |
353 EXPECT_CALL(delegate_, OnClose()); | |
354 QuicRstStreamFrame rst(kTestStreamId, QUIC_STREAM_CANCELLED, 0); | 330 QuicRstStreamFrame rst(kTestStreamId, QUIC_STREAM_CANCELLED, 0); |
355 EXPECT_CALL(session_, | 331 EXPECT_CALL(session_, |
356 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0)); | 332 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0)); |
357 stream_->OnStreamReset(rst); | |
358 | |
359 EXPECT_FALSE(handle_->IsOpen()); | |
360 EXPECT_EQ(QUIC_STREAM_CANCELLED, handle_->stream_error()); | |
361 } | |
362 | |
363 TEST_P(QuicChromiumClientStreamTest, HandleAfterClearDelegate) { | |
364 EXPECT_TRUE(handle_->IsOpen()); | |
365 handle_->ClearDelegate(); | |
366 | |
367 // Verify that the delegate's OnClose is not called after ClearDelegate. | |
368 EXPECT_CALL(delegate_, OnClose()).Times(0); | |
369 QuicRstStreamFrame rst(kTestStreamId, QUIC_STREAM_CANCELLED, 0); | |
370 EXPECT_CALL(session_, | |
371 SendRstStream(kTestStreamId, QUIC_RST_ACKNOWLEDGEMENT, 0)); | |
372 stream_->OnStreamReset(rst); | 333 stream_->OnStreamReset(rst); |
373 | 334 |
374 EXPECT_FALSE(handle_->IsOpen()); | 335 EXPECT_FALSE(handle_->IsOpen()); |
375 EXPECT_EQ(QUIC_STREAM_CANCELLED, handle_->stream_error()); | 336 EXPECT_EQ(QUIC_STREAM_CANCELLED, handle_->stream_error()); |
376 } | 337 } |
377 | 338 |
378 TEST_P(QuicChromiumClientStreamTest, OnFinRead) { | 339 TEST_P(QuicChromiumClientStreamTest, OnFinRead) { |
379 InitializeHeaders(); | 340 InitializeHeaders(); |
380 QuicStreamOffset offset = 0; | 341 QuicStreamOffset offset = 0; |
381 ProcessHeadersFull(headers_); | 342 ProcessHeadersFull(headers_); |
382 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece()); | 343 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece()); |
383 EXPECT_CALL(delegate_, OnClose()); | |
384 stream_->OnStreamFrame(frame2); | 344 stream_->OnStreamFrame(frame2); |
385 } | 345 } |
386 | 346 |
387 TEST_P(QuicChromiumClientStreamTest, OnDataAvailable) { | 347 TEST_P(QuicChromiumClientStreamTest, OnDataAvailable) { |
388 InitializeHeaders(); | 348 InitializeHeaders(); |
389 ProcessHeadersFull(headers_); | 349 ProcessHeadersFull(headers_); |
390 | 350 |
391 const char data[] = "hello world!"; | 351 const char data[] = "hello world!"; |
392 int data_len = strlen(data); | 352 int data_len = strlen(data); |
393 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, | 353 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, |
394 /*offset=*/0, data)); | 354 /*offset=*/0, data)); |
395 | 355 |
396 // Read the body and verify that it arrives correctly. | 356 // Read the body and verify that it arrives correctly. |
397 TestCompletionCallback callback; | 357 TestCompletionCallback callback; |
398 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); | 358 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); |
399 EXPECT_EQ(data_len, | 359 EXPECT_EQ(data_len, |
400 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); | 360 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); |
401 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); | 361 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); |
402 | |
403 EXPECT_CALL(delegate_, OnClose()); | |
404 } | 362 } |
405 | 363 |
406 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableAfterReadBody) { | 364 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableAfterReadBody) { |
407 InitializeHeaders(); | 365 InitializeHeaders(); |
408 ProcessHeadersFull(headers_); | 366 ProcessHeadersFull(headers_); |
409 | 367 |
410 const char data[] = "hello world!"; | 368 const char data[] = "hello world!"; |
411 int data_len = strlen(data); | 369 int data_len = strlen(data); |
412 | 370 |
413 // Start to read the body. | 371 // Start to read the body. |
414 TestCompletionCallback callback; | 372 TestCompletionCallback callback; |
415 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); | 373 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); |
416 EXPECT_EQ(ERR_IO_PENDING, | 374 EXPECT_EQ(ERR_IO_PENDING, |
417 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); | 375 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); |
418 | 376 |
419 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, | 377 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, |
420 /*offset=*/0, data)); | 378 /*offset=*/0, data)); |
421 | 379 |
422 EXPECT_EQ(data_len, callback.WaitForResult()); | 380 EXPECT_EQ(data_len, callback.WaitForResult()); |
423 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); | 381 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); |
424 base::RunLoop().RunUntilIdle(); | 382 base::RunLoop().RunUntilIdle(); |
425 | |
426 EXPECT_CALL(delegate_, OnClose()); | |
427 } | 383 } |
428 | 384 |
429 TEST_P(QuicChromiumClientStreamTest, ProcessHeadersWithError) { | 385 TEST_P(QuicChromiumClientStreamTest, ProcessHeadersWithError) { |
430 SpdyHeaderBlock bad_headers; | 386 SpdyHeaderBlock bad_headers; |
431 bad_headers["NAME"] = "..."; | 387 bad_headers["NAME"] = "..."; |
432 EXPECT_CALL(session_, | 388 EXPECT_CALL(session_, |
433 SendRstStream(kTestStreamId, QUIC_BAD_APPLICATION_PAYLOAD, 0)); | 389 SendRstStream(kTestStreamId, QUIC_BAD_APPLICATION_PAYLOAD, 0)); |
434 | 390 |
435 auto headers = AsHeaderList(bad_headers); | 391 auto headers = AsHeaderList(bad_headers); |
436 stream_->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), | 392 stream_->OnStreamHeaderList(false, headers.uncompressed_header_bytes(), |
437 headers); | 393 headers); |
438 | 394 |
439 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
440 | |
441 EXPECT_CALL(delegate_, OnClose()); | |
442 } | 396 } |
443 | 397 |
444 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableWithError) { | 398 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableWithError) { |
445 InitializeHeaders(); | 399 InitializeHeaders(); |
446 auto headers = AsHeaderList(headers_); | 400 auto headers = AsHeaderList(headers_); |
447 ProcessHeadersFull(headers_); | 401 ProcessHeadersFull(headers_); |
448 EXPECT_CALL(session_, SendRstStream(kTestStreamId, QUIC_STREAM_CANCELLED, 0)); | 402 EXPECT_CALL(session_, SendRstStream(kTestStreamId, QUIC_STREAM_CANCELLED, 0)); |
449 | 403 |
450 const char data[] = "hello world!"; | 404 const char data[] = "hello world!"; |
451 int data_len = strlen(data); | 405 int data_len = strlen(data); |
452 | 406 |
453 // Start to read the body. | 407 // Start to read the body. |
454 TestCompletionCallback callback; | 408 TestCompletionCallback callback; |
455 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); | 409 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); |
456 EXPECT_EQ(ERR_IO_PENDING, | 410 EXPECT_EQ(ERR_IO_PENDING, |
457 handle_->ReadBody( | 411 handle_->ReadBody( |
458 buffer.get(), 2 * data_len, | 412 buffer.get(), 2 * data_len, |
459 base::Bind(&QuicChromiumClientStreamTest::ResetStreamCallback, | 413 base::Bind(&QuicChromiumClientStreamTest::ResetStreamCallback, |
460 base::Unretained(this), stream_))); | 414 base::Unretained(this), stream_))); |
461 | 415 |
462 // Receive the data and close the stream during the callback. | 416 // Receive the data and close the stream during the callback. |
463 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, | 417 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, |
464 /*offset=*/0, data)); | 418 /*offset=*/0, data)); |
465 | 419 |
466 base::RunLoop().RunUntilIdle(); | 420 base::RunLoop().RunUntilIdle(); |
467 | |
468 EXPECT_CALL(delegate_, OnClose()); | |
469 } | 421 } |
470 | 422 |
471 TEST_P(QuicChromiumClientStreamTest, OnError) { | 423 TEST_P(QuicChromiumClientStreamTest, OnError) { |
472 EXPECT_CALL(delegate_, OnError(ERR_INTERNET_DISCONNECTED)).Times(1); | 424 // EXPECT_CALL(delegate_, OnError(ERR_INTERNET_DISCONNECTED)).Times(1); |
473 | 425 |
474 stream_->OnError(ERR_INTERNET_DISCONNECTED); | 426 stream_->OnError(ERR_INTERNET_DISCONNECTED); |
475 stream_->OnError(ERR_INTERNET_DISCONNECTED); | 427 stream_->OnError(ERR_INTERNET_DISCONNECTED); |
476 } | 428 } |
477 | 429 |
478 TEST_P(QuicChromiumClientStreamTest, OnTrailers) { | 430 TEST_P(QuicChromiumClientStreamTest, OnTrailers) { |
479 InitializeHeaders(); | 431 InitializeHeaders(); |
480 ProcessHeadersFull(headers_); | 432 ProcessHeadersFull(headers_); |
481 | 433 |
482 const char data[] = "hello world!"; | 434 const char data[] = "hello world!"; |
483 int data_len = strlen(data); | 435 int data_len = strlen(data); |
484 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, | 436 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, |
485 /*offset=*/0, data)); | 437 /*offset=*/0, data)); |
486 | 438 |
487 // Read the body and verify that it arrives correctly. | 439 // Read the body and verify that it arrives correctly. |
488 TestCompletionCallback callback; | 440 TestCompletionCallback callback; |
489 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); | 441 scoped_refptr<IOBuffer> buffer(new IOBuffer(2 * data_len)); |
490 EXPECT_EQ(data_len, | 442 EXPECT_EQ(data_len, |
491 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); | 443 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); |
492 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); | 444 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); |
493 | 445 |
494 SpdyHeaderBlock trailers; | 446 SpdyHeaderBlock trailers; |
495 trailers["bar"] = "foo"; | 447 trailers["bar"] = "foo"; |
496 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); | 448 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); |
497 | 449 |
498 auto t = ProcessTrailers(trailers); | 450 auto t = ProcessTrailers(trailers); |
499 | 451 |
500 TestCompletionCallback trailers_callback; | 452 TestCompletionCallback trailers_callback; |
501 EXPECT_EQ(static_cast<int>(t.uncompressed_header_bytes()), | 453 EXPECT_EQ( |
502 handle_->ReadTrailingHeaders(&delegate_.trailers_, | 454 static_cast<int>(t.uncompressed_header_bytes()), |
503 trailers_callback.callback())); | 455 handle_->ReadTrailingHeaders(&trailers_, trailers_callback.callback())); |
504 | 456 |
505 // Read the body and verify that it arrives correctly. | 457 // Read the body and verify that it arrives correctly. |
506 EXPECT_EQ(0, | 458 EXPECT_EQ(0, |
507 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); | 459 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback())); |
508 | 460 |
509 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. | 461 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. |
510 trailers.erase(kFinalOffsetHeaderKey); | 462 trailers.erase(kFinalOffsetHeaderKey); |
511 EXPECT_EQ(trailers, delegate_.trailers_); | 463 EXPECT_EQ(trailers, trailers_); |
512 base::RunLoop().RunUntilIdle(); | 464 base::RunLoop().RunUntilIdle(); |
513 EXPECT_CALL(delegate_, OnClose()); | |
514 } | 465 } |
515 | 466 |
516 // Tests that trailers are marked as consumed only before delegate is to be | 467 // Tests that trailers are marked as consumed only before delegate is to be |
517 // immediately notified about trailers. | 468 // immediately notified about trailers. |
518 TEST_P(QuicChromiumClientStreamTest, MarkTrailersConsumedWhenNotifyDelegate) { | 469 TEST_P(QuicChromiumClientStreamTest, MarkTrailersConsumedWhenNotifyDelegate) { |
519 InitializeHeaders(); | 470 InitializeHeaders(); |
520 ProcessHeadersFull(headers_); | 471 ProcessHeadersFull(headers_); |
521 | 472 |
522 const char data[] = "hello world!"; | 473 const char data[] = "hello world!"; |
523 int data_len = strlen(data); | 474 int data_len = strlen(data); |
(...skipping 11 matching lines...) Expand all Loading... |
535 EXPECT_THAT( | 486 EXPECT_THAT( |
536 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), | 487 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), |
537 IsError(ERR_IO_PENDING)); | 488 IsError(ERR_IO_PENDING)); |
538 | 489 |
539 SpdyHeaderBlock trailers; | 490 SpdyHeaderBlock trailers; |
540 trailers["bar"] = "foo"; | 491 trailers["bar"] = "foo"; |
541 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); | 492 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); |
542 QuicHeaderList t = ProcessTrailers(trailers); | 493 QuicHeaderList t = ProcessTrailers(trailers); |
543 EXPECT_FALSE(stream_->IsDoneReading()); | 494 EXPECT_FALSE(stream_->IsDoneReading()); |
544 | 495 |
545 EXPECT_EQ( | 496 EXPECT_EQ(static_cast<int>(t.uncompressed_header_bytes()), |
546 static_cast<int>(t.uncompressed_header_bytes()), | 497 handle_->ReadTrailingHeaders(&trailers_, callback.callback())); |
547 handle_->ReadTrailingHeaders(&delegate_.trailers_, callback.callback())); | |
548 | 498 |
549 // Read the body and verify that it arrives correctly. | 499 // Read the body and verify that it arrives correctly. |
550 EXPECT_EQ(0, callback.WaitForResult()); | 500 EXPECT_EQ(0, callback.WaitForResult()); |
551 | 501 |
552 // Make sure the stream is properly closed since trailers and data are all | 502 // Make sure the stream is properly closed since trailers and data are all |
553 // consumed. | 503 // consumed. |
554 EXPECT_TRUE(stream_->IsDoneReading()); | 504 EXPECT_TRUE(stream_->IsDoneReading()); |
555 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. | 505 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. |
556 trailers.erase(kFinalOffsetHeaderKey); | 506 trailers.erase(kFinalOffsetHeaderKey); |
557 EXPECT_EQ(trailers, delegate_.trailers_); | 507 EXPECT_EQ(trailers, trailers_); |
558 | 508 |
559 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
560 EXPECT_CALL(delegate_, OnClose()); | |
561 } | 510 } |
562 | 511 |
563 // Test that if Read() is called after response body is read and after trailers | 512 // Test that if Read() is called after response body is read and after trailers |
564 // are received but not yet delivered, Read() will return ERR_IO_PENDING instead | 513 // are received but not yet delivered, Read() will return ERR_IO_PENDING instead |
565 // of 0 (EOF). | 514 // of 0 (EOF). |
566 TEST_P(QuicChromiumClientStreamTest, ReadAfterTrailersReceivedButNotDelivered) { | 515 TEST_P(QuicChromiumClientStreamTest, ReadAfterTrailersReceivedButNotDelivered) { |
567 InitializeHeaders(); | 516 InitializeHeaders(); |
568 ProcessHeadersFull(headers_); | 517 ProcessHeadersFull(headers_); |
569 | 518 |
570 const char data[] = "hello world!"; | 519 const char data[] = "hello world!"; |
(...skipping 18 matching lines...) Expand all Loading... |
589 EXPECT_FALSE(stream_->IsDoneReading()); | 538 EXPECT_FALSE(stream_->IsDoneReading()); |
590 // Read again, it return ERR_IO_PENDING. | 539 // Read again, it return ERR_IO_PENDING. |
591 EXPECT_THAT( | 540 EXPECT_THAT( |
592 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), | 541 handle_->ReadBody(buffer.get(), 2 * data_len, callback.callback()), |
593 IsError(ERR_IO_PENDING)); | 542 IsError(ERR_IO_PENDING)); |
594 | 543 |
595 // Trailers are not delivered | 544 // Trailers are not delivered |
596 EXPECT_FALSE(stream_->IsDoneReading()); | 545 EXPECT_FALSE(stream_->IsDoneReading()); |
597 | 546 |
598 TestCompletionCallback callback2; | 547 TestCompletionCallback callback2; |
599 EXPECT_EQ( | 548 EXPECT_EQ(static_cast<int>(t.uncompressed_header_bytes()), |
600 static_cast<int>(t.uncompressed_header_bytes()), | 549 handle_->ReadTrailingHeaders(&trailers_, callback2.callback())); |
601 handle_->ReadTrailingHeaders(&delegate_.trailers_, callback2.callback())); | |
602 | 550 |
603 // Read the body and verify that it arrives correctly. | 551 // Read the body and verify that it arrives correctly. |
604 // OnDataAvailable() should follow right after and Read() will return 0. | 552 // OnDataAvailable() should follow right after and Read() will return 0. |
605 EXPECT_EQ(0, callback.WaitForResult()); | 553 EXPECT_EQ(0, callback.WaitForResult()); |
606 | 554 |
607 // Make sure the stream is properly closed since trailers and data are all | 555 // Make sure the stream is properly closed since trailers and data are all |
608 // consumed. | 556 // consumed. |
609 EXPECT_TRUE(stream_->IsDoneReading()); | 557 EXPECT_TRUE(stream_->IsDoneReading()); |
610 | 558 |
611 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. | 559 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. |
612 trailers.erase(kFinalOffsetHeaderKey); | 560 trailers.erase(kFinalOffsetHeaderKey); |
613 EXPECT_EQ(trailers, delegate_.trailers_); | 561 EXPECT_EQ(trailers, trailers_); |
614 | 562 |
615 base::RunLoop().RunUntilIdle(); | 563 base::RunLoop().RunUntilIdle(); |
616 EXPECT_CALL(delegate_, OnClose()); | |
617 } | 564 } |
618 | 565 |
619 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { | 566 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { |
620 EXPECT_CALL(delegate_, OnClose()); | |
621 | |
622 const char kData1[] = "hello world"; | 567 const char kData1[] = "hello world"; |
623 const size_t kDataLen = arraysize(kData1); | 568 const size_t kDataLen = arraysize(kData1); |
624 | 569 |
625 // All data written. | 570 // All data written. |
626 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 571 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
627 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 572 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
628 TestCompletionCallback callback; | 573 TestCompletionCallback callback; |
629 EXPECT_EQ(OK, handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen), | 574 EXPECT_EQ(OK, handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen), |
630 true, callback.callback())); | 575 true, callback.callback())); |
631 } | 576 } |
632 | 577 |
633 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { | 578 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { |
634 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); | |
635 EXPECT_CALL(delegate_, OnClose()); | |
636 | |
637 const char kData1[] = "hello world"; | 579 const char kData1[] = "hello world"; |
638 const size_t kDataLen = arraysize(kData1); | 580 const size_t kDataLen = arraysize(kData1); |
639 | 581 |
640 // No data written. | 582 // No data written. |
641 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 583 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
642 .WillOnce(Return(QuicConsumedData(0, false))); | 584 .WillOnce(Return(QuicConsumedData(0, false))); |
643 TestCompletionCallback callback; | 585 TestCompletionCallback callback; |
644 EXPECT_EQ(ERR_IO_PENDING, | 586 EXPECT_EQ(ERR_IO_PENDING, |
645 handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen), true, | 587 handle_->WriteStreamData(QuicStringPiece(kData1, kDataLen), true, |
646 callback.callback())); | 588 callback.callback())); |
647 ASSERT_FALSE(callback.have_result()); | 589 ASSERT_FALSE(callback.have_result()); |
648 | 590 |
649 // All data written. | 591 // All data written. |
650 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 592 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
651 .WillOnce(Return(QuicConsumedData(kDataLen, true))); | 593 .WillOnce(Return(QuicConsumedData(kDataLen, true))); |
652 stream_->OnCanWrite(); | 594 stream_->OnCanWrite(); |
653 ASSERT_TRUE(callback.have_result()); | 595 ASSERT_TRUE(callback.have_result()); |
654 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 596 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
655 } | 597 } |
656 | 598 |
657 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) { | 599 TEST_P(QuicChromiumClientStreamTest, WritevStreamData) { |
658 EXPECT_CALL(delegate_, OnClose()); | |
659 | |
660 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); | 600 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); |
661 scoped_refptr<StringIOBuffer> buf2( | 601 scoped_refptr<StringIOBuffer> buf2( |
662 new StringIOBuffer("Just a small payload")); | 602 new StringIOBuffer("Just a small payload")); |
663 | 603 |
664 // All data written. | 604 // All data written. |
665 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 605 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
666 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) | 606 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) |
667 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); | 607 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); |
668 TestCompletionCallback callback; | 608 TestCompletionCallback callback; |
669 EXPECT_EQ( | 609 EXPECT_EQ( |
670 OK, handle_->WritevStreamData({buf1, buf2}, {buf1->size(), buf2->size()}, | 610 OK, handle_->WritevStreamData({buf1, buf2}, {buf1->size(), buf2->size()}, |
671 true, callback.callback())); | 611 true, callback.callback())); |
672 } | 612 } |
673 | 613 |
674 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) { | 614 TEST_P(QuicChromiumClientStreamTest, WritevStreamDataAsync) { |
675 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); | |
676 EXPECT_CALL(delegate_, OnClose()); | |
677 | |
678 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); | 615 scoped_refptr<StringIOBuffer> buf1(new StringIOBuffer("hello world!")); |
679 scoped_refptr<StringIOBuffer> buf2( | 616 scoped_refptr<StringIOBuffer> buf2( |
680 new StringIOBuffer("Just a small payload")); | 617 new StringIOBuffer("Just a small payload")); |
681 | 618 |
682 // Only a part of the data is written. | 619 // Only a part of the data is written. |
683 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 620 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
684 // First piece of data is written. | 621 // First piece of data is written. |
685 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) | 622 .WillOnce(Return(QuicConsumedData(buf1->size(), false))) |
686 // Second piece of data is queued. | 623 // Second piece of data is queued. |
687 .WillOnce(Return(QuicConsumedData(0, false))); | 624 .WillOnce(Return(QuicConsumedData(0, false))); |
688 TestCompletionCallback callback; | 625 TestCompletionCallback callback; |
689 EXPECT_EQ(ERR_IO_PENDING, | 626 EXPECT_EQ(ERR_IO_PENDING, |
690 handle_->WritevStreamData({buf1.get(), buf2.get()}, | 627 handle_->WritevStreamData({buf1.get(), buf2.get()}, |
691 {buf1->size(), buf2->size()}, true, | 628 {buf1->size(), buf2->size()}, true, |
692 callback.callback())); | 629 callback.callback())); |
693 ASSERT_FALSE(callback.have_result()); | 630 ASSERT_FALSE(callback.have_result()); |
694 | 631 |
695 // The second piece of data is written. | 632 // The second piece of data is written. |
696 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) | 633 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) |
697 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); | 634 .WillOnce(Return(QuicConsumedData(buf2->size(), true))); |
698 stream_->OnCanWrite(); | 635 stream_->OnCanWrite(); |
699 ASSERT_TRUE(callback.have_result()); | 636 ASSERT_TRUE(callback.have_result()); |
700 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 637 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
701 } | 638 } |
702 | 639 |
703 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeDelegate) { | 640 TEST_P(QuicChromiumClientStreamTest, HeadersBeforeHandle) { |
704 // We don't use stream_ because we want an incoming server push | 641 // We don't use stream_ because we want an incoming server push |
705 // stream. | 642 // stream. |
706 QuicStreamId stream_id = GetNthServerInitiatedStreamId(0); | 643 QuicStreamId stream_id = GetNthServerInitiatedStreamId(0); |
707 QuicChromiumClientStream* stream2 = | 644 QuicChromiumClientStream* stream2 = |
708 new QuicChromiumClientStream(stream_id, &session_, NetLogWithSource()); | 645 new QuicChromiumClientStream(stream_id, &session_, NetLogWithSource()); |
709 session_.ActivateStream(base::WrapUnique(stream2)); | 646 session_.ActivateStream(base::WrapUnique(stream2)); |
710 | 647 |
711 InitializeHeaders(); | 648 InitializeHeaders(); |
712 | 649 |
713 // Receive the headers before the delegate is set. | 650 // Receive the headers before the delegate is set. |
714 QuicHeaderList header_list = AsHeaderList(headers_); | 651 QuicHeaderList header_list = AsHeaderList(headers_); |
715 stream2->OnStreamHeaderList(true, header_list.uncompressed_header_bytes(), | 652 stream2->OnStreamHeaderList(true, header_list.uncompressed_header_bytes(), |
716 header_list); | 653 header_list); |
717 EXPECT_TRUE(delegate2_.headers_.empty()); | |
718 | 654 |
719 // Now set the delegate and verify that the headers are delivered. | 655 // Now set the delegate and verify that the headers are delivered. |
720 handle2_ = stream2->CreateHandle(&delegate2_); | 656 handle2_ = stream2->CreateHandle(); |
721 TestCompletionCallback callback; | 657 TestCompletionCallback callback; |
722 EXPECT_EQ( | 658 EXPECT_EQ(static_cast<int>(header_list.uncompressed_header_bytes()), |
723 static_cast<int>(header_list.uncompressed_header_bytes()), | 659 handle2_->ReadInitialHeaders(&headers_, callback.callback())); |
724 handle2_->ReadInitialHeaders(&delegate2_.headers_, callback.callback())); | 660 EXPECT_EQ(headers_, headers_); |
725 EXPECT_EQ(headers_, delegate2_.headers_); | |
726 | |
727 // Both delegates should be notified that theirs streams are closed. | |
728 EXPECT_CALL(delegate2_, OnClose()); | |
729 EXPECT_CALL(delegate_, OnClose()); | |
730 } | 661 } |
731 | 662 |
732 TEST_P(QuicChromiumClientStreamTest, HeadersAndDataBeforeDelegate) { | 663 TEST_P(QuicChromiumClientStreamTest, HeadersAndDataBeforeHandle) { |
733 // We don't use stream_ because we want an incoming server push | 664 // We don't use stream_ because we want an incoming server push |
734 // stream. | 665 // stream. |
735 QuicStreamId stream_id = GetNthServerInitiatedStreamId(0); | 666 QuicStreamId stream_id = GetNthServerInitiatedStreamId(0); |
736 QuicChromiumClientStream* stream2 = | 667 QuicChromiumClientStream* stream2 = |
737 new QuicChromiumClientStream(stream_id, &session_, NetLogWithSource()); | 668 new QuicChromiumClientStream(stream_id, &session_, NetLogWithSource()); |
738 session_.ActivateStream(base::WrapUnique(stream2)); | 669 session_.ActivateStream(base::WrapUnique(stream2)); |
739 | 670 |
740 InitializeHeaders(); | 671 InitializeHeaders(); |
741 | 672 |
742 // Receive the headers and data before the delegate is set. | 673 // Receive the headers and data before the delegate is set. |
743 QuicHeaderList header_list = AsHeaderList(headers_); | 674 QuicHeaderList header_list = AsHeaderList(headers_); |
744 stream2->OnStreamHeaderList(false, header_list.uncompressed_header_bytes(), | 675 stream2->OnStreamHeaderList(false, header_list.uncompressed_header_bytes(), |
745 header_list); | 676 header_list); |
746 EXPECT_TRUE(delegate2_.headers_.empty()); | |
747 const char data[] = "hello world!"; | 677 const char data[] = "hello world!"; |
748 stream2->OnStreamFrame(QuicStreamFrame(stream_id, /*fin=*/false, | 678 stream2->OnStreamFrame(QuicStreamFrame(stream_id, /*fin=*/false, |
749 /*offset=*/0, data)); | 679 /*offset=*/0, data)); |
750 | 680 |
751 // Now set the delegate and verify that the headers are delivered, but | 681 // Now set the delegate and verify that the headers are delivered, but |
752 // not the data, which needs to be read explicitly. | 682 // not the data, which needs to be read explicitly. |
753 handle2_ = stream2->CreateHandle(&delegate2_); | 683 handle2_ = stream2->CreateHandle(); |
754 TestCompletionCallback callback; | 684 TestCompletionCallback callback; |
755 EXPECT_EQ( | 685 EXPECT_EQ(static_cast<int>(header_list.uncompressed_header_bytes()), |
756 static_cast<int>(header_list.uncompressed_header_bytes()), | 686 handle2_->ReadInitialHeaders(&headers_, callback.callback())); |
757 handle2_->ReadInitialHeaders(&delegate2_.headers_, callback.callback())); | 687 EXPECT_EQ(headers_, headers_); |
758 EXPECT_EQ(headers_, delegate2_.headers_); | |
759 base::RunLoop().RunUntilIdle(); | 688 base::RunLoop().RunUntilIdle(); |
760 | 689 |
761 // Now explicitly read the data. | 690 // Now explicitly read the data. |
762 int data_len = arraysize(data) - 1; | 691 int data_len = arraysize(data) - 1; |
763 scoped_refptr<IOBuffer> buffer(new IOBuffer(data_len + 1)); | 692 scoped_refptr<IOBuffer> buffer(new IOBuffer(data_len + 1)); |
764 ASSERT_EQ(data_len, stream2->Read(buffer.get(), data_len + 1)); | 693 ASSERT_EQ(data_len, stream2->Read(buffer.get(), data_len + 1)); |
765 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); | 694 EXPECT_EQ(QuicStringPiece(data), QuicStringPiece(buffer->data(), data_len)); |
766 | |
767 // Both delegates should be notified that theirs streams are closed. | |
768 EXPECT_CALL(delegate2_, OnClose()); | |
769 EXPECT_CALL(delegate_, OnClose()); | |
770 } | 695 } |
771 | 696 |
772 } // namespace | 697 } // namespace |
773 } // namespace test | 698 } // namespace test |
774 } // namespace net | 699 } // namespace net |
OLD | NEW |