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

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

Issue 1776423004: Only MarkTrailersConsumed when actually sending trailers notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add internal changes and fix tests Created 4 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
« no previous file with comments | « net/quic/quic_chromium_client_stream.cc ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/quic_chromium_client_stream.h" 5 #include "net/quic/quic_chromium_client_stream.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h"
8 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
9 #include "net/base/test_completion_callback.h" 11 #include "net/base/test_completion_callback.h"
10 #include "net/quic/quic_chromium_client_session.h" 12 #include "net/quic/quic_chromium_client_session.h"
11 #include "net/quic/quic_client_session_base.h" 13 #include "net/quic/quic_client_session_base.h"
12 #include "net/quic/quic_utils.h" 14 #include "net/quic/quic_utils.h"
13 #include "net/quic/spdy_utils.h" 15 #include "net/quic/spdy_utils.h"
14 #include "net/quic/test_tools/crypto_test_utils.h" 16 #include "net/quic/test_tools/crypto_test_utils.h"
15 #include "net/quic/test_tools/quic_test_utils.h" 17 #include "net/quic/test_tools/quic_test_utils.h"
16 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gmock_mutant.h" 19 #include "testing/gmock_mutant.h"
(...skipping 10 matching lines...) Expand all
28 namespace { 30 namespace {
29 31
30 const QuicStreamId kTestStreamId = 5u; 32 const QuicStreamId kTestStreamId = 5u;
31 33
32 class MockDelegate : public QuicChromiumClientStream::Delegate { 34 class MockDelegate : public QuicChromiumClientStream::Delegate {
33 public: 35 public:
34 MockDelegate() {} 36 MockDelegate() {}
35 37
36 MOCK_METHOD0(OnSendData, int()); 38 MOCK_METHOD0(OnSendData, int());
37 MOCK_METHOD2(OnSendDataComplete, int(int, bool*)); 39 MOCK_METHOD2(OnSendDataComplete, int(int, bool*));
38 MOCK_METHOD2(OnHeadersAvailable, void(const SpdyHeaderBlock&, size_t)); 40 MOCK_METHOD2(OnHeadersAvailable,
41 void(const SpdyHeaderBlock& headers, size_t frame_len));
39 MOCK_METHOD2(OnDataReceived, int(const char*, int)); 42 MOCK_METHOD2(OnDataReceived, int(const char*, int));
40 MOCK_METHOD0(OnDataAvailable, void()); 43 MOCK_METHOD0(OnDataAvailable, void());
41 MOCK_METHOD1(OnClose, void(QuicErrorCode)); 44 MOCK_METHOD1(OnClose, void(QuicErrorCode));
42 MOCK_METHOD1(OnError, void(int)); 45 MOCK_METHOD1(OnError, void(int));
43 MOCK_METHOD0(HasSendHeadersComplete, bool()); 46 MOCK_METHOD0(HasSendHeadersComplete, bool());
44 47
45 private: 48 private:
46 DISALLOW_COPY_AND_ASSIGN(MockDelegate); 49 DISALLOW_COPY_AND_ASSIGN(MockDelegate);
47 }; 50 };
48 51
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false, 311 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
309 /*offset=*/0, data)); 312 /*offset=*/0, data));
310 313
311 EXPECT_CALL(delegate_, OnDataAvailable()) 314 EXPECT_CALL(delegate_, OnDataAvailable())
312 .WillOnce(testing::Invoke(CreateFunctor( 315 .WillOnce(testing::Invoke(CreateFunctor(
313 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this), 316 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this),
314 StringPiece(data, arraysize(data) - 1)))); 317 StringPiece(data, arraysize(data) - 1))));
315 318
316 SpdyHeaderBlock trailers; 319 SpdyHeaderBlock trailers;
317 trailers["bar"] = "foo"; 320 trailers["bar"] = "foo";
321 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data));
318 std::string uncompressed_trailers = 322 std::string uncompressed_trailers =
319 SpdyUtils::SerializeUncompressedHeaders(trailers); 323 SpdyUtils::SerializeUncompressedHeaders(trailers);
320 324
321 stream_->OnStreamHeaders(uncompressed_trailers); 325 stream_->OnStreamHeaders(uncompressed_trailers);
322 stream_->OnStreamHeadersComplete(true, uncompressed_trailers.length()); 326 stream_->OnStreamHeadersComplete(true, uncompressed_trailers.length());
323 327
328 SpdyHeaderBlock actual_trailers;
329
330 base::RunLoop run_loop;
331 EXPECT_CALL(delegate_, OnHeadersAvailable(_, uncompressed_trailers.length()))
332 .WillOnce(testing::DoAll(
333 testing::SaveArg<0>(&actual_trailers),
334 testing::InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })));
335
336 run_loop.Run();
337 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
338 trailers.erase(kFinalOffsetHeaderKey);
339 EXPECT_EQ(trailers, actual_trailers);
340 base::MessageLoop::current()->RunUntilIdle();
341 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
342 }
343
344 // Tests that trailers are marked as consumed only before delegate is to be
345 // immediately notified about trailers.
346 TEST_P(QuicChromiumClientStreamTest, MarkTrailersConsumedWhenNotifyDelegate) {
347 InitializeHeaders();
348 std::string uncompressed_headers =
349 SpdyUtils::SerializeUncompressedHeaders(headers_);
350 stream_->OnStreamHeaders(uncompressed_headers);
351 stream_->OnStreamHeadersComplete(false, uncompressed_headers.length());
352
324 EXPECT_CALL(delegate_, 353 EXPECT_CALL(delegate_,
325 OnHeadersAvailable(trailers, uncompressed_trailers.length())); 354 OnHeadersAvailable(headers_, uncompressed_headers.length()));
355 base::MessageLoop::current()->RunUntilIdle();
356 EXPECT_TRUE(stream_->decompressed_headers().empty());
357
358 const char data[] = "hello world!";
359 stream_->OnStreamFrame(QuicStreamFrame(kTestStreamId, /*fin=*/false,
360 /*offset=*/0, data));
361
362 base::RunLoop run_loop;
363 EXPECT_CALL(delegate_, OnDataAvailable())
364 .Times(1)
365 .WillOnce(testing::DoAll(
366 testing::Invoke(CreateFunctor(
367 &QuicChromiumClientStreamTest::ReadData, base::Unretained(this),
368 StringPiece(data, arraysize(data) - 1))),
369 testing::Invoke([&run_loop]() { run_loop.Quit(); })));
370
371 // Wait for the read to complete.
372 run_loop.Run();
373
374 // Read again, and it will be pending.
375 scoped_refptr<IOBuffer> buffer(new IOBuffer(1));
376 EXPECT_EQ(ERR_IO_PENDING, stream_->Read(buffer.get(), 1));
377
378 SpdyHeaderBlock trailers;
379 trailers["bar"] = "foo";
380 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(data));
381 std::string uncompressed_trailers =
382 SpdyUtils::SerializeUncompressedHeaders(trailers);
383
384 stream_->OnStreamHeaders(uncompressed_trailers);
385 stream_->OnStreamHeadersComplete(true, uncompressed_trailers.length());
386 EXPECT_FALSE(stream_->IsDoneReading());
387
388 // Now the pending should complete. Make sure that IsDoneReading() is false
389 // even though ReadData returns 0 byte, because OnHeadersAvailable callback
390 // comes after this OnDataAvailable callback.
391 base::RunLoop run_loop2;
392 EXPECT_CALL(delegate_, OnDataAvailable())
393 .Times(1)
394 .WillOnce(testing::DoAll(
395 testing::Invoke(CreateFunctor(&QuicChromiumClientStreamTest::ReadData,
396 base::Unretained(this), StringPiece())),
397 testing::InvokeWithoutArgs([&run_loop2]() { run_loop2.Quit(); })));
398 run_loop2.Run();
399 // Make sure that the stream is not closed, even though ReadData returns 0.
400 EXPECT_FALSE(stream_->IsDoneReading());
401
402 // The OnHeadersAvailable call should follow.
403 base::RunLoop run_loop3;
404 SpdyHeaderBlock actual_trailers;
405 EXPECT_CALL(delegate_,
406 OnHeadersAvailable(trailers, uncompressed_trailers.length()))
407 .WillOnce(testing::DoAll(
408 testing::SaveArg<0>(&actual_trailers),
409 testing::InvokeWithoutArgs([&run_loop3]() { run_loop3.Quit(); })));
410
411 run_loop3.Run();
412 // Make sure the stream is properly closed since trailers and data are all
413 // consumed.
414 EXPECT_TRUE(stream_->IsDoneReading());
415 // Make sure kFinalOffsetHeaderKey is gone from the delivered actual trailers.
416 trailers.erase(kFinalOffsetHeaderKey);
417 EXPECT_EQ(trailers, actual_trailers);
326 418
327 base::MessageLoop::current()->RunUntilIdle(); 419 base::MessageLoop::current()->RunUntilIdle();
328 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 420 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
329 } 421 }
330 422
331 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) { 423 TEST_P(QuicChromiumClientStreamTest, WriteStreamData) {
332 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)); 424 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR));
333 425
334 const char kData1[] = "hello world"; 426 const char kData1[] = "hello world";
335 const size_t kDataLen = arraysize(kData1); 427 const size_t kDataLen = arraysize(kData1);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 stream->SetDelegate(&delegate_); 477 stream->SetDelegate(&delegate_);
386 base::MessageLoop::current()->RunUntilIdle(); 478 base::MessageLoop::current()->RunUntilIdle();
387 479
388 // Times(2) because OnClose will be called for stream and stream_. 480 // Times(2) because OnClose will be called for stream and stream_.
389 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2); 481 EXPECT_CALL(delegate_, OnClose(QUIC_NO_ERROR)).Times(2);
390 } 482 }
391 483
392 } // namespace 484 } // namespace
393 } // namespace test 485 } // namespace test
394 } // namespace net 486 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_chromium_client_stream.cc ('k') | net/quic/quic_http_stream_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698