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