diff options
author | tyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-14 09:54:52 +0000 |
---|---|---|
committer | tyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-14 09:54:52 +0000 |
commit | 53b61907ff94a60204045cdaf1d11a1e6e098f5b (patch) | |
tree | 67a3a47105efa82aca8a480308725f6f6770bbf0 /content/browser/streams | |
parent | 5c63f13e6b1e7ca5b0c53ba673e0ac75e23faab4 (diff) | |
download | chromium_src-53b61907ff94a60204045cdaf1d11a1e6e098f5b.zip chromium_src-53b61907ff94a60204045cdaf1d11a1e6e098f5b.tar.gz chromium_src-53b61907ff94a60204045cdaf1d11a1e6e098f5b.tar.bz2 |
Test that Stream::ReadRawData doesn't return STREAM_EMPTY once Finalized.
Check that once Stream::Finalize() is called and reader_ receives that,
reader_.ReadRawData() never returns STREAM_EMPTY.
Also removed unnecessary reader.Read() call.
BUG=272640
Review URL: https://chromiumcodereview.appspot.com/23007003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217514 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/streams')
-rw-r--r-- | content/browser/streams/stream_unittest.cc | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/content/browser/streams/stream_unittest.cc b/content/browser/streams/stream_unittest.cc index 36add1d..c0077b7 100644 --- a/content/browser/streams/stream_unittest.cc +++ b/content/browser/streams/stream_unittest.cc @@ -41,7 +41,7 @@ class StreamTest : public testing::Test { class TestStreamReader : public StreamReadObserver { public: - TestStreamReader() : buffer_(new net::GrowableIOBuffer()) { + TestStreamReader() : buffer_(new net::GrowableIOBuffer()), completed_(false) { } virtual ~TestStreamReader() {} @@ -50,8 +50,22 @@ class TestStreamReader : public StreamReadObserver { scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize)); int bytes_read = 0; - while (stream->ReadRawData(buffer.get(), kBufferSize, &bytes_read) == - Stream::STREAM_HAS_DATA) { + while (true) { + Stream::StreamState state = + stream->ReadRawData(buffer.get(), kBufferSize, &bytes_read); + switch (state) { + case Stream::STREAM_HAS_DATA: + // TODO(tyoshino): Move these expectations to the beginning of Read() + // method once Stream::Finalize() is fixed. + EXPECT_FALSE(completed_); + break; + case Stream::STREAM_COMPLETE: + completed_ = true; + return; + case Stream::STREAM_EMPTY: + EXPECT_FALSE(completed_); + return; + } size_t old_capacity = buffer_->capacity(); buffer_->SetCapacity(old_capacity + bytes_read); memcpy(buffer_->StartOfBuffer() + old_capacity, @@ -65,8 +79,13 @@ class TestStreamReader : public StreamReadObserver { scoped_refptr<net::GrowableIOBuffer> buffer() { return buffer_; } + bool completed() const { + return completed_; + } + private: scoped_refptr<net::GrowableIOBuffer> buffer_; + bool completed_; }; class TestStreamWriter : public StreamWriteObserver { @@ -137,14 +156,38 @@ TEST_F(StreamTest, Stream) { scoped_refptr<net::IOBuffer> buffer(NewIOBuffer(kBufferSize)); writer.Write(stream.get(), buffer, kBufferSize); stream->Finalize(); - reader.Read(stream.get()); base::MessageLoop::current()->RunUntilIdle(); + EXPECT_TRUE(reader.completed()); ASSERT_EQ(reader.buffer()->capacity(), kBufferSize); for (int i = 0; i < kBufferSize; i++) EXPECT_EQ(buffer->data()[i], reader.buffer()->data()[i]); } +// Test that even if a reader receives an empty buffer, once TransferData() +// method is called on it with |source_complete| = true, following Read() calls +// on it never returns STREAM_EMPTY. Together with StreamTest.Stream above, this +// guarantees that Reader::Read() call returns only STREAM_HAS_DATA +// or STREAM_COMPLETE in |data_available_callback_| call corresponding to +// Writer::Close(). +TEST_F(StreamTest, ClosedReaderDoesNotReturnStreamEmpty) { + TestStreamReader reader; + TestStreamWriter writer; + + GURL url("blob://stream"); + scoped_refptr<Stream> stream( + new Stream(registry_.get(), &writer, url)); + EXPECT_TRUE(stream->SetReadObserver(&reader)); + + const int kBufferSize = 0; + scoped_refptr<net::IOBuffer> buffer(NewIOBuffer(kBufferSize)); + stream->AddData(buffer, kBufferSize); + stream->Finalize(); + base::MessageLoop::current()->RunUntilIdle(); + EXPECT_TRUE(reader.completed()); + EXPECT_EQ(0, reader.buffer()->capacity()); +} + TEST_F(StreamTest, GetStream) { TestStreamWriter writer; |