| 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_ref.h" | 5 #include "ppapi/tests/test_file_ref.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/dev/ppb_file_io_dev.h" | 10 #include "ppapi/c/dev/ppb_file_io_dev.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 expected_result + "' expected."; | 37 expected_result + "' expected."; |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 bool TestFileRef::Init() { | 42 bool TestFileRef::Init() { |
| 43 return InitTestingInterface() && EnsureRunningOverHTTP(); | 43 return InitTestingInterface() && EnsureRunningOverHTTP(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void TestFileRef::RunTest() { | 46 void TestFileRef::RunTest() { |
| 47 RUN_TEST(GetFileSystemType); | 47 RUN_ASYNC_TEST(GetFileSystemType); |
| 48 RUN_TEST(GetName); | 48 RUN_ASYNC_TEST(GetName); |
| 49 RUN_TEST(GetPath); | 49 RUN_ASYNC_TEST(GetPath); |
| 50 RUN_TEST(GetParent); | 50 RUN_ASYNC_TEST(GetParent); |
| 51 RUN_TEST(MakeDirectory); | 51 RUN_ASYNC_TEST(MakeDirectory); |
| 52 RUN_TEST(QueryAndTouchFile); | 52 RUN_ASYNC_TEST(QueryAndTouchFile); |
| 53 RUN_TEST(DeleteFileAndDirectory); | 53 RUN_ASYNC_TEST(DeleteFileAndDirectory); |
| 54 RUN_TEST(RenameFileAndDirectory); | 54 RUN_ASYNC_TEST(RenameFileAndDirectory); |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::string TestFileRef::TestGetFileSystemType() { | 57 std::string TestFileRef::TestGetFileSystemType() { |
| 58 pp::FileSystem_Dev file_system_pers( | 58 pp::FileSystem_Dev file_system_pers( |
| 59 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); | 59 instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); |
| 60 pp::FileSystem_Dev file_system_temp( | 60 pp::FileSystem_Dev file_system_temp( |
| 61 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 61 instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 62 | 62 |
| 63 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); | 63 pp::FileRef_Dev file_ref_pers(file_system_pers, kPersFilePath); |
| 64 if (file_ref_pers.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) | 64 if (file_ref_pers.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) |
| 65 return "file_ref_pers expected to be persistent."; | 65 return "file_ref_pers expected to be persistent."; |
| 66 | 66 |
| 67 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); | 67 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); |
| 68 if (file_ref_temp.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) | 68 if (file_ref_temp.GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) |
| 69 return "file_ref_temp expected to be temporary."; | 69 return "file_ref_temp expected to be temporary."; |
| 70 | 70 |
| 71 pp::URLRequestInfo request(instance_); | 71 pp::URLRequestInfo request(instance_); |
| 72 request.SetURL("test_url_loader_data/hello.txt"); | 72 request.SetURL("test_url_loader_data/hello.txt"); |
| 73 request.SetStreamToFile(true); | 73 request.SetStreamToFile(true); |
| 74 | 74 |
| 75 TestCompletionCallback callback(instance_->pp_instance()); | 75 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 76 | 76 |
| 77 pp::URLLoader loader(instance_); | 77 pp::URLLoader loader(instance_); |
| 78 int32_t rv = loader.Open(request, callback); | 78 int32_t rv = loader.Open(request, callback); |
| 79 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 80 return ReportError("URLLoader::Open force_async", rv); |
| 79 if (rv == PP_OK_COMPLETIONPENDING) | 81 if (rv == PP_OK_COMPLETIONPENDING) |
| 80 rv = callback.WaitForResult(); | 82 rv = callback.WaitForResult(); |
| 81 if (rv != PP_OK) | 83 if (rv != PP_OK) |
| 82 return "URLLoader::Open() failed."; | 84 return "URLLoader::Open() failed."; |
| 83 | 85 |
| 84 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 86 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 85 if (response_info.is_null()) | 87 if (response_info.is_null()) |
| 86 return "URLLoader::GetResponseInfo returned null"; | 88 return "URLLoader::GetResponseInfo returned null"; |
| 87 int32_t status_code = response_info.GetStatusCode(); | 89 int32_t status_code = response_info.GetStatusCode(); |
| 88 if (status_code != 200) | 90 if (status_code != 200) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 114 // Test the "/" case. | 116 // Test the "/" case. |
| 115 pp::FileRef_Dev file_ref_slash(file_system_temp, "/"); | 117 pp::FileRef_Dev file_ref_slash(file_system_temp, "/"); |
| 116 name = file_ref_slash.GetName().AsString(); | 118 name = file_ref_slash.GetName().AsString(); |
| 117 if (name != "/") | 119 if (name != "/") |
| 118 return ReportMismatch("FileRef::GetName", name, "/"); | 120 return ReportMismatch("FileRef::GetName", name, "/"); |
| 119 | 121 |
| 120 pp::URLRequestInfo request(instance_); | 122 pp::URLRequestInfo request(instance_); |
| 121 request.SetURL("test_url_loader_data/hello.txt"); | 123 request.SetURL("test_url_loader_data/hello.txt"); |
| 122 request.SetStreamToFile(true); | 124 request.SetStreamToFile(true); |
| 123 | 125 |
| 124 TestCompletionCallback callback(instance_->pp_instance()); | 126 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 125 | 127 |
| 126 pp::URLLoader loader(instance_); | 128 pp::URLLoader loader(instance_); |
| 127 int32_t rv = loader.Open(request, callback); | 129 int32_t rv = loader.Open(request, callback); |
| 130 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 131 return ReportError("URLLoader::Open force_async", rv); |
| 128 if (rv == PP_OK_COMPLETIONPENDING) | 132 if (rv == PP_OK_COMPLETIONPENDING) |
| 129 rv = callback.WaitForResult(); | 133 rv = callback.WaitForResult(); |
| 130 if (rv != PP_OK) | 134 if (rv != PP_OK) |
| 131 return "URLLoader::Open() failed."; | 135 return "URLLoader::Open() failed."; |
| 132 | 136 |
| 133 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 137 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 134 if (response_info.is_null()) | 138 if (response_info.is_null()) |
| 135 return "URLLoader::GetResponseInfo returned null"; | 139 return "URLLoader::GetResponseInfo returned null"; |
| 136 int32_t status_code = response_info.GetStatusCode(); | 140 int32_t status_code = response_info.GetStatusCode(); |
| 137 if (status_code != 200) | 141 if (status_code != 200) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 158 | 162 |
| 159 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); | 163 pp::FileRef_Dev file_ref_temp(file_system_temp, kTempFilePath); |
| 160 path = file_ref_temp.GetPath().AsString(); | 164 path = file_ref_temp.GetPath().AsString(); |
| 161 if (path != kTempFilePath) | 165 if (path != kTempFilePath) |
| 162 return ReportMismatch("FileRef::GetPath", path, kTempFilePath); | 166 return ReportMismatch("FileRef::GetPath", path, kTempFilePath); |
| 163 | 167 |
| 164 pp::URLRequestInfo request(instance_); | 168 pp::URLRequestInfo request(instance_); |
| 165 request.SetURL("test_url_loader_data/hello.txt"); | 169 request.SetURL("test_url_loader_data/hello.txt"); |
| 166 request.SetStreamToFile(true); | 170 request.SetStreamToFile(true); |
| 167 | 171 |
| 168 TestCompletionCallback callback(instance_->pp_instance()); | 172 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 169 | 173 |
| 170 pp::URLLoader loader(instance_); | 174 pp::URLLoader loader(instance_); |
| 171 int32_t rv = loader.Open(request, callback); | 175 int32_t rv = loader.Open(request, callback); |
| 176 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 177 return ReportError("URLLoader::Open force_async", rv); |
| 172 if (rv == PP_OK_COMPLETIONPENDING) | 178 if (rv == PP_OK_COMPLETIONPENDING) |
| 173 rv = callback.WaitForResult(); | 179 rv = callback.WaitForResult(); |
| 174 if (rv != PP_OK) | 180 if (rv != PP_OK) |
| 175 return "URLLoader::Open() failed."; | 181 return "URLLoader::Open() failed."; |
| 176 | 182 |
| 177 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 183 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 178 if (response_info.is_null()) | 184 if (response_info.is_null()) |
| 179 return "URLLoader::GetResponseInfo returned null"; | 185 return "URLLoader::GetResponseInfo returned null"; |
| 180 int32_t status_code = response_info.GetStatusCode(); | 186 int32_t status_code = response_info.GetStatusCode(); |
| 181 if (status_code != 200) | 187 if (status_code != 200) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // Test the "/foo" case (the parent is "/"). | 219 // Test the "/foo" case (the parent is "/"). |
| 214 pp::FileRef_Dev file_ref_with_root_parent(file_system_temp, "/foo"); | 220 pp::FileRef_Dev file_ref_with_root_parent(file_system_temp, "/foo"); |
| 215 parent_path = file_ref_with_root_parent.GetParent().GetPath().AsString(); | 221 parent_path = file_ref_with_root_parent.GetParent().GetPath().AsString(); |
| 216 if (parent_path != "/") | 222 if (parent_path != "/") |
| 217 return ReportMismatch("FileRef::GetParent", parent_path, "/"); | 223 return ReportMismatch("FileRef::GetParent", parent_path, "/"); |
| 218 | 224 |
| 219 pp::URLRequestInfo request(instance_); | 225 pp::URLRequestInfo request(instance_); |
| 220 request.SetURL("test_url_loader_data/hello.txt"); | 226 request.SetURL("test_url_loader_data/hello.txt"); |
| 221 request.SetStreamToFile(true); | 227 request.SetStreamToFile(true); |
| 222 | 228 |
| 223 TestCompletionCallback callback(instance_->pp_instance()); | 229 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 224 | 230 |
| 225 pp::URLLoader loader(instance_); | 231 pp::URLLoader loader(instance_); |
| 226 int32_t rv = loader.Open(request, callback); | 232 int32_t rv = loader.Open(request, callback); |
| 233 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 234 return ReportError("URLLoader::Open force_async", rv); |
| 227 if (rv == PP_OK_COMPLETIONPENDING) | 235 if (rv == PP_OK_COMPLETIONPENDING) |
| 228 rv = callback.WaitForResult(); | 236 rv = callback.WaitForResult(); |
| 229 if (rv != PP_OK) | 237 if (rv != PP_OK) |
| 230 return "URLLoader::Open() failed."; | 238 return "URLLoader::Open() failed."; |
| 231 | 239 |
| 232 pp::URLResponseInfo response_info(loader.GetResponseInfo()); | 240 pp::URLResponseInfo response_info(loader.GetResponseInfo()); |
| 233 if (response_info.is_null()) | 241 if (response_info.is_null()) |
| 234 return "URLLoader::GetResponseInfo returned null"; | 242 return "URLLoader::GetResponseInfo returned null"; |
| 235 int32_t status_code = response_info.GetStatusCode(); | 243 int32_t status_code = response_info.GetStatusCode(); |
| 236 if (status_code != 200) | 244 if (status_code != 200) |
| 237 return "Unexpected HTTP status code"; | 245 return "Unexpected HTTP status code"; |
| 238 | 246 |
| 239 pp::FileRef_Dev file_ref_ext(response_info.GetBodyAsFileRef()); | 247 pp::FileRef_Dev file_ref_ext(response_info.GetBodyAsFileRef()); |
| 240 if (!file_ref_ext.GetParent().is_null()) | 248 if (!file_ref_ext.GetParent().is_null()) |
| 241 return "The parent of an external FileRef should be null."; | 249 return "The parent of an external FileRef should be null."; |
| 242 | 250 |
| 243 PASS(); | 251 PASS(); |
| 244 } | 252 } |
| 245 | 253 |
| 246 std::string TestFileRef::TestMakeDirectory() { | 254 std::string TestFileRef::TestMakeDirectory() { |
| 247 TestCompletionCallback callback(instance_->pp_instance()); | 255 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 248 | 256 |
| 249 // Open. | 257 // Open. |
| 250 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 258 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 251 int32_t rv = file_system.Open(1024, callback); | 259 int32_t rv = file_system.Open(1024, callback); |
| 260 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 261 return ReportError("FileSystem::Open force_async", rv); |
| 252 if (rv == PP_OK_COMPLETIONPENDING) | 262 if (rv == PP_OK_COMPLETIONPENDING) |
| 253 rv = callback.WaitForResult(); | 263 rv = callback.WaitForResult(); |
| 254 if (rv != PP_OK) | 264 if (rv != PP_OK) |
| 255 return ReportError("FileSystem::Open", rv); | 265 return ReportError("FileSystem::Open", rv); |
| 256 | 266 |
| 257 // MakeDirectory. | 267 // MakeDirectory. |
| 258 pp::FileRef_Dev dir_ref(file_system, "/test_dir_make_directory"); | 268 pp::FileRef_Dev dir_ref(file_system, "/test_dir_make_directory"); |
| 259 rv = dir_ref.MakeDirectory(callback); | 269 rv = dir_ref.MakeDirectory(callback); |
| 270 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 271 return ReportError("FileSystem::MakeDirectory force_async", rv); |
| 260 if (rv == PP_OK_COMPLETIONPENDING) | 272 if (rv == PP_OK_COMPLETIONPENDING) |
| 261 rv = callback.WaitForResult(); | 273 rv = callback.WaitForResult(); |
| 262 if (rv != PP_OK) | 274 if (rv != PP_OK) |
| 263 return ReportError("FileSystem::MakeDirectory", rv); | 275 return ReportError("FileSystem::MakeDirectory", rv); |
| 264 | 276 |
| 265 // MakeDirectory aborted. | 277 // MakeDirectory aborted. |
| 266 callback.reset_run_count(); | 278 callback.reset_run_count(); |
| 267 rv = pp::FileRef_Dev(file_system, "/test_dir_make_abort") | 279 rv = pp::FileRef_Dev(file_system, "/test_dir_make_abort") |
| 268 .MakeDirectory(callback); | 280 .MakeDirectory(callback); |
| 269 if (callback.run_count() > 0) | 281 if (callback.run_count() > 0) |
| 270 return "FileSystem::MakeDirectory ran callback synchronously."; | 282 return "FileSystem::MakeDirectory ran callback synchronously."; |
| 283 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 284 return ReportError("FileSystem::MakeDirectory force_async", rv); |
| 271 if (rv == PP_OK_COMPLETIONPENDING) { | 285 if (rv == PP_OK_COMPLETIONPENDING) { |
| 272 rv = callback.WaitForResult(); | 286 rv = callback.WaitForResult(); |
| 273 if (rv != PP_ERROR_ABORTED) | 287 if (rv != PP_ERROR_ABORTED) |
| 274 return "FileSystem::MakeDirectory not aborted."; | 288 return "FileSystem::MakeDirectory not aborted."; |
| 275 } else if (rv != PP_OK) { | 289 } else if (rv != PP_OK) { |
| 276 return ReportError("FileSystem::MakeDirectory", rv); | 290 return ReportError("FileSystem::MakeDirectory", rv); |
| 277 } | 291 } |
| 278 | 292 |
| 279 // MakeDirectoryIncludingAncestors. | 293 // MakeDirectoryIncludingAncestors. |
| 280 dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_1/dir_make_dir_2"); | 294 dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_1/dir_make_dir_2"); |
| 281 rv = dir_ref.MakeDirectoryIncludingAncestors(callback); | 295 rv = dir_ref.MakeDirectoryIncludingAncestors(callback); |
| 296 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 297 return ReportError("FileSystem::MakeDirectory force_async", rv); |
| 282 if (rv == PP_OK_COMPLETIONPENDING) | 298 if (rv == PP_OK_COMPLETIONPENDING) |
| 283 rv = callback.WaitForResult(); | 299 rv = callback.WaitForResult(); |
| 284 if (rv != PP_OK) | 300 if (rv != PP_OK) |
| 285 return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv); | 301 return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv); |
| 286 | 302 |
| 287 // MakeDirectoryIncludingAncestors aborted. | 303 // MakeDirectoryIncludingAncestors aborted. |
| 288 callback.reset_run_count(); | 304 callback.reset_run_count(); |
| 289 rv = pp::FileRef_Dev(file_system, "/dir_make_abort_1/dir_make_abort_2") | 305 rv = pp::FileRef_Dev(file_system, "/dir_make_abort_1/dir_make_abort_2") |
| 290 .MakeDirectoryIncludingAncestors(callback); | 306 .MakeDirectoryIncludingAncestors(callback); |
| 291 if (callback.run_count() > 0) { | 307 if (callback.run_count() > 0) { |
| 292 return "FileSystem::MakeDirectoryIncludingAncestors " | 308 return "FileSystem::MakeDirectoryIncludingAncestors " |
| 293 "ran callback synchronously."; | 309 "ran callback synchronously."; |
| 294 } | 310 } |
| 311 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 312 return ReportError( |
| 313 "FileSystem::MakeDirectoryIncludingAncestors force_async", rv); |
| 295 if (rv == PP_OK_COMPLETIONPENDING) { | 314 if (rv == PP_OK_COMPLETIONPENDING) { |
| 296 rv = callback.WaitForResult(); | 315 rv = callback.WaitForResult(); |
| 297 if (rv != PP_ERROR_ABORTED) | 316 if (rv != PP_ERROR_ABORTED) |
| 298 return "FileSystem::MakeDirectoryIncludingAncestors not aborted."; | 317 return "FileSystem::MakeDirectoryIncludingAncestors not aborted."; |
| 299 } else if (rv != PP_OK) { | 318 } else if (rv != PP_OK) { |
| 300 return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv); | 319 return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv); |
| 301 } | 320 } |
| 302 | 321 |
| 303 // MakeDirectory with nested path. | 322 // MakeDirectory with nested path. |
| 304 dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_3/dir_make_dir_4"); | 323 dir_ref = pp::FileRef_Dev(file_system, "/dir_make_dir_3/dir_make_dir_4"); |
| 305 rv = dir_ref.MakeDirectory(callback); | 324 rv = dir_ref.MakeDirectory(callback); |
| 325 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 326 return ReportError("FileSystem::MakeDirectory force_async", rv); |
| 306 if (rv == PP_OK_COMPLETIONPENDING) | 327 if (rv == PP_OK_COMPLETIONPENDING) |
| 307 rv = callback.WaitForResult(); | 328 rv = callback.WaitForResult(); |
| 308 if (rv == PP_OK) { | 329 if (rv == PP_OK) { |
| 309 return "Calling FileSystem::MakeDirectory() with a nested directory path " | 330 return "Calling FileSystem::MakeDirectory() with a nested directory path " |
| 310 "should have failed."; | 331 "should have failed."; |
| 311 } | 332 } |
| 312 | 333 |
| 313 PASS(); | 334 PASS(); |
| 314 } | 335 } |
| 315 | 336 |
| 316 std::string TestFileRef::TestQueryAndTouchFile() { | 337 std::string TestFileRef::TestQueryAndTouchFile() { |
| 317 TestCompletionCallback callback(instance_->pp_instance()); | 338 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 318 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 339 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 319 int32_t rv = file_system.Open(1024, callback); | 340 int32_t rv = file_system.Open(1024, callback); |
| 341 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 342 return ReportError("FileSystem::Open force_async", rv); |
| 320 if (rv == PP_OK_COMPLETIONPENDING) | 343 if (rv == PP_OK_COMPLETIONPENDING) |
| 321 rv = callback.WaitForResult(); | 344 rv = callback.WaitForResult(); |
| 322 if (rv != PP_OK) | 345 if (rv != PP_OK) |
| 323 return ReportError("FileSystem::Open", rv); | 346 return ReportError("FileSystem::Open", rv); |
| 324 | 347 |
| 325 pp::FileRef_Dev file_ref(file_system, "/file_touch"); | 348 pp::FileRef_Dev file_ref(file_system, "/file_touch"); |
| 326 pp::FileIO_Dev file_io(instance_); | 349 pp::FileIO_Dev file_io(instance_); |
| 327 rv = file_io.Open(file_ref, | 350 rv = file_io.Open(file_ref, |
| 328 PP_FILEOPENFLAG_CREATE | | 351 PP_FILEOPENFLAG_CREATE | |
| 329 PP_FILEOPENFLAG_TRUNCATE | | 352 PP_FILEOPENFLAG_TRUNCATE | |
| 330 PP_FILEOPENFLAG_WRITE, | 353 PP_FILEOPENFLAG_WRITE, |
| 331 callback); | 354 callback); |
| 355 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 356 return ReportError("FileIO::Open force_async", rv); |
| 332 if (rv == PP_OK_COMPLETIONPENDING) | 357 if (rv == PP_OK_COMPLETIONPENDING) |
| 333 rv = callback.WaitForResult(); | 358 rv = callback.WaitForResult(); |
| 334 if (rv != PP_OK) | 359 if (rv != PP_OK) |
| 335 return ReportError("FileIO::Open", rv); | 360 return ReportError("FileIO::Open", rv); |
| 336 | 361 |
| 337 // Write some data to have a non-zero file size. | 362 // Write some data to have a non-zero file size. |
| 338 rv = file_io.Write(0, "test", 4, callback); | 363 rv = file_io.Write(0, "test", 4, callback); |
| 364 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 365 return ReportError("FileIO::Write force_async", rv); |
| 339 if (rv == PP_OK_COMPLETIONPENDING) | 366 if (rv == PP_OK_COMPLETIONPENDING) |
| 340 rv = callback.WaitForResult(); | 367 rv = callback.WaitForResult(); |
| 341 if (rv != 4) | 368 if (rv != 4) |
| 342 return ReportError("FileIO::Write", rv); | 369 return ReportError("FileIO::Write", rv); |
| 343 | 370 |
| 344 // Touch. | 371 // Touch. |
| 345 // last_access_time's granularity is 1 day | 372 // last_access_time's granularity is 1 day |
| 346 // last_modified_time's granularity is 2 seconds | 373 // last_modified_time's granularity is 2 seconds |
| 347 const PP_Time last_access_time = 123 * 24 * 3600.0; | 374 const PP_Time last_access_time = 123 * 24 * 3600.0; |
| 348 const PP_Time last_modified_time = 246.0; | 375 const PP_Time last_modified_time = 246.0; |
| 349 rv = file_ref.Touch(last_access_time, last_modified_time, callback); | 376 rv = file_ref.Touch(last_access_time, last_modified_time, callback); |
| 377 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 378 return ReportError("FileSystem::Touch force_async", rv); |
| 350 if (rv == PP_OK_COMPLETIONPENDING) | 379 if (rv == PP_OK_COMPLETIONPENDING) |
| 351 rv = callback.WaitForResult(); | 380 rv = callback.WaitForResult(); |
| 352 if (rv != PP_OK) | 381 if (rv != PP_OK) |
| 353 return ReportError("FileSystem::Touch", rv); | 382 return ReportError("FileSystem::Touch", rv); |
| 354 | 383 |
| 355 // Touch aborted. | 384 // Touch aborted. |
| 356 callback.reset_run_count(); | 385 callback.reset_run_count(); |
| 357 rv = pp::FileRef_Dev(file_system, "/file_touch_abort") | 386 rv = pp::FileRef_Dev(file_system, "/file_touch_abort") |
| 358 .Touch(last_access_time, last_modified_time, callback); | 387 .Touch(last_access_time, last_modified_time, callback); |
| 359 if (callback.run_count() > 0) | 388 if (callback.run_count() > 0) |
| 360 return "FileSystem::Touch ran callback synchronously."; | 389 return "FileSystem::Touch ran callback synchronously."; |
| 390 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 391 return ReportError("FileSystem::Touch force_async", rv); |
| 361 if (rv == PP_OK_COMPLETIONPENDING) { | 392 if (rv == PP_OK_COMPLETIONPENDING) { |
| 362 rv = callback.WaitForResult(); | 393 rv = callback.WaitForResult(); |
| 363 if (rv != PP_ERROR_ABORTED) | 394 if (rv != PP_ERROR_ABORTED) |
| 364 return "FileSystem::Touch not aborted."; | 395 return "FileSystem::Touch not aborted."; |
| 365 } else if (rv != PP_OK) { | 396 } else if (rv != PP_OK) { |
| 366 return ReportError("FileSystem::Touch", rv); | 397 return ReportError("FileSystem::Touch", rv); |
| 367 } | 398 } |
| 368 | 399 |
| 369 // Query. | 400 // Query. |
| 370 PP_FileInfo_Dev info; | 401 PP_FileInfo_Dev info; |
| 371 rv = file_io.Query(&info, callback); | 402 rv = file_io.Query(&info, callback); |
| 403 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 404 return ReportError("FileSystem::Query force_async", rv); |
| 372 if (rv == PP_OK_COMPLETIONPENDING) | 405 if (rv == PP_OK_COMPLETIONPENDING) |
| 373 rv = callback.WaitForResult(); | 406 rv = callback.WaitForResult(); |
| 374 if (rv != PP_OK) | 407 if (rv != PP_OK) |
| 375 return ReportError("FileSystem::Query", rv); | 408 return ReportError("FileSystem::Query", rv); |
| 376 | 409 |
| 377 if ((info.size != 4) || | 410 if ((info.size != 4) || |
| 378 (info.type != PP_FILETYPE_REGULAR) || | 411 (info.type != PP_FILETYPE_REGULAR) || |
| 379 (info.system_type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) || | 412 (info.system_type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) || |
| 380 (info.last_access_time != last_access_time) || | 413 (info.last_access_time != last_access_time) || |
| 381 (info.last_modified_time != last_modified_time)) | 414 (info.last_modified_time != last_modified_time)) |
| 382 return "FileSystem::Query() has returned bad data."; | 415 return "FileSystem::Query() has returned bad data."; |
| 383 | 416 |
| 384 // Cancellation test. | 417 // Cancellation test. |
| 385 // TODO(viettrungluu): this test causes a bunch of LOG(WARNING)s; investigate. | 418 // TODO(viettrungluu): this test causes a bunch of LOG(WARNING)s; investigate. |
| 386 callback.reset_run_count(); | 419 callback.reset_run_count(); |
| 387 // TODO(viettrungluu): check |info| for late writes. | 420 // TODO(viettrungluu): check |info| for late writes. |
| 388 rv = pp::FileRef_Dev(file_system, "/file_touch").Touch( | 421 rv = pp::FileRef_Dev(file_system, "/file_touch").Touch( |
| 389 last_access_time, last_modified_time, callback); | 422 last_access_time, last_modified_time, callback); |
| 390 if (callback.run_count() > 0) | 423 if (callback.run_count() > 0) |
| 391 return "FileSystem::Touch ran callback synchronously."; | 424 return "FileSystem::Touch ran callback synchronously."; |
| 425 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 426 return ReportError("FileSystem::Touch force_async", rv); |
| 392 if (rv == PP_OK_COMPLETIONPENDING) { | 427 if (rv == PP_OK_COMPLETIONPENDING) { |
| 393 rv = callback.WaitForResult(); | 428 rv = callback.WaitForResult(); |
| 394 if (rv != PP_ERROR_ABORTED) | 429 if (rv != PP_ERROR_ABORTED) |
| 395 return "FileSystem::Touch not aborted."; | 430 return "FileSystem::Touch not aborted."; |
| 396 } else if (rv != PP_OK) { | 431 } else if (rv != PP_OK) { |
| 397 return ReportError("FileSystem::Touch", rv); | 432 return ReportError("FileSystem::Touch", rv); |
| 398 } | 433 } |
| 399 | 434 |
| 400 PASS(); | 435 PASS(); |
| 401 } | 436 } |
| 402 | 437 |
| 403 std::string TestFileRef::TestDeleteFileAndDirectory() { | 438 std::string TestFileRef::TestDeleteFileAndDirectory() { |
| 404 TestCompletionCallback callback(instance_->pp_instance()); | 439 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 405 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 440 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 406 int32_t rv = file_system.Open(1024, callback); | 441 int32_t rv = file_system.Open(1024, callback); |
| 442 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 443 return ReportError("FileSystem::Open force_async", rv); |
| 407 if (rv == PP_OK_COMPLETIONPENDING) | 444 if (rv == PP_OK_COMPLETIONPENDING) |
| 408 rv = callback.WaitForResult(); | 445 rv = callback.WaitForResult(); |
| 409 if (rv != PP_OK) | 446 if (rv != PP_OK) |
| 410 return ReportError("FileSystem::Open", rv); | 447 return ReportError("FileSystem::Open", rv); |
| 411 | 448 |
| 412 pp::FileRef_Dev file_ref(file_system, "/file_delete"); | 449 pp::FileRef_Dev file_ref(file_system, "/file_delete"); |
| 413 pp::FileIO_Dev file_io(instance_); | 450 pp::FileIO_Dev file_io(instance_); |
| 414 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); | 451 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); |
| 452 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 453 return ReportError("FileIO::Open force_async", rv); |
| 415 if (rv == PP_OK_COMPLETIONPENDING) | 454 if (rv == PP_OK_COMPLETIONPENDING) |
| 416 rv = callback.WaitForResult(); | 455 rv = callback.WaitForResult(); |
| 417 if (rv != PP_OK) | 456 if (rv != PP_OK) |
| 418 return ReportError("FileIO::Open", rv); | 457 return ReportError("FileIO::Open", rv); |
| 419 | 458 |
| 420 rv = file_ref.Delete(callback); | 459 rv = file_ref.Delete(callback); |
| 460 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 461 return ReportError("FileRef::Delete force_async", rv); |
| 421 if (rv == PP_OK_COMPLETIONPENDING) | 462 if (rv == PP_OK_COMPLETIONPENDING) |
| 422 rv = callback.WaitForResult(); | 463 rv = callback.WaitForResult(); |
| 423 if (rv != PP_OK) | 464 if (rv != PP_OK) |
| 424 return ReportError("FileSystem::Delete", rv); | 465 return ReportError("FileRef::Delete", rv); |
| 425 | 466 |
| 426 pp::FileRef_Dev dir_ref(file_system, "/dir_delete"); | 467 pp::FileRef_Dev dir_ref(file_system, "/dir_delete"); |
| 427 rv = dir_ref.MakeDirectory(callback); | 468 rv = dir_ref.MakeDirectory(callback); |
| 469 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 470 return ReportError("FileRef::MakeDirectory force_async", rv); |
| 428 if (rv == PP_OK_COMPLETIONPENDING) | 471 if (rv == PP_OK_COMPLETIONPENDING) |
| 429 rv = callback.WaitForResult(); | 472 rv = callback.WaitForResult(); |
| 430 if (rv != PP_OK) | 473 if (rv != PP_OK) |
| 431 return ReportError("FileSystem::MakeDirectory", rv); | 474 return ReportError("FileRef::MakeDirectory", rv); |
| 432 | 475 |
| 433 rv = dir_ref.Delete(callback); | 476 rv = dir_ref.Delete(callback); |
| 477 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 478 return ReportError("FileRef::Open force_async", rv); |
| 434 if (rv == PP_OK_COMPLETIONPENDING) | 479 if (rv == PP_OK_COMPLETIONPENDING) |
| 435 rv = callback.WaitForResult(); | 480 rv = callback.WaitForResult(); |
| 436 if (rv != PP_OK) | 481 if (rv != PP_OK) |
| 437 return ReportError("FileSystem::Delete", rv); | 482 return ReportError("FileRef::Delete", rv); |
| 438 | 483 |
| 439 pp::FileRef_Dev nested_dir_ref(file_system, "/dir_delete_1/dir_delete_2"); | 484 pp::FileRef_Dev nested_dir_ref(file_system, "/dir_delete_1/dir_delete_2"); |
| 440 rv = nested_dir_ref.MakeDirectoryIncludingAncestors(callback); | 485 rv = nested_dir_ref.MakeDirectoryIncludingAncestors(callback); |
| 486 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 487 return ReportError("FileRef::Open force_async", rv); |
| 441 if (rv == PP_OK_COMPLETIONPENDING) | 488 if (rv == PP_OK_COMPLETIONPENDING) |
| 442 rv = callback.WaitForResult(); | 489 rv = callback.WaitForResult(); |
| 443 if (rv != PP_OK) | 490 if (rv != PP_OK) |
| 444 return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv); | 491 return ReportError("FileRef::MakeDirectoryIncludingAncestors", rv); |
| 445 | 492 |
| 446 // Hang on to a ref to the parent; otherwise the callback will be aborted. | 493 // Hang on to a ref to the parent; otherwise the callback will be aborted. |
| 447 pp::FileRef_Dev parent_dir_ref = nested_dir_ref.GetParent(); | 494 pp::FileRef_Dev parent_dir_ref = nested_dir_ref.GetParent(); |
| 448 rv = parent_dir_ref.Delete(callback); | 495 rv = parent_dir_ref.Delete(callback); |
| 496 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 497 return ReportError("FileRef::Open force_async", rv); |
| 449 if (rv == PP_OK_COMPLETIONPENDING) | 498 if (rv == PP_OK_COMPLETIONPENDING) |
| 450 rv = callback.WaitForResult(); | 499 rv = callback.WaitForResult(); |
| 451 if (rv != PP_ERROR_FAILED) | 500 if (rv != PP_ERROR_FAILED) |
| 452 return ReportError("FileSystem::Delete", rv); | 501 return ReportError("FileRef::Delete", rv); |
| 453 | 502 |
| 454 pp::FileRef_Dev nonexistent_file_ref(file_system, "/nonexistent_file_delete"); | 503 pp::FileRef_Dev nonexistent_file_ref(file_system, "/nonexistent_file_delete"); |
| 455 rv = nonexistent_file_ref.Delete(callback); | 504 rv = nonexistent_file_ref.Delete(callback); |
| 505 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 506 return ReportError("FileRef::Open force_async", rv); |
| 456 if (rv == PP_OK_COMPLETIONPENDING) | 507 if (rv == PP_OK_COMPLETIONPENDING) |
| 457 rv = callback.WaitForResult(); | 508 rv = callback.WaitForResult(); |
| 458 if (rv != PP_ERROR_FILENOTFOUND) | 509 if (rv != PP_ERROR_FILENOTFOUND) |
| 459 return ReportError("FileSystem::Delete", rv); | 510 return ReportError("FileRef::Delete", rv); |
| 460 | 511 |
| 461 // Delete aborted. | 512 // Delete aborted. |
| 462 { | 513 { |
| 463 pp::FileRef_Dev file_ref_abort(file_system, "/file_delete_abort"); | 514 pp::FileRef_Dev file_ref_abort(file_system, "/file_delete_abort"); |
| 464 pp::FileIO_Dev file_io_abort(instance_); | 515 pp::FileIO_Dev file_io_abort(instance_); |
| 465 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); | 516 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); |
| 517 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 518 return ReportError("FileIO::Open force_async", rv); |
| 466 if (rv == PP_OK_COMPLETIONPENDING) | 519 if (rv == PP_OK_COMPLETIONPENDING) |
| 467 rv = callback.WaitForResult(); | 520 rv = callback.WaitForResult(); |
| 468 if (rv != PP_OK) | 521 if (rv != PP_OK) |
| 469 return ReportError("FileIO::Open", rv); | 522 return ReportError("FileIO::Open", rv); |
| 470 | 523 |
| 471 callback.reset_run_count(); | 524 callback.reset_run_count(); |
| 472 rv = file_ref_abort.Delete(callback); | 525 rv = file_ref_abort.Delete(callback); |
| 473 } | 526 } |
| 474 if (callback.run_count() > 0) | 527 if (callback.run_count() > 0) |
| 475 return "FileSystem::Delete ran callback synchronously."; | 528 return "FileRef::Delete ran callback synchronously."; |
| 529 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 530 return ReportError("FileRef::Open force_async", rv); |
| 476 if (rv == PP_OK_COMPLETIONPENDING) { | 531 if (rv == PP_OK_COMPLETIONPENDING) { |
| 477 rv = callback.WaitForResult(); | 532 rv = callback.WaitForResult(); |
| 478 if (rv != PP_ERROR_ABORTED) | 533 if (rv != PP_ERROR_ABORTED) |
| 479 return "FileSystem::Delete not aborted."; | 534 return "FileRef::Delete not aborted."; |
| 480 } else if (rv != PP_OK) { | 535 } else if (rv != PP_OK) { |
| 481 return ReportError("FileSystem::Delete", rv); | 536 return ReportError("FileRef::Delete", rv); |
| 482 } | 537 } |
| 483 | 538 |
| 484 PASS(); | 539 PASS(); |
| 485 } | 540 } |
| 486 | 541 |
| 487 std::string TestFileRef::TestRenameFileAndDirectory() { | 542 std::string TestFileRef::TestRenameFileAndDirectory() { |
| 488 TestCompletionCallback callback(instance_->pp_instance()); | 543 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 489 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 544 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 490 int32_t rv = file_system.Open(1024, callback); | 545 int32_t rv = file_system.Open(1024, callback); |
| 546 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 547 return ReportError("FileSystem::Open force_async", rv); |
| 491 if (rv == PP_OK_COMPLETIONPENDING) | 548 if (rv == PP_OK_COMPLETIONPENDING) |
| 492 rv = callback.WaitForResult(); | 549 rv = callback.WaitForResult(); |
| 493 if (rv != PP_OK) | 550 if (rv != PP_OK) |
| 494 return ReportError("FileSystem::Open", rv); | 551 return ReportError("FileSystem::Open", rv); |
| 495 | 552 |
| 496 pp::FileRef_Dev file_ref(file_system, "/file_rename"); | 553 pp::FileRef_Dev file_ref(file_system, "/file_rename"); |
| 497 pp::FileIO_Dev file_io(instance_); | 554 pp::FileIO_Dev file_io(instance_); |
| 498 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); | 555 rv = file_io.Open(file_ref, PP_FILEOPENFLAG_CREATE, callback); |
| 556 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 557 return ReportError("FileIO::Open force_async", rv); |
| 499 if (rv == PP_OK_COMPLETIONPENDING) | 558 if (rv == PP_OK_COMPLETIONPENDING) |
| 500 rv = callback.WaitForResult(); | 559 rv = callback.WaitForResult(); |
| 501 if (rv != PP_OK) | 560 if (rv != PP_OK) |
| 502 return ReportError("FileIO::Open", rv); | 561 return ReportError("FileIO::Open", rv); |
| 503 | 562 |
| 504 pp::FileRef_Dev target_file_ref(file_system, "/target_file_rename"); | 563 pp::FileRef_Dev target_file_ref(file_system, "/target_file_rename"); |
| 505 rv = file_ref.Rename(target_file_ref, callback); | 564 rv = file_ref.Rename(target_file_ref, callback); |
| 565 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 566 return ReportError("FileRef::Rename force_async", rv); |
| 506 if (rv == PP_OK_COMPLETIONPENDING) | 567 if (rv == PP_OK_COMPLETIONPENDING) |
| 507 rv = callback.WaitForResult(); | 568 rv = callback.WaitForResult(); |
| 508 if (rv != PP_OK) | 569 if (rv != PP_OK) |
| 509 return ReportError("FileSystem::Rename", rv); | 570 return ReportError("FileRef::Rename", rv); |
| 510 | 571 |
| 511 pp::FileRef_Dev dir_ref(file_system, "/dir_rename"); | 572 pp::FileRef_Dev dir_ref(file_system, "/dir_rename"); |
| 512 rv = dir_ref.MakeDirectory(callback); | 573 rv = dir_ref.MakeDirectory(callback); |
| 574 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 575 return ReportError("FileRef::MakeDirectory force_async", rv); |
| 513 if (rv == PP_OK_COMPLETIONPENDING) | 576 if (rv == PP_OK_COMPLETIONPENDING) |
| 514 rv = callback.WaitForResult(); | 577 rv = callback.WaitForResult(); |
| 515 if (rv != PP_OK) | 578 if (rv != PP_OK) |
| 516 return ReportError("FileSystem::MakeDirectory", rv); | 579 return ReportError("FileRef::MakeDirectory", rv); |
| 517 | 580 |
| 518 pp::FileRef_Dev target_dir_ref(file_system, "/target_dir_rename"); | 581 pp::FileRef_Dev target_dir_ref(file_system, "/target_dir_rename"); |
| 519 rv = dir_ref.Rename(target_dir_ref, callback); | 582 rv = dir_ref.Rename(target_dir_ref, callback); |
| 583 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 584 return ReportError("FileRef::Rename force_async", rv); |
| 520 if (rv == PP_OK_COMPLETIONPENDING) | 585 if (rv == PP_OK_COMPLETIONPENDING) |
| 521 rv = callback.WaitForResult(); | 586 rv = callback.WaitForResult(); |
| 522 if (rv != PP_OK) | 587 if (rv != PP_OK) |
| 523 return ReportError("FileSystem::Rename", rv); | 588 return ReportError("FileRef::Rename", rv); |
| 524 | 589 |
| 525 pp::FileRef_Dev nested_dir_ref(file_system, "/dir_rename_1/dir_rename_2"); | 590 pp::FileRef_Dev nested_dir_ref(file_system, "/dir_rename_1/dir_rename_2"); |
| 526 rv = nested_dir_ref.MakeDirectoryIncludingAncestors(callback); | 591 rv = nested_dir_ref.MakeDirectoryIncludingAncestors(callback); |
| 592 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 593 return ReportError("FileRef::MakeDirectory force_async", rv); |
| 527 if (rv == PP_OK_COMPLETIONPENDING) | 594 if (rv == PP_OK_COMPLETIONPENDING) |
| 528 rv = callback.WaitForResult(); | 595 rv = callback.WaitForResult(); |
| 529 if (rv != PP_OK) | 596 if (rv != PP_OK) |
| 530 return ReportError("FileSystem::MakeDirectoryIncludingAncestors", rv); | 597 return ReportError("FileRef::MakeDirectoryIncludingAncestors", rv); |
| 531 | 598 |
| 532 pp::FileRef_Dev target_nested_dir_ref(file_system, "/dir_rename_1"); | 599 pp::FileRef_Dev target_nested_dir_ref(file_system, "/dir_rename_1"); |
| 533 rv = nested_dir_ref.Rename(target_nested_dir_ref, callback); | 600 rv = nested_dir_ref.Rename(target_nested_dir_ref, callback); |
| 601 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 602 return ReportError("FileRef::Open force_async", rv); |
| 534 if (rv == PP_OK_COMPLETIONPENDING) | 603 if (rv == PP_OK_COMPLETIONPENDING) |
| 535 rv = callback.WaitForResult(); | 604 rv = callback.WaitForResult(); |
| 536 if (rv != PP_ERROR_FAILED) | 605 if (rv != PP_ERROR_FAILED) |
| 537 return ReportError("FileSystem::Rename", rv); | 606 return ReportError("FileRef::Rename", rv); |
| 538 | 607 |
| 539 // Rename aborted. | 608 // Rename aborted. |
| 540 // TODO(viettrungluu): Figure out what we want to do if the target file | 609 // TODO(viettrungluu): Figure out what we want to do if the target file |
| 541 // resource is destroyed before completion. | 610 // resource is destroyed before completion. |
| 542 pp::FileRef_Dev target_file_ref_abort(file_system, | 611 pp::FileRef_Dev target_file_ref_abort(file_system, |
| 543 "/target_file_rename_abort"); | 612 "/target_file_rename_abort"); |
| 544 { | 613 { |
| 545 pp::FileRef_Dev file_ref_abort(file_system, "/file_rename_abort"); | 614 pp::FileRef_Dev file_ref_abort(file_system, "/file_rename_abort"); |
| 546 pp::FileIO_Dev file_io_abort(instance_); | 615 pp::FileIO_Dev file_io_abort(instance_); |
| 547 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); | 616 rv = file_io_abort.Open(file_ref_abort, PP_FILEOPENFLAG_CREATE, callback); |
| 617 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 618 return ReportError("FileIO::Open force_async", rv); |
| 548 if (rv == PP_OK_COMPLETIONPENDING) | 619 if (rv == PP_OK_COMPLETIONPENDING) |
| 549 rv = callback.WaitForResult(); | 620 rv = callback.WaitForResult(); |
| 550 if (rv != PP_OK) | 621 if (rv != PP_OK) |
| 551 return ReportError("FileIO::Open", rv); | 622 return ReportError("FileIO::Open", rv); |
| 552 | 623 |
| 553 callback.reset_run_count(); | 624 callback.reset_run_count(); |
| 554 rv = file_ref_abort.Rename(target_file_ref_abort, callback); | 625 rv = file_ref_abort.Rename(target_file_ref_abort, callback); |
| 555 } | 626 } |
| 556 if (callback.run_count() > 0) | 627 if (callback.run_count() > 0) |
| 557 return "FileSystem::Rename ran callback synchronously."; | 628 return "FileSystem::Rename ran callback synchronously."; |
| 629 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 630 return ReportError("FileSystem::Rename force_async", rv); |
| 558 if (rv == PP_OK_COMPLETIONPENDING) { | 631 if (rv == PP_OK_COMPLETIONPENDING) { |
| 559 rv = callback.WaitForResult(); | 632 rv = callback.WaitForResult(); |
| 560 if (rv != PP_ERROR_ABORTED) | 633 if (rv != PP_ERROR_ABORTED) |
| 561 return "FileSystem::Rename not aborted."; | 634 return "FileSystem::Rename not aborted."; |
| 562 } else if (rv != PP_OK) { | 635 } else if (rv != PP_OK) { |
| 563 return ReportError("FileSystem::Rename", rv); | 636 return ReportError("FileSystem::Rename", rv); |
| 564 } | 637 } |
| 565 | 638 |
| 566 PASS(); | 639 PASS(); |
| 567 } | 640 } |
| OLD | NEW |