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

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

Issue 2053133002: Remove MessageLoop::current()->RunUntilIdle() in net. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/quic_http_stream.h" 5 #include "net/quic/quic_http_stream.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/run_loop.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
14 #include "net/base/chunked_upload_data_stream.h" 15 #include "net/base/chunked_upload_data_stream.h"
15 #include "net/base/elements_upload_data_stream.h" 16 #include "net/base/elements_upload_data_stream.h"
16 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h" 18 #include "net/base/test_completion_callback.h"
18 #include "net/base/test_data_directory.h" 19 #include "net/base/test_data_directory.h"
19 #include "net/base/upload_bytes_element_reader.h" 20 #include "net/base/upload_bytes_element_reader.h"
20 #include "net/http/http_response_headers.h" 21 #include "net/http/http_response_headers.h"
21 #include "net/http/transport_security_state.h" 22 #include "net/http/transport_security_state.h"
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 ProcessPacket( 623 ProcessPacket(
623 ConstructServerDataPacket(3, false, !kFin, /*offset=*/0, kResponseBody)); 624 ConstructServerDataPacket(3, false, !kFin, /*offset=*/0, kResponseBody));
624 SpdyHeaderBlock trailers; 625 SpdyHeaderBlock trailers;
625 size_t spdy_trailers_frame_length; 626 size_t spdy_trailers_frame_length;
626 trailers["foo"] = "bar"; 627 trailers["foo"] = "bar";
627 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody)); 628 trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody));
628 ProcessPacket(ConstructResponseTrailersPacket( 629 ProcessPacket(ConstructResponseTrailersPacket(
629 4, kFin, trailers, &spdy_trailers_frame_length, &offset)); 630 4, kFin, trailers, &spdy_trailers_frame_length, &offset));
630 631
631 // Make sure trailers are processed. 632 // Make sure trailers are processed.
632 base::MessageLoop::current()->RunUntilIdle(); 633 base::RunLoop().RunUntilIdle();
633 634
634 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), 635 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)),
635 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), 636 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
636 callback_.callback())); 637 callback_.callback()));
637 EXPECT_TRUE(stream_->IsResponseBodyComplete()); 638 EXPECT_TRUE(stream_->IsResponseBodyComplete());
638 639
639 EXPECT_EQ(OK, 640 EXPECT_EQ(OK,
640 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), 641 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
641 callback_.callback())); 642 callback_.callback()));
642 643
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 1149
1149 // Ack the request. 1150 // Ack the request.
1150 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); 1151 ProcessPacket(ConstructServerAckPacket(1, 0, 0));
1151 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback())); 1152 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
1152 1153
1153 // Send the response with a body. 1154 // Send the response with a body.
1154 SetResponse("404 OK", "hello world!"); 1155 SetResponse("404 OK", "hello world!");
1155 // In the course of processing this packet, the QuicHttpStream close itself. 1156 // In the course of processing this packet, the QuicHttpStream close itself.
1156 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); 1157 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr));
1157 1158
1158 base::MessageLoop::current()->RunUntilIdle(); 1159 base::RunLoop().RunUntilIdle();
1159 1160
1160 EXPECT_TRUE(AtEof()); 1161 EXPECT_TRUE(AtEof());
1161 1162
1162 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1163 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1163 // headers and payload. 1164 // headers and payload.
1164 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1165 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1165 stream_->GetTotalSentBytes()); 1166 stream_->GetTotalSentBytes());
1166 // Zero since the stream is closed before processing the headers. 1167 // Zero since the stream is closed before processing the headers.
1167 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1168 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
1168 } 1169 }
(...skipping 28 matching lines...) Expand all
1197 1198
1198 // Ack the request. 1199 // Ack the request.
1199 ProcessPacket(ConstructServerAckPacket(1, 0, 0)); 1200 ProcessPacket(ConstructServerAckPacket(1, 0, 0));
1200 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback())); 1201 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
1201 1202
1202 // Send the response with a body. 1203 // Send the response with a body.
1203 SetResponse("404 OK", "hello world!"); 1204 SetResponse("404 OK", "hello world!");
1204 // In the course of processing this packet, the QuicHttpStream close itself. 1205 // In the course of processing this packet, the QuicHttpStream close itself.
1205 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); 1206 ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr));
1206 1207
1207 base::MessageLoop::current()->RunUntilIdle(); 1208 base::RunLoop().RunUntilIdle();
1208 1209
1209 EXPECT_TRUE(AtEof()); 1210 EXPECT_TRUE(AtEof());
1210 1211
1211 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1212 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1212 // headers and payload. 1213 // headers and payload.
1213 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), 1214 EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length),
1214 stream_->GetTotalSentBytes()); 1215 stream_->GetTotalSentBytes());
1215 // Zero since the stream is closed before processing the headers. 1216 // Zero since the stream is closed before processing the headers.
1216 EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); 1217 EXPECT_EQ(0, stream_->GetTotalReceivedBytes());
1217 } 1218 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 response_headers_ = promised_response_; 1394 response_headers_ = promised_response_;
1394 size_t spdy_response_headers_frame_length; 1395 size_t spdy_response_headers_frame_length;
1395 ProcessPacket(InnerConstructResponseHeadersPacket( 1396 ProcessPacket(InnerConstructResponseHeadersPacket(
1396 1, promise_id_, false, &spdy_response_headers_frame_length)); 1397 1, promise_id_, false, &spdy_response_headers_frame_length));
1397 1398
1398 // Receive the promised response body. 1399 // Receive the promised response body.
1399 const char kResponseBody[] = "Hello world!"; 1400 const char kResponseBody[] = "Hello world!";
1400 ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0, 1401 ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0,
1401 kResponseBody, &server_maker_)); 1402 kResponseBody, &server_maker_));
1402 1403
1403 base::MessageLoop::current()->RunUntilIdle(); 1404 base::RunLoop().RunUntilIdle();
1404 1405
1405 // Rendezvous should have succeeded now, so the promised stream 1406 // Rendezvous should have succeeded now, so the promised stream
1406 // should point at our push stream, and we should be able read 1407 // should point at our push stream, and we should be able read
1407 // headers and data from it. 1408 // headers and data from it.
1408 EXPECT_EQ(OK, callback_.WaitForResult()); 1409 EXPECT_EQ(OK, callback_.WaitForResult());
1409 1410
1410 EXPECT_EQ( 1411 EXPECT_EQ(
1411 QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) 1412 QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get())
1412 ->id(), 1413 ->id(),
1413 promise_id_); 1414 promise_id_);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 response_headers_ = promised_response_; 1569 response_headers_ = promised_response_;
1569 size_t spdy_response_headers_frame_length; 1570 size_t spdy_response_headers_frame_length;
1570 ProcessPacket(InnerConstructResponseHeadersPacket( 1571 ProcessPacket(InnerConstructResponseHeadersPacket(
1571 1, promise_id_, false, &spdy_response_headers_frame_length)); 1572 1, promise_id_, false, &spdy_response_headers_frame_length));
1572 1573
1573 // Receive the promised response body. 1574 // Receive the promised response body.
1574 const char kResponseBody[] = "Hello world!"; 1575 const char kResponseBody[] = "Hello world!";
1575 ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0, 1576 ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0,
1576 kResponseBody, &server_maker_)); 1577 kResponseBody, &server_maker_));
1577 1578
1578 base::MessageLoop::current()->RunUntilIdle(); 1579 base::RunLoop().RunUntilIdle();
1579 1580
1580 // Rendezvous should have succeeded now, so the promised stream 1581 // Rendezvous should have succeeded now, so the promised stream
1581 // should point at our push stream, and we should be able read 1582 // should point at our push stream, and we should be able read
1582 // headers and data from it. 1583 // headers and data from it.
1583 EXPECT_EQ(OK, callback_.WaitForResult()); 1584 EXPECT_EQ(OK, callback_.WaitForResult());
1584 1585
1585 EXPECT_EQ( 1586 EXPECT_EQ(
1586 QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) 1587 QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get())
1587 ->id(), 1588 ->id(),
1588 promise_id_); 1589 promise_id_);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 EXPECT_EQ(ERR_IO_PENDING, promised_stream_->SendRequest( 1654 EXPECT_EQ(ERR_IO_PENDING, promised_stream_->SendRequest(
1654 headers_, &response_, callback_.callback())); 1655 headers_, &response_, callback_.callback()));
1655 1656
1656 // Receive the promised response headers. 1657 // Receive the promised response headers.
1657 promised_response_["vary"] = "accept-encoding"; 1658 promised_response_["vary"] = "accept-encoding";
1658 response_headers_ = promised_response_; 1659 response_headers_ = promised_response_;
1659 size_t spdy_response_headers_frame_length; 1660 size_t spdy_response_headers_frame_length;
1660 ProcessPacket(InnerConstructResponseHeadersPacket( 1661 ProcessPacket(InnerConstructResponseHeadersPacket(
1661 1, promise_id_, false, &spdy_response_headers_frame_length)); 1662 1, promise_id_, false, &spdy_response_headers_frame_length));
1662 1663
1663 base::MessageLoop::current()->RunUntilIdle(); 1664 base::RunLoop().RunUntilIdle();
1664 1665
1665 // Rendezvous should have failed due to vary mismatch, so the 1666 // Rendezvous should have failed due to vary mismatch, so the
1666 // promised stream should have been aborted, and instead we have a 1667 // promised stream should have been aborted, and instead we have a
1667 // new, regular client initiated stream. 1668 // new, regular client initiated stream.
1668 EXPECT_EQ(OK, callback_.WaitForResult()); 1669 EXPECT_EQ(OK, callback_.WaitForResult());
1669 1670
1670 // Not a server-initiated stream. 1671 // Not a server-initiated stream.
1671 EXPECT_NE( 1672 EXPECT_NE(
1672 QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) 1673 QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get())
1673 ->id(), 1674 ->id(),
(...skipping 12 matching lines...) Expand all
1686 // client-initiated version of |promised_stream_| works as intended. 1687 // client-initiated version of |promised_stream_| works as intended.
1687 1688
1688 // Ack the request. 1689 // Ack the request.
1689 ProcessPacket(ConstructServerAckPacket(2, 0, 0)); 1690 ProcessPacket(ConstructServerAckPacket(2, 0, 0));
1690 1691
1691 SetResponse("404 Not Found", string()); 1692 SetResponse("404 Not Found", string());
1692 size_t spdy_response_header_frame_length; 1693 size_t spdy_response_header_frame_length;
1693 ProcessPacket(InnerConstructResponseHeadersPacket( 1694 ProcessPacket(InnerConstructResponseHeadersPacket(
1694 3, stream_id_ + 2, kFin, &spdy_response_header_frame_length)); 1695 3, stream_id_ + 2, kFin, &spdy_response_header_frame_length));
1695 1696
1696 base::MessageLoop::current()->RunUntilIdle(); 1697 base::RunLoop().RunUntilIdle();
1697 1698
1698 EXPECT_EQ(OK, promised_stream_->ReadResponseHeaders(callback_.callback())); 1699 EXPECT_EQ(OK, promised_stream_->ReadResponseHeaders(callback_.callback()));
1699 ASSERT_TRUE(response_.headers.get()); 1700 ASSERT_TRUE(response_.headers.get());
1700 EXPECT_EQ(404, response_.headers->response_code()); 1701 EXPECT_EQ(404, response_.headers->response_code());
1701 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); 1702 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
1702 EXPECT_FALSE(response_.response_time.is_null()); 1703 EXPECT_FALSE(response_.response_time.is_null());
1703 EXPECT_FALSE(response_.request_time.is_null()); 1704 EXPECT_FALSE(response_.request_time.is_null());
1704 1705
1705 // There is no body, so this should return immediately. 1706 // There is no body, so this should return immediately.
1706 EXPECT_EQ( 1707 EXPECT_EQ(
1707 0, promised_stream_->ReadResponseBody( 1708 0, promised_stream_->ReadResponseBody(
1708 read_buffer_.get(), read_buffer_->size(), callback_.callback())); 1709 read_buffer_.get(), read_buffer_->size(), callback_.callback()));
1709 EXPECT_TRUE(promised_stream_->IsResponseBodyComplete()); 1710 EXPECT_TRUE(promised_stream_->IsResponseBodyComplete());
1710 1711
1711 stream_->Close(true); 1712 stream_->Close(true);
1712 1713
1713 EXPECT_TRUE(AtEof()); 1714 EXPECT_TRUE(AtEof());
1714 1715
1715 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the 1716 // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the
1716 // headers and payload. 1717 // headers and payload.
1717 EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), 1718 EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length),
1718 promised_stream_->GetTotalSentBytes()); 1719 promised_stream_->GetTotalSentBytes());
1719 EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), 1720 EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length),
1720 promised_stream_->GetTotalReceivedBytes()); 1721 promised_stream_->GetTotalReceivedBytes());
1721 } 1722 }
1722 1723
1723 } // namespace test 1724 } // namespace test
1724 } // namespace net 1725 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_chromium_client_stream_test.cc ('k') | net/quic/quic_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698