| 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/file_system.h" | 10 #include "ppapi/cpp/file_system.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 CheckTestingInterface() && EnsureRunningOverHTTP(); | 17 return CheckTestingInterface() && EnsureRunningOverHTTP(); |
| 18 } | 18 } |
| 19 | 19 |
| 20 void TestFileSystem::RunTests(const std::string& filter) { | 20 void TestFileSystem::RunTests(const std::string& filter) { |
| 21 RUN_TEST_FORCEASYNC_AND_NOT(Open, filter); | 21 RUN_TEST_FORCEASYNC_AND_NOT(Open, filter); |
| 22 RUN_TEST_FORCEASYNC_AND_NOT(MultipleOpens, filter); | 22 RUN_TEST_FORCEASYNC_AND_NOT(MultipleOpens, filter); |
| 23 } | 23 } |
| 24 | 24 |
| 25 std::string TestFileSystem::TestOpen() { | 25 std::string TestFileSystem::TestOpen() { |
| 26 TestCompletionCallback callback(instance_->pp_instance(), force_async_); | 26 TestCompletionCallback callback(instance_->pp_instance(), force_async_); |
| 27 | 27 |
| 28 // Open. | 28 // Open. |
| 29 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 29 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 30 int32_t rv = file_system.Open(1024, callback); | 30 callback.WaitForResult(file_system.Open(1024, callback)); |
| 31 if (rv == PP_OK_COMPLETIONPENDING) | 31 CHECK_CALLBACK_BEHAVIOR(callback); |
| 32 rv = callback.WaitForResult(); | 32 ASSERT_EQ(PP_OK, callback.result()); |
| 33 if (rv != PP_OK) | |
| 34 return ReportError("FileSystem::Open", rv); | |
| 35 | 33 |
| 36 // Open aborted (see the DirectoryReader test for comments). | 34 // Open aborted (see the DirectoryReader test for comments). |
| 37 callback.reset_run_count(); | 35 int32_t rv = 0; |
| 38 rv = pp::FileSystem(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY) | 36 { |
| 39 .Open(1024, callback); | 37 rv = pp::FileSystem(instance_, |
| 40 if (callback.run_count() > 0) | 38 PP_FILESYSTEMTYPE_LOCALTEMPORARY).Open(1024, callback); |
| 41 return "FileSystem::Open ran callback synchronously."; | |
| 42 if (force_async_ && rv != PP_OK_COMPLETIONPENDING) | |
| 43 return ReportError("FileSystem::Open force_async", rv); | |
| 44 if (rv == PP_OK_COMPLETIONPENDING) { | |
| 45 rv = callback.WaitForResult(); | |
| 46 if (rv != PP_ERROR_ABORTED) | |
| 47 return "FileSystem::Open not aborted."; | |
| 48 } else if (rv != PP_OK) { | |
| 49 return ReportError("FileSystem::Open", rv); | |
| 50 } | 39 } |
| 40 callback.WaitForAbortResult(rv); |
| 41 CHECK_CALLBACK_BEHAVIOR(callback); |
| 51 | 42 |
| 52 PASS(); | 43 PASS(); |
| 53 } | 44 } |
| 54 | 45 |
| 55 std::string TestFileSystem::TestMultipleOpens() { | 46 std::string TestFileSystem::TestMultipleOpens() { |
| 56 // Should not allow multiple opens, no matter the first open has completed or | 47 // Should not allow multiple opens, regardless of whether or not the first |
| 57 // not. | 48 // open has completed. |
| 58 TestCompletionCallback callback_1(instance_->pp_instance(), force_async_); | 49 TestCompletionCallback callback_1(instance_->pp_instance(), force_async_); |
| 59 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); | 50 pp::FileSystem file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); |
| 60 int32_t rv_1 = file_system.Open(1024, callback_1); | 51 int32_t rv_1 = file_system.Open(1024, callback_1); |
| 61 if (callback_1.run_count() > 0) | |
| 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); | |
| 65 | 52 |
| 66 TestCompletionCallback callback_2(instance_->pp_instance(), force_async_); | 53 TestCompletionCallback callback_2(instance_->pp_instance(), force_async_); |
| 67 int32_t rv_2 = file_system.Open(1024, callback_2); | 54 callback_2.WaitForResult(file_system.Open(1024, callback_2)); |
| 68 if (force_async_ && rv_2 != PP_OK_COMPLETIONPENDING) | 55 CHECK_CALLBACK_BEHAVIOR(callback_2); |
| 69 return ReportError("FileSystem::Open2 force_async", rv_2); | 56 // FileSystem should not allow multiple opens. |
| 70 if (rv_2 == PP_OK_COMPLETIONPENDING) | 57 ASSERT_NE(PP_OK, callback_2.result()); |
| 71 rv_2 = callback_2.WaitForResult(); | |
| 72 if (rv_2 == PP_OK) | |
| 73 return "FileSystem::Open2 should not allow multiple opens."; | |
| 74 | 58 |
| 75 if (rv_1 == PP_OK_COMPLETIONPENDING) | 59 callback_1.WaitForResult(rv_1); |
| 76 rv_1 = callback_1.WaitForResult(); | 60 CHECK_CALLBACK_BEHAVIOR(callback_1); |
| 77 if (rv_1 != PP_OK) | 61 ASSERT_EQ(PP_OK, callback_1.result()); |
| 78 return ReportError("FileSystem::Open1", rv_1); | |
| 79 | 62 |
| 80 TestCompletionCallback callback_3(instance_->pp_instance(), force_async_); | 63 TestCompletionCallback callback_3(instance_->pp_instance(), force_async_); |
| 81 int32_t rv_3 = file_system.Open(1024, callback_3); | 64 callback_3.WaitForResult(file_system.Open(1024, callback_3)); |
| 82 if (force_async_ && rv_3 != PP_OK_COMPLETIONPENDING) | 65 CHECK_CALLBACK_BEHAVIOR(callback_3); |
| 83 return ReportError("FileSystem::Open3 force_async", rv_3); | 66 ASSERT_NE(PP_OK, callback_3.result()); |
| 84 if (rv_3 == PP_OK_COMPLETIONPENDING) | |
| 85 rv_3 = callback_3.WaitForResult(); | |
| 86 if (rv_3 == PP_OK) | |
| 87 return "FileSystem::Open3 should not allow multiple opens."; | |
| 88 | 67 |
| 89 PASS(); | 68 PASS(); |
| 90 } | 69 } |
| OLD | NEW |