diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 00:36:22 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-04 00:36:22 +0000 |
commit | de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019 (patch) | |
tree | 7e714193e2f5abad3d3ca54d353b62a7f9ebf7e3 /ppapi/tests/test_utils.cc | |
parent | f8ce465c025d457778f8376eca12d94e723965bb (diff) | |
download | chromium_src-de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019.zip chromium_src-de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019.tar.gz chromium_src-de9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019.tar.bz2 |
Pepper's directory reader implementation + test.
BUG=none
TEST=test_directory_reader.cc
Review URL: http://codereview.chromium.org/4107004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65002 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_utils.cc')
-rw-r--r-- | ppapi/tests/test_utils.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/ppapi/tests/test_utils.cc b/ppapi/tests/test_utils.cc new file mode 100644 index 0000000..a062922 --- /dev/null +++ b/ppapi/tests/test_utils.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2010 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_utils.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/cpp/module.h" + +const PPB_Testing_Dev* GetTestingInterface() { + static const PPB_Testing_Dev* g_testing_interface = + reinterpret_cast<PPB_Testing_Dev const*>( + pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE)); + return g_testing_interface; +} + +std::string ReportError(const char* method, int32_t error) { + char error_as_string[12]; + sprintf(error_as_string, "%d", error); + std::string result = method + std::string(" failed with error: ") + + error_as_string; + if (error == PP_ERROR_NOSPACE) + result += ". Did you run the test with --unlimited-quota-for-files?"; + return result; +} + +TestCompletionCallback::TestCompletionCallback() + : result_(PP_ERROR_WOULDBLOCK), + post_quit_task_(false) { +} + +int32_t TestCompletionCallback::WaitForResult() { + result_ = PP_ERROR_WOULDBLOCK; // Reset + post_quit_task_ = true; + GetTestingInterface()->RunMessageLoop(); + return result_; +} + +TestCompletionCallback::operator pp::CompletionCallback() const { + return pp::CompletionCallback(&TestCompletionCallback::Handler, + const_cast<TestCompletionCallback*>(this)); +} + +// static +void TestCompletionCallback::Handler(void* user_data, int32_t result) { + TestCompletionCallback* callback = + static_cast<TestCompletionCallback*>(user_data); + callback->result_ = result; + if (callback->post_quit_task_) { + callback->post_quit_task_ = false; + GetTestingInterface()->QuitMessageLoop(); + } +} |