blob: 2d29083f455781f306f2dc1a061b977916c43cf7 [file] [log] [blame]
[email protected]ba7cc8c2012-06-19 19:03:391// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5469a772010-12-09 22:59:532// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f7a299602013-08-15 16:23:335#include "content/test/ppapi_unittest.h"
[email protected]5469a772010-12-09 22:59:536
avi66a07722015-12-25 23:38:127#include <stdint.h>
8
[email protected]20790a222013-07-25 02:23:059#include "content/renderer/pepper/gfx_conversion.h"
10#include "content/renderer/pepper/host_globals.h"
[email protected]adab2332013-07-25 18:04:3211#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]20790a222013-07-25 02:23:0512#include "content/renderer/pepper/plugin_module.h"
krasindd5416a2016-11-01 17:02:3713#include "content/renderer/pepper/renderer_ppapi_host_impl.h"
[email protected]a8462d12013-07-30 15:14:4414#include "ppapi/c/pp_errors.h"
[email protected]5469a772010-12-09 22:59:5315#include "ppapi/c/pp_var.h"
16#include "ppapi/c/ppp_instance.h"
[email protected]4e7a8c32013-04-23 04:09:5917#include "ppapi/shared_impl/ppapi_globals.h"
[email protected]24cddd42012-07-13 04:28:4018#include "ppapi/shared_impl/ppapi_permissions.h"
[email protected]5469a772010-12-09 22:59:5319
[email protected]adab2332013-07-25 18:04:3220namespace content {
[email protected]5469a772010-12-09 22:59:5321
22namespace {
23
24PpapiUnittest* current_unittest = NULL;
[email protected]0bd753682010-12-16 18:15:5225
[email protected]5469a772010-12-09 22:59:5326const void* MockGetInterface(const char* interface_name) {
27 return current_unittest->GetMockInterface(interface_name);
28}
29
30int MockInitializeModule(PP_Module, PPB_GetInterface) {
31 return PP_OK;
32}
33
[email protected]5469a772010-12-09 22:59:5334// PPP_Instance implementation ------------------------------------------------
35
36PP_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
43void Instance_DidDestroy(PP_Instance instance) {
44}
45
[email protected]e8f07ac2012-01-03 17:43:3646void Instance_DidChangeView(PP_Instance pp_instance, PP_Resource view) {
[email protected]5469a772010-12-09 22:59:5347}
48
49void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) {
50}
51
[email protected]5469a772010-12-09 22:59:5352PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance,
53 PP_Resource pp_url_loader) {
54 return PP_FALSE;
55}
56
[email protected]5469a772010-12-09 22:59:5357static PPP_Instance mock_instance_interface = {
58 &Instance_DidCreate,
59 &Instance_DidDestroy,
60 &Instance_DidChangeView,
61 &Instance_DidChangeFocus,
[email protected]95cfdc82011-05-24 18:37:0462 &Instance_HandleDocumentLoad
[email protected]5469a772010-12-09 22:59:5363};
64
65} // namespace
66
67// PpapiUnittest --------------------------------------------------------------
68
69PpapiUnittest::PpapiUnittest() {
70 DCHECK(!current_unittest);
71 current_unittest = this;
72}
73
74PpapiUnittest::~PpapiUnittest() {
75 DCHECK(current_unittest == this);
76 current_unittest = NULL;
77}
78
79void PpapiUnittest::SetUp() {
[email protected]5469a772010-12-09 22:59:5380 // Initialize the mock module.
krasindd5416a2016-11-01 17:02:3781 ppapi::PpapiPermissions perms;
[email protected]069c7b12014-08-20 19:23:2082 module_ = new PluginModule("Mock plugin", "1.0", base::FilePath(),
krasindd5416a2016-11-01 17:02:3783 perms);
[email protected]49323b32013-08-09 16:05:0684 ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting();
[email protected]adab2332013-07-25 18:04:3285 PepperPluginInfo::EntryPoints entry_points;
[email protected]5469a772010-12-09 22:59:5386 entry_points.get_interface = &MockGetInterface;
87 entry_points.initialize_module = &MockInitializeModule;
88 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points));
[email protected]0bd753682010-12-16 18:15:5289
krasindd5416a2016-11-01 17:02:3790 // Initialize renderer ppapi host.
91 CHECK(RendererPpapiHostImpl::CreateOnModuleForInProcess(module(), perms));
92 CHECK(module_->renderer_ppapi_host());
93
[email protected]5469a772010-12-09 22:59:5394 // Initialize the mock instance.
[email protected]ea2fb972013-08-07 05:44:2695 instance_ = PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL());
[email protected]5469a772010-12-09 22:59:5396}
97
98void PpapiUnittest::TearDown() {
[email protected]132c7cd52011-02-01 19:02:0199 instance_ = NULL;
100 module_ = NULL;
[email protected]11211ea2013-05-15 15:54:20101 PluginModule::ResetHostGlobalsForTest();
[email protected]5469a772010-12-09 22:59:53102}
103
104const void* PpapiUnittest::GetMockInterface(const char* interface_name) const {
[email protected]13a8f492011-07-20 19:55:39105 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0)
[email protected]5469a772010-12-09 22:59:53106 return &mock_instance_interface;
107 return NULL;
108}
109
[email protected]64264ef2010-12-21 00:45:43110void PpapiUnittest::ShutdownModule() {
111 DCHECK(instance_->HasOneRef());
112 instance_ = NULL;
113 DCHECK(module_->HasOneRef());
114 module_ = NULL;
115}
116
[email protected]e1262d1c2013-02-19 20:33:49117void PpapiUnittest::SetViewSize(int width, int height) const {
[email protected]75dae502012-10-17 13:22:34118 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height));
119 instance_->view_data_.clip_rect = instance_->view_data_.rect;
[email protected]75dae502012-10-17 13:22:34120}
121
[email protected]adab2332013-07-25 18:04:32122} // namespace content