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 "ppapi/tests/test_file_io.h" | 5 #include "ppapi/tests/test_file_io.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 RUN_CALLBACK_TEST(TestFileIO, OpenDirectory, filter); | 177 RUN_CALLBACK_TEST(TestFileIO, OpenDirectory, filter); |
178 RUN_CALLBACK_TEST(TestFileIO, ReadWriteSetLength, filter); | 178 RUN_CALLBACK_TEST(TestFileIO, ReadWriteSetLength, filter); |
179 RUN_CALLBACK_TEST(TestFileIO, ReadToArrayWriteSetLength, filter); | 179 RUN_CALLBACK_TEST(TestFileIO, ReadToArrayWriteSetLength, filter); |
180 RUN_CALLBACK_TEST(TestFileIO, TouchQuery, filter); | 180 RUN_CALLBACK_TEST(TestFileIO, TouchQuery, filter); |
181 RUN_CALLBACK_TEST(TestFileIO, AbortCalls, filter); | 181 RUN_CALLBACK_TEST(TestFileIO, AbortCalls, filter); |
182 RUN_CALLBACK_TEST(TestFileIO, ParallelReads, filter); | 182 RUN_CALLBACK_TEST(TestFileIO, ParallelReads, filter); |
183 RUN_CALLBACK_TEST(TestFileIO, ParallelWrites, filter); | 183 RUN_CALLBACK_TEST(TestFileIO, ParallelWrites, filter); |
184 RUN_CALLBACK_TEST(TestFileIO, NotAllowMixedReadWrite, filter); | 184 RUN_CALLBACK_TEST(TestFileIO, NotAllowMixedReadWrite, filter); |
185 RUN_CALLBACK_TEST(TestFileIO, WillWriteWillSetLength, filter); | 185 RUN_CALLBACK_TEST(TestFileIO, WillWriteWillSetLength, filter); |
186 RUN_CALLBACK_TEST(TestFileIO, RequestOSFileHandle, filter); | 186 RUN_CALLBACK_TEST(TestFileIO, RequestOSFileHandle, filter); |
| 187 RUN_CALLBACK_TEST(TestFileIO, RequestOSFileHandleWithOpenExclusive, filter); |
187 RUN_CALLBACK_TEST(TestFileIO, Mmap, filter); | 188 RUN_CALLBACK_TEST(TestFileIO, Mmap, filter); |
188 | 189 |
189 // TODO(viettrungluu): add tests: | 190 // TODO(viettrungluu): add tests: |
190 // - that PP_ERROR_PENDING is correctly returned | 191 // - that PP_ERROR_PENDING is correctly returned |
191 // - that operations respect the file open modes (flags) | 192 // - that operations respect the file open modes (flags) |
192 } | 193 } |
193 | 194 |
194 std::string TestFileIO::TestOpen() { | 195 std::string TestFileIO::TestOpen() { |
195 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 196 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
196 | 197 |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 cnt = read(fd, &buf[0], msg.size()); | 1102 cnt = read(fd, &buf[0], msg.size()); |
1102 if (cnt < 0) | 1103 if (cnt < 0) |
1103 return ReportError("read for native FD returned error", errno); | 1104 return ReportError("read for native FD returned error", errno); |
1104 if (cnt != static_cast<ssize_t>(msg.size())) | 1105 if (cnt != static_cast<ssize_t>(msg.size())) |
1105 return ReportError("read for native FD count mismatch", cnt); | 1106 return ReportError("read for native FD count mismatch", cnt); |
1106 if (msg != buf) | 1107 if (msg != buf) |
1107 return ReportMismatch("read for native FD", buf, msg); | 1108 return ReportMismatch("read for native FD", buf, msg); |
1108 PASS(); | 1109 PASS(); |
1109 } | 1110 } |
1110 | 1111 |
| 1112 // Calling RequestOSFileHandle with the FileIO that is opened with |
| 1113 // PP_FILEOPENFLAG_EXCLUSIVE used to cause NaCl module to crash while loading. |
| 1114 // This is a regression test for crbug.com/243241. |
| 1115 std::string TestFileIO::TestRequestOSFileHandleWithOpenExclusive() { |
| 1116 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
| 1117 |
| 1118 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 1119 pp::FileRef file_ref(file_system, "/file_os_fd2"); |
| 1120 |
| 1121 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); |
| 1122 ASSERT_EQ(PP_OK, callback.result()); |
| 1123 |
| 1124 pp::FileIO_Private file_io(instance_); |
| 1125 callback.WaitForResult(file_io.Open(file_ref, |
| 1126 PP_FILEOPENFLAG_CREATE | |
| 1127 PP_FILEOPENFLAG_READ | |
| 1128 PP_FILEOPENFLAG_WRITE | |
| 1129 PP_FILEOPENFLAG_EXCLUSIVE, |
| 1130 callback.GetCallback())); |
| 1131 ASSERT_EQ(PP_OK, callback.result()); |
| 1132 |
| 1133 TestCompletionCallbackWithOutput<pp::PassFileHandle> output_callback( |
| 1134 instance_->pp_instance(), callback_type()); |
| 1135 output_callback.WaitForResult( |
| 1136 file_io.RequestOSFileHandle(output_callback.GetCallback())); |
| 1137 PP_FileHandle handle = output_callback.output().Release(); |
| 1138 if (handle == PP_kInvalidFileHandle) |
| 1139 return "FileIO::RequestOSFileHandle() returned a bad file handle."; |
| 1140 ASSERT_EQ(PP_OK, output_callback.result()); |
| 1141 |
| 1142 PASS(); |
| 1143 } |
| 1144 |
1111 std::string TestFileIO::TestMmap() { | 1145 std::string TestFileIO::TestMmap() { |
1112 #if !defined(PPAPI_OS_WIN) | 1146 #if !defined(PPAPI_OS_WIN) |
1113 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); | 1147 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); |
1114 | 1148 |
1115 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 1149 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
1116 pp::FileRef file_ref(file_system, "/file_os_fd"); | 1150 pp::FileRef file_ref(file_system, "/file_os_fd"); |
1117 | 1151 |
1118 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); | 1152 callback.WaitForResult(file_system.Open(1024, callback.GetCallback())); |
1119 ASSERT_EQ(PP_OK, callback.result()); | 1153 ASSERT_EQ(PP_OK, callback.result()); |
1120 | 1154 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 if ((invalid_combination && callback.result() == PP_OK) || | 1388 if ((invalid_combination && callback.result() == PP_OK) || |
1355 (!invalid_combination && | 1389 (!invalid_combination && |
1356 ((callback.result() == PP_OK) != create_if_doesnt_exist))) { | 1390 ((callback.result() == PP_OK) != create_if_doesnt_exist))) { |
1357 return ReportOpenError(open_flags); | 1391 return ReportOpenError(open_flags); |
1358 } | 1392 } |
1359 | 1393 |
1360 return std::string(); | 1394 return std::string(); |
1361 } | 1395 } |
1362 | 1396 |
1363 // TODO(viettrungluu): Test Close(). crbug.com/69457 | 1397 // TODO(viettrungluu): Test Close(). crbug.com/69457 |
OLD | NEW |