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

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

Issue 7633061: Merge 94892 - Pepper quota support (Closed) Base URL: svn://svn.chromium.org/chrome/branches/835/src/
Patch Set: Created 9 years, 4 months 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/tests/test_file_io.h ('k') | webkit/glue/webkit_glue.gypi » ('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 <stdio.h> 7 #include <stdio.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "ppapi/c/dev/ppb_testing_dev.h" 11 #include "ppapi/c/dev/ppb_testing_dev.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/ppb_file_io.h" 13 #include "ppapi/c/ppb_file_io.h"
14 #include "ppapi/c/trusted/ppb_file_io_trusted.h"
14 #include "ppapi/cpp/file_io.h" 15 #include "ppapi/cpp/file_io.h"
15 #include "ppapi/cpp/file_ref.h" 16 #include "ppapi/cpp/file_ref.h"
16 #include "ppapi/cpp/file_system.h" 17 #include "ppapi/cpp/file_system.h"
17 #include "ppapi/cpp/instance.h" 18 #include "ppapi/cpp/instance.h"
18 #include "ppapi/cpp/module.h" 19 #include "ppapi/cpp/module.h"
19 #include "ppapi/tests/test_utils.h" 20 #include "ppapi/tests/test_utils.h"
20 #include "ppapi/tests/testing_instance.h" 21 #include "ppapi/tests/testing_instance.h"
21 22
22 REGISTER_TEST_CASE(FileIO); 23 REGISTER_TEST_CASE(FileIO);
23 24
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 113 }
113 114
114 void TestFileIO::RunTest() { 115 void TestFileIO::RunTest() {
115 RUN_TEST_FORCEASYNC_AND_NOT(Open); 116 RUN_TEST_FORCEASYNC_AND_NOT(Open);
116 RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSetLength); 117 RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSetLength);
117 RUN_TEST_FORCEASYNC_AND_NOT(TouchQuery); 118 RUN_TEST_FORCEASYNC_AND_NOT(TouchQuery);
118 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls); 119 RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls);
119 RUN_TEST_FORCEASYNC_AND_NOT(ParallelReads); 120 RUN_TEST_FORCEASYNC_AND_NOT(ParallelReads);
120 RUN_TEST_FORCEASYNC_AND_NOT(ParallelWrites); 121 RUN_TEST_FORCEASYNC_AND_NOT(ParallelWrites);
121 RUN_TEST_FORCEASYNC_AND_NOT(NotAllowMixedReadWrite); 122 RUN_TEST_FORCEASYNC_AND_NOT(NotAllowMixedReadWrite);
123 RUN_TEST_FORCEASYNC_AND_NOT(WillWriteWillSetLength);
122 124
123 // TODO(viettrungluu): add tests: 125 // TODO(viettrungluu): add tests:
124 // - that PP_ERROR_PENDING is correctly returned 126 // - that PP_ERROR_PENDING is correctly returned
125 // - that operations respect the file open modes (flags) 127 // - that operations respect the file open modes (flags)
126 } 128 }
127 129
128 std::string TestFileIO::TestOpen() { 130 std::string TestFileIO::TestOpen() {
129 TestCompletionCallback callback(instance_->pp_instance(), force_async_); 131 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
130 132
131 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); 133 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 if (rv_2 == PP_OK_COMPLETIONPENDING) 894 if (rv_2 == PP_OK_COMPLETIONPENDING)
893 rv_2 = callback_2.WaitForResult(); 895 rv_2 = callback_2.WaitForResult();
894 if (rv_2 != PP_ERROR_INPROGRESS) 896 if (rv_2 != PP_ERROR_INPROGRESS)
895 return ReportError("FileIO::Read", rv_2); 897 return ReportError("FileIO::Read", rv_2);
896 898
897 callback_1.WaitForResult(); 899 callback_1.WaitForResult();
898 900
899 PASS(); 901 PASS();
900 } 902 }
901 903
904 std::string TestFileIO::TestWillWriteWillSetLength() {
905 TestCompletionCallback callback(instance_->pp_instance(), force_async_);
906
907 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY);
908 pp::FileRef file_ref(file_system, "/file_will_write");
909 int32_t rv = file_system.Open(1024, callback);
910 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
911 return ReportError("FileSystem::Open force_async", rv);
912 if (rv == PP_OK_COMPLETIONPENDING)
913 rv = callback.WaitForResult();
914 if (rv != PP_OK)
915 return ReportError("FileSystem::Open", rv);
916
917 pp::FileIO file_io(instance_);
918 rv = file_io.Open(file_ref,
919 PP_FILEOPENFLAG_CREATE |
920 PP_FILEOPENFLAG_TRUNCATE |
921 PP_FILEOPENFLAG_READ |
922 PP_FILEOPENFLAG_WRITE,
923 callback);
924 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
925 return ReportError("FileIO::Open force_async", rv);
926 if (rv == PP_OK_COMPLETIONPENDING)
927 rv = callback.WaitForResult();
928 if (rv != PP_OK)
929 return ReportError("FileIO::Open", rv);
930
931 const PPB_FileIOTrusted* trusted = static_cast<const PPB_FileIOTrusted*>(
932 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE));
933 if (!trusted)
934 return ReportError("FileIOTrusted", PP_ERROR_FAILED);
935
936 // Get file descriptor.
937 int32_t fd = trusted->GetOSFileDescriptor(file_io.pp_resource());
938 if (fd < 0)
939 return "FileIO::GetOSFileDescriptor() returned a bad file descriptor.";
940
941 // Calling WillWrite.
942 rv = trusted->WillWrite(
943 file_io.pp_resource(), 0, 9,
944 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
945 if (rv == PP_OK_COMPLETIONPENDING)
946 rv = callback.WaitForResult();
947 if (rv != 9)
948 return ReportError("WillWrite", rv);
949
950 // Writing the actual data.
951 rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, "test_test");
952 if (rv != PP_OK)
953 return ReportError("FileIO::Write", rv);
954
955 std::string read_buffer;
956 rv = ReadEntireFile(instance_->pp_instance(), &file_io, 0, &read_buffer);
957 if (rv != PP_OK)
958 return ReportError("FileIO::Read", rv);
959 if (read_buffer != "test_test")
960 return ReportMismatch("FileIO::Read", read_buffer, "test_test");
961
962 // Calling WillSetLength.
963 rv = trusted->WillSetLength(
964 file_io.pp_resource(), 4,
965 static_cast<pp::CompletionCallback>(callback).pp_completion_callback());
966 if (rv == PP_OK_COMPLETIONPENDING)
967 rv = callback.WaitForResult();
968 if (rv != PP_OK)
969 return ReportError("WillSetLength", rv);
970
971 // Calling actual SetLength.
972 rv = file_io.SetLength(4, callback);
973 if (force_async_ && rv != PP_OK_COMPLETIONPENDING)
974 return ReportError("FileIO::SetLength force_async", rv);
975 if (rv == PP_OK_COMPLETIONPENDING)
976 rv = callback.WaitForResult();
977 if (rv != PP_OK)
978 return ReportError("FileIO::SetLength", rv);
979
980 read_buffer.clear();
981 rv = ReadEntireFile(instance_->pp_instance(), &file_io, 0, &read_buffer);
982 if (rv != PP_OK)
983 return ReportError("FileIO::Read", rv);
984 if (read_buffer != "test")
985 return ReportMismatch("FileIO::Read", read_buffer, "test");
986
987 PASS();
988 }
989
902 std::string TestFileIO::MatchOpenExpectations(pp::FileSystem* file_system, 990 std::string TestFileIO::MatchOpenExpectations(pp::FileSystem* file_system,
903 size_t open_flags, 991 size_t open_flags,
904 size_t expectations) { 992 size_t expectations) {
905 std::string bad_argument = 993 std::string bad_argument =
906 "TestFileIO::MatchOpenExpectations has invalid input arguments."; 994 "TestFileIO::MatchOpenExpectations has invalid input arguments.";
907 bool invalid_combination = !!(expectations & INVALID_FLAG_COMBINATION); 995 bool invalid_combination = !!(expectations & INVALID_FLAG_COMBINATION);
908 if (invalid_combination) { 996 if (invalid_combination) {
909 if (expectations != INVALID_FLAG_COMBINATION) 997 if (expectations != INVALID_FLAG_COMBINATION)
910 return bad_argument; 998 return bad_argument;
911 } else { 999 } else {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 rv = callback.WaitForResult(); 1083 rv = callback.WaitForResult();
996 if ((invalid_combination && rv == PP_OK) || 1084 if ((invalid_combination && rv == PP_OK) ||
997 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) { 1085 (!invalid_combination && ((rv == PP_OK) != create_if_doesnt_exist))) {
998 return ReportOpenError(open_flags); 1086 return ReportOpenError(open_flags);
999 } 1087 }
1000 1088
1001 return std::string(); 1089 return std::string();
1002 } 1090 }
1003 1091
1004 // TODO(viettrungluu): Test Close(). crbug.com/69457 1092 // TODO(viettrungluu): Test Close(). crbug.com/69457
OLDNEW
« no previous file with comments | « ppapi/tests/test_file_io.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698