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

Unified Diff: net/base/file_stream_unittest.cc

Issue 12320003: Fix net::FileStream to handle POSIX errors correctly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
Index: net/base/file_stream_unittest.cc
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index 17579188d026c841dc0ed4400e3b876c12169945..1f79747fb5ebf97b2f648761d85e6619df21f423 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -1031,6 +1031,44 @@ TEST_F(FileStreamTest, AsyncOpenAndDelete) {
EXPECT_FALSE(open_callback.have_result());
}
+// Verify that async Write() errors are mapped correctly.
+TEST_F(FileStreamTest, AsyncWriteError) {
+ scoped_ptr<FileStream> stream(new FileStream(NULL));
+ int flags = base::PLATFORM_FILE_CREATE_ALWAYS |
+ base::PLATFORM_FILE_WRITE |
+ base::PLATFORM_FILE_ASYNC;
+ int rv = stream->OpenSync(temp_file_path(), flags);
+ EXPECT_EQ(OK, rv);
+
+ TestCompletionCallback callback;
+
+ // Try passing NULL buffer to Write() and check that it fails.
+ scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL);
+ rv = stream->Write(buf, 1, callback.callback());
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_LT(rv, 0);
+}
+
+// Verify that async Read() errors are mapped correctly.
+TEST_F(FileStreamTest, AsyncReadError) {
+ scoped_ptr<FileStream> stream(new FileStream(NULL));
+ int flags = base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_ASYNC;
+ int rv = stream->OpenSync(temp_file_path(), flags);
+ EXPECT_EQ(OK, rv);
+
+ TestCompletionCallback callback;
+
+ // Try passing NULL buffer to Read() and check that it fails.
+ scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL);
+ rv = stream->Read(buf, 1, callback.callback());
+ if (rv == ERR_IO_PENDING)
+ rv = callback.WaitForResult();
+ EXPECT_LT(rv, 0);
+}
+
} // namespace
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698