| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #include "webkit/glue/plugins/ppapi_unittest.h" | |
| 6 | |
| 7 #include "ppapi/c/pp_var.h" | |
| 8 #include "ppapi/c/ppp_instance.h" | |
| 9 #include "webkit/glue/plugins/mock_plugin_delegate.h" | |
| 10 #include "webkit/glue/plugins/pepper_plugin_instance.h" | |
| 11 #include "webkit/glue/plugins/pepper_plugin_module.h" | |
| 12 | |
| 13 namespace pepper { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 PpapiUnittest* current_unittest = NULL; | |
| 18 | |
| 19 const void* MockGetInterface(const char* interface_name) { | |
| 20 return current_unittest->GetMockInterface(interface_name); | |
| 21 } | |
| 22 | |
| 23 int MockInitializeModule(PP_Module, PPB_GetInterface) { | |
| 24 return PP_OK; | |
| 25 } | |
| 26 | |
| 27 // PepperPluginDelegate ------------------------------------- | |
| 28 | |
| 29 // PPP_Instance implementation ------------------------------------------------ | |
| 30 | |
| 31 PP_Bool Instance_DidCreate(PP_Instance pp_instance, | |
| 32 uint32_t argc, | |
| 33 const char* argn[], | |
| 34 const char* argv[]) { | |
| 35 return PP_TRUE; | |
| 36 } | |
| 37 | |
| 38 void Instance_DidDestroy(PP_Instance instance) { | |
| 39 } | |
| 40 | |
| 41 void Instance_DidChangeView(PP_Instance pp_instance, | |
| 42 const PP_Rect* position, | |
| 43 const PP_Rect* clip) { | |
| 44 } | |
| 45 | |
| 46 void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) { | |
| 47 } | |
| 48 | |
| 49 PP_Bool Instance_HandleInputEvent(PP_Instance pp_instance, | |
| 50 const PP_InputEvent* event) { | |
| 51 return PP_FALSE; | |
| 52 } | |
| 53 | |
| 54 PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance, | |
| 55 PP_Resource pp_url_loader) { | |
| 56 return PP_FALSE; | |
| 57 } | |
| 58 | |
| 59 PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) { | |
| 60 return PP_MakeUndefined(); | |
| 61 } | |
| 62 | |
| 63 static PPP_Instance mock_instance_interface = { | |
| 64 &Instance_DidCreate, | |
| 65 &Instance_DidDestroy, | |
| 66 &Instance_DidChangeView, | |
| 67 &Instance_DidChangeFocus, | |
| 68 &Instance_HandleInputEvent, | |
| 69 &Instance_HandleDocumentLoad, | |
| 70 &Instance_GetInstanceObject | |
| 71 }; | |
| 72 | |
| 73 } // namespace | |
| 74 | |
| 75 // PpapiUnittest -------------------------------------------------------------- | |
| 76 | |
| 77 PpapiUnittest::PpapiUnittest() { | |
| 78 DCHECK(!current_unittest); | |
| 79 current_unittest = this; | |
| 80 } | |
| 81 | |
| 82 PpapiUnittest::~PpapiUnittest() { | |
| 83 DCHECK(current_unittest == this); | |
| 84 current_unittest = NULL; | |
| 85 } | |
| 86 | |
| 87 void PpapiUnittest::SetUp() { | |
| 88 delegate_.reset(new MockPluginDelegate); | |
| 89 | |
| 90 // Initialize the mock module. | |
| 91 module_ = new PluginModule; | |
| 92 PluginModule::EntryPoints entry_points; | |
| 93 entry_points.get_interface = &MockGetInterface; | |
| 94 entry_points.initialize_module = &MockInitializeModule; | |
| 95 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); | |
| 96 | |
| 97 // Initialize the mock instance. | |
| 98 instance_ = new PluginInstance(delegate_.get(), module(), | |
| 99 static_cast<const PPP_Instance*>( | |
| 100 GetMockInterface(PPP_INSTANCE_INTERFACE))); | |
| 101 } | |
| 102 | |
| 103 void PpapiUnittest::TearDown() { | |
| 104 } | |
| 105 | |
| 106 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { | |
| 107 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) | |
| 108 return &mock_instance_interface; | |
| 109 return NULL; | |
| 110 } | |
| 111 | |
| 112 } // namespace pepper | |
| 113 | |
| OLD | NEW |