OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/file_stream.h" | 5 #include "net/base/file_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1024 EXPECT_EQ(ERR_IO_PENDING, rv); | 1024 EXPECT_EQ(ERR_IO_PENDING, rv); |
1025 | 1025 |
1026 // Delete the stream without waiting for the open operation to be | 1026 // Delete the stream without waiting for the open operation to be |
1027 // complete. Should be safe. | 1027 // complete. Should be safe. |
1028 stream.reset(); | 1028 stream.reset(); |
1029 // open_callback won't be called. | 1029 // open_callback won't be called. |
1030 MessageLoop::current()->RunUntilIdle(); | 1030 MessageLoop::current()->RunUntilIdle(); |
1031 EXPECT_FALSE(open_callback.have_result()); | 1031 EXPECT_FALSE(open_callback.have_result()); |
1032 } | 1032 } |
1033 | 1033 |
| 1034 // Verify that async Write() errors are mapped correctly. |
| 1035 TEST_F(FileStreamTest, AsyncWriteError) { |
| 1036 scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| 1037 int flags = base::PLATFORM_FILE_CREATE_ALWAYS | |
| 1038 base::PLATFORM_FILE_WRITE | |
| 1039 base::PLATFORM_FILE_ASYNC; |
| 1040 int rv = stream->OpenSync(temp_file_path(), flags); |
| 1041 EXPECT_EQ(OK, rv); |
| 1042 |
| 1043 TestCompletionCallback callback; |
| 1044 |
| 1045 // Try passing NULL buffer to Write() and check that it fails. |
| 1046 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL); |
| 1047 rv = stream->Write(buf, 1, callback.callback()); |
| 1048 if (rv == ERR_IO_PENDING) |
| 1049 rv = callback.WaitForResult(); |
| 1050 EXPECT_LT(rv, 0); |
| 1051 } |
| 1052 |
| 1053 // Verify that async Read() errors are mapped correctly. |
| 1054 TEST_F(FileStreamTest, AsyncReadError) { |
| 1055 scoped_ptr<FileStream> stream(new FileStream(NULL)); |
| 1056 int flags = base::PLATFORM_FILE_OPEN | |
| 1057 base::PLATFORM_FILE_READ | |
| 1058 base::PLATFORM_FILE_ASYNC; |
| 1059 int rv = stream->OpenSync(temp_file_path(), flags); |
| 1060 EXPECT_EQ(OK, rv); |
| 1061 |
| 1062 TestCompletionCallback callback; |
| 1063 |
| 1064 // Try passing NULL buffer to Read() and check that it fails. |
| 1065 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL); |
| 1066 rv = stream->Read(buf, 1, callback.callback()); |
| 1067 if (rv == ERR_IO_PENDING) |
| 1068 rv = callback.WaitForResult(); |
| 1069 EXPECT_LT(rv, 0); |
| 1070 } |
| 1071 |
1034 } // namespace | 1072 } // namespace |
1035 | 1073 |
1036 } // namespace net | 1074 } // namespace net |
OLD | NEW |