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