diff options
author | mseaborn <mseaborn@chromium.org> | 2016-03-18 10:56:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 17:57:48 +0000 |
commit | 71342af724ecbe78440633917afa943a2eb0e4b8 (patch) | |
tree | bd3d92682be6c92e0942133e3c0c80d74d83aaa5 /ppapi | |
parent | 71bf1f91727ff40b75ebe08477f4c192101c4b15 (diff) | |
download | chromium_src-71342af724ecbe78440633917afa943a2eb0e4b8.zip chromium_src-71342af724ecbe78440633917afa943a2eb0e4b8.tar.gz chromium_src-71342af724ecbe78440633917afa943a2eb0e4b8.tar.bz2 |
NaCl cleanup: Move ppapi_test_lib to chrome/test/data/nacl/, where it's used
This moves it out of ppapi/native_client/tests/, which is a directory
of deprecated things.
I've changed #include ordering to pass the presubmit checks, and also
removed some unused #includes of
native_client/src/shared/platform/nacl_check.h.
BUG=154400
TEST=browser_tests
Review URL: https://codereview.chromium.org/1815113002
Cr-Commit-Position: refs/heads/master@{#382012}
Diffstat (limited to 'ppapi')
10 files changed, 0 insertions, 1068 deletions
diff --git a/ppapi/native_client/DEPS b/ppapi/native_client/DEPS index 64d0e99..9b7539d 100644 --- a/ppapi/native_client/DEPS +++ b/ppapi/native_client/DEPS @@ -1,5 +1,4 @@ include_rules = [ "+native_client/src/include", - "+native_client/src/shared/platform", "+native_client/src/untrusted", ] diff --git a/ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.cc b/ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.cc deleted file mode 100644 index f960cbc..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.cc +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (c) 2012 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 "native_client/src/shared/platform/nacl_check.h" - -#include "ppapi/c/dev/ppb_memory_dev.h" -#include "ppapi/c/dev/ppb_var_deprecated.h" -#include "ppapi/c/ppb_audio.h" -#include "ppapi/c/ppb_audio_config.h" -#include "ppapi/c/ppb_core.h" -#include "ppapi/c/ppb_file_io.h" -#include "ppapi/c/ppb_file_ref.h" -#include "ppapi/c/ppb_file_system.h" -#include "ppapi/c/ppb_fullscreen.h" -#include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/c/ppb_graphics_3d.h" -#include "ppapi/c/ppb_image_data.h" -#include "ppapi/c/ppb_input_event.h" -#include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_messaging.h" -#include "ppapi/c/ppb_mouse_cursor.h" -#include "ppapi/c/ppb_opengles2.h" -#include "ppapi/c/ppb_url_loader.h" -#include "ppapi/c/ppb_url_request_info.h" -#include "ppapi/c/ppb_url_response_info.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/ppb_view.h" -#include "ppapi/c/private/ppb_testing_private.h" - -#include "ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h" -#include "ppapi/native_client/tests/ppapi_test_lib/internal_utils.h" - -// Use for dev interfaces that might not be present. -const void* GetBrowserInterface(const char* interface_name) { - return (*ppb_get_interface())(interface_name); -} - -// Use for stable interfaces that must always be present. -const void* GetBrowserInterfaceSafe(const char* interface_name) { - const void* ppb_interface = (*ppb_get_interface())(interface_name); - CHECK(ppb_interface != NULL); - return ppb_interface; -} - -// Stable interfaces. - -const PPB_Audio* PPBAudio() { - return reinterpret_cast<const PPB_Audio*>( - GetBrowserInterfaceSafe(PPB_AUDIO_INTERFACE)); -} - -const PPB_AudioConfig* PPBAudioConfig() { - return reinterpret_cast<const PPB_AudioConfig*>( - GetBrowserInterfaceSafe(PPB_AUDIO_CONFIG_INTERFACE)); -} - -const PPB_Core* PPBCore() { - return reinterpret_cast<const PPB_Core*>( - GetBrowserInterfaceSafe(PPB_CORE_INTERFACE)); -} - -const PPB_FileIO* PPBFileIO() { - return reinterpret_cast<const PPB_FileIO*>( - GetBrowserInterfaceSafe(PPB_FILEIO_INTERFACE)); -} - -const PPB_FileRef* PPBFileRef() { - return reinterpret_cast<const PPB_FileRef*>( - GetBrowserInterfaceSafe(PPB_FILEREF_INTERFACE)); -} - -const PPB_FileSystem* PPBFileSystem() { - return reinterpret_cast<const PPB_FileSystem*>( - GetBrowserInterfaceSafe(PPB_FILESYSTEM_INTERFACE)); -} - -const PPB_Fullscreen* PPBFullscreen() { - return reinterpret_cast<const PPB_Fullscreen*>( - GetBrowserInterfaceSafe(PPB_FULLSCREEN_INTERFACE)); -} - -const PPB_Graphics2D* PPBGraphics2D() { - return reinterpret_cast<const PPB_Graphics2D*>( - GetBrowserInterfaceSafe(PPB_GRAPHICS_2D_INTERFACE)); -} - -const PPB_Graphics3D* PPBGraphics3D() { - return reinterpret_cast<const PPB_Graphics3D*>( - GetBrowserInterfaceSafe(PPB_GRAPHICS_3D_INTERFACE)); -} - -const PPB_ImageData* PPBImageData() { - return reinterpret_cast<const PPB_ImageData*>( - GetBrowserInterfaceSafe(PPB_IMAGEDATA_INTERFACE)); -} - -const PPB_InputEvent* PPBInputEvent() { - return reinterpret_cast<const PPB_InputEvent*>( - GetBrowserInterfaceSafe(PPB_INPUT_EVENT_INTERFACE)); -} - -const PPB_Instance* PPBInstance() { - return reinterpret_cast<const PPB_Instance*>( - GetBrowserInterfaceSafe(PPB_INSTANCE_INTERFACE)); -} - -const PPB_KeyboardInputEvent* PPBKeyboardInputEvent() { - return reinterpret_cast<const PPB_KeyboardInputEvent*>( - GetBrowserInterfaceSafe(PPB_KEYBOARD_INPUT_EVENT_INTERFACE)); -} - -const PPB_Messaging* PPBMessaging() { - return reinterpret_cast<const PPB_Messaging*>( - GetBrowserInterfaceSafe(PPB_MESSAGING_INTERFACE)); -} - -const PPB_MouseCursor_1_0* PPBMouseCursor() { - return reinterpret_cast<const PPB_MouseCursor_1_0*>( - GetBrowserInterfaceSafe(PPB_MOUSECURSOR_INTERFACE_1_0)); -} - -const PPB_MouseInputEvent* PPBMouseInputEvent() { - return reinterpret_cast<const PPB_MouseInputEvent*>( - GetBrowserInterfaceSafe(PPB_MOUSE_INPUT_EVENT_INTERFACE)); -} - -const PPB_OpenGLES2* PPBOpenGLES2() { - return reinterpret_cast<const PPB_OpenGLES2*>( - GetBrowserInterfaceSafe(PPB_OPENGLES2_INTERFACE)); -} - -const PPB_URLLoader* PPBURLLoader() { - return reinterpret_cast<const PPB_URLLoader*>( - GetBrowserInterfaceSafe(PPB_URLLOADER_INTERFACE)); -} - -const PPB_URLRequestInfo* PPBURLRequestInfo() { - return reinterpret_cast<const PPB_URLRequestInfo*>( - GetBrowserInterfaceSafe(PPB_URLREQUESTINFO_INTERFACE)); -} - -const PPB_URLResponseInfo* PPBURLResponseInfo() { - return reinterpret_cast<const PPB_URLResponseInfo*>( - GetBrowserInterfaceSafe(PPB_URLRESPONSEINFO_INTERFACE)); -} - -const PPB_Var* PPBVar() { - return reinterpret_cast<const PPB_Var*>( - GetBrowserInterfaceSafe(PPB_VAR_INTERFACE)); -} - -const PPB_WheelInputEvent* PPBWheelInputEvent() { - return reinterpret_cast<const PPB_WheelInputEvent*>( - GetBrowserInterfaceSafe(PPB_WHEEL_INPUT_EVENT_INTERFACE)); -} - - -// Dev interfaces. - -const PPB_Memory_Dev* PPBMemoryDev() { - return reinterpret_cast<const PPB_Memory_Dev*>( - // Change to GetBrowserInterfaceSafe when moving out of dev. - GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); -} - -const PPB_Testing_Private* PPBTestingPrivate() { - return reinterpret_cast<const PPB_Testing_Private*>( - GetBrowserInterface(PPB_TESTING_PRIVATE_INTERFACE)); -} - -const PPB_View* PPBView() { - return reinterpret_cast<const PPB_View*>( - GetBrowserInterface(PPB_VIEW_INTERFACE)); -} diff --git a/ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h b/ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h deleted file mode 100644 index 0ed8c16..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2012 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. -// -// Defines helper functions for all interfaces supported by the Native Client -// proxy. - -#ifndef PPAPI_NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_GET_BROWSER_INTERFACE_H_ -#define PPAPI_NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_GET_BROWSER_INTERFACE_H_ - -#include "ppapi/c/ppb_audio.h" -#include "ppapi/c/ppb_audio_config.h" -#include "ppapi/c/ppb_core.h" -#include "ppapi/c/ppb_file_io.h" -#include "ppapi/c/ppb_file_ref.h" -#include "ppapi/c/ppb_file_system.h" -#include "ppapi/c/ppb_fullscreen.h" -#include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/c/ppb_graphics_3d.h" -#include "ppapi/c/ppb_image_data.h" -#include "ppapi/c/ppb_input_event.h" -#include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_messaging.h" -#include "ppapi/c/ppb_mouse_cursor.h" -#include "ppapi/c/ppb_opengles2.h" -#include "ppapi/c/ppb_url_loader.h" -#include "ppapi/c/ppb_url_request_info.h" -#include "ppapi/c/ppb_url_response_info.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/ppb_view.h" -#include "ppapi/c/dev/ppb_memory_dev.h" -#include "ppapi/c/private/ppb_testing_private.h" - -// Looks up the interface and returns its pointer or NULL. -const void* GetBrowserInterface(const char* interface_name); -// Uses GetBrowserInterface() and CHECKs for NULL. -const void* GetBrowserInterfaceSafe(const char* interface_name); - -// -// Stable interfaces. -// Lookup guarantees that the interface is available by using NULL CHECKs. -// - -const PPB_Audio* PPBAudio(); -const PPB_AudioConfig* PPBAudioConfig(); -const PPB_Core* PPBCore(); -const PPB_FileIO* PPBFileIO(); -const PPB_FileRef* PPBFileRef(); -const PPB_FileSystem* PPBFileSystem(); -const PPB_Fullscreen* PPBFullscreen(); -const PPB_Graphics2D* PPBGraphics2D(); -const PPB_Graphics3D* PPBGraphics3D(); -const PPB_ImageData* PPBImageData(); -const PPB_InputEvent* PPBInputEvent(); -const PPB_Instance* PPBInstance(); -const PPB_KeyboardInputEvent* PPBKeyboardInputEvent(); -const PPB_Messaging* PPBMessaging(); -const PPB_MouseCursor* PPBMouseCursor(); -const PPB_MouseInputEvent* PPBMouseInputEvent(); -const PPB_OpenGLES2* PPBOpenGLES2(); -const PPB_URLLoader* PPBURLLoader(); -const PPB_URLRequestInfo* PPBURLRequestInfo(); -const PPB_URLResponseInfo* PPBURLResponseInfo(); -const PPB_Var* PPBVar(); -const PPB_View* PPBView(); -const PPB_WheelInputEvent* PPBWheelInputEvent(); - -// -// Experimental (aka Dev) interfaces. -// Lookup returns NULL if the interface is not available. -// - -const PPB_Memory_Dev* PPBMemoryDev(); - -// -// Private interfaces. -// Lookup returns NULL if the interface is not available. -// - -const PPB_Testing_Private* PPBTestingPrivate(); - -#endif // PPAPI_NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_GET_BROWSER_INTERFACE_H_ diff --git a/ppapi/native_client/tests/ppapi_test_lib/internal_utils.cc b/ppapi/native_client/tests/ppapi_test_lib/internal_utils.cc deleted file mode 100644 index c49aee1..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/internal_utils.cc +++ /dev/null @@ -1,22 +0,0 @@ -// 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/native_client/tests/ppapi_test_lib/internal_utils.h" - -namespace { - -PP_Module global_pp_module = 0; -PP_Instance global_pp_instance = 0; -PPB_GetInterface global_ppb_get_interface = NULL; - -} // namespace - -void set_ppb_get_interface(PPB_GetInterface get_interface) { - global_ppb_get_interface = get_interface; -} -void set_pp_instance(PP_Instance instance) { global_pp_instance = instance; } -void set_pp_module(PP_Module module) { global_pp_module = module; } -PPB_GetInterface ppb_get_interface() { return global_ppb_get_interface; } -PP_Module pp_module() { return global_pp_module; } -PP_Instance pp_instance() { return global_pp_instance; } diff --git a/ppapi/native_client/tests/ppapi_test_lib/internal_utils.h b/ppapi/native_client/tests/ppapi_test_lib/internal_utils.h deleted file mode 100644 index b1997b6..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/internal_utils.h +++ /dev/null @@ -1,31 +0,0 @@ -// 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. -// -// This is an internal header. Do not include in your test implementation. - -#ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_INTERNAL_UTILS_H -#define NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_INTERNAL_UTILS_H - -#include "native_client/src/include/nacl_string.h" - -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb.h" - -void set_ppb_get_interface(PPB_GetInterface get_interface); -void set_pp_instance(PP_Instance instance); -void set_pp_module(PP_Module module); -PPB_GetInterface ppb_get_interface(); -PP_Module pp_module(); -PP_Instance pp_instance(); - -PP_Var GetScriptableObject(PP_Instance instance); - -bool HasScriptableTest(nacl::string test_name); -PP_Var RunScriptableTest(nacl::string test_name); - -void RunTest(nacl::string test_name); -#endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_INTERNAL_UTILS_H diff --git a/ppapi/native_client/tests/ppapi_test_lib/module_instance.cc b/ppapi/native_client/tests/ppapi_test_lib/module_instance.cc deleted file mode 100644 index 7073708..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/module_instance.cc +++ /dev/null @@ -1,175 +0,0 @@ -// 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. -// -// This implements the required interfaces for representing a plugin module -// instance in browser interactions and provides a way to register custom -// plugin interfaces. -// - -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -#include <map> - -#include "native_client/src/include/nacl_macros.h" -#include "native_client/src/shared/platform/nacl_check.h" - -#include "ppapi/c/dev/ppb_var_deprecated.h" -#include "ppapi/c/pp_errors.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/ppp.h" -#include "ppapi/c/ppp_instance.h" -#include "ppapi/c/ppp_messaging.h" - -#include "ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h" -#include "ppapi/native_client/tests/ppapi_test_lib/internal_utils.h" -#include "ppapi/native_client/tests/ppapi_test_lib/test_interface.h" - -/////////////////////////////////////////////////////////////////////////////// -// Plugin interface registration -/////////////////////////////////////////////////////////////////////////////// - -namespace { - -class PluginInterfaceTable { - public: - // Return singleton intsance. - static PluginInterfaceTable* Get() { - static PluginInterfaceTable table; - return &table; - } - - void AddInterface(const char* interface_name, const void* ppp_interface) { - interface_map_[nacl::string(interface_name)] = ppp_interface; - } - const void* GetInterface(const char* interface_name) { - // This will add a NULL element for missing interfaces. - return interface_map_[nacl::string(interface_name)]; - } - - private: - NACL_DISALLOW_COPY_AND_ASSIGN(PluginInterfaceTable); - - PluginInterfaceTable() {} - - typedef std::map<nacl::string, const void*> InterfaceMap; - InterfaceMap interface_map_; -}; - -} // namespace - -void RegisterPluginInterface(const char* interface_name, - const void* ppp_interface) { - PluginInterfaceTable::Get()->AddInterface(interface_name, ppp_interface); -} - - -/////////////////////////////////////////////////////////////////////////////// -// PPP_Instance implementation -/////////////////////////////////////////////////////////////////////////////// - -PP_Bool DidCreateDefault(PP_Instance instance, - uint32_t /*argc*/, - const char* /*argn*/[], - const char* /*argv*/[]) { - CHECK(ppb_get_interface() != NULL); - CHECK(PPBCore() != NULL); - CHECK(PPBGraphics2D() != NULL); - CHECK(PPBImageData() != NULL); - CHECK(PPBInstance() != NULL); - CHECK(PPBMessaging() != NULL); - CHECK(PPBURLLoader() != NULL); - CHECK(PPBURLRequestInfo() != NULL); - CHECK(PPBURLResponseInfo() != NULL); - CHECK(PPBVar() != NULL); - - set_pp_instance(instance); - SetupTests(); - - return PP_TRUE; -} - -void DidDestroyDefault(PP_Instance /*instance*/) { -} - -void DidChangeViewDefault(PP_Instance /*instance*/, PP_Resource /*view*/) { -} - -void DidChangeFocusDefault(PP_Instance /*instance*/, - PP_Bool /*has_focus*/) { -} - -PP_Bool HandleDocumentLoadDefault(PP_Instance instance, - PP_Resource url_loader) { - return PP_TRUE; -} - -namespace { - -const PPP_Instance ppp_instance_interface = { - DidCreateDefault, - DidDestroyDefault, - DidChangeViewDefault, - DidChangeFocusDefault, - HandleDocumentLoadDefault -}; - -/////////////////////////////////////////////////////////////////////////////// -// PPP_Messaging implementation -/////////////////////////////////////////////////////////////////////////////// - -void HandleMessage(PP_Instance instance, PP_Var message) { - if (message.type != PP_VARTYPE_STRING) - return; - uint32_t len = 0; - const char* test_name = PPBVar()->VarToUtf8(message, &len); - RunTest(test_name); -} - -const PPP_Messaging ppp_messaging_interface = { - HandleMessage -}; - -} // namespace - -/////////////////////////////////////////////////////////////////////////////// -// PPP implementation -/////////////////////////////////////////////////////////////////////////////// - -int32_t PPP_InitializeModule(PP_Module module, - PPB_GetInterface get_browser_interface) { - set_pp_module(module); - set_ppb_get_interface(get_browser_interface); - SetupPluginInterfaces(); - return PP_OK; -} - -void PPP_ShutdownModule() { -} - -const void* PPP_GetInterface(const char* interface_name) { - const void* ppp = PluginInterfaceTable::Get()->GetInterface(interface_name); - - // The PPP_Instance interface is required for every plugin, - // so supply one if the tester has not. - if (ppp == NULL && 0 == strncmp(PPP_INSTANCE_INTERFACE, interface_name, - strlen(PPP_INSTANCE_INTERFACE))) { - return &ppp_instance_interface; - } - // The PPP_Messaging interface is required for the test set-up, - // so we supply our own. - if (0 == strncmp(PPP_MESSAGING_INTERFACE, interface_name, - strlen(PPP_MESSAGING_INTERFACE))) { - CHECK(ppp == NULL); - return &ppp_messaging_interface; - } - // All other interfaces are to be optionally supplied by the tester, - // so we return whatever was added in SetupPluginInterfaces() (if anything). - return ppp; -} diff --git a/ppapi/native_client/tests/ppapi_test_lib/test_interface.cc b/ppapi/native_client/tests/ppapi_test_lib/test_interface.cc deleted file mode 100644 index ad5ef21..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/test_interface.cc +++ /dev/null @@ -1,239 +0,0 @@ -// 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/native_client/tests/ppapi_test_lib/test_interface.h" - -#include <string.h> -#include <map> -#include <new> - -#include "native_client/src/include/nacl_macros.h" -#include "native_client/src/shared/platform/nacl_check.h" - -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_rect.h" -#include "ppapi/c/pp_size.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb_core.h" -#include "ppapi/c/ppb_graphics_2d.h" -#include "ppapi/c/ppb_image_data.h" -#include "ppapi/c/ppb_instance.h" -#include "ppapi/c/ppb_messaging.h" -#include "ppapi/c/ppb_var.h" -#include "ppapi/c/private/ppb_testing_private.h" - -#include "ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h" -#include "ppapi/native_client/tests/ppapi_test_lib/internal_utils.h" - -void PostTestMessage(nacl::string test_name, nacl::string message) { - nacl::string test_message = test_name; - test_message += ":"; - test_message += message; - PP_Var post_var = PPBVar()->VarFromUtf8(test_message.c_str(), - test_message.size()); - PPBMessaging()->PostMessage(pp_instance(), post_var); - PPBVar()->Release(post_var); -} - -PP_Var PP_MakeString(const char* s) { - return PPBVar()->VarFromUtf8(s, strlen(s)); -} - -nacl::string StringifyVar(const PP_Var& var) { - uint32_t dummy_size; - switch (var.type) { - default: - return "<UNKNOWN>" + toString(var.type); - case PP_VARTYPE_NULL: - return "<NULL>"; - case PP_VARTYPE_BOOL: - return "<BOOL>" + toString(var.value.as_bool); - case PP_VARTYPE_INT32: - return "<INT32>" + toString(var.value.as_int); - case PP_VARTYPE_DOUBLE: - return "<DOUBLE>" + toString(var.value.as_double); - case PP_VARTYPE_STRING: - return "<STRING>" + nacl::string(PPBVar()->VarToUtf8(var, &dummy_size)); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// Test registration -//////////////////////////////////////////////////////////////////////////////// - -namespace { - -class TestTable { - public: - // Return singleton intsance. - static TestTable* Get() { - static TestTable table; - return &table; - } - - void AddTest(nacl::string test_name, TestFunction test_function) { - test_map_[test_name] = test_function; - } - void RunTest(nacl::string test_name); - - private: - NACL_DISALLOW_COPY_AND_ASSIGN(TestTable); - - TestTable() {} - - typedef std::map<nacl::string, TestFunction> TestMap; - TestMap test_map_; -}; - -void TestTable::RunTest(nacl::string test_name) { - TestMap::iterator it = test_map_.find(test_name); - if (it == test_map_.end()) { - PostTestMessage(test_name, "NOTFOUND"); - return; - } - CHECK(it->second != NULL); - TestFunction test_function = it->second; - return test_function(); -} - -} // namespace - -void RegisterTest(nacl::string test_name, TestFunction test_func) { - TestTable::Get()->AddTest(test_name, test_func); -} - -void RunTest(nacl::string test_name) { - TestTable::Get()->RunTest(test_name); -} - -//////////////////////////////////////////////////////////////////////////////// -// Testable callback support -//////////////////////////////////////////////////////////////////////////////// - -namespace { - -struct CallbackInfo { - nacl::string callback_name; - PP_CompletionCallback user_callback; -}; - -void ReportCallbackInvocationToJS(const char* callback_name) { - PP_Var callback_var = PPBVar()->VarFromUtf8(callback_name, - strlen(callback_name)); - // Report using postmessage for async tests. - PPBMessaging()->PostMessage(pp_instance(), callback_var); - PPBVar()->Release(callback_var); -} - -void CallbackWrapper(void* user_data, int32_t result) { - CallbackInfo* callback_info = reinterpret_cast<CallbackInfo*>(user_data); - PP_RunCompletionCallback(&callback_info->user_callback, result); - ReportCallbackInvocationToJS(callback_info->callback_name.c_str()); - delete callback_info; -} - -} // namespace - -PP_CompletionCallback MakeTestableCompletionCallback( - const char* callback_name, // Tested for by JS harness. - PP_CompletionCallback_Func func, - void* user_data) { - CHECK(callback_name != NULL && strlen(callback_name) > 0); - CHECK(func != NULL); - - CallbackInfo* callback_info = new(std::nothrow) CallbackInfo; - CHECK(callback_info != NULL); - callback_info->callback_name = callback_name; - callback_info->user_callback = - PP_MakeOptionalCompletionCallback(func, user_data); - - return PP_MakeOptionalCompletionCallback(CallbackWrapper, callback_info); -} - -PP_CompletionCallback MakeTestableCompletionCallback( - const char* callback_name, // Tested for by JS harness. - PP_CompletionCallback_Func func) { - return MakeTestableCompletionCallback(callback_name, func, NULL); -} - - -//////////////////////////////////////////////////////////////////////////////// -// PPAPI Helpers -//////////////////////////////////////////////////////////////////////////////// - -bool IsSizeInRange(PP_Size size, PP_Size min_size, PP_Size max_size) { - return (min_size.width <= size.width && size.width <= max_size.width && - min_size.height <= size.height && size.height <= max_size.height); -} - -bool IsSizeEqual(PP_Size size, PP_Size expected) { - return (size.width == expected.width && size.height == expected.height); -} - -bool IsRectEqual(PP_Rect position, PP_Rect expected) { - return (position.point.x == expected.point.x && - position.point.y == expected.point.y && - IsSizeEqual(position.size, expected.size)); -} - -uint32_t FormatColor(PP_ImageDataFormat format, ColorPremul color) { - if (format == PP_IMAGEDATAFORMAT_BGRA_PREMUL) - return (color.A << 24) | (color.R << 16) | (color.G << 8) | (color.B); - else if (format == PP_IMAGEDATAFORMAT_RGBA_PREMUL) - return (color.A << 24) | (color.B << 16) | (color.G << 8) | (color.R); - else - NACL_NOTREACHED(); -} - -PP_Resource CreateImageData(PP_Size size, ColorPremul pixel_color, void** bmp) { - PP_ImageDataFormat image_format = PPBImageData()->GetNativeImageDataFormat(); - uint32_t formatted_pixel_color = FormatColor(image_format, pixel_color); - PP_Resource image_data = PPBImageData()->Create( - pp_instance(), image_format, &size, PP_TRUE /*init_to_zero*/); - CHECK(image_data != kInvalidResource); - PP_ImageDataDesc image_desc; - CHECK(PPBImageData()->Describe(image_data, &image_desc) == PP_TRUE); - *bmp = NULL; - *bmp = PPBImageData()->Map(image_data); - CHECK(*bmp != NULL); - uint32_t* bmp_words = static_cast<uint32_t*>(*bmp); - int num_pixels = image_desc.stride / kBytesPerPixel * image_desc.size.height; - for (int i = 0; i < num_pixels; i++) - bmp_words[i] = formatted_pixel_color; - return image_data; -} - -bool IsImageRectOnScreen(PP_Resource graphics2d, - PP_Point origin, - PP_Size size, - ColorPremul color) { - PP_Size size2d; - PP_Bool dummy; - CHECK(PP_TRUE == PPBGraphics2D()->Describe(graphics2d, &size2d, &dummy)); - - void* bitmap = NULL; - PP_Resource image = CreateImageData(size2d, kOpaqueBlack, &bitmap); - - PP_ImageDataDesc image_desc; - CHECK(PP_TRUE == PPBImageData()->Describe(image, &image_desc)); - int32_t stride = image_desc.stride / kBytesPerPixel; // width + padding. - uint32_t expected_color = FormatColor(image_desc.format, color); - CHECK(origin.x >= 0 && origin.y >= 0 && - (origin.x + size.width) <= stride && - (origin.y + size.height) <= image_desc.size.height); - - CHECK(PP_TRUE == PPBTestingPrivate()->ReadImageData( - graphics2d, image, &kOrigin)); - bool found_error = false; - for (int y = origin.y; y < origin.y + size.height && !found_error; y++) { - for (int x = origin.x; x < origin.x + size.width && !found_error; x++) { - uint32_t pixel_color = static_cast<uint32_t*>(bitmap)[stride * y + x]; - found_error = (pixel_color != expected_color); - } - } - - PPBCore()->ReleaseResource(image); - return !found_error; -} diff --git a/ppapi/native_client/tests/ppapi_test_lib/test_interface.h b/ppapi/native_client/tests/ppapi_test_lib/test_interface.h deleted file mode 100644 index f00fd94..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/test_interface.h +++ /dev/null @@ -1,225 +0,0 @@ -// 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. -// -// Functions and constants for test registration and setup. -// -// NOTE: These must be implemented by the tester: -// - SetupTests() -// - SetupPluginInterfaces() -// -// Sample Usage: -// -// void MyCallback(void* user_data, int32_t result) { ... } -// -// void TestPPBFoo() { -// // sync test case -// PP_Resource my_resource = PPBFoo()->Create(kInvalidInstance); -// EXPECT(my_resource == kInvalidResource); -// -// // async test case -// PP_CompletionCallback testable_callback = -// MakeTestableCompletionCallback("MyCallback", MyCallback, NULL); -// int32_t pp_error = PPBFoo()->AsyncFunction(testable_callback); -// EXPECT(pp_error == PP_OK_COMPLETIONPENDING); -// -// TEST_PASSED; -// } -// -// void SetupTests() { -// RegisterTest("TestPPBFoo", TestPPBFoo); -// } -// -// const PPP_Bar ppp_bar_interface = { ... }; -// -// void SetupPluginInterface() { -// RegisterPluginInterface(PPP_BAR_INTERFACE, &ppp_bar_interface); -// } -// - -#ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H -#define NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H - -#include <stdint.h> -#include <stdio.h> -#include <limits> - -#include <sstream> - -#include "native_client/src/include/nacl_string.h" - -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_module.h" -#include "ppapi/c/pp_point.h" -#include "ppapi/c/pp_resource.h" -#include "ppapi/c/pp_var.h" -#include "ppapi/c/ppb_image_data.h" - -struct PP_Rect; -struct PP_Size; - -//////////////////////////////////////////////////////////////////////////////// -// These must be implemented by the tester -//////////////////////////////////////////////////////////////////////////////// - -// Use RegisterTest() to register each TestFunction. -void SetupTests(); -// Use RegisterPluginInterface() to register custom PPP_ interfaces other than -// PPP_Instance that is required and provided by default. -void SetupPluginInterfaces(); - -//////////////////////////////////////////////////////////////////////////////// -// Test helpers -//////////////////////////////////////////////////////////////////////////////// - -// Registers test_function, so it is callable from JS using -// plugin.postMessage(test_name); -typedef void (*TestFunction)(); -void RegisterTest(nacl::string test_name, TestFunction test_function); - -// Registers ppp_interface, so it is returned by PPP_GetInterface(). -void RegisterPluginInterface(const char* interface_name, - const void* ppp_interface); - -// Helper for creating user callbacks whose invocation will be reported to JS. -// Callback setting allows for synchronous completion to make it easier to -// test error conditions. -// WARNING: Do not reuse this callback if the operation that took it as an arg -// returned PP_OK_COMPLETIONPENDING. The wrapper allocates data on creation -// and then deallocates it when the callback is invoked. -PP_CompletionCallback MakeTestableCompletionCallback( - const char* callback_name, // will be postmessage'ed to JS - PP_CompletionCallback_Func func, - void* user_data); -PP_CompletionCallback MakeTestableCompletionCallback( - const char* callback_name, // will be postmessage'ed to JS - PP_CompletionCallback_Func func); - -// Uses PPB_Messaging interface to post "test_name:message". -void PostTestMessage(nacl::string test_name, nacl::string message); - -// Make a STRING var. -PP_Var PP_MakeString(const char* s); - -// Convert var into printable string (for debuggin) -nacl::string StringifyVar(const PP_Var& var); - -// Use to verify the result of a test and report failures. -#define EXPECT(expr) do { \ - if (!(expr)) { \ - char error[1024]; \ - snprintf(error, sizeof(error), \ - "ERROR at %s:%d: %s\n", __FILE__, __LINE__, #expr); \ - fprintf(stderr, "%s", error); \ - PostTestMessage(__FUNCTION__, error); \ - } \ -} while (0) - -// Check expected value of INT32 var. -#define EXPECT_VAR_INT(var, val) \ - EXPECT(var.type == PP_VARTYPE_INT32 && var.value.as_int == val) - -// Check expected value of STRING var (val is 'char*') -#define EXPECT_VAR_STRING(var, val) \ - do { \ - EXPECT(var.type == PP_VARTYPE_STRING); \ - uint32_t dummy_size; \ - const char* expected = PPBVar()->VarToUtf8(var, &dummy_size); \ - EXPECT(0 == strcmp(expected, val)); \ - } while (0) - -// Check expected value of BOOL var. -#define EXPECT_VAR_BOOL(var, val) \ - EXPECT(var.type == PP_VARTYPE_BOOL && var.value.as_bool == val) - -// Use to report success. -#define TEST_PASSED PostTestMessage(__FUNCTION__, "PASSED"); -// Or failure. -#define TEST_FAILED EXPECT(false) - -// Handy for use with LOG_TO_BROWSER() convert arbitrary objects into strings. -template<typename T> nacl::string toString(T v) { - std::stringstream s; - s << v; - return s.str(); -} - -// Log message for debugging or progress reporting purposes. -// If you use this with nacltest.js::expectMessageSequence -// it will not interfere with output used for correctness checking. -#define LOG_TO_BROWSER(message) PostTestMessage("@", message) - -// Cause a crash in a way that is guaranteed not to get optimized out by LLVM. -#define CRASH *(volatile int *) 0 = 0; - -// Use this constant for stress testing -// (i.e. creating and using a large number of resources). -const int kManyResources = 1000; - -//////////////////////////////////////////////////////////////////////////////// -// PPAPI Helpers -//////////////////////////////////////////////////////////////////////////////// - -const PP_Instance kInvalidInstance = 0; -const PP_Module kInvalidModule = 0; -const PP_Resource kInvalidResource = 0; - -// These should not exist. -// Chrome uses the bottom 2 bits to differentiate between different id types. -// 00 - module, 01 - instance, 10 - resource, 11 - var. -const PP_Instance kNotAnInstance = 0xFFFFF0; -const PP_Resource kNotAResource = 0xAAAAA0; - -const PP_Point kOrigin = PP_MakePoint(0, 0); - -// Interface pointers and ids corresponding to this plugin; -// set at initialization/creation. -PP_Instance pp_instance(); -PP_Module pp_module(); - -// If you are providing your own version of PPP_Instance::DidCreate -// call this function to ensure proper test set-up. -PP_Bool DidCreateDefault(PP_Instance instance, - uint32_t argc, const char* argn[], const char* argv[]); -// Other default implementations of the required PPP_Instance functions. -void DidDestroyDefault(PP_Instance instance); -void DidChangeViewDefault(PP_Instance instance, PP_Resource view); -void DidChangeFocusDefault(PP_Instance instance, PP_Bool has_focus); -PP_Bool HandleDocumentLoadDefault(PP_Instance instance, PP_Resource url_loader); - - -bool IsSizeInRange(PP_Size size, PP_Size min_size, PP_Size max_size); -bool IsSizeEqual(PP_Size size, PP_Size expected); -bool IsRectEqual(PP_Rect position, PP_Rect expected); - -// TODO(polina, nfullagar): allow specification of non-premultipled colors -// and provide alpha premultiplcation in FormatColor(). This will be required -// when future PPAPI pixel formats are extended to include non-premultipled -// or ignored alpha. - -struct ColorPremul { uint32_t A, R, G, B; }; // Use premultipled Alpha. -const ColorPremul kSheerRed = { 0x88, 0x88, 0x00, 0x00 }; -const ColorPremul kSheerBlue = { 0x88, 0x00, 0x00, 0x88 }; -const ColorPremul kSheerGray = { 0x77, 0x55, 0x55, 0x55 }; -const ColorPremul kOpaqueGreen = { 0xFF, 0x00, 0xFF, 0x00 }; -const ColorPremul kOpaqueBlack = { 0xFF, 0x00, 0x00, 0x00 }; -const ColorPremul kOpaqueWhite = { 0xFF, 0xFF, 0xFF, 0xFF }; -const ColorPremul kOpaqueYellow = { 0xFF, 0xFF, 0xFF, 0x00 }; -const int kBytesPerPixel = sizeof(uint32_t); // 4 bytes for BGRA or RGBA. - -// Assumes premultipled Alpha. -uint32_t FormatColor(PP_ImageDataFormat format, ColorPremul color); - -// Creates image data resource and bitmap for a rectangular region of |size| -// and |pixel_color|. -PP_Resource CreateImageData(PP_Size size, ColorPremul pixel_color, void** bmp); - - -// Checks if the image rect of |color| and |size| is on the screen at |origin|. -bool IsImageRectOnScreen(PP_Resource graphics2d, - PP_Point origin, - PP_Size size, - ColorPremul color); - -#endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_PPB_TEMPLATE_TEST_INTERFACE_H diff --git a/ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc b/ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc deleted file mode 100644 index f353d53..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/testable_callback.cc +++ /dev/null @@ -1,53 +0,0 @@ -// 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/c/pp_errors.h" -#include "ppapi/c/private/ppb_testing_private.h" -#include "ppapi/native_client/tests/ppapi_test_lib/get_browser_interface.h" -#include "ppapi/native_client/tests/ppapi_test_lib/testable_callback.h" - -TestableCallback::TestableCallback(PP_Instance instance, bool force_async) - : have_result_(false), - result_(PP_OK_COMPLETIONPENDING), - force_async_(force_async), - post_quit_task_(false), - run_count_(0), - instance_(instance) { -} - -int32_t TestableCallback::WaitForResult() { - if (!have_result_) { - result_ = PP_OK_COMPLETIONPENDING; // Reset - post_quit_task_ = true; - - // This waits until PPBTestingDev()->QuitMessageLoop() is called - // by the "Handler" which represents the actual callback code. - PPBTestingPrivate()->RunMessageLoop(instance_); - } - have_result_ = false; - return result_; -} - -PP_CompletionCallback TestableCallback::GetCallback() { - int32_t flags = force_async_ ? 0 : PP_COMPLETIONCALLBACK_FLAG_OPTIONAL; - PP_CompletionCallback cc = - PP_MakeCompletionCallback(&TestableCallback::Handler, this); - cc.flags = flags; - return cc; -} - -// static, so we can take it's address -// This is the actual callback, all it does is record -// the result and wake up whoever is block on -// "WaitForResult" -void TestableCallback::Handler(void* user_data, int32_t result) { - TestableCallback* callback = static_cast<TestableCallback*>(user_data); - callback->result_ = result; - callback->have_result_ = true; - ++callback->run_count_; - if (callback->post_quit_task_) { - callback->post_quit_task_ = false; - PPBTestingPrivate()->QuitMessageLoop(callback->instance_); - } -} diff --git a/ppapi/native_client/tests/ppapi_test_lib/testable_callback.h b/ppapi/native_client/tests/ppapi_test_lib/testable_callback.h deleted file mode 100644 index b474710f..0000000 --- a/ppapi/native_client/tests/ppapi_test_lib/testable_callback.h +++ /dev/null @@ -1,65 +0,0 @@ -// 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. - -#ifndef NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H -#define NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H - -#include "ppapi/c/pp_completion_callback.h" -#include "ppapi/c/pp_instance.h" -#include "ppapi/c/pp_stdint.h" - -// NOTE: if you use you TestableCallback you will need to enable -// testing interfaces in PPAPIBrowserTester(), e.g. -// "--enable-pepper-testing", c.f. -// tests/ppapi_browser/ppb_graphics2d/nacl.scons -// -// Example Usage: -// -// void TestProgressSimple() { -// TestableCallback callback(pp_instance(), true); -// ... -// rv = PPBURLLoader()->Open(loader, request, callback.GetCallback()); -// EXPECT(rv == PP_OK_COMPLETIONPENDING); - -// rv = callback.WaitForResult(); -// EXPECT(rv == PP_OK); -// ... -// } - -class TestableCallback { - public: - TestableCallback(PP_Instance instance, bool force_async); - - // Get the callback to be passed to an asynchronous PPAPI call - PP_CompletionCallback GetCallback(); - - // Waits for the callback to be called and returns the - // result. Returns immediately if the callback was previously called - // and the result wasn't returned (i.e. each result value received - // by the callback is returned by WaitForResult() once and only - // once). - int32_t WaitForResult(); - - bool HasRun() const { return run_count_ != 0; } - - // Make instance runnable again. - void Reset() { - run_count_ = 0; - have_result_ = false; - } - - int32_t Result() const { return result_; } - - private: - static void Handler(void* user_data, int32_t result); - - bool have_result_; // is a result available? - int32_t result_; // value of the result - bool force_async_; // force callback to be always called - bool post_quit_task_; // has cleanup beem performed - unsigned run_count_; // number of times the callback has been called - PP_Instance instance_; -}; - -#endif // NATIVE_CLIENT_TESTS_PPAPI_TEST_LIB_TESTABLE_CALLBACK_H |