diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-25 18:52:53 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-25 18:52:53 +0000 |
commit | 8bf0c566acc6bb42b59daab2b814cb27ae9c4235 (patch) | |
tree | 05fd9d0cfe11949638e32202a086e04a033916e4 /net/base/file_stream_unittest.cc | |
parent | 4c0e28bc0012fef534b6f83003df98df21a3a666 (diff) | |
download | chromium_src-8bf0c566acc6bb42b59daab2b814cb27ae9c4235.zip chromium_src-8bf0c566acc6bb42b59daab2b814cb27ae9c4235.tar.gz chromium_src-8bf0c566acc6bb42b59daab2b814cb27ae9c4235.tar.bz2 |
Fix net::FileStream to handle all errors correctly.
This CL adds FileStream::Context::IOResult struct that's used to pass
results of IO operations inside FileStream::Context. Following bugs are
fixes:
1. On POSIX net::FileStream::Read() and net::FileStream::Write() would
return a positive result in case of an error. This happens because
POSIX errors are positive integers and FileStream was written with
assumption that they are negative.
2. On Windows Seek() and Flush() errors were not handled correctly.
This is because CheckForIOError() was assuming that all error codes
are negative, but RecordAndMapError() was mapping positive errors.
3. On Windows results of asynchronous ReadFile() and WriteFile() were
not handled correctly - ERR_IO_PENDING would be returned even when
operation completes synchronously.
4. On Windows OVERLAPPED struct wasn't set to zeros as necessary.
Also added unittests to check that error codes are handled correctly
now.
Review URL: https://codereview.chromium.org/12321100
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@184453 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/file_stream_unittest.cc')
-rw-r--r-- | net/base/file_stream_unittest.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc index 1757918..1f79747 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 |