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

Side by Side Diff: net/quic/chromium/quic_chromium_client_stream_test.cc

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 months 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 (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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 QuicIOVector data, 83 QuicIOVector data,
84 QuicStreamOffset offset, 84 QuicStreamOffset offset,
85 bool fin, 85 bool fin,
86 QuicReferenceCountedPointer<QuicAckListenerInterface>)); 86 QuicReferenceCountedPointer<QuicAckListenerInterface>));
87 MOCK_METHOD3(SendRstStream, 87 MOCK_METHOD3(SendRstStream,
88 void(QuicStreamId stream_id, 88 void(QuicStreamId stream_id,
89 QuicRstStreamErrorCode error, 89 QuicRstStreamErrorCode error,
90 QuicStreamOffset bytes_written)); 90 QuicStreamOffset bytes_written));
91 91
92 MOCK_METHOD2(OnStreamHeaders, 92 MOCK_METHOD2(OnStreamHeaders,
93 void(QuicStreamId stream_id, base::StringPiece headers_data)); 93 void(QuicStreamId stream_id, QuicStringPiece headers_data));
94 MOCK_METHOD2(OnStreamHeadersPriority, 94 MOCK_METHOD2(OnStreamHeadersPriority,
95 void(QuicStreamId stream_id, SpdyPriority priority)); 95 void(QuicStreamId stream_id, SpdyPriority priority));
96 MOCK_METHOD3(OnStreamHeadersComplete, 96 MOCK_METHOD3(OnStreamHeadersComplete,
97 void(QuicStreamId stream_id, bool fin, size_t frame_len)); 97 void(QuicStreamId stream_id, bool fin, size_t frame_len));
98 MOCK_METHOD2(OnPromiseHeaders, 98 MOCK_METHOD2(OnPromiseHeaders,
99 void(QuicStreamId stream_id, StringPiece headers_data)); 99 void(QuicStreamId stream_id, QuicStringPiece headers_data));
100 MOCK_METHOD3(OnPromiseHeadersComplete, 100 MOCK_METHOD3(OnPromiseHeadersComplete,
101 void(QuicStreamId stream_id, 101 void(QuicStreamId stream_id,
102 QuicStreamId promised_stream_id, 102 QuicStreamId promised_stream_id,
103 size_t frame_len)); 103 size_t frame_len));
104 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool()); 104 MOCK_METHOD0(IsCryptoHandshakeConfirmed, bool());
105 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be 105 // Methods taking non-copyable types like SpdyHeaderBlock by value cannot be
106 // mocked directly. 106 // mocked directly.
107 size_t WriteHeaders(QuicStreamId id, 107 size_t WriteHeaders(QuicStreamId id,
108 SpdyHeaderBlock headers, 108 SpdyHeaderBlock headers,
109 bool fin, 109 bool fin,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6" 203 "ARHKyW-koxuhMZHUnGBJAM1gJODe0cATO_KGoX4pbbFxxJ5IicRxOrWK_5rU3cdy6"
204 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b" 204 "edlR9FsEdH6iujMcHkbE5l18ehJDwTWmBKBzVD87naobhMMrF6VvnDGxQVGp9Ir_b"
205 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6" 205 "Rgj3RWUoPumQVCxtSOBdX0GlJOEcDTNCzQIm9BSfetog_eP_TfYubKudt5eMsXmN6"
206 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG" 206 "QnyXHeGeK2UINUzJ-D30AFcpqYgH9_1BvYSpi7fc7_ydBU8TaD8ZRxvtnzXqj0RfG"
207 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk" 207 "tuHghmv3aD-uzSYJ75XDdzKdizZ86IG6Fbn1XFhYZM-fbHhm3mVEXnyRW4ZuNOLFk"
208 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn" 208 "Fas6LMcVC6Q8QLlHYbXBpdNFuGbuZGUnav5C-2I_-46lL0NGg3GewxGKGHvHEfoyn"
209 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr" 209 "EFFlEYHsBQ98rXImL8ySDycdLEFvBPdtctPmWCfTxwmoSMLHU2SCVDhbqMWU5b0yr"
210 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo "; 210 "JBCScs_ejbKaqBDoB7ZGxTvqlrB__2ZmnHHjCr8RgMRtKNtIeuZAo ";
211 } 211 }
212 212
213 void ReadData(StringPiece expected_data) { 213 void ReadData(QuicStringPiece expected_data) {
214 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected_data.length() + 1)); 214 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected_data.length() + 1));
215 EXPECT_EQ(static_cast<int>(expected_data.length()), 215 EXPECT_EQ(static_cast<int>(expected_data.length()),
216 stream_->Read(buffer.get(), expected_data.length() + 1)); 216 stream_->Read(buffer.get(), expected_data.length() + 1));
217 EXPECT_EQ(expected_data, 217 EXPECT_EQ(expected_data,
218 StringPiece(buffer->data(), expected_data.length())); 218 QuicStringPiece(buffer->data(), expected_data.length()));
219 } 219 }
220 220
221 QuicHeaderList ProcessHeaders(const SpdyHeaderBlock& headers) { 221 QuicHeaderList ProcessHeaders(const SpdyHeaderBlock& headers) {
222 QuicHeaderList h = AsHeaderList(headers); 222 QuicHeaderList h = AsHeaderList(headers);
223 stream_->OnStreamHeaderList(false, h.uncompressed_header_bytes(), h); 223 stream_->OnStreamHeaderList(false, h.uncompressed_header_bytes(), h);
224 return h; 224 return h;
225 } 225 }
226 226
227 QuicHeaderList ProcessTrailers(const SpdyHeaderBlock& headers) { 227 QuicHeaderList ProcessTrailers(const SpdyHeaderBlock& headers) {
228 QuicHeaderList h = AsHeaderList(headers); 228 QuicHeaderList h = AsHeaderList(headers);
(...skipping 22 matching lines...) Expand all
251 }; 251 };
252 252
253 INSTANTIATE_TEST_CASE_P(Version, 253 INSTANTIATE_TEST_CASE_P(Version,
254 QuicChromiumClientStreamTest, 254 QuicChromiumClientStreamTest,
255 ::testing::ValuesIn(AllSupportedVersions())); 255 ::testing::ValuesIn(AllSupportedVersions()));
256 256
257 TEST_P(QuicChromiumClientStreamTest, OnFinRead) { 257 TEST_P(QuicChromiumClientStreamTest, OnFinRead) {
258 InitializeHeaders(); 258 InitializeHeaders();
259 QuicStreamOffset offset = 0; 259 QuicStreamOffset offset = 0;
260 ProcessHeadersFull(headers_); 260 ProcessHeadersFull(headers_);
261 QuicStreamFrame frame2(kTestStreamId, true, offset, StringPiece()); 261 QuicStreamFrame frame2(kTestStreamId, true, offset, QuicStringPiece());
262 EXPECT_CALL(delegate_, OnClose()); 262 EXPECT_CALL(delegate_, OnClose());
263 stream_->OnStreamFrame(frame2); 263 stream_->OnStreamFrame(frame2);
264 } 264 }
265 265
266 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableBeforeHeaders) { 266 TEST_P(QuicChromiumClientStreamTest, OnDataAvailableBeforeHeaders) {
267 EXPECT_CALL(delegate_, OnClose()); 267 EXPECT_CALL(delegate_, OnClose());
268 268
269 EXPECT_CALL(delegate_, OnDataAvailable()).Times(0); 269 EXPECT_CALL(delegate_, OnDataAvailable()).Times(0);
270 stream_->OnDataAvailable(); 270 stream_->OnDataAvailable();
271 } 271 }
272 272
273 TEST_P(QuicChromiumClientStreamTest, OnDataAvailable) { 273 TEST_P(QuicChromiumClientStreamTest, OnDataAvailable) {
274 InitializeHeaders(); 274 InitializeHeaders();
275 ProcessHeadersFull(headers_); 275 ProcessHeadersFull(headers_);
276 276
277 const char data[] = "hello world!"; 277 const char data[] = "hello world!";
278 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, 278 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
279 /*offset=*/0, data)); 279 /*offset=*/0, data));
280 280
281 EXPECT_CALL(delegate_, OnDataAvailable()) 281 EXPECT_CALL(delegate_, OnDataAvailable())
282 .WillOnce(testing::Invoke( 282 .WillOnce(testing::Invoke(CreateFunctor(
283 CreateFunctor(&QuicChromiumClientStreamTest::ReadData, 283 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this),
284 base::Unretained(this), 284 QuicStringPiece(data, arraysize(data) - 1))));
285 StringPiece(data, arraysize(data) - 1))));
286 base::RunLoop().RunUntilIdle(); 285 base::RunLoop().RunUntilIdle();
287 286
288 EXPECT_CALL(delegate_, OnClose()); 287 EXPECT_CALL(delegate_, OnClose());
289 } 288 }
290 289
291 TEST_P(QuicChromiumClientStreamTest, ProcessHeadersWithError) { 290 TEST_P(QuicChromiumClientStreamTest, ProcessHeadersWithError) {
292 SpdyHeaderBlock bad_headers; 291 SpdyHeaderBlock bad_headers;
293 bad_headers["NAME"] = "..."; 292 bad_headers["NAME"] = "...";
294 EXPECT_CALL(session_, 293 EXPECT_CALL(session_,
295 SendRstStream(kTestStreamId, QUIC_BAD_APPLICATION_PAYLOAD, 0)); 294 SendRstStream(kTestStreamId, QUIC_BAD_APPLICATION_PAYLOAD, 0));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 InitializeHeaders(); 330 InitializeHeaders();
332 ProcessHeadersFull(headers_); 331 ProcessHeadersFull(headers_);
333 332
334 const char data[] = "hello world!"; 333 const char data[] = "hello world!";
335 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, 334 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
336 /*offset=*/0, data)); 335 /*offset=*/0, data));
337 336
338 EXPECT_CALL(delegate_, OnDataAvailable()) 337 EXPECT_CALL(delegate_, OnDataAvailable())
339 .WillOnce(testing::Invoke(CreateFunctor( 338 .WillOnce(testing::Invoke(CreateFunctor(
340 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this), 339 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this),
341 StringPiece(data, arraysize(data) - 1)))); 340 QuicStringPiece(data, arraysize(data) - 1))));
342 341
343 SpdyHeaderBlock trailers; 342 SpdyHeaderBlock trailers;
344 trailers["bar"] = "foo"; 343 trailers["bar"] = "foo";
345 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); 344 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data));
346 345
347 auto t = ProcessTrailers(trailers); 346 auto t = ProcessTrailers(trailers);
348 base::RunLoop run_loop; 347 base::RunLoop run_loop;
349 EXPECT_CALL(delegate_, 348 EXPECT_CALL(delegate_,
350 OnHeadersAvailableMock(_, t.uncompressed_header_bytes())) 349 OnHeadersAvailableMock(_, t.uncompressed_header_bytes()))
351 .WillOnce(testing::InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 350 .WillOnce(testing::InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
352 351
353 run_loop.Run(); 352 run_loop.Run();
354 353
355 // OnDataAvailable callback should follow trailers notification. 354 // OnDataAvailable callback should follow trailers notification.
356 base::RunLoop run_loop3; 355 base::RunLoop run_loop3;
357 EXPECT_CALL(delegate_, OnDataAvailable()) 356 EXPECT_CALL(delegate_, OnDataAvailable())
358 .Times(1) 357 .Times(1)
359 .WillOnce(testing::DoAll( 358 .WillOnce(testing::DoAll(
360 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData, 359 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData,
361 base::Unretained(this), StringPiece())), 360 base::Unretained(this),
361 QuicStringPiece())),
362 testing::InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }))); 362 testing::InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); })));
363 run_loop3.Run(); 363 run_loop3.Run();
364 364
365 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. 365 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
366 trailers.erase(kFinalOffsetHeaderKey); 366 trailers.erase(kFinalOffsetHeaderKey);
367 EXPECT_EQ(trailers, delegate_.headers_); 367 EXPECT_EQ(trailers, delegate_.headers_);
368 base::RunLoop().RunUntilIdle(); 368 base::RunLoop().RunUntilIdle();
369 EXPECT_CALL(delegate_, OnClose()); 369 EXPECT_CALL(delegate_, OnClose());
370 } 370 }
371 371
372 // Tests that trailers are marked as consumed only before delegate is to be 372 // Tests that trailers are marked as consumed only before delegate is to be
373 // immediately notified about trailers. 373 // immediately notified about trailers.
374 TEST_P(QuicChromiumClientStreamTest, MarkTrailersConsumedWhenNotifyDelegate) { 374 TEST_P(QuicChromiumClientStreamTest, MarkTrailersConsumedWhenNotifyDelegate) {
375 InitializeHeaders(); 375 InitializeHeaders();
376 ProcessHeadersFull(headers_); 376 ProcessHeadersFull(headers_);
377 377
378 const char data[] = "hello world!"; 378 const char data[] = "hello world!";
379 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, 379 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
380 /*offset=*/0, data)); 380 /*offset=*/0, data));
381 381
382 base::RunLoop run_loop; 382 base::RunLoop run_loop;
383 EXPECT_CALL(delegate_, OnDataAvailable()) 383 EXPECT_CALL(delegate_, OnDataAvailable())
384 .Times(1) 384 .Times(1)
385 .WillOnce(testing::DoAll( 385 .WillOnce(testing::DoAll(
386 testing::Invoke(CreateFunctor( 386 testing::Invoke(CreateFunctor(
387 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this), 387 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this),
388 StringPiece(data, arraysize(data) - 1))), 388 QuicStringPiece(data, arraysize(data) - 1))),
389 testing::Invoke([&run_loop]() { run_loop.Quit(); }))); 389 testing::Invoke([&run_loop]() { run_loop.Quit(); })));
390 390
391 // Wait for the read to complete. 391 // Wait for the read to complete.
392 run_loop.Run(); 392 run_loop.Run();
393 393
394 // Read again, and it will be pending. 394 // Read again, and it will be pending.
395 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); 395 scoped_refptr<IOBuffer> buffer(new IOBuffer(1));
396 EXPECT_THAT(stream_->Read(buffer.get(), 1), IsError(ERR_IO_PENDING)); 396 EXPECT_THAT(stream_->Read(buffer.get(), 1), IsError(ERR_IO_PENDING));
397 397
398 SpdyHeaderBlock trailers; 398 SpdyHeaderBlock trailers;
399 trailers["bar"] = "foo"; 399 trailers["bar"] = "foo";
400 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); 400 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data));
401 QuicHeaderList t = ProcessTrailers(trailers); 401 QuicHeaderList t = ProcessTrailers(trailers);
402 EXPECT_FALSE(stream_->IsDoneReading()); 402 EXPECT_FALSE(stream_->IsDoneReading());
403 403
404 base::RunLoop run_loop2; 404 base::RunLoop run_loop2;
405 EXPECT_CALL(delegate_, 405 EXPECT_CALL(delegate_,
406 OnHeadersAvailableMock(_, t.uncompressed_header_bytes())) 406 OnHeadersAvailableMock(_, t.uncompressed_header_bytes()))
407 .WillOnce( 407 .WillOnce(
408 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); 408 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); }));
409 409
410 run_loop2.Run(); 410 run_loop2.Run();
411 411
412 // OnDataAvailable callback should follow trailers notification. 412 // OnDataAvailable callback should follow trailers notification.
413 base::RunLoop run_loop3; 413 base::RunLoop run_loop3;
414 EXPECT_CALL(delegate_, OnDataAvailable()) 414 EXPECT_CALL(delegate_, OnDataAvailable())
415 .Times(1) 415 .Times(1)
416 .WillOnce(testing::DoAll( 416 .WillOnce(testing::DoAll(
417 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData, 417 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData,
418 base::Unretained(this), StringPiece())), 418 base::Unretained(this),
419 QuicStringPiece())),
419 testing::InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); }))); 420 testing::InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); })));
420 run_loop3.Run(); 421 run_loop3.Run();
421 422
422 // Make sure the stream is properly closed since trailers and data are all 423 // Make sure the stream is properly closed since trailers and data are all
423 // consumed. 424 // consumed.
424 EXPECT_TRUE(stream_->IsDoneReading()); 425 EXPECT_TRUE(stream_->IsDoneReading());
425 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. 426 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
426 trailers.erase(kFinalOffsetHeaderKey); 427 trailers.erase(kFinalOffsetHeaderKey);
427 EXPECT_EQ(trailers, delegate_.headers_); 428 EXPECT_EQ(trailers, delegate_.headers_);
428 429
(...skipping 11 matching lines...) Expand all
440 const char data[] = "hello world!"; 441 const char data[] = "hello world!";
441 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, 442 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
442 /*offset=*/0, data)); 443 /*offset=*/0, data));
443 444
444 base::RunLoop run_loop; 445 base::RunLoop run_loop;
445 EXPECT_CALL(delegate_, OnDataAvailable()) 446 EXPECT_CALL(delegate_, OnDataAvailable())
446 .Times(1) 447 .Times(1)
447 .WillOnce(testing::DoAll( 448 .WillOnce(testing::DoAll(
448 testing::Invoke(CreateFunctor( 449 testing::Invoke(CreateFunctor(
449 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this), 450 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this),
450 StringPiece(data, arraysize(data) - 1))), 451 QuicStringPiece(data, arraysize(data) - 1))),
451 testing::Invoke([&run_loop]() { run_loop.Quit(); }))); 452 testing::Invoke([&run_loop]() { run_loop.Quit(); })));
452 453
453 // Wait for the read to complete. 454 // Wait for the read to complete.
454 run_loop.Run(); 455 run_loop.Run();
455 456
456 // Deliver trailers. Delegate notification is posted asynchronously. 457 // Deliver trailers. Delegate notification is posted asynchronously.
457 SpdyHeaderBlock trailers; 458 SpdyHeaderBlock trailers;
458 trailers["bar"] = "foo"; 459 trailers["bar"] = "foo";
459 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data)); 460 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data));
460 461
(...skipping 12 matching lines...) Expand all
473 .WillOnce( 474 .WillOnce(
474 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })); 475 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); }));
475 476
476 run_loop2.Run(); 477 run_loop2.Run();
477 478
478 base::RunLoop run_loop3; 479 base::RunLoop run_loop3;
479 // OnDataAvailable() should follow right after and Read() will return 0. 480 // OnDataAvailable() should follow right after and Read() will return 0.
480 EXPECT_CALL(delegate_, OnDataAvailable()) 481 EXPECT_CALL(delegate_, OnDataAvailable())
481 .WillOnce(testing::DoAll( 482 .WillOnce(testing::DoAll(
482 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData, 483 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData,
483 base::Unretained(this), StringPiece())), 484 base::Unretained(this),
485 QuicStringPiece())),
484 testing::Invoke([&run_loop3]() { run_loop3.Quit(); }))); 486 testing::Invoke([&run_loop3]() { run_loop3.Quit(); })));
485 run_loop3.Run(); 487 run_loop3.Run();
486 488
487 // Make sure the stream is properly closed since trailers and data are all 489 // Make sure the stream is properly closed since trailers and data are all
488 // consumed. 490 // consumed.
489 EXPECT_TRUE(stream_->IsDoneReading()); 491 EXPECT_TRUE(stream_->IsDoneReading());
490 492
491 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers. 493 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
492 trailers.erase(kFinalOffsetHeaderKey); 494 trailers.erase(kFinalOffsetHeaderKey);
493 EXPECT_EQ(trailers, delegate_.headers_); 495 EXPECT_EQ(trailers, delegate_.headers_);
494 496
495 base::RunLoop().RunUntilIdle(); 497 base::RunLoop().RunUntilIdle();
496 EXPECT_CALL(delegate_, OnClose()); 498 EXPECT_CALL(delegate_, OnClose());
497 } 499 }
498 500
499 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { 501 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) {
500 EXPECT_CALL(delegate_, OnClose()); 502 EXPECT_CALL(delegate_, OnClose());
501 503
502 const char kData1[] = "hello world"; 504 const char kData1[] = "hello world";
503 const size_t kDataLen = arraysize(kData1); 505 const size_t kDataLen = arraysize(kData1);
504 506
505 // All data written. 507 // All data written.
506 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 508 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
507 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 509 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
508 TestCompletionCallback callback; 510 TestCompletionCallback callback;
509 EXPECT_EQ(OK, stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), 511 EXPECT_EQ(OK, stream_->WriteStreamData(QuicStringPiece(kData1, kDataLen),
510 true, callback.callback())); 512 true, callback.callback()));
511 } 513 }
512 514
513 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) { 515 TEST_P(QuicChromiumClientStreamTest, WriteStreamDataAsync) {
514 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber()); 516 EXPECT_CALL(delegate_, HasSendHeadersComplete()).Times(AnyNumber());
515 EXPECT_CALL(delegate_, OnClose()); 517 EXPECT_CALL(delegate_, OnClose());
516 518
517 const char kData1[] = "hello world"; 519 const char kData1[] = "hello world";
518 const size_t kDataLen = arraysize(kData1); 520 const size_t kDataLen = arraysize(kData1);
519 521
520 // No data written. 522 // No data written.
521 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 523 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
522 .WillOnce(Return(QuicConsumedData(0, false))); 524 .WillOnce(Return(QuicConsumedData(0, false)));
523 TestCompletionCallback callback; 525 TestCompletionCallback callback;
524 EXPECT_EQ(ERR_IO_PENDING, 526 EXPECT_EQ(ERR_IO_PENDING,
525 stream_->WriteStreamData(base::StringPiece(kData1, kDataLen), true, 527 stream_->WriteStreamData(QuicStringPiece(kData1, kDataLen), true,
526 callback.callback())); 528 callback.callback()));
527 ASSERT_FALSE(callback.have_result()); 529 ASSERT_FALSE(callback.have_result());
528 530
529 // All data written. 531 // All data written.
530 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _)) 532 EXPECT_CALL(session_, WritevData(stream_, stream_->id(), _, _, _, _))
531 .WillOnce(Return(QuicConsumedData(kDataLen, true))); 533 .WillOnce(Return(QuicConsumedData(kDataLen, true)));
532 stream_->OnCanWrite(); 534 stream_->OnCanWrite();
533 ASSERT_TRUE(callback.have_result()); 535 ASSERT_TRUE(callback.have_result());
534 EXPECT_THAT(callback.WaitForResult(), IsOk()); 536 EXPECT_THAT(callback.WaitForResult(), IsOk());
535 } 537 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 stream->SetDelegate(&delegate_); 593 stream->SetDelegate(&delegate_);
592 ProcessHeadersFull(headers_); 594 ProcessHeadersFull(headers_);
593 595
594 // Times(2) because OnClose will be called for stream and stream_. 596 // Times(2) because OnClose will be called for stream and stream_.
595 EXPECT_CALL(delegate_, OnClose()).Times(2); 597 EXPECT_CALL(delegate_, OnClose()).Times(2);
596 } 598 }
597 599
598 } // namespace 600 } // namespace
599 } // namespace test 601 } // namespace test
600 } // namespace net 602 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/chromium/quic_chromium_client_stream.cc ('k') | net/quic/chromium/quic_connection_logger.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698