[email protected] | ba7cc8c | 2012-06-19 19:03:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f7a29960 | 2013-08-15 16:23:33 | [diff] [blame] | 5 | #include "content/test/ppapi_unittest.h" |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 6 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 9 | #include "content/renderer/pepper/gfx_conversion.h" |
| 10 | #include "content/renderer/pepper/host_globals.h" |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 11 | #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 12 | #include "content/renderer/pepper/plugin_module.h" |
krasin | dd5416a | 2016-11-01 17:02:37 | [diff] [blame] | 13 | #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
[email protected] | a8462d1 | 2013-07-30 15:14:44 | [diff] [blame] | 14 | #include "ppapi/c/pp_errors.h" |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 15 | #include "ppapi/c/pp_var.h" |
| 16 | #include "ppapi/c/ppp_instance.h" |
[email protected] | 4e7a8c3 | 2013-04-23 04:09:59 | [diff] [blame] | 17 | #include "ppapi/shared_impl/ppapi_globals.h" |
[email protected] | 24cddd4 | 2012-07-13 04:28:40 | [diff] [blame] | 18 | #include "ppapi/shared_impl/ppapi_permissions.h" |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 19 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 20 | namespace content { |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 21 | |
| 22 | namespace { |
| 23 | |
| 24 | PpapiUnittest* current_unittest = NULL; |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 25 | |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 26 | const void* MockGetInterface(const char* interface_name) { |
| 27 | return current_unittest->GetMockInterface(interface_name); |
| 28 | } |
| 29 | |
| 30 | int MockInitializeModule(PP_Module, PPB_GetInterface) { |
| 31 | return PP_OK; |
| 32 | } |
| 33 | |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 34 | // PPP_Instance implementation ------------------------------------------------ |
| 35 | |
| 36 | PP_Bool Instance_DidCreate(PP_Instance pp_instance, |
| 37 | uint32_t argc, |
| 38 | const char* argn[], |
| 39 | const char* argv[]) { |
| 40 | return PP_TRUE; |
| 41 | } |
| 42 | |
| 43 | void Instance_DidDestroy(PP_Instance instance) { |
| 44 | } |
| 45 | |
[email protected] | e8f07ac | 2012-01-03 17:43:36 | [diff] [blame] | 46 | void Instance_DidChangeView(PP_Instance pp_instance, PP_Resource view) { |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) { |
| 50 | } |
| 51 | |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 52 | PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance, |
| 53 | PP_Resource pp_url_loader) { |
| 54 | return PP_FALSE; |
| 55 | } |
| 56 | |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 57 | static PPP_Instance mock_instance_interface = { |
| 58 | &Instance_DidCreate, |
| 59 | &Instance_DidDestroy, |
| 60 | &Instance_DidChangeView, |
| 61 | &Instance_DidChangeFocus, |
[email protected] | 95cfdc8 | 2011-05-24 18:37:04 | [diff] [blame] | 62 | &Instance_HandleDocumentLoad |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | } // namespace |
| 66 | |
| 67 | // PpapiUnittest -------------------------------------------------------------- |
| 68 | |
| 69 | PpapiUnittest::PpapiUnittest() { |
| 70 | DCHECK(!current_unittest); |
| 71 | current_unittest = this; |
| 72 | } |
| 73 | |
| 74 | PpapiUnittest::~PpapiUnittest() { |
| 75 | DCHECK(current_unittest == this); |
| 76 | current_unittest = NULL; |
| 77 | } |
| 78 | |
| 79 | void PpapiUnittest::SetUp() { |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 80 | // Initialize the mock module. |
krasin | dd5416a | 2016-11-01 17:02:37 | [diff] [blame] | 81 | ppapi::PpapiPermissions perms; |
[email protected] | 069c7b1 | 2014-08-20 19:23:20 | [diff] [blame] | 82 | module_ = new PluginModule("Mock plugin", "1.0", base::FilePath(), |
krasin | dd5416a | 2016-11-01 17:02:37 | [diff] [blame] | 83 | perms); |
[email protected] | 49323b3 | 2013-08-09 16:05:06 | [diff] [blame] | 84 | ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting(); |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 85 | PepperPluginInfo::EntryPoints entry_points; |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 86 | entry_points.get_interface = &MockGetInterface; |
| 87 | entry_points.initialize_module = &MockInitializeModule; |
| 88 | ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 89 | |
krasin | dd5416a | 2016-11-01 17:02:37 | [diff] [blame] | 90 | // Initialize renderer ppapi host. |
| 91 | CHECK(RendererPpapiHostImpl::CreateOnModuleForInProcess(module(), perms)); |
| 92 | CHECK(module_->renderer_ppapi_host()); |
| 93 | |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 94 | // Initialize the mock instance. |
[email protected] | ea2fb97 | 2013-08-07 05:44:26 | [diff] [blame] | 95 | instance_ = PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL()); |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void PpapiUnittest::TearDown() { |
[email protected] | 132c7cd5 | 2011-02-01 19:02:01 | [diff] [blame] | 99 | instance_ = NULL; |
| 100 | module_ = NULL; |
[email protected] | 11211ea | 2013-05-15 15:54:20 | [diff] [blame] | 101 | PluginModule::ResetHostGlobalsForTest(); |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { |
[email protected] | 13a8f49 | 2011-07-20 19:55:39 | [diff] [blame] | 105 | if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) |
[email protected] | 5469a77 | 2010-12-09 22:59:53 | [diff] [blame] | 106 | return &mock_instance_interface; |
| 107 | return NULL; |
| 108 | } |
| 109 | |
[email protected] | 64264ef | 2010-12-21 00:45:43 | [diff] [blame] | 110 | void PpapiUnittest::ShutdownModule() { |
| 111 | DCHECK(instance_->HasOneRef()); |
| 112 | instance_ = NULL; |
| 113 | DCHECK(module_->HasOneRef()); |
| 114 | module_ = NULL; |
| 115 | } |
| 116 | |
[email protected] | e1262d1c | 2013-02-19 20:33:49 | [diff] [blame] | 117 | void PpapiUnittest::SetViewSize(int width, int height) const { |
[email protected] | 75dae50 | 2012-10-17 13:22:34 | [diff] [blame] | 118 | instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); |
| 119 | instance_->view_data_.clip_rect = instance_->view_data_.rect; |
[email protected] | 75dae50 | 2012-10-17 13:22:34 | [diff] [blame] | 120 | } |
| 121 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 122 | } // namespace content |