Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: webkit/plugins/ppapi/ppapi_unittest.cc

Issue 20165002: Move webkit/plugins/ppapi to content/renderer/pepper. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: more more clang fun Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppapi_unittest.h ('k') | webkit/plugins/ppapi/ppapi_webplugin_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "webkit/plugins/ppapi/ppapi_unittest.h"
6
7 #include "base/message_loop/message_loop.h"
8 #include "ppapi/c/pp_var.h"
9 #include "ppapi/c/ppp_instance.h"
10 #include "ppapi/shared_impl/ppapi_globals.h"
11 #include "ppapi/shared_impl/ppapi_permissions.h"
12 #include "webkit/plugins/ppapi/gfx_conversion.h"
13 #include "webkit/plugins/ppapi/host_globals.h"
14 #include "webkit/plugins/ppapi/mock_plugin_delegate.h"
15 #include "webkit/plugins/ppapi/plugin_module.h"
16 #include "webkit/plugins/ppapi/ppapi_interface_factory.h"
17 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h"
18
19 namespace webkit {
20 namespace ppapi {
21
22 namespace {
23
24 PpapiUnittest* current_unittest = NULL;
25
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
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
46 void Instance_DidChangeView(PP_Instance pp_instance, PP_Resource view) {
47 }
48
49 void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) {
50 }
51
52 PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance,
53 PP_Resource pp_url_loader) {
54 return PP_FALSE;
55 }
56
57 static PPP_Instance mock_instance_interface = {
58 &Instance_DidCreate,
59 &Instance_DidDestroy,
60 &Instance_DidChangeView,
61 &Instance_DidChangeFocus,
62 &Instance_HandleDocumentLoad
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() {
80 message_loop_.reset(new base::MessageLoop());
81 delegate_.reset(NewPluginDelegate());
82
83 // Initialize the mock module.
84 module_ = new PluginModule("Mock plugin", base::FilePath(), this,
85 ::ppapi::PpapiPermissions());
86 ::ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting();
87 PluginModule::EntryPoints entry_points;
88 entry_points.get_interface = &MockGetInterface;
89 entry_points.initialize_module = &MockInitializeModule;
90 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points));
91
92 // Initialize the mock instance.
93 instance_ = PluginInstanceImpl::Create(
94 delegate_.get(), NULL, module(), NULL, GURL());
95 }
96
97 void PpapiUnittest::TearDown() {
98 instance_ = NULL;
99 module_ = NULL;
100 message_loop_.reset();
101 PluginModule::ResetHostGlobalsForTest();
102 }
103
104 MockPluginDelegate* PpapiUnittest::NewPluginDelegate() {
105 return new MockPluginDelegate;
106 }
107
108 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const {
109 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0)
110 return &mock_instance_interface;
111 return NULL;
112 }
113
114 void PpapiUnittest::ShutdownModule() {
115 DCHECK(instance_->HasOneRef());
116 instance_ = NULL;
117 DCHECK(module_->HasOneRef());
118 module_ = NULL;
119 }
120
121 void PpapiUnittest::SetViewSize(int width, int height) const {
122 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height));
123 instance_->view_data_.clip_rect = instance_->view_data_.rect;
124 }
125
126 void PpapiUnittest::PluginModuleDead(PluginModule* /* dead_module */) {
127 // Nothing needed (this is necessary to make the module compile).
128 }
129
130 // Tests whether custom PPAPI interface factories are called when PPAPI
131 // interfaces are requested.
132 class PpapiCustomInterfaceFactoryTest : public PpapiUnittest {
133 public:
134 PpapiCustomInterfaceFactoryTest() {}
135 virtual ~PpapiCustomInterfaceFactoryTest() {}
136
137 bool result() {
138 return result_;
139 }
140
141 void reset_result() {
142 result_ = false;
143 }
144
145 static const void* InterfaceFactory(const std::string& interface_name) {
146 result_ = true;
147 return NULL;
148 }
149
150 private:
151 static bool result_;
152 };
153
154 bool PpapiCustomInterfaceFactoryTest::result_ = false;
155
156 // This test validates whether custom PPAPI interface factories are invoked in
157 // response to PluginModule::GetPluginInterface calls.
158 TEST_F(PpapiCustomInterfaceFactoryTest, BasicFactoryTest) {
159 PpapiInterfaceFactoryManager::GetInstance()->RegisterFactory(
160 PpapiCustomInterfaceFactoryTest::InterfaceFactory);
161 (*PluginModule::GetLocalGetInterfaceFunc())("DummyInterface");
162 EXPECT_TRUE(result());
163
164 reset_result();
165 PpapiInterfaceFactoryManager::GetInstance()->UnregisterFactory(
166 PpapiCustomInterfaceFactoryTest::InterfaceFactory);
167
168 (*PluginModule::GetLocalGetInterfaceFunc())("DummyInterface");
169 EXPECT_FALSE(result());
170 }
171
172 } // namespace ppapi
173 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_unittest.h ('k') | webkit/plugins/ppapi/ppapi_webplugin_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698