| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 char buf_2[3]; | 896 char buf_2[3]; |
| 897 int32_t rv_2 = file_io.Read(read_offset_2, buf_2, sizeof(buf_2), | 897 int32_t rv_2 = file_io.Read(read_offset_2, buf_2, sizeof(buf_2), |
| 898 callback_2); | 898 callback_2); |
| 899 if (force_async_ && rv_2 != PP_OK_COMPLETIONPENDING) | 899 if (force_async_ && rv_2 != PP_OK_COMPLETIONPENDING) |
| 900 return ReportError("FileIO::Read force_async", rv_2); | 900 return ReportError("FileIO::Read force_async", rv_2); |
| 901 if (rv_2 == PP_OK_COMPLETIONPENDING) | 901 if (rv_2 == PP_OK_COMPLETIONPENDING) |
| 902 rv_2 = callback_2.WaitForResult(); | 902 rv_2 = callback_2.WaitForResult(); |
| 903 if (rv_2 != PP_ERROR_INPROGRESS) | 903 if (rv_2 != PP_ERROR_INPROGRESS) |
| 904 return ReportError("FileIO::Read", rv_2); | 904 return ReportError("FileIO::Read", rv_2); |
| 905 | 905 |
| 906 // Cannot query while the write is pending. | |
| 907 TestCompletionCallback callback_3(instance_->pp_instance(), force_async_); | |
| 908 PP_FileInfo info; | |
| 909 int32_t rv_3 = file_io.Query(&info, callback_3); | |
| 910 if (rv_3 == PP_OK_COMPLETIONPENDING) | |
| 911 rv_3 = callback_3.WaitForResult(); | |
| 912 if (rv_3 != PP_ERROR_INPROGRESS) | |
| 913 return ReportError("FileIO::Query", rv_3); | |
| 914 | |
| 915 // Cannot touch while the write is pending. | |
| 916 TestCompletionCallback callback_4(instance_->pp_instance(), force_async_); | |
| 917 int32_t rv_4 = file_io.Touch(1234.0, 5678.0, callback_4); | |
| 918 if (rv_4 == PP_OK_COMPLETIONPENDING) | |
| 919 rv_4 = callback_4.WaitForResult(); | |
| 920 if (rv_4 != PP_ERROR_INPROGRESS) | |
| 921 return ReportError("FileIO::Touch", rv_4); | |
| 922 | |
| 923 // Cannot set length while the write is pending. | |
| 924 TestCompletionCallback callback_5(instance_->pp_instance(), force_async_); | |
| 925 int32_t rv_5 = file_io.SetLength(123, callback_5); | |
| 926 if (rv_5 == PP_OK_COMPLETIONPENDING) | |
| 927 rv_5 = callback_5.WaitForResult(); | |
| 928 if (rv_5 != PP_ERROR_INPROGRESS) | |
| 929 return ReportError("FileIO::SetLength", rv_5); | |
| 930 | |
| 931 callback_1.WaitForResult(); | 906 callback_1.WaitForResult(); |
| 932 | 907 |
| 933 PASS(); | 908 PASS(); |
| 934 } | 909 } |
| 935 | 910 |
| 936 std::string TestFileIO::TestWillWriteWillSetLength() { | 911 std::string TestFileIO::TestWillWriteWillSetLength() { |
| 937 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 912 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 938 | 913 |
| 939 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 914 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 940 pp::FileRef file_ref(file_system, "/file_will_write"); | 915 pp::FileRef file_ref(file_system, "/file_will_write"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 958 if (rv == PP_OK_COMPLETIONPENDING) | 933 if (rv == PP_OK_COMPLETIONPENDING) |
| 959 rv = callback.WaitForResult(); | 934 rv = callback.WaitForResult(); |
| 960 if (rv != PP_OK) | 935 if (rv != PP_OK) |
| 961 return ReportError("FileIO::Open", rv); | 936 return ReportError("FileIO::Open", rv); |
| 962 | 937 |
| 963 const PPB_FileIOTrusted* trusted = static_cast<const PPB_FileIOTrusted*>( | 938 const PPB_FileIOTrusted* trusted = static_cast<const PPB_FileIOTrusted*>( |
| 964 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); | 939 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); |
| 965 if (!trusted) | 940 if (!trusted) |
| 966 return ReportError("FileIOTrusted", PP_ERROR_FAILED); | 941 return ReportError("FileIOTrusted", PP_ERROR_FAILED); |
| 967 | 942 |
| 968 // Get file descriptor. This is only supported in-process for now, so don't | 943 // Get file descriptor. |
| 969 // test out of process. | 944 int32_t fd = trusted->GetOSFileDescriptor(file_io.pp_resource()); |
| 970 const PPB_Testing_Dev* testing_interface = GetTestingInterface(); | 945 if (fd < 0) |
| 971 if (testing_interface && !testing_interface->IsOutOfProcess()) { | 946 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; |
| 972 int32_t fd = trusted->GetOSFileDescriptor(file_io.pp_resource()); | |
| 973 if (fd < 0) | |
| 974 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; | |
| 975 } | |
| 976 | 947 |
| 977 // Calling WillWrite. | 948 // Calling WillWrite. |
| 978 rv = trusted->WillWrite( | 949 rv = trusted->WillWrite( |
| 979 file_io.pp_resource(), 0, 9, | 950 file_io.pp_resource(), 0, 9, |
| 980 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); | 951 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); |
| 981 if (rv == PP_OK_COMPLETIONPENDING) | 952 if (rv == PP_OK_COMPLETIONPENDING) |
| 982 rv = callback.WaitForResult(); | 953 rv = callback.WaitForResult(); |
| 983 if (rv != 9) | 954 if (rv != 9) |
| 984 return ReportError("WillWrite", rv); | 955 return ReportError("WillWrite", rv); |
| 985 | 956 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 rv = callback.WaitForResult(); | 1090 rv = callback.WaitForResult(); |
| 1120 if ((invalid_combination && rv == PP_OK) || | 1091 if ((invalid_combination && rv == PP_OK) || |
| 1121 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) { | 1092 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) { |
| 1122 return ReportOpenError(open_flags); | 1093 return ReportOpenError(open_flags); |
| 1123 } | 1094 } |
| 1124 | 1095 |
| 1125 return std::string(); | 1096 return std::string(); |
| 1126 } | 1097 } |
| 1127 | 1098 |
| 1128 // TODO(viettrungluu): Test Close(). crbug.com/69457 | 1099 // TODO(viettrungluu): Test Close(). crbug.com/69457 |
| OLD | NEW |