diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-28 22:17:15 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-28 22:17:15 +0000 |
commit | 95caad2e61b35b02db3aa2cb8c3b2d58c49a8e37 (patch) | |
tree | 1655b1aecb32691f939ed83f35e4cb9c61c81f2e /ppapi/tests/test_file_system.cc | |
parent | d58ff1d5cb29625e031c15f57512bba18a9a46c8 (diff) | |
download | chromium_src-95caad2e61b35b02db3aa2cb8c3b2d58c49a8e37.zip chromium_src-95caad2e61b35b02db3aa2cb8c3b2d58c49a8e37.tar.gz chromium_src-95caad2e61b35b02db3aa2cb8c3b2d58c49a8e37.tar.bz2 |
Don't allow multiple opens for Pepper FileSystem.
BUG=73667
TEST=test_file_system.{h,cc}
Review URL: http://codereview.chromium.org/6596026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76278 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_file_system.cc')
-rw-r--r-- | ppapi/tests/test_file_system.cc | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/ppapi/tests/test_file_system.cc b/ppapi/tests/test_file_system.cc new file mode 100644 index 0000000..958f896 --- /dev/null +++ b/ppapi/tests/test_file_system.cc @@ -0,0 +1,79 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/tests/test_file_system.h" + +#include <string.h> + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/dev/file_system_dev.h" +#include "ppapi/tests/test_utils.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(FileSystem); + +bool TestFileSystem::Init() { + return InitTestingInterface() && EnsureRunningOverHTTP(); +} + +void TestFileSystem::RunTest() { + RUN_TEST(Open); + RUN_TEST(MultipleOpens); +} + +std::string TestFileSystem::TestOpen() { + TestCompletionCallback callback(instance_->pp_instance()); + + // Open. + pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); + int32_t rv = file_system.Open(1024, callback); + if (rv == PP_ERROR_WOULDBLOCK) + rv = callback.WaitForResult(); + if (rv != PP_OK) + return ReportError("FileSystem::Open", rv); + + // Open aborted (see the DirectoryReader test for comments). + callback.reset_run_count(); + rv = pp::FileSystem_Dev(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY) + .Open(1024, callback); + if (callback.run_count() > 0) + return "FileSystem::Open ran callback synchronously."; + if (rv == PP_ERROR_WOULDBLOCK) { + rv = callback.WaitForResult(); + if (rv != PP_ERROR_ABORTED) + return "FileSystem::Open not aborted."; + } else if (rv != PP_OK) { + return ReportError("FileSystem::Open", rv); + } + + PASS(); +} + +std::string TestFileSystem::TestMultipleOpens() { + // Should not allow multiple opens, no matter the first open has completed or + // not. + TestCompletionCallback callback_1(instance_->pp_instance()); + pp::FileSystem_Dev file_system(instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); + int32_t rv_1 = file_system.Open(1024, callback_1); + if (callback_1.run_count() > 0) + return "FileSystem::Open ran callback synchronously."; + + TestCompletionCallback callback_2(instance_->pp_instance()); + int32_t rv_2 = file_system.Open(1024, callback_2); + if (rv_2 == PP_ERROR_WOULDBLOCK || rv_2 == PP_OK) + return "FileSystem::Open should not allow multiple opens."; + + if (rv_1 == PP_ERROR_WOULDBLOCK) + rv_1 = callback_1.WaitForResult(); + if (rv_1 != PP_OK) + return ReportError("FileSystem::Open", rv_1); + + TestCompletionCallback callback_3(instance_->pp_instance()); + int32_t rv_3 = file_system.Open(1024, callback_3); + if (rv_3 == PP_ERROR_WOULDBLOCK || rv_3 == PP_OK) + return "FileSystem::Open should not allow multiple opens."; + + PASS(); +} + |