summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-22 03:34:54 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-22 03:34:54 +0000
commit06b802b3122ce2a9cca32121001ee0e6b09824dc (patch)
tree06a896a06b97b051237aaff7711db32ee94dc68c
parent58e10450ae1f2afc686fc3b1f0d59e95c0eb3736 (diff)
downloadchromium_src-06b802b3122ce2a9cca32121001ee0e6b09824dc.zip
chromium_src-06b802b3122ce2a9cca32121001ee0e6b09824dc.tar.gz
chromium_src-06b802b3122ce2a9cca32121001ee0e6b09824dc.tar.bz2
net: Add a "async read and delete" test to FleStream.
This is to ensure that FileStream deletion is safe while an async operation is in flight. BUG=115067 TEST=net_unittests Review URL: http://codereview.chromium.org/9372064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@122954 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/file_stream_unittest.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index 91eb075..274d267 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -291,6 +291,38 @@ TEST_F(FileStreamTest, AsyncRead_EarlyClose) {
}
}
+// Similar to AsyncRead_EarlyClose but deletes a stream instead, to ensure
+// that deleting a stream is safe while an async read is in flight.
+TEST_F(FileStreamTest, AsyncRead_EarlyDelete) {
+ int64 file_size;
+ bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
+ EXPECT_TRUE(ok);
+
+ scoped_ptr<FileStream> stream(new FileStream(NULL));
+ int flags = base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_ASYNC;
+ TestCompletionCallback callback;
+ int rv = stream->Open(temp_file_path(), flags, callback.callback());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+
+ int64 total_bytes_avail = stream->Available();
+ EXPECT_EQ(file_size, total_bytes_avail);
+
+ scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
+ rv = stream->Read(buf, buf->size(), callback.callback());
+ stream.reset(); // Delete instead of closing it.
+ if (rv < 0) {
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ // The callback should not be called if the request is cancelled.
+ MessageLoop::current()->RunAllPending();
+ EXPECT_FALSE(callback.have_result());
+ } else {
+ EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv));
+ }
+}
+
TEST_F(FileStreamTest, BasicRead_FromOffset) {
int64 file_size;
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);