| 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_system.h" | 5 #include "ppapi/tests/test_file_system.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/cpp/dev/file_system_dev.h" | 10 #include "ppapi/cpp/dev/file_system_dev.h" |
| 11 #include "ppapi/tests/test_utils.h" | 11 #include "ppapi/tests/test_utils.h" |
| 12 #include "ppapi/tests/testing_instance.h" | 12 #include "ppapi/tests/testing_instance.h" |
| 13 | 13 |
| 14 REGISTER_TEST_CASE(FileSystem); | 14 REGISTER_TEST_CASE(FileSystem); |
| 15 | 15 |
| 16 bool TestFileSystem::Init() { | 16 bool TestFileSystem::Init() { |
| 17 return InitTestingInterface() && EnsureRunningOverHTTP(); | 17 return InitTestingInterface() && EnsureRunningOverHTTP(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void TestFileSystem::RunTest() { | 20 void TestFileSystem::RunTest() { |
| 21 RUN_TEST(Open); | 21 RUN_TEST_FORCEASYNC_AND_NOT(Open); |
| 22 RUN_TEST(MultipleOpens); | 22 RUN_TEST_FORCEASYNC_AND_NOT(MultipleOpens); |
| 23 } | 23 } |
| 24 | 24 |
| 25 std::string TestFileSystem::TestOpen() { | 25 std::string TestFileSystem::TestOpen() { |
| 26 TestCompletionCallback callback(instance_->pp_instance()); | 26 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 27 | 27 |
| 28 // Open. | 28 // Open. |
| 29 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 29 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 30 int32_t rv = file_system.Open(1024, callback); | 30 int32_t rv = file_system.Open(1024, callback); |
| 31 if (rv == PP_OK_COMPLETIONPENDING) | 31 if (rv == PP_OK_COMPLETIONPENDING) |
| 32 rv = callback.WaitForResult(); | 32 rv = callback.WaitForResult(); |
| 33 if (rv != PP_OK) | 33 if (rv != PP_OK) |
| 34 return ReportError("FileSystem::Open", rv); | 34 return ReportError("FileSystem::Open", rv); |
| 35 | 35 |
| 36 // Open aborted (see the DirectoryReader test for comments). | 36 // Open aborted (see the DirectoryReader test for comments). |
| 37 callback.reset_run_count(); | 37 callback.reset_run_count(); |
| 38 rv = pp::FileSystem_Dev(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY) | 38 rv = pp::FileSystem_Dev(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY) |
| 39 .Open(1024, callback); | 39 .Open(1024, callback); |
| 40 if (callback.run_count() > 0) | 40 if (callback.run_count() > 0) |
| 41 return "FileSystem::Open ran callback synchronously."; | 41 return "FileSystem::Open ran callback synchronously."; |
| 42 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) |
| 43 return ReportError("FileSystem::Open force_async", rv); |
| 42 if (rv == PP_OK_COMPLETIONPENDING) { | 44 if (rv == PP_OK_COMPLETIONPENDING) { |
| 43 rv = callback.WaitForResult(); | 45 rv = callback.WaitForResult(); |
| 44 if (rv != PP_ERROR_ABORTED) | 46 if (rv != PP_ERROR_ABORTED) |
| 45 return "FileSystem::Open not aborted."; | 47 return "FileSystem::Open not aborted."; |
| 46 } else if (rv != PP_OK) { | 48 } else if (rv != PP_OK) { |
| 47 return ReportError("FileSystem::Open", rv); | 49 return ReportError("FileSystem::Open", rv); |
| 48 } | 50 } |
| 49 | 51 |
| 50 PASS(); | 52 PASS(); |
| 51 } | 53 } |
| 52 | 54 |
| 53 std::string TestFileSystem::TestMultipleOpens() { | 55 std::string TestFileSystem::TestMultipleOpens() { |
| 54 // Should not allow multiple opens, no matter the first open has completed or | 56 // Should not allow multiple opens, no matter the first open has completed or |
| 55 // not. | 57 // not. |
| 56 TestCompletionCallback callback_1(instance_->pp_instance()); | 58 TestCompletionCallback callback_1(instance_->pp_instance(), force_async_); |
| 57 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 59 pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 58 int32_t rv_1 = file_system.Open(1024, callback_1); | 60 int32_t rv_1 = file_system.Open(1024, callback_1); |
| 59 if (callback_1.run_count() > 0) | 61 if (callback_1.run_count() > 0) |
| 60 return "FileSystem::Open ran callback synchronously."; | 62 return "FileSystem::Open1 ran callback synchronously."; |
| 63 if (force_async_ && rv_1 != PP_OK_COMPLETIONPENDING) |
| 64 return ReportError("FileSystem::Open1 force_async", rv_1); |
| 61 | 65 |
| 62 TestCompletionCallback callback_2(instance_->pp_instance()); | 66 TestCompletionCallback callback_2(instance_->pp_instance(), force_async_); |
| 63 int32_t rv_2 = file_system.Open(1024, callback_2); | 67 int32_t rv_2 = file_system.Open(1024, callback_2); |
| 68 if (force_async_ && rv_2 != PP_OK_COMPLETIONPENDING) |
| 69 return ReportError("FileSystem::Open2 force_async", rv_2); |
| 64 if (rv_2 == PP_OK_COMPLETIONPENDING || rv_2 == PP_OK) | 70 if (rv_2 == PP_OK_COMPLETIONPENDING || rv_2 == PP_OK) |
| 65 return "FileSystem::Open should not allow multiple opens."; | 71 return "FileSystem::Open2 should not allow multiple opens."; |
| 66 | 72 |
| 67 if (rv_1 == PP_OK_COMPLETIONPENDING) | 73 if (rv_1 == PP_OK_COMPLETIONPENDING) |
| 68 rv_1 = callback_1.WaitForResult(); | 74 rv_1 = callback_1.WaitForResult(); |
| 69 if (rv_1 != PP_OK) | 75 if (rv_1 != PP_OK) |
| 70 return ReportError("FileSystem::Open", rv_1); | 76 return ReportError("FileSystem::Open1", rv_1); |
| 71 | 77 |
| 72 TestCompletionCallback callback_3(instance_->pp_instance()); | 78 TestCompletionCallback callback_3(instance_->pp_instance(), force_async_); |
| 73 int32_t rv_3 = file_system.Open(1024, callback_3); | 79 int32_t rv_3 = file_system.Open(1024, callback_3); |
| 80 if (force_async_ && rv_3 != PP_OK_COMPLETIONPENDING) |
| 81 return ReportError("FileSystem::Open3 force_async", rv_3); |
| 74 if (rv_3 == PP_OK_COMPLETIONPENDING || rv_3 == PP_OK) | 82 if (rv_3 == PP_OK_COMPLETIONPENDING || rv_3 == PP_OK) |
| 75 return "FileSystem::Open should not allow multiple opens."; | 83 return "FileSystem::Open3 should not allow multiple opens."; |
| 76 | 84 |
| 77 PASS(); | 85 PASS(); |
| 78 } | 86 } |
| 79 | |
| OLD | NEW |