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

Unified Diff: net/http/http_response_body_drainer_unittest.cc

Issue 11112021: Treat 0 returned from HttpStream::ReadResponseBody correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_response_body_drainer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_body_drainer_unittest.cc
diff --git a/net/http/http_response_body_drainer_unittest.cc b/net/http/http_response_body_drainer_unittest.cc
index d9b6492a5378ad55986d89375c2a53894e441bc9..23356abc030eec8d719e4bffa5f17b9d79366d3e 100644
--- a/net/http/http_response_body_drainer_unittest.cc
+++ b/net/http/http_response_body_drainer_unittest.cc
@@ -69,6 +69,7 @@ class MockHttpStream : public HttpStream {
closed_(false),
stall_reads_forever_(false),
num_chunks_(0),
+ delay_eof_chunk_(false),
is_complete_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
virtual ~MockHttpStream() {}
@@ -130,6 +131,8 @@ class MockHttpStream : public HttpStream {
void set_num_chunks(int num_chunks) { num_chunks_ = num_chunks; }
+ void DelayEofChunk() { delay_eof_chunk_ = true; }
mmenke 2012/10/12 18:55:05 Think the logic would be a little simpler if you m
+
private:
void CompleteRead();
@@ -141,6 +144,7 @@ class MockHttpStream : public HttpStream {
bool closed_;
bool stall_reads_forever_;
int num_chunks_;
+ bool delay_eof_chunk_;
bool is_complete_;
base::WeakPtrFactory<MockHttpStream> weak_factory_;
};
@@ -154,10 +158,10 @@ int MockHttpStream::ReadResponseBody(
if (stall_reads_forever_)
return ERR_IO_PENDING;
- if (num_chunks_ == 0)
+ if (num_chunks_ == 0 && !delay_eof_chunk_)
return ERR_UNEXPECTED;
- if (buf_len > kMagicChunkSize && num_chunks_ > 1) {
+ if (buf_len > kMagicChunkSize && (num_chunks_ > 1 || delay_eof_chunk_)) {
user_buf_ = buf;
callback_ = callback;
MessageLoop::current()->PostTask(
@@ -178,10 +182,15 @@ void MockHttpStream::CompleteRead() {
std::memset(user_buf_->data(), 1, kMagicChunkSize);
user_buf_ = NULL;
callback_.Reset();
- num_chunks_--;
- if (!num_chunks_)
+ if (num_chunks_) {
+ num_chunks_--;
+ if (!num_chunks_ && !delay_eof_chunk_)
+ is_complete_ = true;
+ callback.Run(kMagicChunkSize);
+ } else {
is_complete_ = true;
- callback.Run(kMagicChunkSize);
+ callback.Run(0);
+ }
}
class HttpResponseBodyDrainerTest : public testing::Test {
@@ -225,6 +234,13 @@ TEST_F(HttpResponseBodyDrainerTest, DrainBodyAsyncOK) {
EXPECT_FALSE(result_waiter_.WaitForResult());
}
+TEST_F(HttpResponseBodyDrainerTest, DrainBodyAsyncDelayedOK) {
+ mock_stream_->set_num_chunks(3);
+ mock_stream_->DelayEofChunk();
+ drainer_->Start(session_);
+ EXPECT_FALSE(result_waiter_.WaitForResult());
+}
+
TEST_F(HttpResponseBodyDrainerTest, DrainBodySizeEqualsDrainBuffer) {
mock_stream_->set_num_chunks(
HttpResponseBodyDrainer::kDrainBodyBufferSize / kMagicChunkSize);
« no previous file with comments | « net/http/http_response_body_drainer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698