Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: ppapi/tests/test_file_io.cc

Issue 8764003: Implement a proxy for Pepper FileIO. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Homestarmy Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/ppb_file_io_shared.cc ('k') | ppapi/tests/test_url_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
906 callback_1.WaitForResult(); 931 callback_1.WaitForResult();
907 932
908 PASS(); 933 PASS();
909 } 934 }
910 935
911 std::string TestFileIO::TestWillWriteWillSetLength() { 936 std::string TestFileIO::TestWillWriteWillSetLength() {
912 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 937 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
913 938
914 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 939 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
915 pp::FileRef file_ref(file_system, "/file_will_write"); 940 pp::FileRef file_ref(file_system, "/file_will_write");
(...skipping 17 matching lines...) Expand all
933 if (rv == PP_OK_COMPLETIONPENDING) 958 if (rv == PP_OK_COMPLETIONPENDING)
934 rv = callback.WaitForResult(); 959 rv = callback.WaitForResult();
935 if (rv != PP_OK) 960 if (rv != PP_OK)
936 return ReportError("FileIO::Open", rv); 961 return ReportError("FileIO::Open", rv);
937 962
938 const PPB_FileIOTrusted* trusted = static_cast<const PPB_FileIOTrusted*>( 963 const PPB_FileIOTrusted* trusted = static_cast<const PPB_FileIOTrusted*>(
939 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); 964 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE));
940 if (!trusted) 965 if (!trusted)
941 return ReportError("FileIOTrusted", PP_ERROR_FAILED); 966 return ReportError("FileIOTrusted", PP_ERROR_FAILED);
942 967
943 // Get file descriptor. 968 // Get file descriptor. This is only supported in-process for now, so don't
944 int32_t fd = trusted->GetOSFileDescriptor(file_io.pp_resource()); 969 // test out of process.
945 if (fd < 0) 970 const PPB_Testing_Dev* testing_interface = GetTestingInterface();
946 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor."; 971 if (testing_interface && !testing_interface->IsOutOfProcess()) {
972 int32_t fd = trusted->GetOSFileDescriptor(file_io.pp_resource());
973 if (fd < 0)
974 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor.";
975 }
947 976
948 // Calling WillWrite. 977 // Calling WillWrite.
949 rv = trusted->WillWrite( 978 rv = trusted->WillWrite(
950 file_io.pp_resource(), 0, 9, 979 file_io.pp_resource(), 0, 9,
951 static_cast<pp::CompletionCallback>(callback).pp_completion_callback()); 980 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
952 if (rv == PP_OK_COMPLETIONPENDING) 981 if (rv == PP_OK_COMPLETIONPENDING)
953 rv = callback.WaitForResult(); 982 rv = callback.WaitForResult();
954 if (rv != 9) 983 if (rv != 9)
955 return ReportError("WillWrite", rv); 984 return ReportError("WillWrite", rv);
956 985
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 rv = callback.WaitForResult(); 1119 rv = callback.WaitForResult();
1091 if ((invalid_combination && rv == PP_OK) || 1120 if ((invalid_combination && rv == PP_OK) ||
1092 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) { 1121 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) {
1093 return ReportOpenError(open_flags); 1122 return ReportOpenError(open_flags);
1094 } 1123 }
1095 1124
1096 return std::string(); 1125 return std::string();
1097 } 1126 }
1098 1127
1099 // TODO(viettrungluu): Test Close(). crbug.com/69457 1128 // TODO(viettrungluu): Test Close(). crbug.com/69457
OLDNEW
« no previous file with comments | « ppapi/shared_impl/ppb_file_io_shared.cc ('k') | ppapi/tests/test_url_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698