Update broken references to image assets
[chromium-blink-merge.git] / content / test / ppapi_unittest.cc
blobab2955b596a31340e7c0b0941e6f564472c105fe
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/ppapi_unittest.h"
7 #include "base/message_loop/message_loop.h"
8 #include "content/renderer/pepper/gfx_conversion.h"
9 #include "content/renderer/pepper/host_globals.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
11 #include "content/renderer/pepper/plugin_module.h"
12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/c/ppp_instance.h"
15 #include "ppapi/shared_impl/ppapi_globals.h"
16 #include "ppapi/shared_impl/ppapi_permissions.h"
18 namespace content {
20 namespace {
22 PpapiUnittest* current_unittest = NULL;
24 const void* MockGetInterface(const char* interface_name) {
25 return current_unittest->GetMockInterface(interface_name);
28 int MockInitializeModule(PP_Module, PPB_GetInterface) {
29 return PP_OK;
32 // PPP_Instance implementation ------------------------------------------------
34 PP_Bool Instance_DidCreate(PP_Instance pp_instance,
35 uint32_t argc,
36 const char* argn[],
37 const char* argv[]) {
38 return PP_TRUE;
41 void Instance_DidDestroy(PP_Instance instance) {
44 void Instance_DidChangeView(PP_Instance pp_instance, PP_Resource view) {
47 void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) {
50 PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance,
51 PP_Resource pp_url_loader) {
52 return PP_FALSE;
55 static PPP_Instance mock_instance_interface = {
56 &Instance_DidCreate,
57 &Instance_DidDestroy,
58 &Instance_DidChangeView,
59 &Instance_DidChangeFocus,
60 &Instance_HandleDocumentLoad
63 } // namespace
65 // PpapiUnittest --------------------------------------------------------------
67 PpapiUnittest::PpapiUnittest() {
68 DCHECK(!current_unittest);
69 current_unittest = this;
72 PpapiUnittest::~PpapiUnittest() {
73 DCHECK(current_unittest == this);
74 current_unittest = NULL;
77 void PpapiUnittest::SetUp() {
78 message_loop_.reset(new base::MessageLoop());
80 // Initialize the mock module.
81 module_ = new PluginModule("Mock plugin", "1.0", base::FilePath(),
82 ppapi::PpapiPermissions());
83 ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting();
84 PepperPluginInfo::EntryPoints entry_points;
85 entry_points.get_interface = &MockGetInterface;
86 entry_points.initialize_module = &MockInitializeModule;
87 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points));
89 // Initialize the mock instance.
90 instance_ = PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL());
93 void PpapiUnittest::TearDown() {
94 instance_ = NULL;
95 module_ = NULL;
96 message_loop_.reset();
97 PluginModule::ResetHostGlobalsForTest();
100 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const {
101 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0)
102 return &mock_instance_interface;
103 return NULL;
106 void PpapiUnittest::ShutdownModule() {
107 DCHECK(instance_->HasOneRef());
108 instance_ = NULL;
109 DCHECK(module_->HasOneRef());
110 module_ = NULL;
113 void PpapiUnittest::SetViewSize(int width, int height) const {
114 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height));
115 instance_->view_data_.clip_rect = instance_->view_data_.rect;
118 } // namespace content