summaryrefslogtreecommitdiffstats
path: root/ppapi
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 00:36:22 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 00:36:22 +0000
commitde9bdd1e4d2f87f53b1c2d3eacfbe43ef6ca1019 (patch)
tree7e714193e2f5abad3d3ca54d353b62a7f9ebf7e3 /ppapi
parentf8ce465c025d457778f8376eca12d94e723965bb (diff)
downloadchromium_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')
-rw-r--r--ppapi/ppapi.gyp4
-rw-r--r--ppapi/tests/test_case.cc27
-rw-r--r--ppapi/tests/test_case.h6
-rw-r--r--ppapi/tests/test_directory_reader.cc143
-rw-r--r--ppapi/tests/test_directory_reader.h25
-rw-r--r--ppapi/tests/test_file_io.cc60
-rw-r--r--ppapi/tests/test_file_ref.cc60
-rw-r--r--ppapi/tests/test_transport.cc18
-rw-r--r--ppapi/tests/test_transport.h6
-rw-r--r--ppapi/tests/test_url_loader.cc63
-rw-r--r--ppapi/tests/test_url_util.cc1
-rw-r--r--ppapi/tests/test_utils.cc53
-rw-r--r--ppapi/tests/test_utils.h32
-rw-r--r--ppapi/tests/test_var.cc14
-rw-r--r--ppapi/tests/test_var.h2
15 files changed, 301 insertions, 213 deletions
diff --git a/ppapi/ppapi.gyp b/ppapi/ppapi.gyp
index 2af075f..3a747d7 100644
--- a/ppapi/ppapi.gyp
+++ b/ppapi/ppapi.gyp
@@ -421,6 +421,8 @@
'tests/test_buffer.h',
'tests/test_char_set.cc',
'tests/test_char_set.h',
+ 'tests/test_directory_reader.cc',
+ 'tests/test_directory_reader.h',
'tests/test_file_io.cc',
'tests/test_file_io.h',
'tests/test_file_ref.cc',
@@ -439,6 +441,8 @@
'tests/test_url_loader.h',
'tests/test_url_util.cc',
'tests/test_url_util.h',
+ 'tests/test_utils.cc',
+ 'tests/test_utils.h',
'tests/test_var.cc',
'tests/test_var.h',
diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc
index a37bfc3..20a7f5f 100644
--- a/ppapi/tests/test_case.cc
+++ b/ppapi/tests/test_case.cc
@@ -6,6 +6,9 @@
#include <sstream>
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
+
std::string TestCase::MakeFailureMessage(const char* file,
int line,
const char* cmd) {
@@ -35,3 +38,27 @@ pp::deprecated::ScriptableObject* TestCase::CreateTestObject() {
return NULL;
}
+bool TestCase::InitTestingInterface() {
+ if (!GetTestingInterface()) {
+ // Give a more helpful error message for the testing interface being gone
+ // since that needs special enabling in Chrome.
+ instance_->AppendError("This test needs the testing interface, which is "
+ "not currently available. In Chrome, use "
+ "--enable-pepper-testing when launching.");
+ return false;
+ }
+
+ return true;
+}
+
+bool TestCase::EnsureRunningOverHTTP() {
+ pp::Var window = instance_->GetWindowObject();
+ pp::Var location = window.GetProperty("location");
+ pp::Var protocol = location.GetProperty("protocol");
+ if (!protocol.is_string() || protocol.AsString() != "http:") {
+ instance_->AppendError("This test needs to be run over HTTP.");
+ return false;
+ }
+
+ return true;
+}
diff --git a/ppapi/tests/test_case.h b/ppapi/tests/test_case.h
index 0ca6d8e..35026fe 100644
--- a/ppapi/tests/test_case.h
+++ b/ppapi/tests/test_case.h
@@ -47,6 +47,12 @@ class TestCase {
// caller. Return NULL if there is no supported test object (the default).
virtual pp::deprecated::ScriptableObject* CreateTestObject();
+ // Initializes the testing interface.
+ bool InitTestingInterface();
+
+ // Makes sure the test is run over HTTP.
+ bool EnsureRunningOverHTTP();
+
// Pointer to the instance that owns us.
TestingInstance* instance_;
diff --git a/ppapi/tests/test_directory_reader.cc b/ppapi/tests/test_directory_reader.cc
new file mode 100644
index 0000000..d8bf737
--- /dev/null
+++ b/ppapi/tests/test_directory_reader.cc
@@ -0,0 +1,143 @@
+// 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_directory_reader.h"
+
+#include <stdio.h>
+#include <set>
+#include <vector>
+
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/c/dev/ppb_file_io_dev.h"
+#include "ppapi/cpp/dev/directory_entry_dev.h"
+#include "ppapi/cpp/dev/directory_reader_dev.h"
+#include "ppapi/cpp/dev/file_io_dev.h"
+#include "ppapi/cpp/dev/file_ref_dev.h"
+#include "ppapi/cpp/dev/file_system_dev.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
+
+REGISTER_TEST_CASE(DirectoryReader);
+
+namespace {
+
+std::string IntegerToString(int value) {
+ char result[12];
+ sprintf(result, "%d", value);
+ return result;
+}
+
+} // namespace
+
+bool TestDirectoryReader::Init() {
+ return InitTestingInterface() && EnsureRunningOverHTTP();
+}
+
+void TestDirectoryReader::RunTest() {
+ RUN_TEST(GetNextFile);
+}
+
+std::string TestDirectoryReader::TestGetNextFile() {
+ TestCompletionCallback callback;
+ 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);
+
+ pp::FileRef_Dev dir_ref(file_system, "/");
+ pp::FileRef_Dev file_ref_1(file_system, "/file_1");
+ pp::FileRef_Dev file_ref_2(file_system, "/file_2");
+ pp::FileRef_Dev file_ref_3(file_system, "/file_3");
+
+ pp::FileIO_Dev file_io_1;
+ rv = file_io_1.Open(file_ref_1, PP_FILEOPENFLAG_CREATE, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+ pp::FileIO_Dev file_io_2;
+ rv = file_io_2.Open(file_ref_2, PP_FILEOPENFLAG_CREATE, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+ pp::FileIO_Dev file_io_3;
+ rv = file_io_3.Open(file_ref_3, PP_FILEOPENFLAG_CREATE, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileIO::Open", rv);
+
+ pp::FileRef_Dev dir_ref_1(file_system, "/dir_1");
+ pp::FileRef_Dev dir_ref_2(file_system, "/dir_2");
+ pp::FileRef_Dev dir_ref_3(file_system, "/dir_3");
+ rv = dir_ref_1.MakeDirectory(callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileRef::MakeDirectory", rv);
+ rv = dir_ref_2.MakeDirectory(callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileRef::MakeDirectory", rv);
+ rv = dir_ref_3.MakeDirectory(callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("FileRef::MakeDirectory", rv);
+
+ pp::DirectoryReader_Dev directory_reader(dir_ref);
+ std::vector<pp::DirectoryEntry_Dev> entries;
+ pp::DirectoryEntry_Dev entry;
+ do {
+ rv = directory_reader.GetNextEntry(&entry, callback);
+ if (rv == PP_ERROR_WOULDBLOCK)
+ rv = callback.WaitForResult();
+ if (rv != PP_OK)
+ return ReportError("DirectoryReader::GetNextEntry", rv);
+ if (!entry.is_null())
+ entries.push_back(entry);
+ } while (!entry.is_null());
+
+ if (entries.size() != 6)
+ return "Expected 6 entries, got " + IntegerToString(entries.size());
+
+ std::set<std::string> expected_file_names;
+ expected_file_names.insert("/file_1");
+ expected_file_names.insert("/file_2");
+ expected_file_names.insert("/file_3");
+
+ std::set<std::string> expected_dir_names;
+ expected_dir_names.insert("/dir_1");
+ expected_dir_names.insert("/dir_2");
+ expected_dir_names.insert("/dir_3");
+
+ for (std::vector<pp::DirectoryEntry_Dev>::const_iterator it = entries.begin();
+ it != entries.end(); it++) {
+ pp::FileRef_Dev file_ref = it->file_ref();
+ std::string file_path = file_ref.GetPath().AsString();
+ std::set<std::string>::iterator found = expected_file_names.find(file_path);
+ if (found != expected_file_names.end()) {
+ if (it->file_type() != PP_FILETYPE_REGULAR)
+ return file_path + " should have been a regular file.";
+ expected_file_names.erase(found);
+ } else {
+ found = expected_dir_names.find(file_path);
+ if (found == expected_dir_names.end())
+ return "Unexpected file path: " + file_path;
+ if (it->file_type() != PP_FILETYPE_DIRECTORY)
+ return file_path + " should have been a directory.";
+ expected_dir_names.erase(found);
+ }
+ }
+ if (!expected_file_names.empty() || !expected_dir_names.empty())
+ return "Expected more file paths.";
+
+ return "";
+}
diff --git a/ppapi/tests/test_directory_reader.h b/ppapi/tests/test_directory_reader.h
new file mode 100644
index 0000000..932d1b3
--- /dev/null
+++ b/ppapi/tests/test_directory_reader.h
@@ -0,0 +1,25 @@
+// 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.
+
+#ifndef PAPPI_TESTS_TEST_DIRECTORY_READER_H_
+#define PAPPI_TESTS_TEST_DIRECTORY_READER_H_
+
+#include <string>
+
+#include "ppapi/tests/test_case.h"
+
+class TestDirectoryReader : public TestCase {
+ public:
+ explicit TestDirectoryReader(TestingInstance* instance)
+ : TestCase(instance) {}
+
+ // TestCase implementation.
+ virtual bool Init();
+ virtual void RunTest();
+
+ private:
+ std::string TestGetNextFile();
+};
+
+#endif // PAPPI_TESTS_TEST_DIRECTORY_READER_H_
diff --git a/ppapi/tests/test_file_io.cc b/ppapi/tests/test_file_io.cc
index 300052d..5ba571a 100644
--- a/ppapi/tests/test_file_io.cc
+++ b/ppapi/tests/test_file_io.cc
@@ -14,49 +14,13 @@
#include "ppapi/cpp/dev/file_system_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(FileIO);
namespace {
-const PPB_Testing_Dev* g_testing_interface;
-
-class TestCompletionCallback {
- public:
- TestCompletionCallback() : result_(PP_ERROR_WOULDBLOCK) {
- }
-
- operator pp::CompletionCallback() const {
- return pp::CompletionCallback(&TestCompletionCallback::Handler,
- const_cast<TestCompletionCallback*>(this));
- }
-
- int32_t WaitForResult() {
- result_ = PP_ERROR_WOULDBLOCK; // Reset
- g_testing_interface->RunMessageLoop();
- return result_;
- }
-
- private:
- static void Handler(void* user_data, int32_t result) {
- static_cast<TestCompletionCallback*>(user_data)->result_ = result;
- g_testing_interface->QuitMessageLoop();
- }
-
- int32_t result_;
-};
-
-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;
-}
-
std::string ReportMismatch(const std::string& method_name,
const std::string& returned_result,
const std::string& expected_result) {
@@ -112,27 +76,7 @@ int32_t WriteEntireBuffer(pp::FileIO_Dev* file_io,
} // namespace
bool TestFileIO::Init() {
- g_testing_interface = reinterpret_cast<PPB_Testing_Dev const*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE));
- if (!g_testing_interface) {
- // Give a more helpful error message for the testing interface being gone
- // since that needs special enabling in Chrome.
- instance_->AppendError("This test needs the testing interface, which is "
- "not currently available. In Chrome, use --enable-pepper-testing when "
- "launching.");
- return false;
- }
-
- // Make sure we're running over HTTP.
- pp::Var window = instance_->GetWindowObject();
- pp::Var location = window.GetProperty("location");
- pp::Var protocol = location.GetProperty("protocol");
- if (!protocol.is_string() || protocol.AsString() != "http:") {
- instance_->AppendError("This test needs to be run over HTTP.");
- return false;
- }
-
- return true;
+ return InitTestingInterface() && EnsureRunningOverHTTP();
}
void TestFileIO::RunTest() {
diff --git a/ppapi/tests/test_file_ref.cc b/ppapi/tests/test_file_ref.cc
index b83a2f4..513f5dd 100644
--- a/ppapi/tests/test_file_ref.cc
+++ b/ppapi/tests/test_file_ref.cc
@@ -17,6 +17,7 @@
#include "ppapi/cpp/dev/url_response_info_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(FileRef);
@@ -29,33 +30,6 @@ const char* kParentPath = "/foo/bar";
const char* kPersFilePath = "/foo/bar/persistent";
const char* kTempFilePath = "/foo/bar/temporary";
-const PPB_Testing_Dev* g_testing_interface;
-
-class TestCompletionCallback {
- public:
- TestCompletionCallback() : result_(PP_ERROR_WOULDBLOCK) {
- }
-
- operator pp::CompletionCallback() const {
- return pp::CompletionCallback(&TestCompletionCallback::Handler,
- const_cast<TestCompletionCallback*>(this));
- }
-
- int32_t WaitForResult() {
- result_ = PP_ERROR_WOULDBLOCK; // Reset
- g_testing_interface->RunMessageLoop();
- return result_;
- }
-
- private:
- static void Handler(void* user_data, int32_t result) {
- static_cast<TestCompletionCallback*>(user_data)->result_ = result;
- g_testing_interface->QuitMessageLoop();
- }
-
- int32_t result_;
-};
-
std::string ReportMismatch(const std::string& method_name,
const std::string& returned_result,
const std::string& expected_result) {
@@ -63,40 +37,10 @@ std::string ReportMismatch(const std::string& method_name,
expected_result + "' expected.";
}
-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;
-}
-
} // namespace
bool TestFileRef::Init() {
- g_testing_interface = reinterpret_cast<PPB_Testing_Dev const*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE));
- if (!g_testing_interface) {
- // Give a more helpful error message for the testing interface being gone
- // since that needs special enabling in Chrome.
- instance_->AppendError("This test needs the testing interface, which is "
- "not currently available. In Chrome, use --enable-pepper-testing when "
- "launching.");
- return false;
- }
-
- // Make sure we're running over HTTP.
- pp::Var window = instance_->GetWindowObject();
- pp::Var location = window.GetProperty("location");
- pp::Var protocol = location.GetProperty("protocol");
- if (!protocol.is_string() || protocol.AsString() != "http:") {
- instance_->AppendError("This test needs to be run over HTTP.");
- return false;
- }
-
- return true;
+ return InitTestingInterface() && EnsureRunningOverHTTP();
}
void TestFileRef::RunTest() {
diff --git a/ppapi/tests/test_transport.cc b/ppapi/tests/test_transport.cc
index 9f506f6..2f3c09f 100644
--- a/ppapi/tests/test_transport.cc
+++ b/ppapi/tests/test_transport.cc
@@ -14,6 +14,7 @@
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(Transport);
@@ -21,17 +22,7 @@ REGISTER_TEST_CASE(Transport);
bool TestTransport::Init() {
transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>(
pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE));
- testing_interface_ = reinterpret_cast<PPB_Testing_Dev const*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE));
- if (!testing_interface_) {
- // Give a more helpful error message for the testing interface being gone
- // since that needs special enabling in Chrome.
- instance_->AppendError("This test needs the testing interface, which is "
- "not currently available. In Chrome, use --enable-pepper-testing when "
- "launching.");
- }
-
- return transport_interface_ && testing_interface_;
+ return transport_interface_ && InitTestingInterface();
}
void TestTransport::RunTest() {
@@ -39,12 +30,7 @@ void TestTransport::RunTest() {
// TODO(juberti): more Transport tests here...
}
-void TestTransport::QuitMessageLoop() {
- testing_interface_->QuitMessageLoop();
-}
-
std::string TestTransport::TestFirstTransport() {
// TODO(juberti): actual test
return "";
}
-
diff --git a/ppapi/tests/test_transport.h b/ppapi/tests/test_transport.h
index f7b57be..e52983a 100644
--- a/ppapi/tests/test_transport.h
+++ b/ppapi/tests/test_transport.h
@@ -7,10 +7,8 @@
#include <string>
-#include "ppapi/c/pp_stdint.h"
#include "ppapi/tests/test_case.h"
-struct PPB_Testing_Dev;
struct PPB_Transport_Dev;
namespace pp {
@@ -25,15 +23,11 @@ class TestTransport : public TestCase {
virtual bool Init();
virtual void RunTest();
- void QuitMessageLoop();
-
private:
std::string TestFirstTransport();
// Used by the tests that access the C API directly.
- const PPB_Testing_Dev* testing_interface_;
const PPB_Transport_Dev* transport_interface_;
};
#endif // PAPPI_TESTS_TEST_TRANSPORT_H_
-
diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc
index 9fb64f2..b1cdd6f 100644
--- a/ppapi/tests/test_url_loader.cc
+++ b/ppapi/tests/test_url_loader.cc
@@ -5,13 +5,12 @@
#include "ppapi/tests/test_url_loader.h"
#include <stdio.h>
-#include <string.h>
+#include <string>
#include "ppapi/c/dev/ppb_file_io_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_url_loader_dev.h"
#include "ppapi/c/pp_errors.h"
-#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/dev/file_io_dev.h"
#include "ppapi/cpp/dev/file_ref_dev.h"
#include "ppapi/cpp/dev/file_system_dev.h"
@@ -20,69 +19,13 @@
#include "ppapi/cpp/dev/url_response_info_dev.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(URLLoader);
-namespace {
-
-const PPB_Testing_Dev* g_testing_interface;
-
-class TestCompletionCallback {
- public:
- TestCompletionCallback() : result_(PP_ERROR_WOULDBLOCK) {
- }
-
- operator pp::CompletionCallback() const {
- return pp::CompletionCallback(&TestCompletionCallback::Handler,
- const_cast<TestCompletionCallback*>(this));
- }
-
- int32_t WaitForResult() {
- result_ = PP_ERROR_WOULDBLOCK; // Reset
- g_testing_interface->RunMessageLoop();
- return result_;
- }
-
- private:
- static void Handler(void* user_data, int32_t result) {
- static_cast<TestCompletionCallback*>(user_data)->result_ = result;
- g_testing_interface->QuitMessageLoop();
- }
-
- int32_t result_;
-};
-
-std::string ReportError(const char* method, int32_t error) {
- char error_as_string[12];
- sprintf(error_as_string, "%d", error);
- return method + std::string(" failed with error: ") + error_as_string;
-}
-
-} // namespace
-
bool TestURLLoader::Init() {
- g_testing_interface = reinterpret_cast<PPB_Testing_Dev const*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE));
- if (!g_testing_interface) {
- // Give a more helpful error message for the testing interface being gone
- // since that needs special enabling in Chrome.
- instance_->AppendError("This test needs the testing interface, which is "
- "not currently available. In Chrome, use --enable-pepper-testing when "
- "launching.");
- return false;
- }
-
- // Make sure we're running over HTTP.
- pp::Var window = instance_->GetWindowObject();
- pp::Var location = window.GetProperty("location");
- pp::Var protocol = location.GetProperty("protocol");
- if (!protocol.is_string() || protocol.AsString() != "http:") {
- instance_->AppendError("This test needs to be run over HTTP.");
- return false;
- }
-
- return true;
+ return InitTestingInterface() && EnsureRunningOverHTTP();
}
void TestURLLoader::RunTest() {
diff --git a/ppapi/tests/test_url_util.cc b/ppapi/tests/test_url_util.cc
index a5749d7..ea91506 100644
--- a/ppapi/tests/test_url_util.cc
+++ b/ppapi/tests/test_url_util.cc
@@ -115,4 +115,3 @@ std::string TestUrlUtil::TestDocumentCanAccessDocument() {
ASSERT_TRUE(util_->DocumentCanAccessDocument(*instance_, *instance_));
return std::string();
}
-
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();
+ }
+}
diff --git a/ppapi/tests/test_utils.h b/ppapi/tests/test_utils.h
new file mode 100644
index 0000000..7af515d
--- /dev/null
+++ b/ppapi/tests/test_utils.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef PPAPI_TESTS_TEST_UTILS_H_
+#define PPAPI_TESTS_TEST_UTILS_H_
+
+#include <string>
+
+#include "ppapi/c/dev/ppb_testing_dev.h"
+#include "ppapi/c/pp_stdint.h"
+#include "ppapi/cpp/completion_callback.h"
+
+const PPB_Testing_Dev* GetTestingInterface();
+std::string ReportError(const char* method, int32_t error);
+
+class TestCompletionCallback {
+ public:
+ TestCompletionCallback();
+
+ int32_t WaitForResult();
+
+ operator pp::CompletionCallback() const;
+
+ private:
+ static void Handler(void* user_data, int32_t result);
+
+ int32_t result_;
+ bool post_quit_task_;
+};
+
+#endif // PPAPI_TESTS_TEST_UTILS_H_
diff --git a/ppapi/tests/test_var.cc b/ppapi/tests/test_var.cc
index efd0dd1..c9a1339 100644
--- a/ppapi/tests/test_var.cc
+++ b/ppapi/tests/test_var.cc
@@ -7,10 +7,10 @@
#include <limits>
#include "ppapi/c/pp_var.h"
-#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
+#include "ppapi/tests/test_utils.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(Var);
@@ -24,16 +24,7 @@ pp::Var adoptVar(PP_Var var) {
bool TestVar::Init() {
var_interface_ = reinterpret_cast<PPB_Var const*>(
pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE));
- testing_interface_ = reinterpret_cast<PPB_Testing_Dev const*>(
- pp::Module::Get()->GetBrowserInterface(PPB_TESTING_DEV_INTERFACE));
- if (!testing_interface_) {
- // Give a more helpful error message for the testing interface being gone
- // since that needs special enabling in Chrome.
- instance_->AppendError("This test needs the testing interface, which is "
- "not currently available. In Chrome, use --enable-pepper-testing when "
- "launching.");
- }
- return var_interface_ && testing_interface_;
+ return var_interface_ && InitTestingInterface();
}
void TestVar::RunTest() {
@@ -175,4 +166,3 @@ std::string TestVar::TestDefineProperty() {
PASS();
}
-
diff --git a/ppapi/tests/test_var.h b/ppapi/tests/test_var.h
index 8499003..3a0229b 100644
--- a/ppapi/tests/test_var.h
+++ b/ppapi/tests/test_var.h
@@ -9,7 +9,6 @@
#include "ppapi/tests/test_case.h"
-struct PPB_Testing_Dev;
struct PPB_Var;
class TestVar : public TestCase {
@@ -26,7 +25,6 @@ class TestVar : public TestCase {
// Used by the tests that access the C API directly.
const PPB_Var* var_interface_;
- const PPB_Testing_Dev* testing_interface_;
};
#endif // PPAPI_TEST_TEST_VAR_H_